From 93cc22867f247de9f73f822a45c401ad8dc22634 Mon Sep 17 00:00:00 2001 From: CesarHernandezGt Date: Fri, 1 May 2020 20:18:27 -0600 Subject: [PATCH 1/4] Added -e flag to exclude repair of a file containing DO NOT ALTER OR REMOVE COPYRIGHT NOTICES Signed-off-by: CesarHernandezGt --- .../copyright/AbstractCopyright.java | 42 +++++++++++++++++-- .../org/glassfish/copyright/Copyright.java | 8 +++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/glassfish/copyright/AbstractCopyright.java b/src/main/java/org/glassfish/copyright/AbstractCopyright.java index 43ffac3..c56a460 100644 --- a/src/main/java/org/glassfish/copyright/AbstractCopyright.java +++ b/src/main/java/org/glassfish/copyright/AbstractCopyright.java @@ -68,6 +68,8 @@ public abstract class AbstractCopyright { "permission notice:\n" + "\n"; + private static final String DONT_ALTER_HEADER = "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER."; + private static final String DEFAULT_CORRECT = "epl-copyright.txt"; private static final String DEFAULT_ALTERNATE = "apache-copyright.txt"; private static final String DEFAULT_BSD = "edl-copyright.txt"; @@ -93,6 +95,8 @@ public abstract class AbstractCopyright { private static Pattern bsdpat = Pattern.compile( "(THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS)"+ "|(SPDX-License-Identifier: BSD-3-Clause)", Pattern.MULTILINE); + // patter to detect DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + protected static Pattern dontpat = Pattern.compile(DONT_ALTER_HEADER); protected static final String allrights = "All rights reserved."; @@ -215,8 +219,17 @@ protected void checkCopyright(File file) throws IOException { System.out.println(comment); System.out.println("---"); } - if (c.warn && !c.quiet) - warnCopyright(file, r); + if (c.warn && !c.quiet){ + warnCopyright(file, r); + } + + if (c.explicitExclude){ + if (isEditableCopyright(file, r)){ + err(file + ": EXCLUDED FROM REPAIR: contains: " + DONT_ALTER_HEADER); + return; + } + } + } finally { if (r != null) r.close(); @@ -332,7 +345,24 @@ else if (lc == null) System.out.println("No errors: " + file); } - /** + /** + * Verifies if he file contains the message: + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * @param file + * @return + */ + protected boolean isEditableCopyright(final File file, BufferedReader in) throws IOException{ + String line; + while ((line = in.readLine()) != null) { + Matcher m2 = dontpat.matcher(line); + if (m2.find()) { + return false; + } + } + return true; + } + + /** * Does the string match the pattern? */ protected boolean matches(Pattern pat, String s) { @@ -511,6 +541,12 @@ protected void warnCopyright(File file, BufferedReader in) System.out.println(file + ": WARNING: extra copyright: " + line); } + + Matcher m2 = dontpat.matcher(line); + if (m2.find()){ + System.out.println(file + + ": WARNING: contains: " + line); + } /* * XXX - too many false positives for this one else if (line.indexOf("Copyright") >= 0) diff --git a/src/main/java/org/glassfish/copyright/Copyright.java b/src/main/java/org/glassfish/copyright/Copyright.java index d404c2d..97ac315 100644 --- a/src/main/java/org/glassfish/copyright/Copyright.java +++ b/src/main/java/org/glassfish/copyright/Copyright.java @@ -20,7 +20,7 @@ * * Usage: java -jar copyright.jar * [-w] -[y] [-r] [-n] [-s] [-h] [-m] [-g] [-S] [-c] [-q] [-j] [-x] - * [-p] [-t] [-N] [-D] [-X pat] [-C file] [-A file] [-B file] [-P] + * [-p] [-t] [-e] [-N] [-D] [-X pat] [-C file] [-A file] [-B file] [-P] * [-v] [-V] [files ...] * * Options: @@ -39,6 +39,7 @@ * -x check XML syntax files * -p check properties syntax files * -t check other text files + * -e exclude files that contains DO NOT ALTER OR REMOVE COPYRIGHT NOTICES * -N normalize format of repaired copyright to match template * -D use dash instead of comma in years when repairing files * -X exclude files matching pat (substring only) @@ -79,6 +80,7 @@ public class Copyright { public boolean doText = false; public boolean preserveCopyrights = false; public boolean verbose = false; + public boolean explicitExclude = false; public File correctTemplate; public List alternateTemplates = new ArrayList(); public File correctBSDTemplate; @@ -343,7 +345,9 @@ public static void main(String[] argv) throws Exception { c.doProps = true; } else if (argv[optind].equals("-t")) { c.doText = true; - } else if (argv[optind].equals("-X")) { + } else if (argv[optind].equals("-e")) { + c.explicitExclude = true; + }else if (argv[optind].equals("-X")) { String ex = argv[++optind]; if (ex.startsWith("@")) c.addExcludes(ex.substring(1)); From 620fdb207832e090dba2f0ac01aa3db89af8554e Mon Sep 17 00:00:00 2001 From: CesarHernandezGt Date: Fri, 8 May 2020 15:34:39 -0600 Subject: [PATCH 2/4] Applied to this PR the ee4j codeStyle Signed-off-by: CesarHernandezGt --- .../copyright/AbstractCopyright.java | 26 +++++++++---------- .../org/glassfish/copyright/Copyright.java | 8 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/glassfish/copyright/AbstractCopyright.java b/src/main/java/org/glassfish/copyright/AbstractCopyright.java index c56a460..e8afeef 100644 --- a/src/main/java/org/glassfish/copyright/AbstractCopyright.java +++ b/src/main/java/org/glassfish/copyright/AbstractCopyright.java @@ -68,7 +68,7 @@ public abstract class AbstractCopyright { "permission notice:\n" + "\n"; - private static final String DONT_ALTER_HEADER = "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER."; + private static final String DONT_ALTER_HEADER = "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER."; private static final String DEFAULT_CORRECT = "epl-copyright.txt"; private static final String DEFAULT_ALTERNATE = "apache-copyright.txt"; @@ -95,8 +95,8 @@ public abstract class AbstractCopyright { private static Pattern bsdpat = Pattern.compile( "(THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS)"+ "|(SPDX-License-Identifier: BSD-3-Clause)", Pattern.MULTILINE); - // patter to detect DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - protected static Pattern dontpat = Pattern.compile(DONT_ALTER_HEADER); + // pattern to detect DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + protected static Pattern doNotAlterPattern = Pattern.compile(DONT_ALTER_HEADER); protected static final String allrights = "All rights reserved."; @@ -219,12 +219,12 @@ protected void checkCopyright(File file) throws IOException { System.out.println(comment); System.out.println("---"); } - if (c.warn && !c.quiet){ + if (c.warn && !c.quiet) { warnCopyright(file, r); } - if (c.explicitExclude){ - if (isEditableCopyright(file, r)){ + if (c.explicitExclude) { + if (isEditableCopyright(file, r)) { err(file + ": EXCLUDED FROM REPAIR: contains: " + DONT_ALTER_HEADER); return; } @@ -346,15 +346,16 @@ else if (lc == null) } /** - * Verifies if he file contains the message: + * Verifies if the file contains the message: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * * @param file * @return */ - protected boolean isEditableCopyright(final File file, BufferedReader in) throws IOException{ + protected boolean isEditableCopyright(final File file, BufferedReader in) throws IOException { String line; while ((line = in.readLine()) != null) { - Matcher m2 = dontpat.matcher(line); + Matcher m2 = doNotAlterPattern.matcher(line); if (m2.find()) { return false; } @@ -542,10 +543,9 @@ protected void warnCopyright(File file, BufferedReader in) ": WARNING: extra copyright: " + line); } - Matcher m2 = dontpat.matcher(line); - if (m2.find()){ - System.out.println(file + - ": WARNING: contains: " + line); + Matcher m2 = doNotAlterPattern.matcher(line); + if (m2.find()) { + System.out.println(file + ": WARNING: contains: " + line); } /* * XXX - too many false positives for this one diff --git a/src/main/java/org/glassfish/copyright/Copyright.java b/src/main/java/org/glassfish/copyright/Copyright.java index 97ac315..83b73cd 100644 --- a/src/main/java/org/glassfish/copyright/Copyright.java +++ b/src/main/java/org/glassfish/copyright/Copyright.java @@ -39,7 +39,7 @@ * -x check XML syntax files * -p check properties syntax files * -t check other text files - * -e exclude files that contains DO NOT ALTER OR REMOVE COPYRIGHT NOTICES + * -e exclude files that contains DO NOT ALTER OR REMOVE COPYRIGHT NOTICES * -N normalize format of repaired copyright to match template * -D use dash instead of comma in years when repairing files * -X exclude files matching pat (substring only) @@ -80,7 +80,7 @@ public class Copyright { public boolean doText = false; public boolean preserveCopyrights = false; public boolean verbose = false; - public boolean explicitExclude = false; + public boolean explicitExclude = false; public File correctTemplate; public List alternateTemplates = new ArrayList(); public File correctBSDTemplate; @@ -346,8 +346,8 @@ public static void main(String[] argv) throws Exception { } else if (argv[optind].equals("-t")) { c.doText = true; } else if (argv[optind].equals("-e")) { - c.explicitExclude = true; - }else if (argv[optind].equals("-X")) { + c.explicitExclude = true; + } else if (argv[optind].equals("-X")) { String ex = argv[++optind]; if (ex.startsWith("@")) c.addExcludes(ex.substring(1)); From 923b4e03c25e08156cba632cc198977dcc5a4b37 Mon Sep 17 00:00:00 2001 From: CesarHernandezGt Date: Fri, 8 May 2020 15:46:04 -0600 Subject: [PATCH 3/4] Updated PR code format without detect and use existing file indents for editing Signed-off-by: CesarHernandezGt --- .../copyright/AbstractCopyright.java | 64 +++++++++---------- .../org/glassfish/copyright/Copyright.java | 4 +- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/glassfish/copyright/AbstractCopyright.java b/src/main/java/org/glassfish/copyright/AbstractCopyright.java index e8afeef..5809956 100644 --- a/src/main/java/org/glassfish/copyright/AbstractCopyright.java +++ b/src/main/java/org/glassfish/copyright/AbstractCopyright.java @@ -95,8 +95,8 @@ public abstract class AbstractCopyright { private static Pattern bsdpat = Pattern.compile( "(THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS)"+ "|(SPDX-License-Identifier: BSD-3-Clause)", Pattern.MULTILINE); - // pattern to detect DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - protected static Pattern doNotAlterPattern = Pattern.compile(DONT_ALTER_HEADER); + // pattern to detect DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + protected static Pattern doNotAlterPattern = Pattern.compile(DONT_ALTER_HEADER); protected static final String allrights = "All rights reserved."; @@ -219,16 +219,16 @@ protected void checkCopyright(File file) throws IOException { System.out.println(comment); System.out.println("---"); } - if (c.warn && !c.quiet) { - warnCopyright(file, r); - } + if (c.warn && !c.quiet) { + warnCopyright(file, r); + } - if (c.explicitExclude) { - if (isEditableCopyright(file, r)) { - err(file + ": EXCLUDED FROM REPAIR: contains: " + DONT_ALTER_HEADER); - return; - } - } + if (c.explicitExclude) { + if (isEditableCopyright(file, r)) { + err(file + ": EXCLUDED FROM REPAIR: contains: " + DONT_ALTER_HEADER); + return; + } + } } finally { if (r != null) @@ -345,23 +345,23 @@ else if (lc == null) System.out.println("No errors: " + file); } - /** - * Verifies if the file contains the message: - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * @param file - * @return - */ - protected boolean isEditableCopyright(final File file, BufferedReader in) throws IOException { - String line; - while ((line = in.readLine()) != null) { - Matcher m2 = doNotAlterPattern.matcher(line); - if (m2.find()) { - return false; - } - } - return true; - } + /** + * Verifies if the file contains the message: + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * @param file + * @return + */ + protected boolean isEditableCopyright(final File file, BufferedReader in) throws IOException { + String line; + while ((line = in.readLine()) != null) { + Matcher m2 = doNotAlterPattern.matcher(line); + if (m2.find()) { + return false; + } + } + return true; + } /** * Does the string match the pattern? @@ -543,10 +543,10 @@ protected void warnCopyright(File file, BufferedReader in) ": WARNING: extra copyright: " + line); } - Matcher m2 = doNotAlterPattern.matcher(line); - if (m2.find()) { - System.out.println(file + ": WARNING: contains: " + line); - } + Matcher m2 = doNotAlterPattern.matcher(line); + if (m2.find()) { + System.out.println(file + ": WARNING: contains: " + line); + } /* * XXX - too many false positives for this one else if (line.indexOf("Copyright") >= 0) diff --git a/src/main/java/org/glassfish/copyright/Copyright.java b/src/main/java/org/glassfish/copyright/Copyright.java index 83b73cd..c4cb307 100644 --- a/src/main/java/org/glassfish/copyright/Copyright.java +++ b/src/main/java/org/glassfish/copyright/Copyright.java @@ -80,7 +80,7 @@ public class Copyright { public boolean doText = false; public boolean preserveCopyrights = false; public boolean verbose = false; - public boolean explicitExclude = false; + public boolean explicitExclude = false; public File correctTemplate; public List alternateTemplates = new ArrayList(); public File correctBSDTemplate; @@ -346,7 +346,7 @@ public static void main(String[] argv) throws Exception { } else if (argv[optind].equals("-t")) { c.doText = true; } else if (argv[optind].equals("-e")) { - c.explicitExclude = true; + c.explicitExclude = true; } else if (argv[optind].equals("-X")) { String ex = argv[++optind]; if (ex.startsWith("@")) From 39e6c63a00da77ac8f71e7fe9daee98fd7027ccb Mon Sep 17 00:00:00 2001 From: CesarHernandezGt Date: Fri, 8 May 2020 15:49:00 -0600 Subject: [PATCH 4/4] Fixed identation for this PR code Signed-off-by: CesarHernandezGt --- src/main/java/org/glassfish/copyright/AbstractCopyright.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/glassfish/copyright/AbstractCopyright.java b/src/main/java/org/glassfish/copyright/AbstractCopyright.java index 5809956..9f8cfe5 100644 --- a/src/main/java/org/glassfish/copyright/AbstractCopyright.java +++ b/src/main/java/org/glassfish/copyright/AbstractCopyright.java @@ -68,7 +68,7 @@ public abstract class AbstractCopyright { "permission notice:\n" + "\n"; - private static final String DONT_ALTER_HEADER = "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER."; + private static final String DONT_ALTER_HEADER = "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER."; private static final String DEFAULT_CORRECT = "epl-copyright.txt"; private static final String DEFAULT_ALTERNATE = "apache-copyright.txt";