in flex/tools/idea-fcsh-fix/flex4_0/src/com/intellij/flex/Fcsh4WithFix0.java [1087:1276]
private static void compc(String[] args, int id)
{
LocalizationManager l10n = ThreadLocalToolkit.getLocalizationManager();
Benchmark benchmark = null;
SwcTarget s = new SwcTarget();
s.id = id;
try
{
// setup the path resolver
CompilerAPI.usePathResolver();
// process configuration
ConfigurationBuffer cfgbuf = new ConfigurationBuffer(CompcConfiguration.class, CompcConfiguration.getAliases());
cfgbuf.setDefaultVar("include-classes");
DefaultsConfigurator.loadCompcDefaults( cfgbuf );
CompcConfiguration configuration = (CompcConfiguration) Mxmlc.processConfiguration(
ThreadLocalToolkit.getLocalizationManager(), "compc", args, cfgbuf, CompcConfiguration.class, "include-classes");
s.configuration = configuration;
CompilerAPI.setupHeadless(configuration);
if (configuration.benchmark())
{
benchmark = CompilerAPI.runBenchmark();
benchmark.startTime(Benchmark.PRECOMPILE);
}
else
{
CompilerAPI.disableBenchmark();
}
targets.put("" + id, s);
s.args = args;
String[] sourceMimeTypes = WebTierAPI.getSourcePathMimeTypes();
CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
// create a SourcePath...
s.sourcePath = new SourcePath(sourceMimeTypes, compilerConfig.allowSourcePathOverlap());
s.sourcePath.addPathElements( compilerConfig.getSourcePath() );
List<VirtualFile>[] array
= CompilerAPI.getVirtualFileList(configuration.getIncludeSources(), configuration.getStylesheets().values(),
new HashSet<String>(Arrays.asList(sourceMimeTypes)), s.sourcePath.getPaths());
NameMappings mappings = CompilerAPI.getNameMappings(configuration);
// 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);
// get standard bundle of compilers, transcoders
Transcoder[] transcoders = WebTierAPI.getTranscoders( configuration );
SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);
// construct the SWC file name...
s.outputName = FileUtil.getCanonicalPath(FileUtil.openFile(configuration.getOutput()));
// create a FileSpec...
s.fileSpec = new FileSpec(array[0], WebTierAPI.getFileSpecMimeTypes(), false);
// create a SourceList...
s.sourceList = new SourceList(array[1], compilerConfig.getSourcePath(), null,
WebTierAPI.getSourceListMimeTypes(), false);
// create a ResourceContainer...
s.resources = new ResourceContainer();
// create a ResourceBundlePath...
s.bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), null);
if (benchmark != null)
{
benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
}
// load SWCs
s.swcCache = new SwcCache();
CompilerSwcContext swcContext = new CompilerSwcContext(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,
null,
mappings,
I18nUtils.getTranslationFormat(compilerConfig),
s.swcCache );
configuration.addExterns( swcContext.getExterns() );
s.checksum = cfgbuf.checksum_ts() + swcContext.checksum();
final SymbolTable symbolTable = new SymbolTable(configuration);
s.perCompileData = symbolTable.perCompileData;
Map licenseMap = configuration.getLicensesConfiguration().getLicenseMap();
s.classes = new HashMap<String, Source>();
s.nsComponents = SwcAPI.setupNamespaceComponents(configuration, mappings, s.sourcePath, s.sourceList, s.classes);
SwcAPI.setupClasses(configuration, s.sourcePath, s.sourceList, s.classes);
Map<String, VirtualFile> rbFiles = new HashMap<String, VirtualFile>();
if (benchmark != null)
{
benchmark.stopTime(Benchmark.PRECOMPILE, false);
}
List<CompilationUnit> units = CompilerAPI.compile(s.fileSpec, s.sourceList, s.classes.values(), s.sourcePath,
s.resources, s.bundlePath, swcContext, symbolTable,
mappings, configuration, compilers,
new CompcPreLink(rbFiles, configuration.getIncludeResourceBundles()),
licenseMap, new ArrayList<Source>());
if (benchmark != null)
{
benchmark.startTime(Benchmark.POSTCOMPILE);
}
s.units = units;
s.rbFiles = rbFiles;
s.sourcePath.clearCache();
s.bundlePath.clearCache();
s.resources.refresh();
// export SWC
SwcAPI.exportSwc( configuration, units, s.nsComponents, s.swcCache, s.rbFiles );
if (s.outputName != null && ThreadLocalToolkit.errorCount() == 0)
{
File file = FileUtil.openFile(s.outputName);
if (file != null && file.exists() && file.isFile())
{
s.outputName = FileUtil.getCanonicalPath(file);
ThreadLocalToolkit.log(new OutputMessage(s.outputName, Long.toString(file.length())));
}
}
}
catch (ConfigurationException ex)
{
Compc.displayStartMessage();
Mxmlc.processConfigurationException(ex, "compc");
}
catch (LicenseException ex)
{
ThreadLocalToolkit.logError(ex.getMessage());
}
catch (CompilerException ex)
{
assert ThreadLocalToolkit.errorCount() > 0;
}
catch (LinkerException ex)
{
assert ThreadLocalToolkit.errorCount() > 0;
}
catch (SwcException ex)
{
assert ThreadLocalToolkit.errorCount() > 0;
}
catch (Exception t) // IOException, Throwable
{
ThreadLocalToolkit.logError(t.getMessage());
if (Trace.error)
{
t.printStackTrace();
}
}
finally
{
if (benchmark != null)
{
if ((ThreadLocalToolkit.errorCount() == 0) &&
benchmark.hasStarted(Benchmark.POSTCOMPILE))
{
benchmark.stopTime(Benchmark.POSTCOMPILE, false);
}
benchmark.totalTime();
benchmark.peakMemoryUsage(true);
}
CompilerAPI.removePathResolver();
}
}