Skip to content

Commit

Permalink
plexus compiler refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Mar 27, 2017
1 parent 91128be commit 384cc66
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import javax.tools.ToolProvider;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerMessage;
import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.compiler.manager.CompilerManager;

/**
Expand Down Expand Up @@ -59,7 +61,19 @@ private String find( final Iterable<String> options, String key, String def ) {
}
*/
private void executePlugin(final Iterable<String> options) throws Exception {

private void printCommand( final org.codehaus.plexus.compiler.Compiler javac, final CompilerConfiguration javacConf ) throws CompilerException {
System.out.println();
System.out.println();
System.out.println( "javac \\");
for( String c : javac.createCommandLine(javacConf) )
System.out.printf( "%s \\\n", c);
System.out.println();
System.out.println();
System.out.println();

}
private void executePlugin(final Iterable<String> options, final Iterable<? extends JavaFileObject> compilationUnits) throws Exception {

final CompilerConfiguration javacConf = new CompilerConfiguration();

Expand Down Expand Up @@ -99,22 +113,32 @@ else if( "-s".equals(option) ) {
javacConf.setGeneratedSourcesDirectory( new java.io.File(ii.next()));
}

javacConf.setSourceVersion("1.6");
javacConf.setTargetVersion("1.6");
javacConf.setSourceVersion("1.7");
javacConf.setTargetVersion("1.7");
javacConf.setWorkingDirectory(project.getBasedir());

final java.util.Set<java.io.File> sourceFiles =
new java.util.HashSet<java.io.File>();
for( JavaFileObject src : compilationUnits ) {
sourceFiles.add( new java.io.File( src.toUri() ) );
}

javacConf.setSourceFiles(sourceFiles);
}

javacConf.setFork(false);

javacConf.setDebug(true);
javacConf.setFork(true);
javacConf.setVerbose(true);
//javacConf.setExecutable("javac");
final org.codehaus.plexus.compiler.Compiler javac = plexusCompiler.getCompiler("javac");

String[] cli = javac.createCommandLine(javacConf);

for( String c : cli ) {
System.out.printf( "CLI: [%s]\n", c);
}
javac.performCompile( javacConf );
//printCommand(javac, javacConf);

final CompilerResult result = javac.performCompile( javacConf );

for( CompilerMessage m : result.getCompilerMessages())
System.out.printf( "message [%s]\n", m.getMessage() );

System.out.printf( "Compiler success [%b]\n", result.isSuccess());
}

@Override
Expand Down Expand Up @@ -158,7 +182,7 @@ public Boolean call() {
}

try {
executePlugin(options);
executePlugin(options, compilationUnits);
return true;
} catch (final Exception ex) {
diagnosticListener.report( new Diagnostic<JavaFileObject>() {
Expand Down
19 changes: 12 additions & 7 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<proc>none</proc>
</configuration>
</plugin>

Expand All @@ -62,7 +63,7 @@ PROCESSOR PLUGIN

</dependencies>
<executions>

<!--
<execution>
<id>process-test</id>
Expand All @@ -73,14 +74,13 @@ PROCESSOR PLUGIN
<configuration>
<outputDirectory>${basedir}/src/site</outputDirectory>
<additionalSourceDirectories>
<additionalSourceDirectories>
<item>${user.home}/src</item>
<item>./src/main/java</item>
</additionalSourceDirectories>
<failOnError>false</failOnError>
<processors>
<!-- list of processors to use -->
<processor>org.bsc.maven.plugin.processor.test.TESTWikiProcessor</processor>
<processor>org.bsc.jaxrs.JAXRSWikiProcessor</processor>
</processors>
Expand All @@ -91,6 +91,7 @@ PROCESSOR PLUGIN
</execution>
-->
<execution>

<id>process</id>
Expand All @@ -102,14 +103,18 @@ PROCESSOR PLUGIN
<outputDirectory>${basedir}/src/site</outputDirectory>

<additionalSourceDirectories>
<item>${basedir}/src/main/java</item>
<item>${basedir}/src/main/java</item>
<!--
<item>${user.home}/src</item>
-->
</additionalSourceDirectories>

<failOnError>false</failOnError>
<processors>
<!-- list of processors to use -->
<processor>org.bsc.maven.plugin.processor.test.TESTWikiProcessor</processor>
<!--
<processor>org.bsc.jaxrs.JAXRSWikiProcessor</processor>
-->
</processors>

<options>
Expand Down Expand Up @@ -140,7 +145,7 @@ PROCESSOR PLUGIN
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
Expand Down

0 comments on commit 384cc66

Please sign in to comment.