#202 allow remote debugging an intetegration test using a command like "mvn test -Dtest=SimpleTest#oracle_java_6 -DprocessorIntegrationTest.debug=true"

This commit is contained in:
Andreas Gudian 2014-10-05 20:54:36 +02:00
parent 15aa13012e
commit e9a74d1fc0
3 changed files with 84 additions and 18 deletions

View File

@ -47,6 +47,16 @@ import static org.apache.maven.shared.utils.io.FileUtils.deleteDirectory;
*/ */
public class ProcessorSuiteRunner extends ParentRunner<ProcessorTestCase> { public class ProcessorSuiteRunner extends ParentRunner<ProcessorTestCase> {
/**
* System property for specifying the location of the toolchains.xml file
*/
public static final String SYS_PROP_TOOLCHAINS_FILE = "processorIntegrationTest.toolchainsFile";
/**
* System property to enable remote debugging of the processor execution in the integration test
*/
public static final String SYS_PROP_DEBUG = "processorIntegrationTest.debug";
public static final class ProcessorTestCase { public static final class ProcessorTestCase {
private final String baseDir; private final String baseDir;
private final ProcessorType processor; private final ProcessorType processor;
@ -147,7 +157,22 @@ public class ProcessorSuiteRunner extends ParentRunner<ProcessorTestCase> {
File destination = extractTest( child, description ); File destination = extractTest( child, description );
PrintStream originalOut = System.out; PrintStream originalOut = System.out;
Verifier verifier = new Verifier( destination.getCanonicalPath() ); final Verifier verifier;
if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) {
if ( child.processor.getToolchain() == null ) {
// when not using toolchains for a test, then the compiler is executed within the Maven JVM. So make
// sure we fork a new JVM for that, and let that new JVM use the command 'mvnDebug' instead of 'mvn'
verifier = new Verifier( destination.getCanonicalPath(), null, true, true );
verifier.setDebugJvm( true );
}
else {
verifier = new Verifier( destination.getCanonicalPath() );
verifier.addCliOption( "-Pdebug-forked-javac" );
}
}
else {
verifier = new Verifier( destination.getCanonicalPath() );
}
List<String> goals = new ArrayList<String>( 3 ); List<String> goals = new ArrayList<String>( 3 );
@ -166,6 +191,11 @@ public class ProcessorSuiteRunner extends ParentRunner<ProcessorTestCase> {
verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct" ); verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct" );
} }
if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) {
originalOut.print( "Processor Integration Test: " );
originalOut.println( "Listening for transport dt_socket at address: 8000 (in some seconds)" );
}
goals.add( "test" ); goals.add( "test" );
originalOut.println( "executing " + child.processor.name().toLowerCase() ); originalOut.println( "executing " + child.processor.name().toLowerCase() );
@ -222,7 +252,7 @@ public class ProcessorSuiteRunner extends ParentRunner<ProcessorTestCase> {
} }
private static File getSpecifiedToolchainsFile() { private static File getSpecifiedToolchainsFile() {
String specifiedToolchainsFile = System.getProperty( "processorIntegrationTest.toolchainsFile" ); String specifiedToolchainsFile = System.getProperty( SYS_PROP_TOOLCHAINS_FILE );
if ( null != specifiedToolchainsFile ) { if ( null != specifiedToolchainsFile ) {
try { try {
File canonical = new File( specifiedToolchainsFile ).getCanonicalFile(); File canonical = new File( specifiedToolchainsFile ).getCanonicalFile();

View File

@ -115,6 +115,34 @@
</plugins> </plugins>
</build> </build>
</profile> </profile>
<profile>
<id>debug-forked-javac</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-J-Xdebug</arg>
<arg>-J-Xnoagent</arg>
<arg>-J-Djava.compiler=NONE</arg>
<arg>-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles> </profiles>
<dependencies> <dependencies>

View File

@ -43,6 +43,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<com.jolira.hickory.version>1.0.0</com.jolira.hickory.version> <com.jolira.hickory.version>1.0.0</com.jolira.hickory.version>
<org.apache.maven.plugins.enforcer.version>1.2</org.apache.maven.plugins.enforcer.version> <org.apache.maven.plugins.enforcer.version>1.2</org.apache.maven.plugins.enforcer.version>
<org.apache.maven.plugins.surefire.version>2.17</org.apache.maven.plugins.surefire.version>
<org.springframework.version>4.0.3.RELEASE</org.springframework.version> <org.springframework.version>4.0.3.RELEASE</org.springframework.version>
<forkCount>1</forkCount> <forkCount>1</forkCount>
@ -337,10 +338,17 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version> <version>${org.apache.maven.plugins.surefire.version}</version>
<configuration> <configuration>
<forkCount>${forkCount}</forkCount> <forkCount>${forkCount}</forkCount>
</configuration> </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${org.apache.maven.plugins.surefire.version}</version>
</dependency>
</dependencies>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.mycila.maven-license-plugin</groupId> <groupId>com.mycila.maven-license-plugin</groupId>