use of org.eclipse.n4js.generator.GeneratorException in project n4js by eclipse.
the class N4HeadlessCompiler method generateProject.
/*
* ===============================================================================================================
*
* GENERATING CODE
*
* ===============================================================================================================
*/
/**
* Generates code for all resources in the given project.
*
* @param markedProject
* project to compile.
* @param resSet
* outer resource set
* @param compileFilter
* if not empty limit to this.
* @param rec
* state reporter
* @throws N4JSCompileException
* in case of compile-problems. Possibly wrapping other N4SJCompileExceptions.
*/
private void generateProject(MarkedProject markedProject, ResourceSet resSet, Predicate<URI> compileFilter, N4ProgressStateRecorder rec) throws N4JSCompileException {
rec.markStartCompiling(markedProject);
final String projectId = markedProject.project.getProjectId();
if (logger.isVerbose()) {
logger.info("Generating " + projectId);
}
Lazy<N4JSCompoundCompileException> collectedErrors = Lazy.create(() -> {
return new N4JSCompoundCompileException("Errors during generation of project " + projectId);
});
ConfiguredGenerator generator = generatorFactory.getConfiguredGenerator(markedProject.project);
// then compile each file.
for (Resource resource : markedProject.resources) {
if (compileFilter.test(resource.getURI())) {
boolean isTest = markedProject.isTest(resource);
boolean compile = (isTest && isProcessTestCode()) || (!isTest && isCompileSourceCode());
if (compile) {
try {
rec.markStartCompile(resource);
if (logger.isVerbose()) {
logger.info(" Generating resource " + resource.getURI());
}
// Ask composite generator to try to generate the current resource
generator.generate(resource);
rec.markEndCompile(resource);
} catch (GeneratorException e) {
rec.markBrokenCompile(e);
if (isKeepOnCompiling()) {
collectedErrors.get().add(new N4JSCompileErrorException(e.getMessage(), projectId, e));
if (logger.isVerbose()) {
logger.info(e.getMessage());
}
} else {
// fail fast
throw e;
}
}
} else {
rec.markSkippedCompile(resource);
}
}
}
rec.markEndCompiling(markedProject);
if (collectedErrors.isInitialized()) {
throw collectedErrors.get();
}
}
Aggregations