From 9a4e51801fcca415c91aab60c95f2b8abed390b9 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Wed, 26 Jun 2013 20:15:31 +0200 Subject: [PATCH] #32 Making build work on JDK 6 --- .../ErronuousCollectionMappingTest.java | 4 ++-- .../ErroneousMappingsTest.java | 4 ++-- .../typemismatch/ErroneousMappingsTest.java | 8 +++---- .../mapstruct/ap/testutil/MapperTestBase.java | 4 ++-- .../compilation/annotation/Diagnostic.java | 5 ++++- .../model/DiagnosticDescriptor.java | 22 ++++++++++++++++++- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erronuous/ErronuousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erronuous/ErronuousCollectionMappingTest.java index 8bf7a0733..ac90935b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erronuous/ErronuousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erronuous/ErronuousCollectionMappingTest.java @@ -44,11 +44,11 @@ public class ErronuousCollectionMappingTest extends MapperTestBase { @Diagnostic(type = ErronuousMapper.class, kind = Kind.ERROR, 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, kind = Kind.ERROR, 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() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index ba2ebee0c..1a85e693c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -44,7 +44,7 @@ public class ErroneousMappingsTest extends MapperTestBase { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 27, - messageRegExp = ".*Unknown property \"bar\" in return type.*"), + messageRegExp = "Unknown property \"bar\" in return type"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.WARNING, line = 28, @@ -52,7 +52,7 @@ public class ErroneousMappingsTest extends MapperTestBase { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 30, - messageRegExp = ".*Unknown property \"bar\" in parameter type.*") + messageRegExp = "Unknown property \"bar\" in parameter type") } ) public void shouldFailToGenerateMappings() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index 761513783..ad31b6a91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -44,19 +44,19 @@ public class ErroneousMappingsTest extends MapperTestBase { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, 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, kind = Kind.ERROR, 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, kind = Kind.ERROR, 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, kind = Kind.ERROR, 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() { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java b/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java index 1a88566b6..bb0fdf572 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/MapperTestBase.java @@ -164,12 +164,12 @@ public abstract class MapperTestBase { assertThat( actual.getKind() ).isEqualTo( expected.getKind() ); assertThat( actual.getMessage() ).describedAs( String.format( - "%s:%s %s", + "Unexpected message for diagnostic %s:%s %s", actual.getSourceFileName(), actual.getLine(), actual.getKind() ) - ).matches( expected.getMessage() ); + ).matches( ".*" + expected.getMessage() + ".*" ); } assertThat( expectedIterator.hasNext() ).describedAs( diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java index 22702130b..9960fed7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java @@ -50,8 +50,11 @@ public @interface 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 ".*"; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index f508a766d..327e89993 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -20,6 +20,8 @@ package org.mapstruct.ap.testutil.compilation.model; import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import javax.tools.Diagnostic.Kind; import javax.tools.JavaFileObject; @@ -69,8 +71,10 @@ public class DiagnosticDescriptor { return null; } + URI uri = getUri( diagnostic ); + try { - String sourceName = new File( diagnostic.getSource().toUri() ).getCanonicalPath(); + String sourceName = new File( uri ).getCanonicalPath(); return sourceName.length() > sourceDir.length() ? sourceName.substring( sourceDir.length() + 1 ) : sourceName; @@ -80,6 +84,22 @@ public class DiagnosticDescriptor { } } + private static URI getUri(javax.tools.Diagnostic 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() { return sourceFileName; }