mirror of https://github.com/apache/openjpa.git
Add ASL header with -addHeader option
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@785082 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
acd00ecc61
commit
c9d62822d4
|
@ -88,7 +88,7 @@ import org.apache.openjpa.persistence.util.SourceCode;
|
|||
"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 @@ public class AnnotationProcessor6 extends AbstractProcessor {
|
|||
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 @@ public class AnnotationProcessor6 extends AbstractProcessor {
|
|||
setSourceVersion();
|
||||
setFileManager();
|
||||
setNamingPolicy();
|
||||
addHeader = "true".equalsIgnoreCase(processingEnv.getOptions()
|
||||
.get("header"));
|
||||
handler = new SourceAnnotationHandler(processingEnv, logger);
|
||||
}
|
||||
|
||||
|
@ -214,7 +217,6 @@ public class AnnotationProcessor6 extends AbstractProcessor {
|
|||
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 @@ public class AnnotationProcessor6 extends AbstractProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,6 +55,7 @@ public class SourceCode {
|
|||
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 class SourceCode {
|
|||
|
||||
|
||||
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 @@ public class SourceCode {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
|
|
@ -52,21 +52,15 @@ meta-class-no-anno: Meta class "{0}" registered for "{1}" is not annotated \
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue