mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#390 included maven coordinates as comments in generated code
This commit is contained in:
parent
aa0e658f58
commit
7d2932c9b5
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user