diff --git a/processor/pom.xml b/processor/pom.xml
index 9cbad0986..9071a0d83 100644
--- a/processor/pom.xml
+++ b/processor/pom.xml
@@ -189,18 +189,6 @@
-
- copy
- generate-test-resources
-
- copy-dependencies
-
-
- ${project.build.directory}/test-dependencies
-
- true
-
-
diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java
index c8b027688..ff972348a 100644
--- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java
+++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java
@@ -102,12 +102,7 @@ class CompilingStatement extends Statement {
}
};
- private static final List LIBRARIES = Arrays.asList(
- "mapstruct.jar",
- "guava.jar",
- "javax.inject.jar",
- "joda-time.jar"
- );
+ private static final List COMPILER_CLASSPATH = buildCompilerClasspath();
private Statement next;
private final FrameworkMethod method;
@@ -115,7 +110,6 @@ class CompilingStatement extends Statement {
private JavaCompiler compiler;
private String classOutputDir;
private String sourceOutputDir;
- private List classPath;
private CompilationRequest compilationRequest;
public CompilingStatement(FrameworkMethod method) {
@@ -149,18 +143,48 @@ class CompilingStatement extends Statement {
classOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/classes";
sourceOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/generated-sources/mapping";
- String testDependenciesDir = basePath + "/target/test-dependencies/";
-
- classPath = new ArrayList();
- for ( String library : LIBRARIES ) {
- classPath.add( new File( testDependenciesDir, library ) );
- }
-
createOutputDirs();
( (ModifiableURLClassLoader) Thread.currentThread().getContextClassLoader() ).addOutputDir( classOutputDir );
}
+ private static List buildCompilerClasspath() {
+ String[] bootClasspath =
+ System.getProperty( "java.class.path" ).split( System.getProperty( "path.separator" ) );
+ String fs = System.getProperty( "file.separator" );
+ String testClasses = "target" + fs + "test-classes";
+
+ String[] whitelist =
+ new String[] {
+ "processor" + fs + "target", // the processor itself
+ "core" + fs + "target", // MapStruct annotations in multi-module reactor build or IDE
+ "org" + fs + "mapstruct" + fs + "mapstruct" + fs, // MapStruct annotations in single module build
+ "freemarker",
+ "guava",
+ "javax.inject",
+ "spring-beans",
+ "spring-context",
+ "joda-time" };
+
+ List classpath = new ArrayList();
+ for ( String path : bootClasspath ) {
+ if ( !path.contains( testClasses ) && isWhitelisted( path, whitelist ) ) {
+ classpath.add( new File( path ) );
+ }
+ }
+
+ return classpath;
+ }
+
+ private static boolean isWhitelisted(String path, String[] whitelist) {
+ for ( String whitelisted : whitelist ) {
+ if ( path.contains( whitelisted ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected void generateMapperImplementation() throws Exception {
CompilationResultHolder compilationResult = compile();
@@ -380,7 +404,7 @@ class CompilingStatement extends Statement {
fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.sourceClasses ) );
try {
- fileManager.setLocation( StandardLocation.CLASS_PATH, classPath );
+ fileManager.setLocation( StandardLocation.CLASS_PATH, COMPILER_CLASSPATH );
fileManager.setLocation( StandardLocation.CLASS_OUTPUT, Arrays.asList( new File( classOutputDir ) ) );
fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Arrays.asList( new File( sourceOutputDir ) ) );
}
diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java
index e4e67a1fd..7e19f6aca 100644
--- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java
+++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java
@@ -56,9 +56,6 @@ public class ModifiableURLClassLoader extends URLClassLoader {
}
}
- /**
- * @param basePath
- */
public void addURL(String basePath) {
try {
addURL( new URL( basePath ) );