Fixing bundles handling.
Project: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/commit/97838d66 Tree: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/tree/97838d66 Diff: http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/diff/97838d66 Branch: refs/heads/master Commit: 97838d665f83ff56dcddc19b18f53f8963fe50c5 Parents: ab25500 Author: Jan Lahoda <[email protected]> Authored: Sun Sep 17 07:47:36 2017 +0200 Committer: Jan Lahoda <[email protected]> Committed: Sun Sep 17 07:47:36 2017 +0200 ---------------------------------------------------------------------- convert/nbproject/project.properties | 4 +- convert/src/convert/CategorizeLicenses.java | 23 +++++---- convert/src/convert/Convert.java | 4 +- .../test/convert/CategorizeLicensesTest.java | 49 ++++++++++++++++++++ 4 files changed, 68 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/blob/97838d66/convert/nbproject/project.properties ---------------------------------------------------------------------- diff --git a/convert/nbproject/project.properties b/convert/nbproject/project.properties index 7fe4bb0..7dc3b49 100644 --- a/convert/nbproject/project.properties +++ b/convert/nbproject/project.properties @@ -50,7 +50,9 @@ javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ - ${build.classes.dir} + ${build.classes.dir}:\ + ${libs.junit_4.classpath}:\ + ${libs.hamcrest.classpath} javac.test.modulepath=\ ${javac.modulepath} javac.test.processorpath=\ http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/blob/97838d66/convert/src/convert/CategorizeLicenses.java ---------------------------------------------------------------------- diff --git a/convert/src/convert/CategorizeLicenses.java b/convert/src/convert/CategorizeLicenses.java index 0928f10..42b57cf 100644 --- a/convert/src/convert/CategorizeLicenses.java +++ b/convert/src/convert/CategorizeLicenses.java @@ -176,12 +176,13 @@ public class CategorizeLicenses { return createUnifiedDescriptionOrNull(startM.start(), endM.end(), lic, commentType); } - private static Description snipLicenseBundle(String code, String firstLinePattern) { + public static Description snipLicenseBundle(String code, String firstLinePattern) { StringBuilder res = new StringBuilder(); boolean firstLine = true; int start = -1; int pos; int next = 0; + int end = 0; String[] lines = code.split("\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; @@ -192,18 +193,24 @@ public class CategorizeLicenses { continue; if (firstLine && line.trim().isEmpty()) continue; - if (firstLine) { - start = pos; - } - firstLine = false; if (line.startsWith("#")) { - res.append(line.substring(1).trim()); + String part = line.substring(1).trim(); + if (firstLine && part.isEmpty()) + continue; + if (firstLine) { + start = pos; + } + firstLine = false; + res.append(part); res.append("\n"); + if (!part.isEmpty()) { + end = next; + } } else { - return createUnifiedDescriptionOrNull(start, next, res.toString(), CommentType.PROPERTIES); + return createUnifiedDescriptionOrNull(start, end, res.toString(), CommentType.PROPERTIES); } } - return createUnifiedDescriptionOrNull(start, next, res.toString(), CommentType.PROPERTIES); + return createUnifiedDescriptionOrNull(start, end, res.toString(), CommentType.PROPERTIES); } private static Description createUnifiedDescriptionOrNull(int start, int end, String lic, CommentType commentType) { http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/blob/97838d66/convert/src/convert/Convert.java ---------------------------------------------------------------------- diff --git a/convert/src/convert/Convert.java b/convert/src/convert/Convert.java index c8fc1fa..1cd72f2 100644 --- a/convert/src/convert/Convert.java +++ b/convert/src/convert/Convert.java @@ -121,7 +121,6 @@ public class Convert { "-->"; private static final String BUNDLE_OUTPUT = - "#\n" + "# Licensed to the Apache Software Foundation (ASF) under one\n" + "# or more contributor license agreements. See the NOTICE file\n" + "# distributed with this work for additional information\n" + @@ -137,8 +136,7 @@ public class Convert { "# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" + "# KIND, either express or implied. See the License for the\n" + "# specific language governing permissions and limitations\n" + - "# under the License.\n" + - "#\n"; + "# under the License.\n"; public static void main(String[] args) throws IOException { if (args.length != 1) { http://git-wip-us.apache.org/repos/asf/incubator-netbeans-tools/blob/97838d66/convert/test/convert/CategorizeLicensesTest.java ---------------------------------------------------------------------- diff --git a/convert/test/convert/CategorizeLicensesTest.java b/convert/test/convert/CategorizeLicensesTest.java new file mode 100644 index 0000000..e77e4f9 --- /dev/null +++ b/convert/test/convert/CategorizeLicensesTest.java @@ -0,0 +1,49 @@ +/** + * 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. + */ +package convert; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author lahvac + */ +public class CategorizeLicensesTest { + + public CategorizeLicensesTest() { + } + + @Test + public void testSnipLicenseBundle1() { + final String code = "\n" + + "#\n" + + "#CDDL\n" + + "#\n" + + "#lic\n" + + "#\n" + + "\n"; + CategorizeLicenses.Description desc = + CategorizeLicenses.snipLicenseBundle(code, + null); + assertEquals("CDDL\nlic", desc.header); + assertEquals("#CDDL\n#\n#lic\n", code.substring(desc.start, desc.end)); + } + +}
