javax.tools Compiler Test Fixture

CommonJava top-level parent POM.

License

License

GroupId

GroupId

org.commonjava.test
ArtifactId

ArtifactId

compiler-test-fixture
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

javax.tools Compiler Test Fixture
CommonJava top-level parent POM.
Source Code Management

Source Code Management

https://github.com/jdcasey/compiler-test-fixture

Download compiler-test-fixture

How to add to project

<!-- https://jarcasting.com/artifacts/org.commonjava.test/compiler-test-fixture/ -->
<dependency>
    <groupId>org.commonjava.test</groupId>
    <artifactId>compiler-test-fixture</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.commonjava.test/compiler-test-fixture/
implementation 'org.commonjava.test:compiler-test-fixture:0.2'
// https://jarcasting.com/artifacts/org.commonjava.test/compiler-test-fixture/
implementation ("org.commonjava.test:compiler-test-fixture:0.2")
'org.commonjava.test:compiler-test-fixture:jar:0.2'
<dependency org="org.commonjava.test" name="compiler-test-fixture" rev="0.2">
  <artifact name="compiler-test-fixture" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.commonjava.test', module='compiler-test-fixture', version='0.2')
)
libraryDependencies += "org.commonjava.test" % "compiler-test-fixture" % "0.2"
[org.commonjava.test/compiler-test-fixture "0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
junit : junit jar
commons-io : commons-io jar
commons-lang : commons-lang jar
ch.qos.logback : logback-core jar
ch.qos.logback : logback-classic Optional jar

Project Modules

There are no modules declared in this project.

compiler-test-fixture

JUnit test fixture (@Rule) an accompanying classes for compiling sources during a test using javax.tools.JavaCompiler

Usage Example

@Test
public void annotationProcessorGeneratedSourcesGetCompiled()
    throws Exception
{
    final CompilerResult result =
        compiler.compileSourceDirWithThisClass( "anno-proc-gen-src",
                                                "org.test.Hello",
                                                new CompilerFixtureConfig().withAnnotationProcessor( TestProcessor.class ) );
    
    final List<File> classfiles = compiler.scan( result.getClasses(), "**/*.class" );
    System.out.printf( "%d classes generated in: %s\n%s\n", classfiles.size(), result.getClasses(),
                       join( classfiles, "\n" ) );
    
    final List<File> gensrcfiles = compiler.scan( result.getGeneratedSources(), "**/*.java" );
    System.out.printf( "%d generated source files in: %s\n%s\n", gensrcfiles.size(), result.getGeneratedSources(),
                       join( gensrcfiles, "\n" ) );
    
    final Class<?> cls = result.getClassLoader()
                               .loadClass( "org.test.HelloDoc" );
    
    final Method method = cls.getMethod( "main", new Class[] { String[].class } );
    
    System.out.println( method );
    method.invoke( null, new Object[] { new String[] {} } );
}

Versions

Version
0.2
0.1