o Add option to suppress timestamp in @Generated

This commit is contained in:
Andreas Gudian 2013-05-13 21:09:06 +02:00
parent c247bfbe5b
commit 1d52cb434e
7 changed files with 65 additions and 7 deletions

View File

@ -60,6 +60,10 @@
<processors> <processors>
<processor>org.mapstruct.ap.MappingProcessor</processor> <processor>org.mapstruct.ap.MappingProcessor</processor>
</processors> </processors>
<options>
<!-- suppressGeneratorTimestamp=false is the default -->
<suppressGeneratorTimestamp>false</suppressGeneratorTimestamp>
</options>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>

View File

@ -141,7 +141,7 @@
<plugin> <plugin>
<groupId>org.bsc.maven</groupId> <groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId> <artifactId>maven-processor-plugin</artifactId>
<version>2.0.2</version> <version>2.0.4</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -42,6 +42,7 @@ import org.mapstruct.ap.conversion.Conversions;
import org.mapstruct.ap.model.BeanMapping; import org.mapstruct.ap.model.BeanMapping;
import org.mapstruct.ap.model.Mapper; import org.mapstruct.ap.model.Mapper;
import org.mapstruct.ap.model.MappingMethod; import org.mapstruct.ap.model.MappingMethod;
import org.mapstruct.ap.model.Options;
import org.mapstruct.ap.model.PropertyMapping; import org.mapstruct.ap.model.PropertyMapping;
import org.mapstruct.ap.model.Type; import org.mapstruct.ap.model.Type;
import org.mapstruct.ap.model.source.MappedProperty; import org.mapstruct.ap.model.source.MappedProperty;
@ -62,12 +63,14 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
private final Types typeUtils; private final Types typeUtils;
private final Elements elementUtils; private final Elements elementUtils;
private final TypeUtil typeUtil; private final TypeUtil typeUtil;
private final Options options;
public MapperGenerationVisitor(ProcessingEnvironment processingEnvironment) { public MapperGenerationVisitor(ProcessingEnvironment processingEnvironment, Options options) {
this.processingEnvironment = processingEnvironment; this.processingEnvironment = processingEnvironment;
this.typeUtils = processingEnvironment.getTypeUtils(); this.typeUtils = processingEnvironment.getTypeUtils();
this.elementUtils = processingEnvironment.getElementUtils(); this.elementUtils = processingEnvironment.getElementUtils();
this.typeUtil = new TypeUtil( elementUtils, typeUtils ); this.typeUtil = new TypeUtil( elementUtils, typeUtils );
this.options = options;
} }
@Override @Override
@ -103,7 +106,8 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
element.getSimpleName().toString(), element.getSimpleName().toString(),
element.getSimpleName() + IMPLEMENTATION_SUFFIX, element.getSimpleName() + IMPLEMENTATION_SUFFIX,
mappings, mappings,
usedMapperTypes usedMapperTypes,
options
); );
return mapper; return mapper;

View File

@ -30,6 +30,7 @@ import net.java.dev.hickory.prism.GeneratePrisms;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.ap.model.Options;
@SupportedAnnotationTypes("org.mapstruct.Mapper") @SupportedAnnotationTypes("org.mapstruct.Mapper")
@GeneratePrisms({ @GeneratePrisms({
@ -44,9 +45,15 @@ public class MappingProcessor extends AbstractProcessor {
*/ */
private static final boolean ANNOTATIONS_CLAIMED_EXCLUSIVELY = false; private static final boolean ANNOTATIONS_CLAIMED_EXCLUSIVELY = false;
private static final String SUPPRESS_GENERATOR_TIMESTAMP = "suppressGeneratorTimestamp";
private Options options;
@Override @Override
public synchronized void init(ProcessingEnvironment processingEnv) { public synchronized void init(ProcessingEnvironment processingEnv) {
super.init( processingEnv ); super.init( processingEnv );
options = createOptions();
} }
@Override @Override
@ -68,10 +75,15 @@ public class MappingProcessor extends AbstractProcessor {
} }
for ( Element oneAnnotatedElement : roundEnvironment.getElementsAnnotatedWith( oneAnnotation ) ) { for ( Element oneAnnotatedElement : roundEnvironment.getElementsAnnotatedWith( oneAnnotation ) ) {
oneAnnotatedElement.accept( new MapperGenerationVisitor( processingEnv ), null ); oneAnnotatedElement.accept( new MapperGenerationVisitor( processingEnv, options ), null );
} }
} }
return ANNOTATIONS_CLAIMED_EXCLUSIVELY; return ANNOTATIONS_CLAIMED_EXCLUSIVELY;
} }
private Options createOptions() {
System.out.println( processingEnv.getOptions() );
return new Options(Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP )));
}
} }

View File

@ -24,14 +24,16 @@ public class Mapper {
private final String implementationName; private final String implementationName;
private final List<BeanMapping> beanMappings; private final List<BeanMapping> beanMappings;
private final List<Type> usedMapperTypes; private final List<Type> usedMapperTypes;
private final Options options;
public Mapper(String packageName, String interfaceName, public Mapper(String packageName, String interfaceName,
String implementationName, List<BeanMapping> beanMappings, List<Type> usedMapperTypes) { String implementationName, List<BeanMapping> beanMappings, List<Type> usedMapperTypes, Options options) {
this.packageName = packageName; this.packageName = packageName;
this.interfaceName = interfaceName; this.interfaceName = interfaceName;
this.implementationName = implementationName; this.implementationName = implementationName;
this.beanMappings = beanMappings; this.beanMappings = beanMappings;
this.usedMapperTypes = usedMapperTypes; this.usedMapperTypes = usedMapperTypes;
this.options = options;
} }
@Override @Override
@ -72,4 +74,9 @@ public class Mapper {
public List<Type> getUsedMapperTypes() { public List<Type> getUsedMapperTypes() {
return usedMapperTypes; return usedMapperTypes;
} }
public Options getOptions()
{
return options;
}
} }

View File

@ -0,0 +1,31 @@
/**
* Copyright 2012-2013 Gunnar Morling (http://www.gunnarmorling.de/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.ap.model;
public class Options
{
private final boolean suppressGeneratorTimestamp;
public Options( boolean suppressGeneratorTimestamp )
{
this.suppressGeneratorTimestamp = suppressGeneratorTimestamp;
}
public boolean isSuppressGeneratorTimestamp()
{
return suppressGeneratorTimestamp;
}
}

View File

@ -26,8 +26,8 @@ import javax.annotation.Generated;
import java.util.Date; import java.util.Date;
@Generated( @Generated(
value = "org.mapstruct.ap.MappingProcessor", value = "org.mapstruct.ap.MappingProcessor"<#if options.suppressGeneratorTimestamp == false>,
date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}" date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}"</#if>
) )
public class ${implementationName} implements ${interfaceName} { public class ${implementationName} implements ${interfaceName} {