You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2018/05/28 18:52:50 UTC

[incubator-netbeans] branch master updated: Optimize readability of the NOTICE file

This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 88932d0  Optimize readability of the NOTICE file
88932d0 is described below

commit 88932d010f2e7927c7b5c75040dad8e205585f49
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Mon May 28 20:52:31 2018 +0200

    Optimize readability of the NOTICE file
    
    
    While looking into NETBEANS-827 it was found, that the NOTICE file is
    difficult to read, as no clear sections were visible.
    
    This adjust the output as such, that:
    
    - the primary header is separated from the following entries by
      two empty lines
    - all imported entries are normalized, so that multiple empty lines
      are collapsed into one empty line
    - all imported entries are separated from each other by two empty
      lines
---
 .../nbbuild/extlibs/CreateLicenseSummary.java      | 66 +++++++++-------------
 nbbuild/build.xml                                  |  4 +-
 nbbuild/notice-stub.txt                            |  1 +
 3 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
index cf3ed9a..2288436 100644
--- a/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
+++ b/nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateLicenseSummary.java
@@ -149,7 +149,7 @@ public class CreateLicenseSummary extends Task {
         
         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 @@ public class CreateLicenseSummary extends Task {
                     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 @@ public class CreateLicenseSummary extends Task {
                 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 @@ public class CreateLicenseSummary extends Task {
         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 07fa60f..f05f845 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 9c02ba1..d47c7d7 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.
 
+

-- 
To stop receiving notification emails like this one, please contact
matthiasblaesing@apache.org.

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists