From c7c8eb2fc12418914e432b1744f4c5fded54b157 Mon Sep 17 00:00:00 2001 From: "Kevin W. Sutter" Date: Wed, 12 Oct 2011 18:28:26 +0000 Subject: [PATCH] OPENJPA-2044. Updating the processing for the openjpa.header parameter on the AnnotationProcessor6 code. Not only to read the actual data (vs a String representation of the URL stream), but also to make it more flexible on the number of lines contained in the designated header file. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1182512 13f79535-47bb-0310-9956-ffa450edef68 --- .../persistence/meta/AnnotationProcessor6.java | 17 ++++++++++++----- .../openjpa/persistence/util/SourceCode.java | 16 +++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java index 558e39a04..eb2b7bc81 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java @@ -21,12 +21,15 @@ package org.apache.openjpa.persistence.meta; import static javax.lang.model.SourceVersion.RELEASE_6; import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Scanner; import java.util.Set; import javax.annotation.Generated; @@ -107,7 +110,7 @@ public class AnnotationProcessor6 extends AbstractProcessor { private MetaDataFactory factory; private int generatedSourceVersion = 6; private CompileTimeLogger logger; - private String header; + private List header = new ArrayList(); private boolean active; private static Localizer _loc = Localizer.forPackage(AnnotationProcessor6.class); @@ -302,8 +305,8 @@ public class AnnotationProcessor6 extends AbstractProcessor { } private void comment(SourceCode source) { - if (header != null) - source.addComment(false, header); + if (header.size() != 0) + source.addComment(false, header.toArray(new String[header.size()])); String defaultHeader = _loc.get("mmg-tool-sign").getMessage(); source.addComment(false, defaultHeader); } @@ -347,11 +350,15 @@ public class AnnotationProcessor6 extends AbstractProcessor { return; } if ("ASL".equalsIgnoreCase(headerOption)) { - header = _loc.get("mmg-asl-header").getMessage(); + header.add(_loc.get("mmg-asl-header").getMessage()); } else { try { URL url = new URL(headerOption); - header = url.getContent().toString(); + InputStream is = url.openStream(); + Scanner s = new Scanner(is); + while (s.hasNextLine()) { + header.add(s.nextLine()); + } } catch (Throwable t) { } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java index 2f47a9b74..498b1b26c 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java @@ -141,14 +141,20 @@ public class SourceCode { public SourceCode addComment(boolean inline, String... lines) { if (lines == null) return this; - if (lines.length == 1 && lines[0].length() > 120) - return addComment(inline, wrap(lines[0], 120-4)); if (comments == null) comments = new ArrayList(); Comment comment = new Comment(); comments.add(comment); comment.makeInline(inline); - for (String line:lines) comment.append(line); + for (String line:lines) { + // Handle long header comment lines... + if (line.length() > 120-4) { + String[] wrappedLines = wrap(line, 120-4); + for (String w:wrappedLines) comment.append(w); + } else { + comment.append(line); + } + } return this; } @@ -746,8 +752,8 @@ public class SourceCode { if (i == 0) { out.println("/** "); tab(out, tab); - } - out.println(" * " + l); + } + out.println(" * " + l); i++; } tab(out, tab);