You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by GitBox <gi...@apache.org> on 2021/11/30 10:36:01 UTC

[GitHub] [openjpa] bmarwell opened a new pull request #90: [OPENJPA-2891] allow configuration of @Generated annotation.

bmarwell opened a new pull request #90:
URL: https://github.com/apache/openjpa/pull/90


   Question: The annotation dependency is only necessary if compiled with Java9+, but this project cannot be compiled with Java9+ at the moment. I can remove it if you would like me to.
   
   Also, this is my first OpenJPA commit. Please review the code style.
   
   Logic: 
   * If nothing is set, try to see if the annotation is on the classpath and we are on Java6+.
   * If `-Aopenjpa.addGeneratedAnnotation=false` is set, the annotation is never added.
   * If `-Aopenjpa.addGeneratedAnnotation=force` is set, the annotation is always added (regardless of classpath availability and/or Java version).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openjpa] rmannibucau commented on a change in pull request #90: [OPENJPA-2891] allow configuration of @Generated annotation.

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #90:
URL: https://github.com/apache/openjpa/pull/90#discussion_r759147173



##########
File path: openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
##########
@@ -311,10 +314,26 @@ private void annotate(SourceCode source, String originalClass) {
         SourceCode.Class cls = source.getTopLevelClass();
         cls.addAnnotation(StaticMetamodel.class.getName())
             .addArgument("value", originalClass + ".class", false);
-        if (generatedSourceVersion >= 6) {
-            cls.addAnnotation(Generated.class.getName())
-            .addArgument("value", this.getClass().getName())
-            .addArgument("date", new Date().toString());
+        if ("false".equals(this.addGeneratedOption)) {
+            return;
+        }
+
+        if ("force".equals(this.addGeneratedOption)) {
+            cls.addAnnotation(javax.annotation.Generated.class.getName())
+                    .addArgument("value", this.getClass().getName())
+                    .addArgument("date", new Date().toString());

Review comment:
       know it was "before" but can be worth storing the date in init if needed (once the forName moved there it will be easy to know)

##########
File path: openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
##########
@@ -311,10 +314,26 @@ private void annotate(SourceCode source, String originalClass) {
         SourceCode.Class cls = source.getTopLevelClass();
         cls.addAnnotation(StaticMetamodel.class.getName())
             .addArgument("value", originalClass + ".class", false);
-        if (generatedSourceVersion >= 6) {
-            cls.addAnnotation(Generated.class.getName())
-            .addArgument("value", this.getClass().getName())
-            .addArgument("date", new Date().toString());
+        if ("false".equals(this.addGeneratedOption)) {
+            return;
+        }
+
+        if ("force".equals(this.addGeneratedOption)) {
+            cls.addAnnotation(javax.annotation.Generated.class.getName())
+                    .addArgument("value", this.getClass().getName())
+                    .addArgument("date", new Date().toString());
+        }
+
+        try {
+            // only add the annotation if it is on the classpath for Java 6+.
+            Class<?> generatedAnnotation = Class.forName("javax.annotation.Generated", false, null);

Review comment:
       guess we want to do it in init and not each time

##########
File path: openjpa-persistence/pom.xml
##########
@@ -60,5 +60,10 @@
             <version>4.2.0</version>
             <scope>provided</scope>
         </dependency>
+        <!-- annotation javax.annotation.Generated -->
+        <dependency>
+            <groupId>javax.annotation</groupId>

Review comment:
       provided?

##########
File path: openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
##########
@@ -379,6 +398,19 @@ private void setHeader() {
         }
     }
 
+    private void setAddGeneratedAnnotation() {
+        String addGeneratedOption = getOptionValue("openjpa.addGeneratedAnnotation");

Review comment:
       `this.addGeneratedOption = getOptionValue("openjpa.addGeneratedAnnotation")` ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openjpa] bmarwell commented on a change in pull request #90: [OPENJPA-2891] allow configuration of @Generated annotation.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on a change in pull request #90:
URL: https://github.com/apache/openjpa/pull/90#discussion_r759164703



##########
File path: openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
##########
@@ -311,10 +314,26 @@ private void annotate(SourceCode source, String originalClass) {
         SourceCode.Class cls = source.getTopLevelClass();
         cls.addAnnotation(StaticMetamodel.class.getName())
             .addArgument("value", originalClass + ".class", false);
-        if (generatedSourceVersion >= 6) {
-            cls.addAnnotation(Generated.class.getName())
-            .addArgument("value", this.getClass().getName())
-            .addArgument("date", new Date().toString());
+        if ("false".equals(this.addGeneratedOption)) {
+            return;
+        }
+
+        if ("force".equals(this.addGeneratedOption)) {
+            cls.addAnnotation(javax.annotation.Generated.class.getName())
+                    .addArgument("value", this.getClass().getName())
+                    .addArgument("date", new Date().toString());

Review comment:
       Will do!
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openjpa] rmannibucau merged pull request #90: [OPENJPA-2891] allow configuration of @Generated annotation.

Posted by GitBox <gi...@apache.org>.
rmannibucau merged pull request #90:
URL: https://github.com/apache/openjpa/pull/90


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [openjpa] bmarwell commented on pull request #90: [OPENJPA-2891] allow configuration of @Generated annotation.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on pull request #90:
URL: https://github.com/apache/openjpa/pull/90#issuecomment-982553977


   > think addGeneratedOption can be worth a default (auto or whatever)
   
   Can do, that's not much effort and sounds like a sensible option.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@openjpa.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org