You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/05/28 18:52:33 UTC
[GitHub] matthiasblaesing closed pull request #559: Optimize readability of
the NOTICE file
matthiasblaesing closed pull request #559: Optimize readability of the NOTICE file
URL: https://github.com/apache/incubator-netbeans/pull/559
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
index cf3ed9a67..22884369d 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
@@ -149,7 +149,7 @@ void execute() throws BuildException {
try (PrintWriter licenseWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(license), "UTF-8"));
PrintWriter noticeWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(notice), "UTF-8"))) {
-
+
try (Reader r = new InputStreamReader(new FileInputStream(licenseStub), "UTF-8")) {
int read;
while ((read = r.read()) != (-1)) {
@@ -271,14 +271,7 @@ private void evaluateLicenseInfo(final PrintWriter licenseWriter, final PrintWri
licenseNames.add(fs.getLicenseRef());
}
- String notice = fs.getNotice();
- if (notice != null) {
- notice = notice.trim();
- if (!notices.contains(notice)) {
- notices.add(notice);
- addNotice(noticeWriter, notice);
- }
- }
+ addNotice(noticeWriter, fs.getNotice(), notices);
}
}
@@ -340,15 +333,7 @@ private void evaluateBinaries(final PrintWriter licenseWriter, final PrintWriter
System.err.println("No license for: " + binary);
}
- String notice = headers.get("notice");
- if (notice != null) {
- notice = notice.trim();
- if (!notices.contains(notice)) {
- notices.add(notice);
- addNotice(noticeWriter, notice);
- }
- }
-
+ addNotice(noticeWriter, headers.get("notice"), notices);
}
// String[] otherHeaders = {"Name", "Version", "Description", "Origin"};
// Map<Map<String,String>,Set<String>> licenseHeaders2Binaries = new LinkedHashMap<Map<String,String>,Set<String>>();
@@ -435,27 +420,32 @@ private String getMaybeMissing(Map<String, String> headers, String headerName) {
return crc2LicenseHeaders;
}
- private void addNotice(PrintWriter output, String notice) throws IOException {
- String[] lines = notice.split("\n");
- boolean previousLineEmpty = true;
- int n = lines.length;
- for (int i = 0; i < n; i++) {
- String line = lines[i];
- line = line.trim();
- boolean empty = line.length() == 0;
- if (empty && previousLineEmpty) {
- // Skip line
- } else {
- previousLineEmpty = empty;
- if (!empty && i < n - 1 && line.startsWith("This product includes software") && lines[i + 1].startsWith("The Apache Software Foundation")) {
- i += 2;
- previousLineEmpty = false;
- // Skip
- } else {
- output.println(line);
- }
- }
+ private String normalizeNotice(String inputNotice) {
+ if(inputNotice == null) {
+ inputNotice = "";
+ }
+ return inputNotice
+ // Remove the common part required for all ASF project, that is
+ // inserted in the header
+ .replaceAll("This product includes software.*\nThe Apache Software Foundation.*\n?", "")
+ // remove excessive whitespace (the notice entries will be separated
+ // by empty lines, while inside each block only one empty line will
+ // remain)
+ .replaceAll("\n{3,}", "\n\n")
+ // the license file is written with platform line endings, so adjust here
+ .replaceAll("\n", System.getProperty("line.separator"))
+ .trim();
+ }
+
+ private void addNotice(PrintWriter output, String notice, Set<String> alreadyWrittenNotices) throws IOException {
+ notice = normalizeNotice(notice);
+ if(notice.isEmpty() || alreadyWrittenNotices.contains(notice)) {
+ return;
}
+ alreadyWrittenNotices.add(notice);
+ output.println(notice);
+ output.println();
+ output.println();
}
private Entry<Map<String, String>, Long> getHeaders(Map<Long, Map<String, String>> crc2License,
diff --git a/nbbuild/build.xml b/nbbuild/build.xml
index 07fa60f4e..f05f84554 100644
--- a/nbbuild/build.xml
+++ b/nbbuild/build.xml
@@ -1559,8 +1559,8 @@ It is possible to use -Ddebug.port=3234 -Ddebug.pause=y to start the system in d
<filterchain>
<tokenfilter>
<filetokenizer />
- <replaceregex pattern="(\r?\n)(\r?\n)+"
- replace="\1\1"
+ <replaceregex pattern="(\r?\n)(\r?\n)(\r?\n)+"
+ replace="\1\1\1"
flags="g" />
</tokenfilter>
</filterchain>
diff --git a/nbbuild/notice-stub.txt b/nbbuild/notice-stub.txt
index 9c02ba19f..d47c7d7a9 100644
--- a/nbbuild/notice-stub.txt
+++ b/nbbuild/notice-stub.txt
@@ -11,3 +11,4 @@ The code was Copyright 1997-2016 Oracle and/or its affiliates. The Initial
Developer of the Original Software was Sun Microsystems, Inc. Portions
Copyright 1997-2006 Sun Microsystems, Inc.
+
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists