You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/06/16 07:13:33 UTC

svn commit: r785082 - in /openjpa/trunk/openjpa-persistence/src/main: java/org/apache/openjpa/persistence/meta/ java/org/apache/openjpa/persistence/util/ resources/org/apache/openjpa/persistence/meta/

Author: ppoddar
Date: Tue Jun 16 05:13:32 2009
New Revision: 785082

URL: http://svn.apache.org/viewvc?rev=785082&view=rev
Log:
Add ASL header with -addHeader option

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
    openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties

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=785082&r1=785081&r2=785082&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 Tue Jun 16 05:13:32 2009
@@ -88,7 +88,7 @@
     "javax.persistence.Entity",
     "javax.persistence.Embeddable", 
     "javax.persistence.MappedSuperclass" })
-@SupportedOptions( { "log", "out", "source", "naming" })
+@SupportedOptions( { "log", "out", "source", "naming", "header" })
 @SupportedSourceVersion(RELEASE_6)
 
 public class AnnotationProcessor6 extends AbstractProcessor {
@@ -97,6 +97,7 @@
     private MetaDataFactory factory;
     private int generatedSourceVersion = 6;
     private CompileTimeLogger logger;
+    private boolean addHeader = false;
     private static Localizer _loc =
         Localizer.forPackage(AnnotationProcessor6.class);
 
@@ -180,6 +181,8 @@
         setSourceVersion();
         setFileManager();
         setNamingPolicy();
+        addHeader = "true".equalsIgnoreCase(processingEnv.getOptions()
+                .get("header"));
         handler = new SourceAnnotationHandler(processingEnv, logger);
     }
     
@@ -214,7 +217,6 @@
         String metaClass = factory.getMetaModelClassName(originalClass);
 
         SourceCode source = new SourceCode(metaClass);
-        header(source);
         comment(source);
         annotate(source, originalClass);
         TypeElement supCls = handler.getPersistentSupertype(e);
@@ -287,28 +289,12 @@
         }
     }
     
-    // Hack to add ASL header for now, so maven-rat-plugin tests will pass
-    private void header(SourceCode source) {
-        source.addComment(false, _loc.get("mmg-tool-asl2-01").getMessage(),
-                                 _loc.get("mmg-tool-asl2-02").getMessage(),
-                                 _loc.get("mmg-tool-asl2-03").getMessage(),
-                                 _loc.get("mmg-tool-asl2-04").getMessage(),
-                                 _loc.get("mmg-tool-asl2-05").getMessage(),
-                                 _loc.get("mmg-tool-asl2-06").getMessage(),
-                                 _loc.get("mmg-tool-asl2-07").getMessage(),
-                                 _loc.get("mmg-tool-asl2-08").getMessage(),
-                                 _loc.get("mmg-tool-asl2-09").getMessage(),
-                                 _loc.get("mmg-tool-asl2-10").getMessage(),
-                                 _loc.get("mmg-tool-asl2-11").getMessage(),
-                                 _loc.get("mmg-tool-asl2-12").getMessage(),
-                                 _loc.get("mmg-tool-asl2-13").getMessage(),
-                                 _loc.get("mmg-tool-asl2-14").getMessage(),
-                                 _loc.get("mmg-tool-asl2-15").getMessage(),
-                                 _loc.get("mmg-tool-asl2-16").getMessage());
-    }
-    
     private void comment(SourceCode source) {
-        source.addComment(false, _loc.get("mmg-tool-sign").getMessage());
+        if (addHeader) {
+           source.addComment(false, _loc.get("mmg-asl-header").getMessage());
+        } else {
+            source.addComment(false, _loc.get("mmg-tool-sign").getMessage());
+        }
     }
     
     /**

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java?rev=785082&r1=785081&r2=785082&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java Tue Jun 16 05:13:32 2009
@@ -55,6 +55,7 @@
     public static final String  DOT           = ".";
     public static final String  EQUAL         = "=";
     public static final String  QUOTE         = "\"";
+//    public static final String NEWLINE        = "\r\n";
 	private static final String[] BRACKET_BLOCK  = {"{", "}"};
 	private static final String[] BRACKET_ARGS   = {"(", ")"};
     private static final String[] BRACKET_PARAMS = {"<", ">"};
@@ -103,6 +104,10 @@
 	
 	
 	public SourceCode addComment(boolean inline, String... lines) {
+	    if (lines == null)
+	        return this;
+	    if (lines.length == 1 && lines[0].length() > 80)
+	        return addComment(inline, wrap(lines[0], 80-4));
 		if (comment == null) comment = new Comment();
 		comment.makeInline(inline);
 		for (String line:lines) comment.append(line);
@@ -139,6 +144,28 @@
 		}
 	}
 	
+    /**
+     * Wraps the given string into lines of max length width at word boundaries
+     */
+    public static String[] wrap(String longLine, int width) {
+        String[] words = longLine.split("\\ ");
+        List<String> lines = new ArrayList<String>();
+        StringBuffer line = new StringBuffer();
+        for (int i = 0; i < words.length; i++) {
+            String w = words[i];
+            if (line.length() + w.length() < width) {
+                if (line.length() > 0) line.append(" ");
+                line.append(w);
+            } else {
+                lines.add(line.toString());
+                line.setLength(0);
+                line.append(w);
+            }
+        }
+        lines.add(line.toString());
+        return lines.toArray(new String[lines.size()]);
+    }
+	
     static void writeList(PrintWriter out, String header, List<?> list) { 
         writeList(out, header, list, new String[]{BLANK, BLANK}, false);
     }

Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties?rev=785082&r1=785081&r2=785082&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties (original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties Tue Jun 16 05:13:32 2009
@@ -52,21 +52,15 @@
 meta-field-mismatch: The field "{0}" in meta class "{1}" is of type "{2}" does \
 	not match with the persistent property type "{3}".   
 type-wrong-category:"{0}" categorized as "{1}" should be a "{2}"
-# Hack for now, so maven-rat-plugin tests will pass
-mm-tool-asl2-01: Licensed to the Apache Software Foundation (ASF) under one
-mm-tool-asl2-02: or more contributor license agreements.  See the NOTICE file
-mm-tool-asl2-03: distributed with this work for additional information
-mm-tool-asl2-04: regarding copyright ownership.  The ASF licenses this file
-mm-tool-asl2-05: to you under the Apache License, Version 2.0 (the
-mm-tool-asl2-06: "License"); you may not use this file except in compliance
-mm-tool-asl2-07: with the License.  You may obtain a copy of the License at
-mm-tool-asl2-08:  
-mm-tool-asl2-09: http://www.apache.org/licenses/LICENSE-2.0
-mm-tool-asl2-10:  
-mm-tool-asl2-11: Unless required by applicable law or agreed to in writing,
-mm-tool-asl2-12: software distributed under the License is distributed on an
-mm-tool-asl2-13: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-mm-tool-asl2-14: KIND, either express or implied.  See the License for the
-mm-tool-asl2-15: specific language governing permissions and limitations
-mm-tool-asl2-16: under the License.
-
+mmg-asl-header: Licensed to the Apache Software Foundation (ASF) under one \
+	or more contributor license agreements.  See the NOTICE file distributed \
+	with this work for additional information regarding copyright ownership.\
+	The ASF licenses this file to you under the Apache License, Version 2.0 \
+	(the "License"); you may not use this file except in compliance with the \
+	License.  You may obtain a copy of the License at \
+	     http://www.apache.org/licenses/LICENSE-2.0 \
+	Unless required by applicable law or agreed to in writing, software \
+	distributed under the License is distributed on an "AS IS" BASIS, \
+	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \
+	See the License for the specific language governing permissions and \
+	limitations under the License.