METAGEN-79 Unified skipGeneratedAnnotation and addGeneratedAnnotation

This commit is contained in:
Hardy Ferentschik 2012-01-25 16:59:34 +01:00 committed by Strong Liu
parent d5110ad8bc
commit f946f60471
11 changed files with 84 additions and 92 deletions

View File

@ -0,0 +1,37 @@
# Hibernate JPA 2 Metamodel Generator
## Latest stable version
*1.2.0.Final, 06.03.2012*
## What is it?
The Hibernate JPA 2 Metamodel Generator is a Java 6 annotation processor generating meta model classes for JPA 2 type-safe criteria queries.
The processor (*JPAMetaModelEntityProcessor*) processes classes annotated with *@Entity*, *@MappedSuperclass* or *@Embeddable*, as well as entities mapped in */META-INF/orm.xml* and mapping files specified in *persistence.xml*.
## System Requirements
JDK 1.6 or above.
## Licensing
Please see the file called license.txt
## Documentation
[JPA 2 Metamodel Generator Documentation](http://www.hibernate.org/subprojects/jpamodelgen/docs)
## Resources
* [Home Page](http://www.hibernate.org/subprojects/jpamodelgen.html)
* [Source Code](http://github.com/hibernate/hibernate-metamodelgen)
* [Mailing Lists](http://www.hibernate.org/community/mailinglists)
* [Issue Tracking](http://opensource.atlassian.com/projects/hibernate/browse/METAGEN)
## Build from source
git clone git@github.com:hibernate/hibernate-metamodelgen.git
cd hibernate-metamodelgen
mvn clean package

View File

@ -1,6 +1,10 @@
Hibernate JPA 2 Metamodel Generator Changelog Hibernate JPA 2 Metamodel Generator Changelog
============================================= =============================================
1.2.0.Final (06.03.2012)
----------------------
1.2.0.CR1 (25.01.2012) 1.2.0.CR1 (25.01.2012)
---------------------- ----------------------

View File

@ -4,7 +4,7 @@
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId> <artifactId>hibernate-jpamodelgen</artifactId>
<version>1.2.0-SNAPSHOT</version> <version>1.3.0-SNAPSHOT</version>
<name>Hibernate JPA 2 Metamodel Generator</name> <name>Hibernate JPA 2 Metamodel Generator</name>
<description>Annotation Processor to generate JPA 2 static metamodel classes</description> <description>Annotation Processor to generate JPA 2 static metamodel classes</description>
@ -114,7 +114,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version> <version>1.0</version>
<executions> <executions>
<execution> <execution>
<id>enforce-java</id> <id>enforce-java</id>
@ -241,7 +241,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.2</version> <version>2.3.1</version>
<configuration> <configuration>
<archive> <archive>
<manifestEntries> <manifestEntries>
@ -258,26 +258,13 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version> <version>2.2.1</version>
<configuration> <configuration>
<descriptors> <descriptors>
<descriptor>src/main/assembly/dist.xml</descriptor> <descriptor>src/main/assembly/dist.xml</descriptor>
</descriptors> </descriptors>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-9</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<goals>package deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:resources
org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.1:generate assembly:assembly
</goals>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.jboss.maven.plugins</groupId> <groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId> <artifactId>maven-jdocbook-plugin</artifactId>
@ -337,6 +324,24 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<allowTimestampedSnapshots>true</allowTimestampedSnapshots>
<tagNameFormat>@{project.version}</tagNameFormat>
<goals>package deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:resources
org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:generate assembly:assembly
</goals>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -1,42 +0,0 @@
Hibernate JPA 2 Metamodel Generator
What is it?
-----------
This is a Java 6 annotation processor generating meta model classes for the JPA 2 criteria queries.
The processor (JPAMetaModelEntityProcessor) processes all classes annotated with @Entity, @MappedSuperclass
or @Embeddable, as well as entities mapped in /META-INF/orm.xml and mapping files specified in persistence.xml.
Latest stable version
-------------------
1.2.0.CR1, 25.01.2012
System Requirements
-------------------
JDK 1.6 or above.
Documentation
-------------
http://docs.jboss.org/hibernate/stable/jpamodelgen/reference/en-US/
Licensing
---------
Please see the file called license.txt
Resources
---------
Home Page: http://www.hibernate.org/subprojects/jpamodelgen.html
Mailing Lists: http://www.hibernate.org/community/mailinglists
Source Code: http://github.com/hibernate/hibernate-metamodelgen
Issue Tracking: http://opensource.atlassian.com/projects/hibernate/browse/METAGEN

View File

@ -59,7 +59,7 @@
<includes> <includes>
<include>pom.xml</include> <include>pom.xml</include>
<include>license.txt</include> <include>license.txt</include>
<include>readme.txt</include> <include>README.md</include>
<include>changelog.txt</include> <include>changelog.txt</include>
<include>src/**</include> <include>src/**</include>
</includes> </includes>

View File

@ -550,22 +550,12 @@ cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
<row> <row>
<entry>addGeneratedAnnotation</entry> <entry>addGeneratedAnnotation</entry>
<entry>this option is deprecated and has no effect. The
<classname>@Generation</classname> annotation is added per
default.</entry>
</row>
<row>
<entry>skipGeneratedAnnotation</entry>
<entry>If set to <literal>true</literal> the processor will <entry>If set to <literal>true</literal> the processor will
not the <classname>@Generated</classname> to the generated add the <classname>@Generated</classname> to the generated
Java source file. The default for this option is Java source file. Adding this annotation using JDK 5will cause
<constant>false</constant> and the a compilation error. In this case set the flag to
<classname>@Generated</classname> annotation is added to the <constant>false</constant>. The default for this option is
source code. Adding this annotation using JDK 5will cause a <constant>true</constant></entry>
compilation error. In this case set the flag to
<constant>true</constant>.</entry>
</row> </row>
<row> <row>
@ -575,8 +565,8 @@ cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
of the metamodel class will be inserted in the date parameter of the metamodel class will be inserted in the date parameter
of the <classname>@Generated</classname> annotation. The of the <classname>@Generated</classname> annotation. The
default is <constant>false</constant>. This parameter is default is <constant>false</constant>. This parameter is
ignored if <constant>skipGeneratedAnnotation</constant> is ignored if <constant>addGeneratedAnnotation</constant> is set
specified.</entry> to <constant>false</constant>.</entry>
</row> </row>
<row> <row>

View File

@ -106,7 +106,7 @@ public final class ClassWriter {
try { try {
pw = new PrintWriter( sw ); pw = new PrintWriter( sw );
if ( !context.skipGeneratedAnnotation() ) { if ( context.addGeneratedAnnotation() ) {
pw.println( writeGeneratedAnnotation( entity, context ) ); pw.println( writeGeneratedAnnotation( entity, context ) );
} }
if ( context.isAddSuppressWarningsAnnotation() ) { if ( context.isAddSuppressWarningsAnnotation() ) {

View File

@ -61,7 +61,7 @@ public final class Context {
private final List<String> ormXmlFiles; private final List<String> ormXmlFiles;
private boolean isPersistenceUnitCompletelyXmlConfigured; private boolean isPersistenceUnitCompletelyXmlConfigured;
private boolean skipGeneratedAnnotation; private boolean addGeneratedAnnotation = true;
private boolean addGenerationDate; private boolean addGenerationDate;
private boolean addSuppressWarningsAnnotation; private boolean addSuppressWarningsAnnotation;
private AccessType persistenceUnitDefaultAccessType; private AccessType persistenceUnitDefaultAccessType;
@ -102,12 +102,12 @@ public final class Context {
return pe; return pe;
} }
public boolean skipGeneratedAnnotation() { public boolean addGeneratedAnnotation() {
return skipGeneratedAnnotation; return addGeneratedAnnotation;
} }
public void setSkipGeneratedAnnotation(boolean skipGeneratedAnnotation) { public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) {
this.skipGeneratedAnnotation = skipGeneratedAnnotation; this.addGeneratedAnnotation = addGeneratedAnnotation;
} }
public boolean addGeneratedDate() { public boolean addGeneratedDate() {

View File

@ -63,7 +63,6 @@ import org.hibernate.jpamodelgen.xml.XmlParser;
JPAMetaModelEntityProcessor.ORM_XML_OPTION, JPAMetaModelEntityProcessor.ORM_XML_OPTION,
JPAMetaModelEntityProcessor.FULLY_ANNOTATION_CONFIGURED_OPTION, JPAMetaModelEntityProcessor.FULLY_ANNOTATION_CONFIGURED_OPTION,
JPAMetaModelEntityProcessor.LAZY_XML_PARSING, JPAMetaModelEntityProcessor.LAZY_XML_PARSING,
JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION,
JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION, JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION,
JPAMetaModelEntityProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION JPAMetaModelEntityProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION
}) })
@ -73,11 +72,7 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
public static final String ORM_XML_OPTION = "ormXml"; public static final String ORM_XML_OPTION = "ormXml";
public static final String FULLY_ANNOTATION_CONFIGURED_OPTION = "fullyAnnotationConfigured"; public static final String FULLY_ANNOTATION_CONFIGURED_OPTION = "fullyAnnotationConfigured";
public static final String LAZY_XML_PARSING = "lazyXmlParsing"; public static final String LAZY_XML_PARSING = "lazyXmlParsing";
public static final String SKIP_GENERATED_ANNOTATION = "skipGeneratedAnnotation";
public static final String ADD_GENERATION_DATE = "addGenerationDate"; public static final String ADD_GENERATION_DATE = "addGenerationDate";
/**
* @deprecated since 1.2
*/
public static final String ADD_GENERATED_ANNOTATION = "addGeneratedAnnotation"; public static final String ADD_GENERATED_ANNOTATION = "addGeneratedAnnotation";
public static final String ADD_SUPPRESS_WARNINGS_ANNOTATION = "addSuppressWarningsAnnotation"; public static final String ADD_SUPPRESS_WARNINGS_ANNOTATION = "addSuppressWarningsAnnotation";
@ -93,9 +88,11 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString() Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString()
); );
String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION ); String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION );
boolean addGeneratedAnnotation = Boolean.parseBoolean( tmp ); if ( tmp != null ) {
context.setSkipGeneratedAnnotation( addGeneratedAnnotation ); boolean addGeneratedAnnotation = Boolean.parseBoolean( tmp );
context.setAddGeneratedAnnotation( addGeneratedAnnotation );
}
tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATION_DATE ); tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATION_DATE );
boolean addGenerationDate = Boolean.parseBoolean( tmp ); boolean addGenerationDate = Boolean.parseBoolean( tmp );

View File

@ -90,6 +90,7 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6<Annotatio
return new AnnotationMetaSingleAttribute( entity, element, TypeUtils.toTypeString( t ) ); return new AnnotationMetaSingleAttribute( entity, element, TypeUtils.toTypeString( t ) );
} }
@Override
public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) { public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) {
// METAGEN-29 - for a type variable we use the upper bound // METAGEN-29 - for a type variable we use the upper bound
TypeMirror mirror = t.getUpperBound(); TypeMirror mirror = t.getUpperBound();

View File

@ -48,7 +48,7 @@ public class SkipGeneratedAnnotationTest extends CompilationTest {
@Override @Override
protected Map<String, String> getProcessorOptions() { protected Map<String, String> getProcessorOptions() {
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<String, String>();
properties.put( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION, "true" ); properties.put( JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION, "false" );
return properties; return properties;
} }