use of org.codehaus.plexus.compiler.CompilerError in project maven-plugins by apache.
the class CompilerStub method compile.
public List<CompilerError> compile(CompilerConfiguration compilerConfiguration) throws CompilerException {
File outputDir = new File(compilerConfiguration.getOutputLocation());
try {
outputDir.mkdirs();
File outputFile = new File(outputDir, "compiled.class");
if (!outputFile.exists() && !outputFile.createNewFile()) {
throw new CompilerException("could not create output file: " + outputFile.getAbsolutePath());
}
} catch (IOException e) {
throw new CompilerException("An exception occurred while creating output file", e);
}
return Collections.singletonList(new CompilerError("message 1", shouldFail));
}
use of org.codehaus.plexus.compiler.CompilerError in project jangaroo-tools by CoreMedia.
the class AbstractCompilerMojo method execute.
/**
* Runs the compile mojo
*
* @throws MojoExecutionException
* @throws MojoFailureException
*/
public void execute() throws MojoExecutionException, MojoFailureException {
final Log log = getLog();
if (getCompileSourceRoots().isEmpty()) {
log.info("No sources to compile");
return;
}
// ----------------------------------------------------------------------
// Create the compiler configuration
// ----------------------------------------------------------------------
JoocConfiguration configuration = new JoocConfiguration();
configuration.setEnableAssertions(enableAssertions);
configuration.setAllowDuplicateLocalVariables(allowDuplicateLocalVariables);
configuration.setVerbose(verbose);
configuration.setExcludeClassByDefault(excludeClassByDefault);
if (StringUtils.isNotEmpty(debuglevel)) {
try {
configuration.setDebugMode(DebugMode.valueOf(debuglevel.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The specified debug level: '" + debuglevel + "' is unsupported. " + "Legal values are 'none', 'lines', and 'source'.");
}
}
if (StringUtils.isNotEmpty(autoSemicolon)) {
try {
configuration.setSemicolonInsertionMode(SemicolonInsertionMode.valueOf(autoSemicolon.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The specified semicolon insertion mode: '" + autoSemicolon + "' is unsupported. " + "Legal values are 'error', 'warn', and 'quirks'.");
}
}
if (StringUtils.isNotEmpty(publicApiViolations)) {
try {
configuration.setPublicApiViolationsMode(PublicApiViolationsMode.valueOf(publicApiViolations.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("The specified public API violations mode: '" + publicApiViolations + "' is unsupported. " + "Legal values are 'error', 'warn', and 'allow'.");
}
}
HashSet<File> sources = new HashSet<File>();
log.debug("starting source inclusion scanner");
sources.addAll(computeStaleSources(staleMillis));
if (sources.isEmpty()) {
log.info("Nothing to compile - all classes are up to date");
return;
}
configuration.setSourceFiles(new ArrayList<File>(sources));
try {
configuration.setSourcePath(getCompileSourceRoots());
} catch (IOException e) {
throw new MojoFailureException("could not canonicalize source paths: " + getCompileSourceRoots(), e);
}
configuration.setClassPath(getActionScriptClassPath());
configuration.setOutputDirectory(getClassesOutputDirectory());
configuration.setApiOutputDirectory(getApiOutputDirectory());
if (log.isDebugEnabled()) {
log.debug("Source path: " + configuration.getSourcePath().toString().replace(',', '\n'));
log.debug("Class path: " + configuration.getClassPath().toString().replace(',', '\n'));
log.debug("Output directory: " + configuration.getOutputDirectory());
if (configuration.getApiOutputDirectory() != null) {
log.debug("API output directory: " + configuration.getApiOutputDirectory());
}
}
int result = compile(configuration);
boolean compilationError = (result != CompilationResult.RESULT_CODE_OK);
if (!compilationError) {
// for now, always set debug mode to "false" for concatenated file:
configuration.setDebugMode(null);
configuration.setOutputDirectory(getTempClassesOutputDirectory());
configuration.setApiOutputDirectory(null);
result = compile(configuration);
if (result == CompilationResult.RESULT_CODE_OK) {
buildOutputFile(getTempClassesOutputDirectory(), getModuleClassesJsFile());
}
compilationError = (result != CompilationResult.RESULT_CODE_OK);
}
List<CompilerError> messages = Collections.emptyList();
if (compilationError && failOnError) {
log.info("-------------------------------------------------------------");
log.error("COMPILATION ERROR : ");
log.info("-------------------------------------------------------------");
if (messages != null) {
for (CompilerError message : messages) {
log.error(message.toString());
}
log.info(messages.size() + ((messages.size() > 1) ? " errors " : "error"));
log.info("-------------------------------------------------------------");
}
throw new MojoFailureException("Compilation failed");
} else {
for (CompilerError message : messages) {
log.warn(message.toString());
}
}
}
use of org.codehaus.plexus.compiler.CompilerError in project maven-plugins by apache.
the class AbstractCompilerMojo method convertToCompilerResult.
protected CompilerResult convertToCompilerResult(List<CompilerError> compilerErrors) {
if (compilerErrors == null) {
return new CompilerResult();
}
List<CompilerMessage> messages = new ArrayList<CompilerMessage>(compilerErrors.size());
boolean success = true;
for (CompilerError compilerError : compilerErrors) {
messages.add(new CompilerMessage(compilerError.getFile(), compilerError.getKind(), compilerError.getStartLine(), compilerError.getStartColumn(), compilerError.getEndLine(), compilerError.getEndColumn(), compilerError.getMessage()));
if (compilerError.isError()) {
success = false;
}
}
return new CompilerResult(success, messages);
}
Aggregations