HHH-12990 Auto-detect the fqcn of the Generated annotation in jpamodelgen
It's "javax.annotation.Generated" in Java 8 and below, but "javax.annotation.processing.Generated" in Java 9 and above.
This commit is contained in:
parent
a69de05e44
commit
b151f396f6
|
@ -198,7 +198,7 @@ public final class ClassWriter {
|
||||||
private static String writeGeneratedAnnotation(MetaEntity entity, Context context) {
|
private static String writeGeneratedAnnotation(MetaEntity entity, Context context) {
|
||||||
StringBuilder generatedAnnotation = new StringBuilder();
|
StringBuilder generatedAnnotation = new StringBuilder();
|
||||||
generatedAnnotation.append( "@" )
|
generatedAnnotation.append( "@" )
|
||||||
.append( entity.importType( "javax.annotation.Generated" ) )
|
.append( entity.importType( context.getGeneratedAnnotation().getQualifiedName().toString() ) )
|
||||||
.append( "(value = \"" )
|
.append( "(value = \"" )
|
||||||
.append( JPAMetaModelEntityProcessor.class.getName() );
|
.append( JPAMetaModelEntityProcessor.class.getName() );
|
||||||
if ( context.addGeneratedDate() ) {
|
if ( context.addGeneratedDate() ) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ public final class Context {
|
||||||
private final boolean lazyXmlParsing;
|
private final boolean lazyXmlParsing;
|
||||||
private final String persistenceXmlLocation;
|
private final String persistenceXmlLocation;
|
||||||
private final List<String> ormXmlFiles;
|
private final List<String> ormXmlFiles;
|
||||||
|
private final TypeElement generatedAnnotation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether all mapping files are xml-mapping-metadata-complete. In this case no annotation processing will take
|
* Whether all mapping files are xml-mapping-metadata-complete. In this case no annotation processing will take
|
||||||
|
@ -94,6 +95,16 @@ public final class Context {
|
||||||
|
|
||||||
lazyXmlParsing = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.LAZY_XML_PARSING ) );
|
lazyXmlParsing = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.LAZY_XML_PARSING ) );
|
||||||
logDebug = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.DEBUG_OPTION ) );
|
logDebug = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.DEBUG_OPTION ) );
|
||||||
|
|
||||||
|
TypeElement java8AndBelowGeneratedAnnotation =
|
||||||
|
pe.getElementUtils().getTypeElement( "javax.annotation.Generated" );
|
||||||
|
if ( java8AndBelowGeneratedAnnotation != null ) {
|
||||||
|
generatedAnnotation = java8AndBelowGeneratedAnnotation;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Using the new name for this annotation in Java 9 and above
|
||||||
|
generatedAnnotation = pe.getElementUtils().getTypeElement( "javax.annotation.processing.Generated" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessingEnvironment getProcessingEnvironment() {
|
public ProcessingEnvironment getProcessingEnvironment() {
|
||||||
|
@ -104,6 +115,10 @@ public final class Context {
|
||||||
return addGeneratedAnnotation;
|
return addGeneratedAnnotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeElement getGeneratedAnnotation() {
|
||||||
|
return generatedAnnotation;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) {
|
public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) {
|
||||||
this.addGeneratedAnnotation = addGeneratedAnnotation;
|
this.addGeneratedAnnotation = addGeneratedAnnotation;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue