mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#32 Making build work on JDK 6
This commit is contained in:
parent
17ffcfe104
commit
9a4e51801f
@ -44,11 +44,11 @@ public class ErronuousCollectionMappingTest extends MapperTestBase {
|
|||||||
@Diagnostic(type = ErronuousMapper.class,
|
@Diagnostic(type = ErronuousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 28,
|
line = 28,
|
||||||
messageRegExp = ".*Can't generate mapping method from iterable type to non-iterable type\\."),
|
messageRegExp = "Can't generate mapping method from iterable type to non-iterable type\\."),
|
||||||
@Diagnostic(type = ErronuousMapper.class,
|
@Diagnostic(type = ErronuousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 30,
|
line = 30,
|
||||||
messageRegExp = ".*Can't generate mapping method from non-iterable type to iterable type\\.")
|
messageRegExp = "Can't generate mapping method from non-iterable type to iterable type\\.")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailToGenerateMappingFromListToString() {
|
public void shouldFailToGenerateMappingFromListToString() {
|
||||||
|
@ -44,7 +44,7 @@ public class ErroneousMappingsTest extends MapperTestBase {
|
|||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 27,
|
line = 27,
|
||||||
messageRegExp = ".*Unknown property \"bar\" in return type.*"),
|
messageRegExp = "Unknown property \"bar\" in return type"),
|
||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.WARNING,
|
kind = Kind.WARNING,
|
||||||
line = 28,
|
line = 28,
|
||||||
@ -52,7 +52,7 @@ public class ErroneousMappingsTest extends MapperTestBase {
|
|||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 30,
|
line = 30,
|
||||||
messageRegExp = ".*Unknown property \"bar\" in parameter type.*")
|
messageRegExp = "Unknown property \"bar\" in parameter type")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailToGenerateMappings() {
|
public void shouldFailToGenerateMappings() {
|
||||||
|
@ -44,19 +44,19 @@ public class ErroneousMappingsTest extends MapperTestBase {
|
|||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 26,
|
line = 26,
|
||||||
messageRegExp = ".*Can't map property \"boolean foo\" to \"int foo\"\\."),
|
messageRegExp = "Can't map property \"boolean foo\" to \"int foo\"\\."),
|
||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 28,
|
line = 28,
|
||||||
messageRegExp = ".*Can't map property \"int foo\" to \"boolean foo\"\\."),
|
messageRegExp = "Can't map property \"int foo\" to \"boolean foo\"\\."),
|
||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 30,
|
line = 30,
|
||||||
messageRegExp = ".*Can't generate mapping method with primitive return type\\."),
|
messageRegExp = "Can't generate mapping method with primitive return type\\."),
|
||||||
@Diagnostic(type = ErroneousMapper.class,
|
@Diagnostic(type = ErroneousMapper.class,
|
||||||
kind = Kind.ERROR,
|
kind = Kind.ERROR,
|
||||||
line = 32,
|
line = 32,
|
||||||
messageRegExp = ".*Can't generate mapping method with primitive parameter type\\.")
|
messageRegExp = "Can't generate mapping method with primitive parameter type\\.")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public void shouldFailToGenerateMappings() {
|
public void shouldFailToGenerateMappings() {
|
||||||
|
@ -164,12 +164,12 @@ public abstract class MapperTestBase {
|
|||||||
assertThat( actual.getKind() ).isEqualTo( expected.getKind() );
|
assertThat( actual.getKind() ).isEqualTo( expected.getKind() );
|
||||||
assertThat( actual.getMessage() ).describedAs(
|
assertThat( actual.getMessage() ).describedAs(
|
||||||
String.format(
|
String.format(
|
||||||
"%s:%s %s",
|
"Unexpected message for diagnostic %s:%s %s",
|
||||||
actual.getSourceFileName(),
|
actual.getSourceFileName(),
|
||||||
actual.getLine(),
|
actual.getLine(),
|
||||||
actual.getKind()
|
actual.getKind()
|
||||||
)
|
)
|
||||||
).matches( expected.getMessage() );
|
).matches( ".*" + expected.getMessage() + ".*" );
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat( expectedIterator.hasNext() ).describedAs(
|
assertThat( expectedIterator.hasNext() ).describedAs(
|
||||||
|
@ -50,8 +50,11 @@ public @interface Diagnostic {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A regular expression matching the expected message of the diagnostic.
|
* A regular expression matching the expected message of the diagnostic.
|
||||||
|
* Wild-cards matching any character (".*") will be added to the beginning
|
||||||
|
* and end of the given expression when applying it.
|
||||||
*
|
*
|
||||||
* @return A regular expression matching the expected message of the diagnostic.
|
* @return A regular expression matching the expected message of the
|
||||||
|
* diagnostic.
|
||||||
*/
|
*/
|
||||||
String messageRegExp() default ".*";
|
String messageRegExp() default ".*";
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ package org.mapstruct.ap.testutil.compilation.model;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
@ -69,8 +71,10 @@ public class DiagnosticDescriptor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URI uri = getUri( diagnostic );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String sourceName = new File( diagnostic.getSource().toUri() ).getCanonicalPath();
|
String sourceName = new File( uri ).getCanonicalPath();
|
||||||
return sourceName.length() > sourceDir.length() ?
|
return sourceName.length() > sourceDir.length() ?
|
||||||
sourceName.substring( sourceDir.length() + 1 ) :
|
sourceName.substring( sourceDir.length() + 1 ) :
|
||||||
sourceName;
|
sourceName;
|
||||||
@ -80,6 +84,22 @@ public class DiagnosticDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static URI getUri(javax.tools.Diagnostic<? extends JavaFileObject> diagnostic) {
|
||||||
|
URI uri = diagnostic.getSource().toUri();
|
||||||
|
|
||||||
|
if ( uri.isAbsolute() ) {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Make the URI absolute in case it isn't (the case with JDK 6)
|
||||||
|
try {
|
||||||
|
return new URI( "file:" + uri.toString() );
|
||||||
|
}
|
||||||
|
catch ( URISyntaxException e ) {
|
||||||
|
throw new RuntimeException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getSourceFileName() {
|
public String getSourceFileName() {
|
||||||
return sourceFileName;
|
return sourceFileName;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user