Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions src/main/java/org/glassfish/copyright/AbstractCopyright.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit typo: "pattern"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 620fdb2

protected static Pattern dontpat = Pattern.compile(DONT_ALTER_HEADER);
Copy link

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 620fdb2


protected static final String allrights = "All rights reserved.";

Expand Down Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting doesn't look right. Are you using tabs or spaces (preferred)?

Copy link

Choose a reason for hiding this comment

The 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();
Expand Down Expand Up @@ -332,7 +345,24 @@ else if (lc == null)
System.out.println("No errors: " + file);
}

/**
/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation problem again?

* Verifies if he file contains the message:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit typo: "if the file.."

Copy link
Author

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/glassfish/copyright/Copyright.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Copy link

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down