in modules/compiler/src/java/flex2/tools/oem/Library.java [1381:1718]
protected int compile(boolean incremental)
{
try
{
messages.clear();
// if there is no configuration, use the default... but don't populate this.configuration.
OEMConfiguration tempOEMConfiguration;
if (oemConfiguration == null)
{
tempOEMConfiguration = (OEMConfiguration) getDefaultConfiguration(true);
}
else
{
tempOEMConfiguration = OEMUtil.getLibraryConfiguration(constructCommandLine(oemConfiguration),
oemConfiguration.keepLinkReport(),
oemConfiguration.keepSizeReport(),
OEMUtil.getLogger(logger, messages),
resolver, mimeMappings);
}
// if c is null, which indicates problems, this method will return.
if (tempOEMConfiguration == null)
{
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return FAIL;
}
else if (oemConfiguration != null && oemConfiguration.keepConfigurationReport())
{
configurationReport = OEMUtil.formatConfigurationBuffer(tempOEMConfiguration.cfgbuf);
}
if (oemConfiguration != null)
{
oemConfiguration.cfgbuf = tempOEMConfiguration.cfgbuf;
}
if (tempOEMConfiguration.configuration.benchmark())
{
benchmark = CompilerAPI.runBenchmark();
benchmark.setTimeFilter(tempOEMConfiguration.configuration.getBenchmarkTimeFilter());
benchmark.startTime(Benchmark.PRECOMPILE);
}
else
{
CompilerAPI.disableBenchmark();
}
// add archive files to the link checksum
for (Map.Entry<String, VirtualFile>entry : files.entrySet())
{
tempOEMConfiguration.cfgbuf.calculateLinkChecksum(entry.getKey(), entry.getValue().getLastModified());
}
// initialize some ThreadLocal variables...
cc.run();
OEMUtil.init(OEMUtil.getLogger(logger, messages), mimeMappings, meter, resolver, cc);
// if there is any problem getting the licenses, this method will return.
Map licenseMap = OEMUtil.getLicenseMap(tempOEMConfiguration.configuration);
// if there are no SWC inputs, output an error and return -1
VirtualFile[] includeLibs = (tempOEMConfiguration.configuration == null) ? null : tempOEMConfiguration.configuration.getCompilerConfiguration().getIncludeLibraries();
if (sources.size() == 0 && classes.size() == 0 && namespaces.size() == 0 &&
resourceBundles.size() == 0 && files.size() == 0 && stylesheets.size() == 0 &&
(includeLibs == null || includeLibs.length == 0))
{
ThreadLocalToolkit.log(new ConfigurationException.NoSwcInputs( null, null, -1 ));
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return FAIL;
}
// if nothing has been built yet, let's rebuild.
if (data == null || !incremental)
{
String compilationType = (cacheName != null) ? "inactive" : "full";
if (benchmark != null)
{
benchmark.benchmark2("Starting " + compilationType + " compile for " + getOutput(), true);
}
int returnValue = recompile(false, licenseMap, tempOEMConfiguration);
if (benchmark != null)
{
benchmark.benchmark2("Ending " + compilationType + " compile for " + getOutput(), true);
}
clean(returnValue != OK, false, false);
return returnValue;
}
CompilerAPI.setupHeadless(tempOEMConfiguration.configuration);
NameMappings mappings = CompilerAPI.getNameMappings(tempOEMConfiguration.configuration), copy = mappings.copy();
// Clear out ASC's userDefined, so definitions from a
// previous compilation don't spill over into this one.
data.perCompileData.userDefined.clear();
data.sourcePath.clearCache();
data.bundlePath.clearCache();
data.resources.refresh();
CompilerConfiguration compilerConfig = tempOEMConfiguration.configuration.getCompilerConfiguration();
compilerConfig.setMetadataExport(true);
if (output != null || directory != null)
{
OEMUtil.setGeneratedDirectory(compilerConfig, output != null ? output : directory);
}
Transcoder[] transcoders = WebTierAPI.getTranscoders(tempOEMConfiguration.configuration);
SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);
CompilerSwcContext swcContext = new CompilerSwcContext(true);
try
{
swcContext.load( compilerConfig.getLibraryPath(),
compilerConfig.getExternalLibraryPath(),
null,
compilerConfig.getIncludeLibraries(),
mappings,
I18nUtils.getTranslationFormat(compilerConfig),
data.swcCache );
}
catch (SwcException ex)
{
if (Trace.error)
{
ex.printStackTrace();
}
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return FAIL;
}
// save the generated swcCache if the class has a libraryCache.
if (libraryCache != null)
{
libraryCache.setSwcCache(data.swcCache);
}
// If checksum is different, rebuild.
if (OEMUtil.isRecompilationNeeded(data, swcContext, tempOEMConfiguration))
{
if (benchmark != null)
{
benchmark.benchmark2("Starting full compile for " + getOutput(), true);
}
clean(true /* cleanData */,
false /* cleanCache */,
false /* cleanOutput */,
true /* cleanConfig */,
false /* cleanMessages */,
false /* cleanThreadLocals */);
int returnValue = recompile(true, licenseMap, tempOEMConfiguration);
if (benchmark != null)
{
benchmark.benchmark2("Ending full compile for " + getOutput(), true);
}
clean(returnValue != OK, false, false);
return returnValue;
}
// If --include-sources is different, rebuild.
Set<VirtualFile> fileSet = null;
if ((fileSet = processSources(compilerConfig)) == null)
{
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return FAIL;
}
// If --include-stylesheets is different, rebuild.
fileSet.addAll(processStylesheets());
boolean isFileSpecDifferent = isDifferent(data.fileSet, fileSet);
if (isFileSpecDifferent)
{
if (benchmark != null)
{
benchmark.benchmark2("Starting full compile for " + getOutput(), true);
}
clean(true /* cleanData */,
false /* cleanCache */,
false /* cleanOutput */,
true /* cleanConfig */,
false /* cleanMessages */,
false /* cleanThreadLocals */);
int returnValue = recompile(true, licenseMap, tempOEMConfiguration);
if (benchmark != null)
{
benchmark.benchmark2("Ending full compile for " + getOutput(), true);
}
clean(returnValue != OK, false, false);
return returnValue;
}
if (benchmark != null)
{
// We aren't really starting the compile here, but it's
// the earliest that we know that it's going to be an
// active compilation.
benchmark.benchmark2("Starting active compile for " + getOutput(), true);
}
data.includes = new HashSet<String>(swcContext.getIncludes());
data.excludes = new HashSet<String>(swcContext.getExterns());
tempOEMConfiguration.configuration.addExterns( swcContext.getExterns() );
tempOEMConfiguration.configuration.addIncludes( swcContext.getIncludes() );
data.swcArchiveFiles = new HashMap<String, VirtualFile>(swcContext.getIncludeFiles());
// The ToolsConfiguration expects class names in QName format.
Set<String> qNameClasses = new HashSet<String>();
for (String className : classes)
{
qNameClasses.add(NameFormatter.toColon(className));
}
// Allow -include-classes to override the -external-library-path.
tempOEMConfiguration.configuration.removeExterns(qNameClasses);
// If we want only inheritance dependencies of -include-classes then
// add the classes to the includes list. When
// -include-inheritance-dependencies-only is turned on the dependency
// walker will ignore all the classes except for the includes.
if (tempOEMConfiguration.configuration.getIncludeInheritanceDependenciesOnly())
{
tempOEMConfiguration.configuration.addIncludes(qNameClasses);
}
int count = CompilerAPI.validateCompilationUnits(data.fileSpec, data.sourceList, data.sourcePath,
data.bundlePath, data.resources, swcContext,
data.classes, data.perCompileData,
tempOEMConfiguration.configuration);
Map<String, Source> classes = new TreeMap<String, Source>();
Set<SwcComponent> nsComponents = null;
if ((nsComponents = processInputs(swcContext, copy, classes)) == null)
{
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return FAIL;
}
// If the other --include-* are different, build incrementally.
boolean isDifferent = isDifferent(data.classes.keySet(), classes.keySet());
if (count > 0 || isDifferent || isResourceBundleListDifferent() ||
data.swcChecksum != swcContext.checksum())
{
// create a symbol table
SymbolTable symbolTable = new SymbolTable(tempOEMConfiguration.configuration, data.perCompileData);
data.configuration = tempOEMConfiguration.configuration;
data.nsComponents = nsComponents;
data.classes = classes;
data.fileSet = fileSet;
data.linkChecksum = tempOEMConfiguration.cfgbuf.link_checksum_ts();
data.swcChecksum = swcContext.checksum();
// compile
data.sources = new ArrayList<Source>();
data.units = compile(compilers, swcContext, symbolTable, mappings, licenseMap, classes, data.sources);
boolean forcedToStop = CompilerAPI.forcedToStop();
if (data.units == null || forcedToStop)
{
clean(true, false, false);
return FAIL;
}
else
{
if (benchmark != null)
{
benchmark.benchmark2("Ending active compile for " + getOutput(), true);
}
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
return OK;
}
}
else
{
if (benchmark != null)
{
benchmark.stopTime(Benchmark.PRECOMPILE, false);
benchmark.startTime(Benchmark.POSTCOMPILE);
}
int retVal = SKIP;
if (data != null)
{
CompilerAPI.displayWarnings(data.units);
if (data.linkChecksum != tempOEMConfiguration.cfgbuf.link_checksum_ts())
{
retVal = LINK;
}
}
else
{
retVal = LINK;
}
data.linkChecksum = tempOEMConfiguration.cfgbuf.link_checksum_ts();
data.swcChecksum = swcContext.checksum();
if (CompilerAPI.forcedToStop()) retVal = FAIL;
if (benchmark != null)
{
benchmark.benchmark2("Ending active compile for " + getOutput(), true);
}
if (retVal == LINK)
{
clean(false /* cleanData */,
false /* cleanCache */,
false /* cleanOutput */,
false /* cleanConfig */,
false /* cleanMessages */,
false /* cleanThreadLocals */);
}
else
{
clean(false /* cleanData */, false /* cleanCache */, false /* cleanOutput */);
}
return retVal;
}
}
finally
{
// clean thread locals
OEMUtil.clean();
}
}