#2728 Add new WithTestDependency annotation for our processor testing

Adding this dependency allows us to dynamically pick the dependencies that we want to have on the test compilation classpath.
It would allow us to more granularly test things with different dependencies, such as javax inject and jakarta inject
This commit is contained in:
Filip Hrisafov 2022-01-29 11:13:16 +01:00 committed by GitHub
parent ec30f5d279
commit 20ff51ebb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 319 additions and 32 deletions

View File

@ -8,6 +8,7 @@ package org.mapstruct.ap.test.bugs._1395;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
@ -18,6 +19,7 @@ import org.mapstruct.ap.testutil.WithClasses;
Source.class, Source.class,
Target.class Target.class
} ) } )
@WithSpring
@IssueKey( "1395" ) @IssueKey( "1395" )
public class Issue1395Test { public class Issue1395Test {

View File

@ -9,6 +9,7 @@ import org.joda.time.LocalDate;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJoda;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -21,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
Target.class Target.class
}) })
@IssueKey("1425") @IssueKey("1425")
@WithJoda
public class Issue1425Test { public class Issue1425Test {
@ProcessorTest @ProcessorTest

View File

@ -12,6 +12,7 @@ import org.joda.time.DateTime;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJoda;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -24,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat;
Target.class Target.class
}) })
@IssueKey("1460") @IssueKey("1460")
@WithJoda
public class Issue1460Test { public class Issue1460Test {
@ProcessorTest @ProcessorTest

View File

@ -8,11 +8,13 @@ package org.mapstruct.ap.test.bugs._2145;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("2145") @IssueKey("2145")
@WithClasses(Issue2145Mapper.class) @WithClasses(Issue2145Mapper.class)
@WithJavaxJaxb
public class Issue2145Test { public class Issue2145Test {
@ProcessorTest @ProcessorTest

View File

@ -11,6 +11,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.MappingConstants; import org.mapstruct.MappingConstants;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
@ -30,6 +31,7 @@ import org.springframework.stereotype.Component;
@ProcessorOptions({ @ProcessorOptions({
@ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING), @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING),
@ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") }) @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") })
@WithSpring
public class Issue880Test { public class Issue880Test {
@RegisterExtension @RegisterExtension
final GeneratedSource generatedSource = new GeneratedSource(); final GeneratedSource generatedSource = new GeneratedSource();

View File

@ -58,6 +58,7 @@ import org.mapstruct.ap.test.builtin.source.MapSource;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -71,8 +72,6 @@ import static org.assertj.core.api.Assertions.assertThat;
MapTarget.class, MapTarget.class,
CalendarProperty.class, CalendarProperty.class,
DateProperty.class, DateProperty.class,
JaxbElementListProperty.class,
JaxbElementProperty.class,
StringListProperty.class, StringListProperty.class,
StringProperty.class, StringProperty.class,
BigDecimalProperty.class, BigDecimalProperty.class,
@ -81,13 +80,16 @@ import static org.assertj.core.api.Assertions.assertThat;
XmlGregorianCalendarProperty.class, XmlGregorianCalendarProperty.class,
ZonedDateTimeProperty.class, ZonedDateTimeProperty.class,
IterableSource.class, IterableSource.class,
MapSource.class
}) })
@DefaultTimeZone("Europe/Berlin") @DefaultTimeZone("Europe/Berlin")
public class BuiltInTest { public class BuiltInTest {
@ProcessorTest @ProcessorTest
@WithClasses( JaxbMapper.class ) @WithClasses( {
JaxbMapper.class,
JaxbElementProperty.class,
} )
@WithJavaxJaxb
public void shouldApplyBuiltInOnJAXBElement() { public void shouldApplyBuiltInOnJAXBElement() {
JaxbElementProperty source = new JaxbElementProperty(); JaxbElementProperty source = new JaxbElementProperty();
source.setProp( createJaxb( "TEST" ) ); source.setProp( createJaxb( "TEST" ) );
@ -100,7 +102,11 @@ public class BuiltInTest {
} }
@ProcessorTest @ProcessorTest
@WithClasses( JaxbMapper.class ) @WithClasses( {
JaxbMapper.class,
JaxbElementProperty.class,
} )
@WithJavaxJaxb
@IssueKey( "1698" ) @IssueKey( "1698" )
public void shouldApplyBuiltInOnJAXBElementExtra() { public void shouldApplyBuiltInOnJAXBElementExtra() {
JaxbElementProperty source = new JaxbElementProperty(); JaxbElementProperty source = new JaxbElementProperty();
@ -123,7 +129,11 @@ public class BuiltInTest {
} }
@ProcessorTest @ProcessorTest
@WithClasses( JaxbListMapper.class ) @WithClasses( {
JaxbListMapper.class,
JaxbElementListProperty.class,
} )
@WithJavaxJaxb
@IssueKey( "141" ) @IssueKey( "141" )
public void shouldApplyBuiltInOnJAXBElementList() { public void shouldApplyBuiltInOnJAXBElementList() {
@ -347,7 +357,11 @@ public class BuiltInTest {
} }
@ProcessorTest @ProcessorTest
@WithClasses( MapSourceTargetMapper.class ) @WithClasses( {
MapSourceTargetMapper.class,
MapSource.class,
} )
@WithJavaxJaxb
public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException { public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException {
MapSource source = new MapSource(); MapSource source = new MapSource();

View File

@ -30,6 +30,8 @@ import org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocal
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import org.mapstruct.ap.testutil.WithJoda;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -45,6 +47,8 @@ import static org.assertj.core.api.Assertions.assertThat;
XmlGregorianCalendarBean.class XmlGregorianCalendarBean.class
}) })
@IssueKey( "689" ) @IssueKey( "689" )
@WithJoda
@WithJavaxJaxb
public class JodaTimeTest { public class JodaTimeTest {
@ProcessorTest @ProcessorTest

View File

@ -13,6 +13,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
@ -133,6 +134,7 @@ public class WildCardTest {
@ProcessorTest @ProcessorTest
@WithClasses( { BeanMapper.class, GoodIdea.class, CunningPlan.class } ) @WithClasses( { BeanMapper.class, GoodIdea.class, CunningPlan.class } )
@WithJavaxJaxb
public void shouldMapBean() { public void shouldMapBean() {
GoodIdea aGoodIdea = new GoodIdea(); GoodIdea aGoodIdea = new GoodIdea();

View File

@ -8,6 +8,7 @@ package org.mapstruct.ap.test.conversion.erroneous;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJoda;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
@ -19,6 +20,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutco
Source.class, Source.class,
Target.class Target.class
}) })
@WithJoda
@IssueKey("725") @IssueKey("725")
public class InvalidDateFormatTest { public class InvalidDateFormatTest {

View File

@ -20,6 +20,7 @@ import org.junitpioneer.jupiter.DefaultLocale;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJoda;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -31,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
@IssueKey("75") @IssueKey("75")
@DefaultLocale("de") @DefaultLocale("de")
@WithJoda
public class JodaConversionTest { public class JodaConversionTest {
@ProcessorTest @ProcessorTest

View File

@ -19,6 +19,7 @@ import org.mapstruct.ap.test.decorator.PersonDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -44,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("592") @IssueKey("592")
@ComponentScan(basePackageClasses = Jsr330DecoratorTest.class) @ComponentScan(basePackageClasses = Jsr330DecoratorTest.class)
@Configuration @Configuration
@WithJavaxInject
public class Jsr330DecoratorTest { public class Jsr330DecoratorTest {
@RegisterExtension @RegisterExtension

View File

@ -16,6 +16,7 @@ import org.mapstruct.ap.test.decorator.PersonDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -40,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("592") @IssueKey("592")
@ComponentScan(basePackageClasses = SpringDecoratorTest.class) @ComponentScan(basePackageClasses = SpringDecoratorTest.class)
@Configuration @Configuration
@WithSpring
public class SpringDecoratorTest { public class SpringDecoratorTest {
@Autowired @Autowired

View File

@ -16,6 +16,7 @@ import org.mapstruct.ap.test.decorator.PersonDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -37,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
PersonMapper.class, PersonMapper.class,
PersonMapperDecorator.class PersonMapperDecorator.class
}) })
@WithSpring
@IssueKey("592") @IssueKey("592")
@ComponentScan(basePackageClasses = SpringDecoratorTest.class) @ComponentScan(basePackageClasses = SpringDecoratorTest.class)
@Configuration @Configuration

View File

@ -7,6 +7,7 @@ package org.mapstruct.ap.test.destination;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -25,6 +26,7 @@ public class DestinationClassNameTest {
@ProcessorTest @ProcessorTest
@WithClasses({ DestinationClassNameWithJsr330Mapper.class }) @WithClasses({ DestinationClassNameWithJsr330Mapper.class })
@WithJavaxInject
public void shouldNotGenerateSpi() throws Exception { public void shouldNotGenerateSpi() throws Exception {
Class<DestinationClassNameWithJsr330Mapper> clazz = DestinationClassNameWithJsr330Mapper.class; Class<DestinationClassNameWithJsr330Mapper> clazz = DestinationClassNameWithJsr330Mapper.class;

View File

@ -15,6 +15,7 @@ import org.mapstruct.ap.test.imports.referenced.Target;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -41,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
org.mapstruct.ap.test.imports.to.FooWrapper.class, org.mapstruct.ap.test.imports.to.FooWrapper.class,
SecondSourceTargetMapper.class SecondSourceTargetMapper.class
}) })
@WithJavaxInject
public class ConflictingTypesNamesTest { public class ConflictingTypesNamesTest {
@RegisterExtension @RegisterExtension

View File

@ -17,6 +17,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -41,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
GenderJsr330DefaultCompileOptionFieldMapper.class GenderJsr330DefaultCompileOptionFieldMapper.class
}) })
@ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class) @ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class)
@WithJavaxInject
@Configuration @Configuration
public class Jsr330DefaultCompileOptionFieldMapperTest { public class Jsr330DefaultCompileOptionFieldMapperTest {

View File

@ -14,6 +14,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor")
@ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class) @ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class)
@Configuration @Configuration
@WithJavaxInject
public class Jsr330CompileOptionConstructorMapperTest { public class Jsr330CompileOptionConstructorMapperTest {
@RegisterExtension @RegisterExtension

View File

@ -15,6 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("571") @IssueKey("571")
@ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class) @ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class)
@Configuration @Configuration
@WithJavaxInject
public class Jsr330ConstructorMapperTest { public class Jsr330ConstructorMapperTest {
@RegisterExtension @RegisterExtension

View File

@ -18,6 +18,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -44,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("571") @IssueKey("571")
@ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class) @ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class)
@Configuration @Configuration
@WithJavaxInject
public class Jsr330FieldMapperTest { public class Jsr330FieldMapperTest {
@RegisterExtension @RegisterExtension

View File

@ -15,6 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@ -41,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("571") @IssueKey("571")
@ComponentScan(basePackageClasses = CustomerSpringDefaultMapper.class) @ComponentScan(basePackageClasses = CustomerSpringDefaultMapper.class)
@Configuration @Configuration
@WithSpring
public class SpringDefaultMapperTest { public class SpringDefaultMapperTest {
@RegisterExtension @RegisterExtension

View File

@ -21,6 +21,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -52,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor")
@ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class) @ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class)
@Configuration @Configuration
@WithSpring
@DefaultTimeZone("Europe/Berlin") @DefaultTimeZone("Europe/Berlin")
public class SpringCompileOptionConstructorMapperTest { public class SpringCompileOptionConstructorMapperTest {

View File

@ -23,6 +23,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@ -53,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey( "571" ) @IssueKey( "571" )
@ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class) @ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class)
@Configuration @Configuration
@WithSpring
@DefaultTimeZone("Europe/Berlin") @DefaultTimeZone("Europe/Berlin")
public class SpringConstructorMapperTest { public class SpringConstructorMapperTest {

View File

@ -15,6 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithSpring;
import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.ap.testutil.runner.GeneratedSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@IssueKey("571") @IssueKey("571")
@ComponentScan(basePackageClasses = CustomerSpringFieldMapper.class) @ComponentScan(basePackageClasses = CustomerSpringFieldMapper.class)
@Configuration @Configuration
@WithSpring
public class SpringFieldMapperTest { public class SpringFieldMapperTest {
@RegisterExtension @RegisterExtension

View File

@ -20,6 +20,7 @@ import org.junitpioneer.jupiter.DefaultLocale;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -42,6 +43,7 @@ public class NestedMappingMethodInvocationTest {
OrderDetailsType.class, OrderDetailsType.class,
OrderType.class OrderType.class
} ) } )
@WithJavaxJaxb
public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException { public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException {
OrderTypeToOrderDtoMapper instance = OrderTypeToOrderDtoMapper.INSTANCE; OrderTypeToOrderDtoMapper instance = OrderTypeToOrderDtoMapper.INSTANCE;
OrderDto target = instance.sourceToTarget( createOrderType() ); OrderDto target = instance.sourceToTarget( createOrderType() );
@ -62,6 +64,7 @@ public class NestedMappingMethodInvocationTest {
ObjectFactory.class, ObjectFactory.class,
TargetDto.class TargetDto.class
} ) } )
@WithJavaxJaxb
public void shouldMapViaMethodAndConversion() { public void shouldMapViaMethodAndConversion() {
SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE;
@ -78,6 +81,7 @@ public class NestedMappingMethodInvocationTest {
ObjectFactory.class, ObjectFactory.class,
TargetDto.class TargetDto.class
} ) } )
@WithJavaxJaxb
public void shouldMapViaConversionAndMethod() { public void shouldMapViaConversionAndMethod() {
SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE;

View File

@ -12,6 +12,7 @@ import org.mapstruct.ap.test.references.samename.model.Target;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxInject;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -30,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
Jsr330SourceTargetMapper.class, Jsr330SourceTargetMapper.class,
AnotherSourceTargetMapper.class AnotherSourceTargetMapper.class
}) })
@WithJavaxInject
public class SeveralReferencedMappersWithSameSimpleNameTest { public class SeveralReferencedMappersWithSameSimpleNameTest {
@ProcessorTest @ProcessorTest

View File

@ -13,6 +13,7 @@ import org.mapstruct.ap.test.selection.jaxb.test2.OrderShippingDetailsType;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -28,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class, OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class,
OrderMapper.class OrderMapper.class
}) })
@WithJavaxJaxb
public class JaxbFactoryMethodSelectionTest { public class JaxbFactoryMethodSelectionTest {
@ProcessorTest @ProcessorTest

View File

@ -13,6 +13,7 @@ import org.mapstruct.ap.test.selection.jaxb.underscores.UnderscoreType;
import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithJavaxJaxb;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -23,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@IssueKey( "726" ) @IssueKey( "726" )
@WithClasses( { UnderscoreType.class, ObjectFactory.class, SuperType.class, SubType.class, UnderscoreMapper.class } ) @WithClasses( { UnderscoreType.class, ObjectFactory.class, SuperType.class, SubType.class, UnderscoreMapper.class } )
@WithJavaxJaxb
public class UnderscoreSelectionTest { public class UnderscoreSelectionTest {
@ProcessorTest @ProcessorTest

View File

@ -0,0 +1,27 @@
/*
* 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.testutil;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta annotation that adds the needed Spring Dependencies
*
* @author Filip Hrisafov
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@WithTestDependency({
"javax.inject",
})
public @interface WithJavaxInject {
}

View File

@ -0,0 +1,27 @@
/*
* 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.testutil;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta annotation that adds the needed Spring Dependencies
*
* @author Filip Hrisafov
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@WithTestDependency({
"jaxb-api",
})
public @interface WithJavaxJaxb {
}

View File

@ -0,0 +1,27 @@
/*
* 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.testutil;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta annotation that adds the needed Spring Dependencies
*
* @author Filip Hrisafov
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@WithTestDependency({
"joda-time"
})
public @interface WithJoda {
}

View File

@ -0,0 +1,28 @@
/*
* 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.testutil;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Meta annotation that adds the needed Spring Dependencies
*
* @author Filip Hrisafov
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@WithTestDependency({
"spring-beans",
"spring-context"
})
public @interface WithSpring {
}

View File

@ -0,0 +1,22 @@
/*
* 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.testutil;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Filip Hrisafov
* @see WithTestDependency
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD })
public @interface WithTestDependencies {
WithTestDependency[] value();
}

View File

@ -0,0 +1,28 @@
/*
* 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.testutil;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Specifies the group id of the additional test dependencies that should be added to the test compile path
*
* @author Filip Hrisafov
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD })
@Repeatable( WithTestDependencies.class )
public @interface WithTestDependency {
/**
* @return The group ids of the additional test dependencies for the test compile path
*/
String[] value();
}

View File

@ -5,6 +5,7 @@
*/ */
package org.mapstruct.ap.testutil.runner; package org.mapstruct.ap.testutil.runner;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -17,13 +18,15 @@ public class CompilationRequest {
private final Set<Class<?>> sourceClasses; private final Set<Class<?>> sourceClasses;
private final Map<Class<?>, Class<?>> services; private final Map<Class<?>, Class<?>> services;
private final List<String> processorOptions; private final List<String> processorOptions;
private final Collection<String> testDependencies;
CompilationRequest(Compiler compiler, Set<Class<?>> sourceClasses, Map<Class<?>, Class<?>> services, CompilationRequest(Compiler compiler, Set<Class<?>> sourceClasses, Map<Class<?>, Class<?>> services,
List<String> processorOptions) { List<String> processorOptions, Collection<String> testDependencies) {
this.compiler = compiler; this.compiler = compiler;
this.sourceClasses = sourceClasses; this.sourceClasses = sourceClasses;
this.services = services; this.services = services;
this.processorOptions = processorOptions; this.processorOptions = processorOptions;
this.testDependencies = testDependencies;
} }
@Override @Override
@ -34,6 +37,7 @@ public class CompilationRequest {
result = prime * result + ( ( processorOptions == null ) ? 0 : processorOptions.hashCode() ); result = prime * result + ( ( processorOptions == null ) ? 0 : processorOptions.hashCode() );
result = prime * result + ( ( services == null ) ? 0 : services.hashCode() ); result = prime * result + ( ( services == null ) ? 0 : services.hashCode() );
result = prime * result + ( ( sourceClasses == null ) ? 0 : sourceClasses.hashCode() ); result = prime * result + ( ( sourceClasses == null ) ? 0 : sourceClasses.hashCode() );
result = prime * result + ( ( testDependencies == null ) ? 0 : testDependencies.hashCode() );
return result; return result;
} }
@ -53,6 +57,7 @@ public class CompilationRequest {
return compiler.equals( other.compiler ) return compiler.equals( other.compiler )
&& processorOptions.equals( other.processorOptions ) && processorOptions.equals( other.processorOptions )
&& services.equals( other.services ) && services.equals( other.services )
&& testDependencies.equals( other.testDependencies )
&& sourceClasses.equals( other.sourceClasses ); && sourceClasses.equals( other.sourceClasses );
} }
@ -67,4 +72,8 @@ public class CompilationRequest {
public Map<Class<?>, Class<?>> getServices() { public Map<Class<?>, Class<?>> getServices() {
return services; return services;
} }
public Collection<String> getTestDependencies() {
return testDependencies;
}
} }

View File

@ -13,6 +13,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -22,7 +23,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.stream.Stream;
import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader; import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
@ -34,6 +34,7 @@ import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithServiceImplementation;
import org.mapstruct.ap.testutil.WithTestDependency;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
@ -98,37 +99,38 @@ abstract class CompilingExtension implements BeforeEachCallback {
return "_" + compiler.name().toLowerCase(); return "_" + compiler.name().toLowerCase();
} }
/**
* Build the default test compilation classpath
* needed for compiling the generated sources once the processor has run.
*/
private static List<String> buildTestCompilationClasspath() { private static List<String> buildTestCompilationClasspath() {
String[] whitelist = Collection<String> whitelist = Arrays.asList(
new String[] {
// MapStruct annotations in multi-module reactor build or IDE // MapStruct annotations in multi-module reactor build or IDE
"core" + File.separator + "target", "core" + File.separator + "target",
// MapStruct annotations in single module build // MapStruct annotations in single module build
"org" + File.separator + "mapstruct" + File.separator + "mapstruct" + File.separator, "org" + File.separator + "mapstruct" + File.separator + "mapstruct" + File.separator,
"guava", "guava"
"javax.inject", );
"spring-beans",
"spring-context",
"jaxb-api",
"joda-time" };
return filterBootClassPath( whitelist ); return filterBootClassPath( whitelist );
} }
/**
* Build the annotation processor classpath.
* i.e. the classpath that is needed to run the annotation processor with its own dependencies only.
* The optional dependencies are not needed in this classpath.
*/
private static List<String> buildProcessorClasspath() { private static List<String> buildProcessorClasspath() {
String[] whitelist = Collection<String> whitelist = Arrays.asList(
new String[] {
"processor" + File.separator + "target", // the processor itself, "processor" + File.separator + "target", // the processor itself,
"freemarker", "freemarker",
"javax.inject", "gem-api"
"spring-context", );
"gem-api",
"joda-time" };
return filterBootClassPath( whitelist ); return filterBootClassPath( whitelist );
} }
protected static List<String> filterBootClassPath(String[] whitelist) { protected static List<String> filterBootClassPath(Collection<String> whitelist) {
String[] bootClasspath = String[] bootClasspath =
System.getProperty( "java.class.path" ).split( File.pathSeparator ); System.getProperty( "java.class.path" ).split( File.pathSeparator );
String testClasses = "target" + File.separator + "test-classes"; String testClasses = "target" + File.separator + "test-classes";
@ -143,8 +145,8 @@ abstract class CompilingExtension implements BeforeEachCallback {
return classpath; return classpath;
} }
private static boolean isWhitelisted(String path, String[] whitelist) { private static boolean isWhitelisted(String path, Collection<String> whitelist) {
return Stream.of( whitelist ).anyMatch( path::contains ); return whitelist.stream().anyMatch( path::contains );
} }
@Override @Override
@ -368,6 +370,17 @@ abstract class CompilingExtension implements BeforeEachCallback {
return services; return services;
} }
private Collection<String> getAdditionalTestDependencies(Method testMethod, Class<?> testClass) {
Collection<String> testDependencies = new HashSet<>();
findRepeatableAnnotations( testMethod, WithTestDependency.class )
.forEach( annotation -> Collections.addAll( testDependencies, annotation.value() ) );
findRepeatableAnnotations( testClass, WithTestDependency.class )
.forEach( annotation -> Collections.addAll( testDependencies, annotation.value() ) );
return testDependencies;
}
private void addServices(Map<Class<?>, Class<?>> services, List<WithServiceImplementation> withImplementations) { private void addServices(Map<Class<?>, Class<?>> services, List<WithServiceImplementation> withImplementations) {
for ( WithServiceImplementation withImplementation : withImplementations ) { for ( WithServiceImplementation withImplementation : withImplementations ) {
addService( services, withImplementation ); addService( services, withImplementation );
@ -446,7 +459,8 @@ abstract class CompilingExtension implements BeforeEachCallback {
compiler, compiler,
getTestClasses( testMethod, testClass ), getTestClasses( testMethod, testClass ),
getServices( testMethod, testClass ), getServices( testMethod, testClass ),
getProcessorOptions( testMethod, testClass ) getProcessorOptions( testMethod, testClass ),
getAdditionalTestDependencies( testMethod, testClass )
); );
ExtensionContext.Store rootStore = context.getRoot().getStore( NAMESPACE ); ExtensionContext.Store rootStore = context.getRoot().getStore( NAMESPACE );

View File

@ -6,6 +6,9 @@
package org.mapstruct.ap.testutil.runner; package org.mapstruct.ap.testutil.runner;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -65,13 +68,27 @@ class EclipseCompilingExtension extends CompilingExtension {
return clHelper.compileInOtherClassloader( return clHelper.compileInOtherClassloader(
compilationRequest, compilationRequest,
TEST_COMPILATION_CLASSPATH, getTestCompilationClasspath( compilationRequest ),
getSourceFiles( compilationRequest.getSourceClasses() ), getSourceFiles( compilationRequest.getSourceClasses() ),
SOURCE_DIR, SOURCE_DIR,
sourceOutputDir, sourceOutputDir,
classOutputDir ); classOutputDir );
} }
private static List<String> getTestCompilationClasspath(CompilationRequest request) {
Collection<String> testDependencies = request.getTestDependencies();
if ( testDependencies.isEmpty() ) {
return TEST_COMPILATION_CLASSPATH;
}
List<String> testCompilationPaths = new ArrayList<>(
TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() );
testCompilationPaths.addAll( TEST_COMPILATION_CLASSPATH );
testCompilationPaths.addAll( filterBootClassPath( testDependencies ) );
return testCompilationPaths;
}
private static FilteringParentClassLoader newFilteringClassLoaderForEclipse() { private static FilteringParentClassLoader newFilteringClassLoaderForEclipse() {
return new FilteringParentClassLoader( return new FilteringParentClassLoader(
// reload eclipse compiler classes // reload eclipse compiler classes
@ -143,12 +160,12 @@ class EclipseCompilingExtension extends CompilingExtension {
} }
private static List<String> buildEclipseCompilerClasspath() { private static List<String> buildEclipseCompilerClasspath() {
String[] whitelist = Collection<String> whitelist = Arrays.asList(
new String[] {
"tycho-compiler", "tycho-compiler",
"ecj", "ecj",
"plexus-compiler-api", "plexus-compiler-api",
"plexus-component-annotations" }; "plexus-component-annotations"
);
return filterBootClassPath( whitelist ); return filterBootClassPath( whitelist );
} }

View File

@ -9,6 +9,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import javax.annotation.processing.Processor; import javax.annotation.processing.Processor;
@ -57,7 +58,7 @@ class JdkCompilingExtension extends CompilingExtension {
fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.getSourceClasses() ) ); fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.getSourceClasses() ) );
try { try {
fileManager.setLocation( StandardLocation.CLASS_PATH, COMPILER_CLASSPATH_FILES ); fileManager.setLocation( StandardLocation.CLASS_PATH, getCompilerClasspathFiles( compilationRequest ) );
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 ) ) );
} }
@ -97,6 +98,23 @@ class JdkCompilingExtension extends CompilingExtension {
diagnostics.getDiagnostics() ); diagnostics.getDiagnostics() );
} }
private static List<File> getCompilerClasspathFiles(CompilationRequest request) {
Collection<String> testDependencies = request.getTestDependencies();
if ( testDependencies.isEmpty() ) {
return COMPILER_CLASSPATH_FILES;
}
List<File> compilerClasspathFiles = new ArrayList<>(
COMPILER_CLASSPATH_FILES.size() + testDependencies.size() );
compilerClasspathFiles.addAll( COMPILER_CLASSPATH_FILES );
for ( String testDependencyPath : filterBootClassPath( testDependencies ) ) {
compilerClasspathFiles.add( new File( testDependencyPath ) );
}
return compilerClasspathFiles;
}
private static List<File> asFiles(List<String> paths) { private static List<File> asFiles(List<String> paths) {
List<File> classpath = new ArrayList<>(); List<File> classpath = new ArrayList<>();
for ( String path : paths ) { for ( String path : paths ) {