-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added -e flag to exclude repair of a file containing DO NOT ALTER OR REMOVE COPYRIGHT NOTICES #10
base: master
Are you sure you want to change the base?
Changes from 1 commit
93cc228
620fdb2
923b4e0
39e6c63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I'd make this variable name a little easier to understand and readable. I know you were just following the pattern for the "bsdpat" variable, but I would think something like "doNotAlterPattern" would be clearer. I'll leave it to you though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 620fdb2 |
||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting doesn't look right. Are you using tabs or spaces (preferred)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting doesn't look right. Are you using tabs or spaces (preferred)? Way too much indentation. |
||
} | ||
|
||
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); | ||
} | ||
|
||
/** | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation problem again? |
||
* Verifies if he file contains the message: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit typo: "if the file.." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 620fdb2 |
||
* 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation again... |
||
* -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<File> alternateTemplates = new ArrayList<File>(); | ||
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)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit typo: "pattern"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 620fdb2