use of spoon.compiler.builder.AdvancedOptions in project spoon by INRIA.
the class JDTBasedSpoonCompiler method buildUnits.
/**
* Build the CompilationUnit found in the source folder
* @param jdtBuilder The instance of JDTBuilder to prepare the right JDT arguments
* @param sourcesFolder The source folder
* @param classpath The complete classpath
* @param debugMessagePrefix Useful to help debugging
* @return All compilationUnitDeclaration from JDT found in source folder
*/
protected CompilationUnitDeclaration[] buildUnits(JDTBuilder jdtBuilder, SpoonFolder sourcesFolder, String[] classpath, String debugMessagePrefix) {
List<SpoonFile> sourceFiles = Collections.unmodifiableList(sourcesFolder.getAllJavaFiles());
if (sourceFiles.isEmpty()) {
return EMPTY_RESULT;
}
JDTBatchCompiler batchCompiler = createBatchCompiler(new FileCompilerConfig(sourceFiles));
String[] args;
if (jdtBuilder == null) {
args = //
new JDTBuilderImpl().classpathOptions(//
new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(classpath)).complianceOptions(//
new ComplianceOptions().compliance(javaCompliance)).advancedOptions(//
new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()).sources(// no sources, handled by the JDTBatchCompiler
new SourceOptions().sources(sourceFiles)).build();
} else {
args = jdtBuilder.build();
}
getFactory().getEnvironment().debugMessage(debugMessagePrefix + "build args: " + Arrays.toString(args));
batchCompiler.configure(args);
CompilationUnitDeclaration[] units = batchCompiler.getUnits();
return units;
}
use of spoon.compiler.builder.AdvancedOptions in project spoon by INRIA.
the class JDTBasedSpoonCompiler method compile.
@Override
public boolean compile(InputType... types) {
factory.getEnvironment().debugMessage("compiling sources: " + factory.CompilationUnit().getMap().keySet());
long t = System.currentTimeMillis();
javaCompliance = factory.getEnvironment().getComplianceLevel();
JDTBatchCompiler batchCompiler = createBatchCompiler(types);
final String[] args = //
new JDTBuilderImpl().classpathOptions(//
new ClasspathOptions().encoding(this.getEnvironment().getEncoding().displayName()).classpath(getSourceClasspath()).binaries(getBinaryOutputDirectory())).complianceOptions(//
new ComplianceOptions().compliance(javaCompliance)).annotationProcessingOptions(//
new AnnotationProcessingOptions().compileProcessors()).advancedOptions(//
new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()).sources(// no sources, handled by the JDTBatchCompiler
new SourceOptions().sources(sources.getAllJavaFiles())).build();
getFactory().getEnvironment().debugMessage("compile args: " + Arrays.toString(args));
System.setProperty("jdt.compiler.useSingleThread", "true");
batchCompiler.compile(args);
reportProblems(factory.getEnvironment());
factory.getEnvironment().debugMessage("compiled in " + (System.currentTimeMillis() - t) + " ms");
return probs.size() == 0;
}
use of spoon.compiler.builder.AdvancedOptions in project spoon by INRIA.
the class JDTBuilderTest method testJdtBuilder.
@Test
public void testJdtBuilder() throws Exception {
final String[] builder = //
new JDTBuilderImpl().classpathOptions(//
new ClasspathOptions().classpath(TEST_CLASSPATH).bootclasspath(TEST_CLASSPATH).binaries(".").encoding("UTF-8")).complianceOptions(//
new ComplianceOptions().compliance(8)).annotationProcessingOptions(//
new AnnotationProcessingOptions().compileProcessors()).advancedOptions(//
new AdvancedOptions().continueExecution().enableJavadoc().preserveUnusedVars()).sources(//
new SourceOptions().sources(".")).build();
assertEquals("-cp", builder[0]);
assertEquals(TEST_CLASSPATH, builder[1]);
assertEquals("-bootclasspath", builder[2]);
assertEquals(TEST_CLASSPATH, builder[3]);
assertEquals("-d", builder[4]);
assertEquals(new File(".").getAbsolutePath(), builder[5]);
assertEquals("-encoding", builder[6]);
assertEquals("UTF-8", builder[7]);
assertEquals("-1.8", builder[8]);
assertEquals("-proc:none", builder[9]);
assertEquals("-noExit", builder[10]);
assertEquals("-enableJavadoc", builder[11]);
assertEquals("-preserveAllLocals", builder[12]);
assertEquals(".", builder[13]);
}
Aggregations