mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
592 allow to use all test-scope dependencies in the on-the-fly compilation classpath
This commit is contained in:
parent
71f4a4b2ca
commit
4eaacbcfe6
@ -189,18 +189,6 @@
|
|||||||
</artifactItems>
|
</artifactItems>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
<execution>
|
|
||||||
<id>copy</id>
|
|
||||||
<phase>generate-test-resources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>copy-dependencies</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<outputDirectory>${project.build.directory}/test-dependencies
|
|
||||||
</outputDirectory>
|
|
||||||
<stripVersion>true</stripVersion>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -102,12 +102,7 @@ class CompilingStatement extends Statement {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final List<String> LIBRARIES = Arrays.asList(
|
private static final List<File> COMPILER_CLASSPATH = buildCompilerClasspath();
|
||||||
"mapstruct.jar",
|
|
||||||
"guava.jar",
|
|
||||||
"javax.inject.jar",
|
|
||||||
"joda-time.jar"
|
|
||||||
);
|
|
||||||
|
|
||||||
private Statement next;
|
private Statement next;
|
||||||
private final FrameworkMethod method;
|
private final FrameworkMethod method;
|
||||||
@ -115,7 +110,6 @@ class CompilingStatement extends Statement {
|
|||||||
private JavaCompiler compiler;
|
private JavaCompiler compiler;
|
||||||
private String classOutputDir;
|
private String classOutputDir;
|
||||||
private String sourceOutputDir;
|
private String sourceOutputDir;
|
||||||
private List<File> classPath;
|
|
||||||
private CompilationRequest compilationRequest;
|
private CompilationRequest compilationRequest;
|
||||||
|
|
||||||
public CompilingStatement(FrameworkMethod method) {
|
public CompilingStatement(FrameworkMethod method) {
|
||||||
@ -149,18 +143,48 @@ class CompilingStatement extends Statement {
|
|||||||
classOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/classes";
|
classOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/classes";
|
||||||
sourceOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/generated-sources/mapping";
|
sourceOutputDir = basePath + TARGET_COMPILATION_TESTS + i + "/generated-sources/mapping";
|
||||||
|
|
||||||
String testDependenciesDir = basePath + "/target/test-dependencies/";
|
|
||||||
|
|
||||||
classPath = new ArrayList<File>();
|
|
||||||
for ( String library : LIBRARIES ) {
|
|
||||||
classPath.add( new File( testDependenciesDir, library ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
createOutputDirs();
|
createOutputDirs();
|
||||||
|
|
||||||
( (ModifiableURLClassLoader) Thread.currentThread().getContextClassLoader() ).addOutputDir( classOutputDir );
|
( (ModifiableURLClassLoader) Thread.currentThread().getContextClassLoader() ).addOutputDir( classOutputDir );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<File> 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<File> classpath = new ArrayList<File>();
|
||||||
|
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 {
|
protected void generateMapperImplementation() throws Exception {
|
||||||
CompilationResultHolder compilationResult = compile();
|
CompilationResultHolder compilationResult = compile();
|
||||||
|
|
||||||
@ -380,7 +404,7 @@ class CompilingStatement extends Statement {
|
|||||||
fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.sourceClasses ) );
|
fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.sourceClasses ) );
|
||||||
|
|
||||||
try {
|
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.CLASS_OUTPUT, Arrays.asList( new File( classOutputDir ) ) );
|
||||||
fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Arrays.asList( new File( sourceOutputDir ) ) );
|
fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Arrays.asList( new File( sourceOutputDir ) ) );
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,6 @@ public class ModifiableURLClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param basePath
|
|
||||||
*/
|
|
||||||
public void addURL(String basePath) {
|
public void addURL(String basePath) {
|
||||||
try {
|
try {
|
||||||
addURL( new URL( basePath ) );
|
addURL( new URL( basePath ) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user