From 7d2932c9b58ba41ed5442093368a086bd29d8133 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Jan 2015 19:45:11 +0100 Subject: [PATCH] #390 included maven coordinates as comments in generated code --- processor/pom.xml | 15 ++++++++-- .../org/mapstruct/ap/model/GeneratedType.java | 30 +++++++++++++++++++ .../org.mapstruct.ap.model.GeneratedType.ftl | 3 +- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/processor/pom.xml b/processor/pom.xml index fe11f2e2d..b131b8f58 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -45,8 +45,8 @@ + these dependencies are not required at runtime, only for prism generation + and tests --> com.jolira hickory @@ -90,6 +90,17 @@ + + org.apache.maven.plugins + maven-jar-plugin + + + + true + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/processor/src/main/java/org/mapstruct/ap/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/model/GeneratedType.java index 56e35c4ec..766cf7725 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/model/GeneratedType.java @@ -18,11 +18,15 @@ */ package org.mapstruct.ap.model; +import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Enumeration; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import java.util.jar.Manifest; import javax.annotation.Generated; import org.mapstruct.ap.model.common.Accessibility; @@ -37,6 +41,9 @@ import org.mapstruct.ap.model.common.TypeFactory; */ public abstract class GeneratedType extends ModelElement { + private static final String COMMENT_TAG = "Implementation-Version"; + private static final String COMMENTS = initComment(); + private final String packageName; private final String name; private final String superClassName; @@ -118,6 +125,10 @@ public abstract class GeneratedType extends ModelElement { return accessibility; } + public String getComments() { + return COMMENTS; + } + @Override public SortedSet getImportTypes() { SortedSet importedTypes = new TreeSet(); @@ -168,4 +179,23 @@ public abstract class GeneratedType extends ModelElement { addWithDependents( collection, type ); } } + + private static String initComment() { + String result = null; + try { + Enumeration resources = GeneratedType.class.getClassLoader().getResources( "META-INF/MANIFEST.MF" ); + while ( resources.hasMoreElements() ) { + Manifest manifest = new Manifest( resources.nextElement().openStream() ); + String resultValue = manifest.getMainAttributes().getValue( COMMENT_TAG ); + if (resultValue != null ) { + result = COMMENT_TAG + ": " + resultValue; + break; + } + } + } + catch ( IOException ex ) { + return result; + } + return result; + } } diff --git a/processor/src/main/resources/org.mapstruct.ap.model.GeneratedType.ftl b/processor/src/main/resources/org.mapstruct.ap.model.GeneratedType.ftl index bf9bca96a..a3b384f08 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.GeneratedType.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.GeneratedType.ftl @@ -26,7 +26,8 @@ import ${importedType.importName}; @Generated( value = "org.mapstruct.ap.MappingProcessor"<#if suppressGeneratorTimestamp == false>, - date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}" + date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}"<#if comments??>, + comments = "${comments}" ) <#list annotations as annotation> <#nt><@includeModel object=annotation/>