Hi,

I'd like to work on GRADLE-3085 [1] and would like guidance on how to
proceed:

* how to configure the javax.tool.JavaCompiler to use in the DSL
* how to implement it
* how to test it

Looking at the current code, I think Gradle could expose some kind of
JavaCompilerProvider on the JavaCompile task or its CompileOptions:

    interface JavaCompilerProvider {
      javax.tool.JavaCompiler getJavaCompiler();
    }

whose default implementation would be the current
Jdk6JavaCompiler::findCompiler.

For my use-case which is about using Google ErrorProne [2], the
implementation would:

1. build a ClassLoader with the error_prone JARs (read from a project
configuration added by my gradle-errorprone-plugin [3]) that delegates to
the current thread class loader
2. create an ErrorProneJavaCompiler [4] in that ClassLoader and return it

In step 2, I could even call the DefaultJavaCompilerProvider (or whichever
JavaCompilerProvider was configured for the JavaCompile task before the
ErrorProneJavaCompilerProvider is plugged in) to inherit its handling of
the java.home system property, and pass the created JavaCompiler to the
ErrorProneJavaCompiler constructor.

Another approach would be to configure the JavaCompiler class and its
classpath in the DSL, and let the Jdk6JavaCompiler instantiate it (create a
ClassLoader from the configured classpath, create an instance of the
configured class in that ClassLoader; this logic would be hidden in the
Jdk6JavaCompiler).

What do you think?

Would that work with the "fork" option? (I think so, but I'm relatively new
to Gradle's code)
Is there any other option that needs to be tested (and possibly dealt with)
?

About testing, how would you do it? Duplicate
InProcessJavaCompilerIntegrationTest and DaemonJavaCompilerIntegrationTest
with an overridden compilerConfiguration that configures a custom
JavaCompiler? (how would you test that it's correctly used then? make it
emit some diagnostic message?) or rather add a test method in
JavaCompilerIntegrationSpec (but then it would be called by
CommandLineJavaCompilerIntegrationTest whereas its behavior would be
overwritten there, so it would have to be disabled if the test checks that
the custom JavaCompiler has been used).

Thanks in advance!


[1] http://issues.gradle.org/browse/GRADLE-3085
[2] https://code.google.com/p/error-prone/
[3] https://github.com/tbroyer/gradle-errorprone-plugin, BTW feedback on
the DSL would be very welcome!
[4]
https://code.google.com/p/error-prone/source/browse/core/src/main/java/com/google/errorprone/ErrorProneJavaCompiler.java

-- 
Thomas Broyer
/tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>

Reply via email to