diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 839bf86f1..89009aaff 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -136,7 +136,11 @@ public class ProcessorInvocationInterceptor implements InvocationInterceptor { private void configureProcessor(Verifier verifier) { String compilerId = processorTestContext.getProcessor().getCompilerId(); if ( compilerId != null ) { - verifier.addCliOption( "-Pgenerate-via-compiler-plugin" ); + String profile = processorTestContext.getProcessor().getProfile(); + if ( profile == null ) { + profile = "generate-via-compiler-plugin"; + } + verifier.addCliOption( "-P" + profile ); verifier.addCliOption( "-Dcompiler-id=" + compilerId ); } else { diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java index eb8553960..95480eee9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java @@ -44,6 +44,7 @@ public @interface ProcessorTest { enum ProcessorType { JAVAC( "javac" ), + JAVAC_WITH_PATHS( "javac", JRE.OTHER, "generate-via-compiler-plugin-with-annotation-processor-paths" ), ECLIPSE_JDT( "jdt", JRE.JAVA_8 ), @@ -51,14 +52,20 @@ public @interface ProcessorTest { private final String compilerId; private final JRE max; + private final String profile; ProcessorType(String compilerId) { this( compilerId, JRE.OTHER ); } ProcessorType(String compilerId, JRE max) { + this( compilerId, max, null ); + } + + ProcessorType(String compilerId, JRE max, String profile) { this.compilerId = compilerId; this.max = max; + this.profile = profile; } public String getCompilerId() { @@ -68,6 +75,10 @@ public @interface ProcessorTest { public JRE maxJre() { return max; } + + public String getProfile() { + return profile; + } } /** @@ -98,6 +109,7 @@ public @interface ProcessorTest { */ ProcessorType[] processorTypes() default { ProcessorType.JAVAC, + ProcessorType.JAVAC_WITH_PATHS, ProcessorType.ECLIPSE_JDT, ProcessorType.PROCESSOR_PLUGIN }; diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index e209daf23..c8a19228f 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -65,6 +65,38 @@ + + generate-via-compiler-plugin-with-annotation-processor-paths + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + \${compiler-id} + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + + + + + + org.eclipse.tycho + tycho-compiler-jdt + ${org.eclipse.tycho.compiler-jdt.version} + + + + + + generate-via-processor-plugin diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index 8e8c328f2..09e4957aa 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -75,7 +75,7 @@ final class DateFormatValidatorFactory { private static boolean isXmlGregorianCalendarSupposedToBeMapped(Type sourceType, Type targetType) { return typesEqualsOneOf( - sourceType, targetType, XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + sourceType, targetType, XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); } private static boolean isJodaDateTimeSupposed(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java index 7a2ac5588..e2ccc3f47 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java @@ -9,16 +9,12 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.ConstructorFragment; import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.common.FinalField; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.XmlConstants; /** * @author Sjaak Derksen @@ -30,12 +26,12 @@ public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod { private final Type dataTypeFactoryType; public AbstractToXmlGregorianCalendar(TypeFactory typeFactory) { - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - this.dataTypeFactoryType = typeFactory.getType( DatatypeFactory.class ); + this.returnType = typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); + this.dataTypeFactoryType = typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_FACTORY ); this.importTypes = asSet( returnType, dataTypeFactoryType, - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONFIGURATION_EXCEPTION ) ); } @@ -51,7 +47,7 @@ public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod { @Override public FieldReference getFieldReference() { - return new FinalField( dataTypeFactoryType, Strings.decapitalize( DatatypeFactory.class.getSimpleName() ) ); + return new FinalField( dataTypeFactoryType, "datatypeFactory" ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 4b096f803..0edae7f10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -59,12 +59,11 @@ public class BuiltInMappingMethods { } private static boolean isJaxbAvailable(TypeFactory typeFactory) { - return JaxbConstants.isJaxbElementPresent() && typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); + return typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); } private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) { - return XmlConstants.isXmlGregorianCalendarPresent() && - typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + return typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); } private static boolean isJodaTimeAvailable(TypeFactory typeFactory) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 4d116266f..0d3d4c30a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -9,11 +9,10 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; import java.util.Set; -import javax.xml.bind.JAXBElement; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.JaxbConstants; /** * @author Sjaak Derksen @@ -25,7 +24,7 @@ public class JaxbElemToValue extends BuiltInMethod { private final Set importTypes; public JaxbElemToValue(TypeFactory typeFactory) { - Type type = typeFactory.getType( JAXBElement.class ); + Type type = typeFactory.getType( JaxbConstants.JAXB_ELEMENT_FQN ); this.parameter = new Parameter( "element", type ); this.returnType = type.getTypeParameters().get( 0 ); this.importTypes = asSet( parameter.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java index fa87bff2d..80fa9ba32 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public class JodaLocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregor this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java index e958ca952..37c89ef36 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public class JodaLocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianC this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java index e9daac39c..b29c7aec5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public class JodaLocalTimeToXmlGregorianCalendar extends AbstractToXmlGregorianC this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java index 8853c1aae..178a77b5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java @@ -9,11 +9,10 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoField; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -30,7 +29,7 @@ public class LocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianC this.parameter = new Parameter( "localDateTime", typeFactory.getType( LocalDateTime.class ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( ChronoField.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java index 96c8a8a31..2e2544ade 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java @@ -7,11 +7,11 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.time.LocalDate; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public class LocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalen this.parameter = new Parameter( "localDate", typeFactory.getType( LocalDate.class ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java index f4d8ceee9..03927fd86 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java @@ -7,11 +7,11 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Calendar; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToCalendar extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( Calendar.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java index 7f270be5f..38f76a66e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java @@ -7,11 +7,11 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Date; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( Date.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java index ab2db49e8..ab6658bfc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( JodaTimeConstants.DATE_TIME_ZONE_FQN ), returnType, parameter.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java index d26cde021..f45488755 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java index 700c19c21..af7fd9e9f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java index b3eae2031..372569113 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java index 1da6951b9..2c9ced341 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java @@ -7,11 +7,11 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.time.LocalDate; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToLocalDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToLocalDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( LocalDate.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java index 5d2989244..b676bd03a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java @@ -9,12 +9,10 @@ import java.time.Duration; import java.time.LocalDateTime; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,12 +26,12 @@ public class XmlGregorianCalendarToLocalDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToLocalDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( LocalDateTime.class ); this.importTypes = asSet( returnType, parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( Duration.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java index 73ac51fa2..c932da667 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java @@ -8,12 +8,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -27,7 +27,7 @@ public class XmlGregorianCalendarToString extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToString(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( String.class ); this.importTypes = asSet( parameter.getType(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java deleted file mode 100644 index d66d81f9b..000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util; - -/** - * Utilities for working with classes. It is mainly needed because using the {@link ElementUtils} - * is not always correct. For example when compiling with JDK 9 and source version 8 classes from different modules - * are available by {@link ElementUtils#getTypeElement(CharSequence)} but they are actually not - * if those modules are not added during compilation. - * - * @author Filip Hrisafov - */ -class ClassUtils { - - private ClassUtils() { - } - - /** - * Determine whether the {@link Class} identified by the supplied name is present - * and can be loaded. Will return {@code false} if either the class or - * one of its dependencies is not present or cannot be loaded. - * - * @param className the name of the class to check - * @param classLoader the class loader to use - * (may be {@code null}, which indicates the default class loader) - * - * @return whether the specified class is present - */ - static boolean isPresent(String className, ClassLoader classLoader) { - try { - ClassLoader classLoaderToUse = classLoader; - if ( classLoaderToUse == null ) { - classLoaderToUse = getDefaultClassLoader(); - } - classLoaderToUse.loadClass( className ); - return true; - } - catch ( ClassNotFoundException ex ) { - // Class or one of its dependencies is not present... - return false; - } - } - - /** - * Return the default ClassLoader to use: typically the thread context - * ClassLoader, if available; the ClassLoader that loaded the ClassUtils - * class will be used as fallback. - *

Call this method if you intend to use the thread context ClassLoader - * in a scenario where you absolutely need a non-null ClassLoader reference: - * for example, for class path resource loading (but not necessarily for - * {@code Class.forName}, which accepts a {@code null} ClassLoader - * reference as well). - * - * @return the default ClassLoader (never {@code null}) - * - * @see Thread#getContextClassLoader() - */ - private static ClassLoader getDefaultClassLoader() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } - catch ( Throwable ex ) { - // Cannot access thread context ClassLoader - falling back to system class loader... - } - if ( cl == null ) { - // No thread context class loader -> use class loader of this class. - cl = ClassUtils.class.getClassLoader(); - } - return cl; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java index f8f01cd18..db18673ba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java @@ -11,18 +11,8 @@ package org.mapstruct.ap.internal.util; public final class JaxbConstants { public static final String JAXB_ELEMENT_FQN = "javax.xml.bind.JAXBElement"; - private static final boolean IS_JAXB_ELEMENT_PRESENT = ClassUtils.isPresent( - JAXB_ELEMENT_FQN, - JaxbConstants.class.getClassLoader() - ); private JaxbConstants() { } - /** - * @return {@code true} if {@link javax.xml.bind.JAXBElement} is present, {@code false} otherwise - */ - public static boolean isJaxbElementPresent() { - return IS_JAXB_ELEMENT_PRESENT; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java index 8216e8312..532b9f0bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java @@ -12,19 +12,14 @@ package org.mapstruct.ap.internal.util; */ public final class XmlConstants { - public static final String JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; - private static final boolean IS_XML_GREGORIAN_CALENDAR_PRESENT = ClassUtils.isPresent( - JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR, - XmlConstants.class.getClassLoader() - ); + // CHECKSTYLE:OFF + public static final String JAVAX_XML_XML_GREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; + public static final String JAVAX_XML_DATATYPE_CONFIGURATION_EXCEPTION = "javax.xml.datatype.DatatypeConfigurationException"; + public static final String JAVAX_XML_DATATYPE_FACTORY = "javax.xml.datatype.DatatypeFactory"; + public static final String JAVAX_XML_DATATYPE_CONSTANTS = "javax.xml.datatype.DatatypeConstants"; + // CHECKSTYLE:ON private XmlConstants() { } - /** - * @return {@code true} if the {@link javax.xml.datatype.XMLGregorianCalendar} is present, {@code false} otherwise - */ - public static boolean isXmlGregorianCalendarPresent() { - return IS_XML_GREGORIAN_CALENDAR_PRESENT; - } }