Skip to content

Commit

Permalink
#2011 Introduce gem as replacement of hickory:prism (#2007)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaakd committed Jan 27, 2020
1 parent 6b49c83 commit 2d37610
Show file tree
Hide file tree
Showing 52 changed files with 836 additions and 772 deletions.
Expand Up @@ -10,8 +10,8 @@
<!-- the annotation processor may not use the annotations or enums specified in org.mapstruct directly... -->
<disallow pkg="org.mapstruct" exact-match="true" />

<subpackage name="internal.prism">
<!-- ... with exception to the package org.mapstruct.ap.internal.prism -->
<subpackage name="internal.gem">
<!-- ... with exception to the package org.mapstruct.ap.internal.gem -->
<allow pkg=".*" regex="true" />
</subpackage>
<subpackage name="test">
Expand Down
17 changes: 11 additions & 6 deletions parent/pom.xml
Expand Up @@ -21,7 +21,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<com.jolira.hickory.version>1.0.0</com.jolira.hickory.version>
<org.mapstruct.gem.version>1.0.0.Alpha1</org.mapstruct.gem.version>
<!-- We can't go to 3.0.0-M2 as it has a regression. See https://issues.apache.org/jira/browse/MENFORCER-306 -->
<org.apache.maven.plugins.enforcer.version>3.0.0-M1</org.apache.maven.plugins.enforcer.version>
<org.apache.maven.plugins.surefire.version>3.0.0-M3</org.apache.maven.plugins.surefire.version>
Expand Down Expand Up @@ -109,9 +109,14 @@
<version>19.0</version>
</dependency>
<dependency>
<groupId>com.jolira</groupId>
<artifactId>hickory</artifactId>
<version>${com.jolira.hickory.version}</version>
<groupId>org.mapstruct.tools.gem</groupId>
<artifactId>gem-api</artifactId>
<version>${org.mapstruct.gem.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct.tools.gem</groupId>
<artifactId>gem-processor</artifactId>
<version>${org.mapstruct.gem.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -287,7 +292,7 @@
specified as patterns within a source folder, so we can't exclude generated-sources
altogether
-->
<excludes>**/*Prism.java,*/itest/jaxb/xsd/*</excludes>
<excludes>**/*Gem.java,*/itest/jaxb/xsd/*</excludes>
</configuration>
<dependencies>
<dependency>
Expand Down Expand Up @@ -376,7 +381,7 @@
<version>${org.apache.maven.plugins.javadoc.version}</version>
<configuration>
<quiet>true</quiet>
<excludePackageNames>org.mapstruct.ap.internal.prism;org.mapstruct.itest.jaxb.xsd.*</excludePackageNames>
<excludePackageNames>org.mapstruct.ap.internal.gem;org.mapstruct.itest.jaxb.xsd.*</excludePackageNames>
<source>8</source>
</configuration>
</plugin>
Expand Down
42 changes: 28 additions & 14 deletions processor/pom.xml
Expand Up @@ -32,18 +32,9 @@
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>

<!-- Compile-only; Using "provided" scope as there is no such scope in Maven;
these dependencies are not required at runtime, only for prism generation
and tests -->
<!-- Using optional as well due to IntelliJ picking up the dependency
and running the hickory processor in projects using the mapstruct-processor.
This happens only when the processor is defined in the maven-compiler annotationProcessorPaths -->
<dependency>
<groupId>com.jolira</groupId>
<artifactId>hickory</artifactId>
<scope>provided</scope>
<optional>true</optional>
<groupId>org.mapstruct.tools.gem</groupId>
<artifactId>gem-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -182,19 +173,37 @@
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>org.freemarker:*</include>
<include>org.mapstruct.tools.gem:gem-api</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>org.freemarker:freemarker</artifact>
<excludes>
<exclude>META-INF/*.*</exclude>
</excludes>
</filter>
<filter>
<artifact>org.mapstruct.tools.gem:gem-api</artifact>
<excludes>
<exclude>META-INF/*.*</exclude>
<exclude>**/GemDefinition.class</exclude>
<exclude>**/GemDefinitions.class</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>freemarker</pattern>
<shadedPattern>org.mapstruct.ap.shaded.freemarker</shadedPattern>
</relocation>
<relocation>
<pattern>org.mapstruct.tools.gem</pattern>
<shadedPattern>org.mapstruct.ap.shaded.org.mapstruct.tools.gem</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down Expand Up @@ -227,9 +236,14 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessors>
<annotationProcessor>net.java.dev.hickory.prism.internal.PrismGenerator</annotationProcessor>
</annotationProcessors>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct.tools.gem</groupId>
<artifactId>gem-processor</artifactId>
<version>${org.mapstruct.gem.version}</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
12 changes: 6 additions & 6 deletions processor/src/main/java/org/mapstruct/ap/MappingProcessor.java
Expand Up @@ -34,8 +34,8 @@

import org.mapstruct.ap.internal.model.Mapper;
import org.mapstruct.ap.internal.option.Options;
import org.mapstruct.ap.internal.prism.MapperPrism;
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
import org.mapstruct.ap.internal.gem.MapperGem;
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
import org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext;
import org.mapstruct.ap.internal.processor.ModelElementProcessor;
import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext;
Expand Down Expand Up @@ -66,8 +66,8 @@
* <li>if no error occurred, write out the model into Java source files</li>
* </ul>
* <p>
* For reading annotation attributes, prisms as generated with help of the <a
* href="https://java.net/projects/hickory">Hickory</a> tool are used. These prisms allow a comfortable access to
* For reading annotation attributes, gems as generated with help of the <a
* href="https://java.net/projects/hickory">Hickory</a> tool are used. These gems allow a comfortable access to
* annotations and their attributes without depending on their class objects.
* <p>
* The creation of Java source files is done using the <a href="http://freemarker.org/"> FreeMarker</a> template engine.
Expand Down Expand Up @@ -137,7 +137,7 @@ private Options createOptions() {
return new Options(
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ),
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ),
unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null,
unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null,
processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ),
processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ),
Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ),
Expand Down Expand Up @@ -236,7 +236,7 @@ private Set<TypeElement> getMappers(final Set<? extends TypeElement> annotations

// on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with
// annotations unknown to the compiler, even though they are not declared Mappers
if ( mapperTypeElement != null && MapperPrism.getInstanceOn( mapperTypeElement ) != null ) {
if ( mapperTypeElement != null && MapperGem.instanceOn( mapperTypeElement ) != null ) {
mapperTypes.add( mapperTypeElement );
}
}
Expand Down
Expand Up @@ -3,14 +3,14 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;

/**
* Prism for the enum {@link org.mapstruct.CollectionMappingStrategy}
* Gem for the enum {@link org.mapstruct.CollectionMappingStrategy}
*
* @author Andreas Gudian
*/
public enum CollectionMappingStrategyPrism {
public enum CollectionMappingStrategyGem {

ACCESSOR_ONLY,
SETTER_PREFERRED,
Expand Down
@@ -0,0 +1,65 @@
/*
* 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.gem;

import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlElementRef;

import org.mapstruct.AfterMapping;
import org.mapstruct.BeanMapping;
import org.mapstruct.BeforeMapping;
import org.mapstruct.Builder;
import org.mapstruct.Context;
import org.mapstruct.DecoratedWith;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.IterableMapping;
import org.mapstruct.MapMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MapperConfig;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.ObjectFactory;
import org.mapstruct.Qualifier;
import org.mapstruct.TargetType;
import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings;
import org.mapstruct.tools.gem.GemDefinition;

/**
* Triggers the generation of ge types using <a href="https://java.net/projects/hickory">Hickory</a>.
*
* @author Gunnar Morling
*/
@GemDefinition(Mapper.class)
@GemDefinition(Mapping.class)
@GemDefinition(Mappings.class)
@GemDefinition(IterableMapping.class)
@GemDefinition(BeanMapping.class)
@GemDefinition(MapMapping.class)
@GemDefinition(TargetType.class)
@GemDefinition(MappingTarget.class)
@GemDefinition(DecoratedWith.class)
@GemDefinition(MapperConfig.class)
@GemDefinition(InheritConfiguration.class)
@GemDefinition(InheritInverseConfiguration.class)
@GemDefinition(Qualifier.class)
@GemDefinition(Named.class)
@GemDefinition(ObjectFactory.class)
@GemDefinition(AfterMapping.class)
@GemDefinition(BeforeMapping.class)
@GemDefinition(ValueMapping.class)
@GemDefinition(ValueMappings.class)
@GemDefinition(Context.class)
@GemDefinition(Builder.class)

// external types
@GemDefinition(XmlElementDecl.class)
@GemDefinition(XmlElementRef.class)
public class GemGenerator {
}
Expand Up @@ -3,14 +3,14 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;

/**
* Prism for the enum {@link org.mapstruct.InjectionStrategy}.
* Gem for the enum {@link org.mapstruct.InjectionStrategy}.
*
* @author Kevin Grüneberg
*/
public enum InjectionStrategyPrism {
public enum InjectionStrategyGem {

FIELD,
CONSTRUCTOR;
Expand Down
Expand Up @@ -3,16 +3,16 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;

/**
* Prism for the enum {@link org.mapstruct.MappingConstants}
* Gem for the enum {@link org.mapstruct.MappingConstants}
*
* @author Sjaak Derksen
*/
public final class MappingConstantsPrism {
public final class MappingConstantsGem {

private MappingConstantsPrism() {
private MappingConstantsGem() {
}

public static final String NULL = "<NULL>";
Expand Down
Expand Up @@ -3,15 +3,15 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;


/**
* Prism for the enum {@link org.mapstruct.MappingInheritanceStrategy}
* Gem for the enum {@link org.mapstruct.MappingInheritanceStrategy}
*
* @author Andreas Gudian
*/
public enum MappingInheritanceStrategyPrism {
public enum MappingInheritanceStrategyGem {

EXPLICIT( false, false, false ),
AUTO_INHERIT_FROM_CONFIG( true, true, false ),
Expand All @@ -22,7 +22,7 @@ public enum MappingInheritanceStrategyPrism {
private final boolean applyForward;
private final boolean applyReverse;

MappingInheritanceStrategyPrism(boolean isAutoInherit, boolean applyForward, boolean applyReverse) {
MappingInheritanceStrategyGem(boolean isAutoInherit, boolean applyForward, boolean applyReverse) {
this.autoInherit = isAutoInherit;
this.applyForward = applyForward;
this.applyReverse = applyReverse;
Expand Down
Expand Up @@ -3,15 +3,15 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;


/**
* Prism for the enum {@link org.mapstruct.NullValueCheckStrategy}
* Gem for the enum {@link org.mapstruct.NullValueCheckStrategy}
*
* @author Sean Huang
*/
public enum NullValueCheckStrategyPrism {
public enum NullValueCheckStrategyGem {

ON_IMPLICIT_CONVERSION,
ALWAYS;
Expand Down
Expand Up @@ -3,21 +3,21 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;

/**
* Prism for the enum {@link org.mapstruct.NullValueMappingStrategy}
* Gem for the enum {@link org.mapstruct.NullValueMappingStrategy}
*
* @author Sjaak Derksen
*/
public enum NullValueMappingStrategyPrism {
public enum NullValueMappingStrategyGem {

RETURN_NULL( false ),
RETURN_DEFAULT( true );

private final boolean returnDefault;

NullValueMappingStrategyPrism(boolean returnDefault) {
NullValueMappingStrategyGem(boolean returnDefault) {
this.returnDefault = returnDefault;
}

Expand Down
Expand Up @@ -3,15 +3,15 @@
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.prism;
package org.mapstruct.ap.internal.gem;


/**
* Prism for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy}
* Gem for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy}
*
* @author Sjaak Derksen
*/
public enum NullValuePropertyMappingStrategyPrism {
public enum NullValuePropertyMappingStrategyGem {

SET_TO_NULL,
SET_TO_DEFAULT,
Expand Down

0 comments on commit 2d37610

Please sign in to comment.