openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r772665 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
Date Thu, 07 May 2009 14:38:41 GMT
Author: ppoddar
Date: Thu May  7 14:38:41 2009
New Revision: 772665

URL: http://svn.apache.org/viewvc?rev=772665&view=rev
Log:
OPENJPA-1010: Add -Asource option to control target compilable version for the generated meta-model
source

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java?rev=772665&r1=772664&r2=772665&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
Thu May  7 14:38:41 2009
@@ -65,7 +65,7 @@
     "javax.persistence.Entity",
     "javax.persistence.Embeddable", 
     "javax.persistence.MappedSuperclass" })
-@SupportedOptions( { "log", "out" })
+@SupportedOptions( { "log", "out", "source" })
 @SupportedSourceVersion(RELEASE_6)
 
 public class AnnotationProcessor6 extends AbstractProcessor {
@@ -244,15 +244,34 @@
         SourceCode.Class cls = source.getTopLevelClass();
         cls.addAnnotation(TypesafeMetamodel.class.getName())
             .addArgument("value", originalClass + ".class", false);
-        cls.addAnnotation(Generated.class.getName())
-           .addArgument("value", this.getClass().getName())
-           .addArgument("date", new Date().toString());
+        if (getSourceVersion() >= 6) {
+            cls.addAnnotation(Generated.class.getName())
+            .addArgument("value", this.getClass().getName())
+            .addArgument("date", new Date().toString());
+        }
     }
     
     private void comment(SourceCode source) {
         source.addComment(false, _loc.get("mmg-tool-sign").getMessage());
     }
     
+    /**
+     * Parse annotation processor option <code>-Asource=n</code> to detect
+     * the source version for the generated classes. 
+     * n must be a integer. Default or wrong specification returns 6.
+     */
+    private int getSourceVersion() {
+        String version = processingEnv.getOptions().get("source");
+        if (version != null) {
+            try {
+                return Integer.parseInt(version);
+            } catch (NumberFormatException e) {
+            
+            }
+        }
+        return 6;
+    }
+    
     private PrintWriter createSourceFile(String metaClass, TypeElement e) 
         throws IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();



Mime
View raw message