#390 included maven coordinates as comments in generated code

This commit is contained in:
sjaakd 2015-01-18 19:45:11 +01:00
parent aa0e658f58
commit 7d2932c9b5
3 changed files with 45 additions and 3 deletions

View File

@ -45,8 +45,8 @@
</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 -->
these dependencies are not required at runtime, only for prism generation
and tests -->
<dependency>
<groupId>com.jolira</groupId>
<artifactId>hickory</artifactId>
@ -90,6 +90,17 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>

View File

@ -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<Type> getImportTypes() {
SortedSet<Type> importedTypes = new TreeSet<Type>();
@ -168,4 +179,23 @@ public abstract class GeneratedType extends ModelElement {
addWithDependents( collection, type );
}
}
private static String initComment() {
String result = null;
try {
Enumeration<URL> 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;
}
}

View File

@ -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")}"</#if>
date = "${.now?string("yyyy-MM-dd'T'HH:mm:ssZ")}"</#if><#if comments??>,
comments = "${comments}"</#if>
)
<#list annotations as annotation>
<#nt><@includeModel object=annotation/>