}
CompilerAPI.setupHeadless(configuration);
String[] sourceMimeTypes = WebTierAPI.getSourcePathMimeTypes();
CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
// create a SourcePath...
SourcePath sourcePath = new SourcePath(sourceMimeTypes, compilerConfig.allowSourcePathOverlap());
sourcePath.addPathElements( compilerConfig.getSourcePath() );
List<VirtualFile>[] array = CompilerAPI.getVirtualFileList(configuration.getIncludeSources(),
configuration.getStylesheets().values(),
new HashSet<String>(Arrays.asList(sourceMimeTypes)),
sourcePath.getPaths());
// note: if Configuration is ever shared with other parts of the system, then this part will need
// to change, since we're setting a compc-specific setting below
compilerConfig.setMetadataExport(true);
// create a FileSpec... can reuse based on appPath, debug settings, etc...
FileSpec fileSpec = new FileSpec(array[0], WebTierAPI.getFileSpecMimeTypes(), false);
// create a SourceList...
SourceList sourceList = new SourceList(array[1], compilerConfig.getSourcePath(), null,
WebTierAPI.getSourceListMimeTypes(), false);
ResourceContainer resources = new ResourceContainer();
ResourceBundlePath bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), null);
Map<String, Source> classes = new HashMap<String, Source>();
NameMappings mappings = CompilerAPI.getNameMappings(configuration);
List<SwcComponent> nsComponents = SwcAPI.setupNamespaceComponents(configuration, mappings, sourcePath,
sourceList, classes);
SwcAPI.setupClasses(configuration, sourcePath, sourceList, classes);
if (benchmark != null)
{
benchmark.benchmark(l10n.getLocalizedTextString(new Mxmlc.InitialSetup()));
}
// load SWCs
CompilerSwcContext swcContext = new CompilerSwcContext();
SwcCache cache = new SwcCache();
// lazy read should only be set by mxmlc/compc
cache.setLazyRead(true);
// for compc the theme and include-libraries values have been purposely not passed in below.
// This is done because the theme attribute doesn't make sense and the include-libraries value
// actually causes issues when the default value is used with external libraries.
// FIXME: why don't we just get rid of these values from the configurator for compc? That's a problem
// for include-libraries at least, since this value appears in flex-config.xml
swcContext.load( compilerConfig.getLibraryPath(),
compilerConfig.getExternalLibraryPath(),
null,
compilerConfig.getIncludeLibraries(),
mappings,
I18nUtils.getTranslationFormat(compilerConfig),
cache );
configuration.addExterns( swcContext.getExterns() );
configuration.addIncludes( swcContext.getIncludes() );
configuration.addFiles( swcContext.getIncludeFiles() );
// Allow -include-classes to override the -external-library-path.
configuration.removeExterns( configuration.getClasses() );
// 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 (configuration.getIncludeInheritanceDependenciesOnly())
configuration.addIncludes(configuration.getClasses());
// The output file.
File swcFile = new File(configuration.getOutput());
// Checksums to figure out if incremental compile can be done.
String incrementalFileName = null;
SwcChecksums swcChecksums = null;
// Should we attempt to build incrementally using the incremental file?
boolean recompile = true;
// If incremental compilation is enabled and the output file exists,
// use the persisted store to figure out if a compile/link is necessary.
// link without a compile is not supported without changes to the
// persistantStore since units for Sources of type isSwcScriptOwner()
// aren't stored/restored properly. units contains null entries for those
// type of Source. To force a rebuild, with -incremental specified, delete the
// incremental file.
if (configuration.getCompilerConfiguration().getIncremental())
{
swcChecksums = new SwcChecksums(swcContext, cfgbuf, configuration);
// If incremental compilation is enabled, read the cached
// compilation units... Do not include the checksum in the file name so that
// cache files don't pile up as the configuration changes. There needs
// to be a 1-to-1 mapping between the swc file and the cache file.
incrementalFileName = configuration.getOutput() + ".cache";
// If the output file doesn't exist don't bother loading the
// cache since a recompile is needed.
if (swcFile.exists())
{
RandomAccessFile incrementalFile = null;
try
{
incrementalFile = new RandomAccessFile(incrementalFileName, "r");
// For loadCompilationUnits, loadedChecksums[1] must match
// the cached value else IOException is thrown.
int[] loadedChecksums = swcChecksums.copy();
CompilerAPI.loadCompilationUnits(configuration, fileSpec, sourceList,
sourcePath, resources, bundlePath,
null /* sources */, null /* units */,
loadedChecksums,
swcChecksums.getSwcDefSignatureChecksums(),
swcChecksums.getSwcFileChecksums(),
swcChecksums.getArchiveFileChecksums(),
incrementalFile, incrementalFileName,
null /* font manager */);
if (!swcChecksums.isRecompilationNeeded(loadedChecksums) && !swcChecksums.isRelinkNeeded(loadedChecksums))
{
recompile = false;
}
}
catch (FileNotFoundException ex)
{
ThreadLocalToolkit.logDebug(ex.getLocalizedMessage());
}
catch (IOException ex)
{
ThreadLocalToolkit.logInfo(ex.getLocalizedMessage());
}
finally
{
if (incrementalFile != null)
{
try
{
incrementalFile.close();
}
catch (IOException ex)
{
}
// If the load failed, or recompilation is needed, reset
// all the variables to their original state.
if (recompile)
{
fileSpec = new FileSpec(array[0], WebTierAPI.getFileSpecMimeTypes(), false);
sourceList = new SourceList(array[1], compilerConfig.getSourcePath(), null, WebTierAPI.getSourceListMimeTypes(), false);
sourcePath = new SourcePath(sourceMimeTypes, compilerConfig.allowSourcePathOverlap());
sourcePath.addPathElements(compilerConfig.getSourcePath());
resources = new ResourceContainer();
bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), null);
classes = new HashMap<String, Source>();