this.resourceLoader = resourceLoader;
}
private void compileModule(TreeLogger logger) throws UnableToCompleteException {
long beforeCompileMs = System.currentTimeMillis();
LibraryWriter libraryWriter = compilerContext.getLibraryWriter();
try {
if (compilerOptions.isValidateOnly()) {
boolean valid = Precompile.validate(logger, compilerContext);
if (!valid) {
// The real cause has been logged.
throw new UnableToCompleteException();
}
}
Precompilation precompilation = Precompile.precompile(logger, compilerContext);
if (precompilation == null) {
// The real cause has been logged.
throw new UnableToCompleteException();
}
// TODO(stalcup): move to precompile() after params are refactored
if (!compilerOptions.shouldSaveSource()) {
precompilation.removeSourceArtifacts(logger);
}
Event compilePermutationsEvent =
SpeedTracerLogger.start(CompilerEventType.COMPILE_PERMUTATIONS);
permutations = new Permutation[] {precompilation.getPermutations()[0]};
List<PersistenceBackedObject<PermutationResult>> permutationResultFiles =
new ArrayList<PersistenceBackedObject<PermutationResult>>();
permutationResultFiles.add(libraryWriter.getPermutationResultHandle());
CompilePerms.compile(logger, compilerContext, precompilation, permutations,
compilerOptions.getLocalWorkers(), permutationResultFiles);
compilePermutationsEvent.end();
generatedArtifacts = precompilation.getGeneratedArtifacts();
libraryWriter.addGeneratedArtifacts(generatedArtifacts);
libraryWriter.setCompilationErrorsIndex(compilerContext.getLocalCompilationErrorsIndex());
} finally {
// Even if a compile problem occurs, close the library cleanly so that it can be examined.
libraryWriter.write();
}
long durationMs = System.currentTimeMillis() - beforeCompileMs;
TreeLogger detailBranch = logger.branch(TreeLogger.INFO,
String.format("%.3fs -- Translating Java to Javascript", durationMs / 1000d));