METAGEN-79 Adding skipGeneratedAnnotation flag. Deprecating addGeneratedAnnotation.
This commit is contained in:
parent
4ac9cbfdb3
commit
4c968d7f7a
|
@ -550,12 +550,22 @@ cq.where( cb.equal(itemNode.get(Item_.id), 5 ) ).distinct(true);
|
|||
<row>
|
||||
<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
|
||||
add the <classname>@Generated</classname> to the generated
|
||||
Java source file. Per default this annotation is not
|
||||
generated, because the code would not compile under JDK 5. If
|
||||
you are using a JDK 6 you can force the generation of this
|
||||
annotation using this flag.</entry>
|
||||
not the <classname>@Generated</classname> to the generated
|
||||
Java source file. The default for this option is
|
||||
<constant>false</constant> and the
|
||||
<classname>@Generated</classname> annotation is added to the
|
||||
source code. Adding this annotation using JDK 5will cause a
|
||||
compilation error. In this case set the flag to
|
||||
<constant>true</constant>.</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
|
|
|
@ -95,7 +95,7 @@ public final class ClassWriter {
|
|||
PrintWriter pw = null;
|
||||
try {
|
||||
pw = new PrintWriter( sw );
|
||||
if ( context.isAddGeneratedAnnotation() ) {
|
||||
if ( !context.skipGeneratedAnnotation() ) {
|
||||
pw.println( writeGeneratedAnnotation( entity ) );
|
||||
}
|
||||
if ( context.isAddSuppressWarningsAnnotation() ) {
|
||||
|
|
|
@ -61,7 +61,7 @@ public final class Context {
|
|||
private final List<String> ormXmlFiles;
|
||||
|
||||
private boolean isPersistenceUnitCompletelyXmlConfigured;
|
||||
private boolean addGeneratedAnnotation;
|
||||
private boolean skipGeneratedAnnotation;
|
||||
private boolean addSuppressWarningsAnnotation;
|
||||
private AccessType persistenceUnitDefaultAccessType;
|
||||
|
||||
|
@ -101,12 +101,12 @@ public final class Context {
|
|||
return pe;
|
||||
}
|
||||
|
||||
public boolean isAddGeneratedAnnotation() {
|
||||
return addGeneratedAnnotation;
|
||||
public boolean skipGeneratedAnnotation() {
|
||||
return skipGeneratedAnnotation;
|
||||
}
|
||||
|
||||
public void setAddGeneratedAnnotation(boolean addGeneratedAnnotation) {
|
||||
this.addGeneratedAnnotation = addGeneratedAnnotation;
|
||||
public void setSkipGeneratedAnnotation(boolean skipGeneratedAnnotation) {
|
||||
this.skipGeneratedAnnotation = skipGeneratedAnnotation;
|
||||
}
|
||||
|
||||
public boolean isAddSuppressWarningsAnnotation() {
|
||||
|
|
|
@ -63,6 +63,7 @@ import org.hibernate.jpamodelgen.xml.XmlParser;
|
|||
JPAMetaModelEntityProcessor.ORM_XML_OPTION,
|
||||
JPAMetaModelEntityProcessor.FULLY_ANNOTATION_CONFIGURED_OPTION,
|
||||
JPAMetaModelEntityProcessor.LAZY_XML_PARSING,
|
||||
JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION,
|
||||
JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION,
|
||||
JPAMetaModelEntityProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION
|
||||
})
|
||||
|
@ -72,6 +73,10 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
|||
public static final String ORM_XML_OPTION = "ormXml";
|
||||
public static final String FULLY_ANNOTATION_CONFIGURED_OPTION = "fullyAnnotationConfigured";
|
||||
public static final String LAZY_XML_PARSING = "lazyXmlParsing";
|
||||
public static final String SKIP_GENERATED_ANNOTATION = "skipGeneratedAnnotation";
|
||||
/**
|
||||
* @deprecated since 1.2
|
||||
*/
|
||||
public static final String ADD_GENERATED_ANNOTATION = "addGeneratedAnnotation";
|
||||
public static final String ADD_SUPPRESS_WARNINGS_ANNOTATION = "addSuppressWarningsAnnotation";
|
||||
|
||||
|
@ -87,9 +92,9 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
|||
Diagnostic.Kind.NOTE, "Hibernate JPA 2 Static-Metamodel Generator " + Version.getVersionString()
|
||||
);
|
||||
|
||||
String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION );
|
||||
String tmp = env.getOptions().get( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION );
|
||||
boolean addGeneratedAnnotation = Boolean.parseBoolean( tmp );
|
||||
context.setAddGeneratedAnnotation( addGeneratedAnnotation );
|
||||
context.setSkipGeneratedAnnotation( addGeneratedAnnotation );
|
||||
|
||||
tmp = env.getOptions().get( JPAMetaModelEntityProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION );
|
||||
boolean addSuppressWarningsAnnotation = Boolean.parseBoolean( tmp );
|
||||
|
|
|
@ -19,10 +19,11 @@ package org.hibernate.jpamodelgen.test.generatedannotation;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.TestForIssue;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetaModelSourceAsString;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
|
@ -30,12 +31,13 @@ import static org.testng.Assert.assertFalse;
|
|||
public class GeneratedAnnotationTest extends CompilationTest {
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "METAGEN-79")
|
||||
public void testGeneratedAnnotationNotGenerated() {
|
||||
assertMetamodelClassGeneratedFor( TestEntity.class );
|
||||
|
||||
// need to check the source because @Generated is not a runtime annotation
|
||||
String metaModelSource = getMetaModelSourceAsString( TestEntity.class );
|
||||
assertFalse( metaModelSource.contains( "@Generated" ), "@Generated should not be added to the metamodel." );
|
||||
assertTrue( metaModelSource.contains( "@Generated" ), "@Generated should be added to the metamodel." );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,36 +25,35 @@ import org.testng.annotations.Test;
|
|||
|
||||
import org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor;
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.TestForIssue;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetaModelSourceAsString;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class GeneratedAnnotationTest2 extends CompilationTest {
|
||||
public class SkipGeneratedAnnotationTest extends CompilationTest {
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "METAGEN-79")
|
||||
public void testGeneratedAnnotationGenerated() {
|
||||
assertMetamodelClassGeneratedFor( TestEntity.class );
|
||||
|
||||
// need to check the source because @Generated is not a runtime annotation
|
||||
String metaModelSource = getMetaModelSourceAsString( TestEntity.class );
|
||||
assertTrue( metaModelSource.contains( "@Generated" ), "@Generated should be added to the metamodel." );
|
||||
assertFalse( metaModelSource.contains( "@Generated" ), "@Generated should not be added to the metamodel." );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getProcessorOptions() {
|
||||
Map<String, String> properties = new HashMap<String, String>();
|
||||
properties.put(
|
||||
JPAMetaModelEntityProcessor.ADD_GENERATED_ANNOTATION,
|
||||
"true"
|
||||
);
|
||||
properties.put( JPAMetaModelEntityProcessor.SKIP_GENERATED_ANNOTATION, "true" );
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPackageNameOfCurrentTest() {
|
||||
return GeneratedAnnotationTest2.class.getPackage().getName();
|
||||
return SkipGeneratedAnnotationTest.class.getPackage().getName();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue