diff --git a/src/main/java/org/glassfish/copyright/AbstractCopyright.java b/src/main/java/org/glassfish/copyright/AbstractCopyright.java index 43ffac3..9f8cfe5 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); + // 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."; @@ -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(); @@ -333,6 +346,24 @@ else if (lc == null) } /** + * 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? */ protected boolean matches(Pattern pat, String s) { @@ -511,6 +542,11 @@ protected void warnCopyright(File file, BufferedReader in) System.out.println(file + ": WARNING: extra copyright: " + 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 d404c2d..c4cb307 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,6 +345,8 @@ 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("-e")) { + c.explicitExclude = true; } else if (argv[optind].equals("-X")) { String ex = argv[++optind]; if (ex.startsWith("@"))