mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#132 Formatting
This commit is contained in:
parent
a41cad17bd
commit
e5272fab2b
@ -120,6 +120,7 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- CDI, Weld, Arquillian -->
|
<!-- CDI, Weld, Arquillian -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.enterprise</groupId>
|
<groupId>javax.enterprise</groupId>
|
||||||
@ -154,7 +155,6 @@
|
|||||||
<version>3.0-b07</version>
|
<version>3.0-b07</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.testutil.runner;
|
package org.mapstruct.ap.testutil.runner;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -32,7 +30,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.tools.DiagnosticCollector;
|
import javax.tools.DiagnosticCollector;
|
||||||
import javax.tools.JavaCompiler;
|
import javax.tools.JavaCompiler;
|
||||||
import javax.tools.JavaCompiler.CompilationTask;
|
import javax.tools.JavaCompiler.CompilationTask;
|
||||||
@ -51,12 +48,15 @@ import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
|
|||||||
import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor;
|
import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor;
|
||||||
import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor;
|
import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor;
|
||||||
|
|
||||||
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A JUnit4 statement that performs source generation using the annotation processor and compiles those sources.
|
* A JUnit4 statement that performs source generation using the annotation processor and compiles those sources.
|
||||||
*
|
*
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*/
|
*/
|
||||||
class CompilingStatement extends Statement {
|
class CompilingStatement extends Statement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property to specify the sub-directory below /target/ where the generated files are placed
|
* Property to specify the sub-directory below /target/ where the generated files are placed
|
||||||
*/
|
*/
|
||||||
@ -67,7 +67,7 @@ class CompilingStatement extends Statement {
|
|||||||
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
|
private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
|
||||||
private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator();
|
private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator();
|
||||||
private static final ThreadLocal<Integer> THREAD_NUMBER = new ThreadLocal<Integer>() {
|
private static final ThreadLocal<Integer> THREAD_NUMBER = new ThreadLocal<Integer>() {
|
||||||
private AtomicInteger highWaterMark = new AtomicInteger( 0 );
|
private final AtomicInteger highWaterMark = new AtomicInteger( 0 );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Integer initialValue() {
|
protected Integer initialValue() {
|
||||||
@ -137,19 +137,24 @@ class CompilingStatement extends Statement {
|
|||||||
CompilationOutcomeDescriptor.forResult(
|
CompilationOutcomeDescriptor.forResult(
|
||||||
sourceDir,
|
sourceDir,
|
||||||
compilationResult.compilationSuccessful,
|
compilationResult.compilationSuccessful,
|
||||||
compilationResult.diagnostics.getDiagnostics() );
|
compilationResult.diagnostics.getDiagnostics()
|
||||||
|
);
|
||||||
CompilationOutcomeDescriptor expectedResult =
|
CompilationOutcomeDescriptor expectedResult =
|
||||||
CompilationOutcomeDescriptor.forExpectedCompilationResult(
|
CompilationOutcomeDescriptor.forExpectedCompilationResult(
|
||||||
method.getAnnotation( ExpectedCompilationOutcome.class ) );
|
method.getAnnotation( ExpectedCompilationOutcome.class )
|
||||||
|
);
|
||||||
|
|
||||||
if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) {
|
if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) {
|
||||||
assertThat( actualResult.getCompilationResult() ).describedAs(
|
assertThat( actualResult.getCompilationResult() ).describedAs(
|
||||||
"Compilation failed. Diagnostics: " + compilationResult.diagnostics.getDiagnostics() ).isEqualTo(
|
"Compilation failed. Diagnostics: " + compilationResult.diagnostics.getDiagnostics()
|
||||||
CompilationResult.SUCCEEDED );
|
).isEqualTo(
|
||||||
|
CompilationResult.SUCCEEDED
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertThat( actualResult.getCompilationResult() ).describedAs(
|
assertThat( actualResult.getCompilationResult() ).describedAs(
|
||||||
"Compilation succeeded but should have failed." ).isEqualTo( CompilationResult.FAILED );
|
"Compilation succeeded but should have failed."
|
||||||
|
).isEqualTo( CompilationResult.FAILED );
|
||||||
}
|
}
|
||||||
|
|
||||||
assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() );
|
assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() );
|
||||||
@ -171,8 +176,11 @@ class CompilingStatement extends Statement {
|
|||||||
actualDiagnostics.toString().replace( ", ", LINE_SEPARATOR ),
|
actualDiagnostics.toString().replace( ", ", LINE_SEPARATOR ),
|
||||||
LINE_SEPARATOR,
|
LINE_SEPARATOR,
|
||||||
LINE_SEPARATOR,
|
LINE_SEPARATOR,
|
||||||
expectedDiagnostics.toString().replace( ", ", LINE_SEPARATOR ) ) ).hasSize(
|
expectedDiagnostics.toString().replace( ", ", LINE_SEPARATOR )
|
||||||
expectedDiagnostics.size() );
|
)
|
||||||
|
).hasSize(
|
||||||
|
expectedDiagnostics.size()
|
||||||
|
);
|
||||||
|
|
||||||
while ( actualIterator.hasNext() ) {
|
while ( actualIterator.hasNext() ) {
|
||||||
|
|
||||||
@ -191,7 +199,9 @@ class CompilingStatement extends Statement {
|
|||||||
"Unexpected message for diagnostic %s:%s %s",
|
"Unexpected message for diagnostic %s:%s %s",
|
||||||
actual.getSourceFileName(),
|
actual.getSourceFileName(),
|
||||||
actual.getLine(),
|
actual.getLine(),
|
||||||
actual.getKind() ) ).matches( ".*" + expected.getMessage() + ".*" );
|
actual.getKind()
|
||||||
|
)
|
||||||
|
).matches( ".*" + expected.getMessage() + ".*" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +209,7 @@ class CompilingStatement extends Statement {
|
|||||||
* Returns the classes to be compiled for this test.
|
* Returns the classes to be compiled for this test.
|
||||||
*
|
*
|
||||||
* @param testMethod The test method of interest
|
* @param testMethod The test method of interest
|
||||||
|
*
|
||||||
* @return A set containing the classes to be compiled for this test
|
* @return A set containing the classes to be compiled for this test
|
||||||
*/
|
*/
|
||||||
private Set<Class<?>> getTestClasses() {
|
private Set<Class<?>> getTestClasses() {
|
||||||
@ -216,7 +227,8 @@ class CompilingStatement extends Statement {
|
|||||||
|
|
||||||
if ( testClasses.isEmpty() ) {
|
if ( testClasses.isEmpty() ) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"The classes to be compiled during the test must be specified via @WithClasses." );
|
"The classes to be compiled during the test must be specified via @WithClasses."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return testClasses;
|
return testClasses;
|
||||||
@ -226,6 +238,7 @@ class CompilingStatement extends Statement {
|
|||||||
* Returns the processor options to be used this test.
|
* Returns the processor options to be used this test.
|
||||||
*
|
*
|
||||||
* @param testMethod The test method of interest
|
* @param testMethod The test method of interest
|
||||||
|
*
|
||||||
* @return A list containing the processor options to be used for this test
|
* @return A list containing the processor options to be used for this test
|
||||||
*/
|
*/
|
||||||
private List<String> getProcessorOptions() {
|
private List<String> getProcessorOptions() {
|
||||||
@ -247,8 +260,12 @@ class CompilingStatement extends Statement {
|
|||||||
Set<File> sourceFiles = new HashSet<File>( classes.size() );
|
Set<File> sourceFiles = new HashSet<File>( classes.size() );
|
||||||
|
|
||||||
for ( Class<?> clazz : classes ) {
|
for ( Class<?> clazz : classes ) {
|
||||||
sourceFiles.add( new File( sourceDir + File.separator + clazz.getName().replace( ".", File.separator )
|
sourceFiles.add(
|
||||||
+ ".java" ) );
|
new File(
|
||||||
|
sourceDir + File.separator + clazz.getName().replace( ".", File.separator )
|
||||||
|
+ ".java"
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sourceFiles;
|
return sourceFiles;
|
||||||
@ -353,8 +370,8 @@ class CompilingStatement extends Statement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class CompilationResultHolder {
|
private static class CompilationResultHolder {
|
||||||
private DiagnosticCollector<JavaFileObject> diagnostics;
|
private final DiagnosticCollector<JavaFileObject> diagnostics;
|
||||||
private boolean compilationSuccessful;
|
private final boolean compilationSuccessful;
|
||||||
|
|
||||||
public CompilationResultHolder(DiagnosticCollector<JavaFileObject> diagnostics, boolean compilationSuccessful) {
|
public CompilationResultHolder(DiagnosticCollector<JavaFileObject> diagnostics, boolean compilationSuccessful) {
|
||||||
this.diagnostics = diagnostics;
|
this.diagnostics = diagnostics;
|
||||||
|
@ -32,13 +32,14 @@ import java.util.concurrent.ConcurrentMap;
|
|||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*/
|
*/
|
||||||
public class ModifiableURLClassLoader extends URLClassLoader {
|
public class ModifiableURLClassLoader extends URLClassLoader {
|
||||||
private static final String ORG_MAPSTRUCT_AP_TEST = "org.mapstruct.ap.test.";
|
|
||||||
static {
|
|
||||||
|
|
||||||
|
private static final String ORG_MAPSTRUCT_AP_TEST = "org.mapstruct.ap.test.";
|
||||||
|
|
||||||
|
static {
|
||||||
ClassLoader.registerAsParallelCapable();
|
ClassLoader.registerAsParallelCapable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<URL, URL>();
|
private final ConcurrentMap<URL, URL> addedURLs = new ConcurrentHashMap<URL, URL>();
|
||||||
|
|
||||||
public ModifiableURLClassLoader() {
|
public ModifiableURLClassLoader() {
|
||||||
super( new URL[] { }, new FilteringParentClassLoader() );
|
super( new URL[] { }, new FilteringParentClassLoader() );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user