You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by GitBox <gi...@apache.org> on 2017/12/17 18:49:32 UTC

[GitHub] jlahoda commented on a change in pull request #327: NOTICE file

jlahoda commented on a change in pull request #327: NOTICE file
URL: https://github.com/apache/incubator-netbeans/pull/327#discussion_r157376403
 
 

 ##########
 File path: nbbuild/antsrc/org/netbeans/nbbuild/extlibs/CreateNoticeFile.java
 ##########
 @@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.nbbuild.extlibs;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+
+/**
+ * Creates an Apache compliant NOTICE file.
+ *
+ * Apache NOTICE files must always start with a preamble. This is specified in
+ * the "preamble" property, usually set to "${nb_all}/nbbuild/notice-stub.txt".
+ *
+ * The NOTICE file must include the NOTICE files of all external binaries that
+ * have one. As a consequence the NOTICE file is different for a platform build
+ * than for an ide build. When "binaryBuild" is set to true (the default) this
+ * task will scan all the appropriate modules in the build and automatically
+ * include the "[module]external/*notice.txt" and "[module]/*notice.txt" files,
+ * if they exist.
+ *
+ * If "binaryBuild" is not set to true then only the preamble and the
+ * "[module]/*notice.txt" files will be included in the final NOTICE file.
+ *
+ */
+public class CreateNoticeFile extends Task {
+
+    private boolean verbose = false;
+
+    public void setVerbose(boolean verbose) {
+        this.verbose = verbose;
+    }
+
+    private boolean binaryBuild = true;
+
+    public void setBinaryBuild(boolean binaryBuild) {
+        this.binaryBuild = binaryBuild;
+    }
+
+    private File preamble;
+
+    public void setPreamble(File preamble) {
+        this.preamble = preamble;
+    }
+
+    private ArrayList<FileSet> fileSets = new ArrayList<FileSet>();
+
+    public void addFileSet(FileSet fs) {
+        fileSets.add(fs);
+    }
+
+    private File destFile;
+
+    public void setDestFile(File destFile) {
+        this.destFile = destFile;
+    }
+
+    private static final void append(PrintWriter output, File file) throws IOException {
+        /* Appends a file to output, rejecting multiple consecutive empty lines. */
+        boolean previousLineEmpty = true;
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"))) {
+            do {
+                String line = reader.readLine();
+                if (line == null) {
+                    break;
+                }
+                line = line.trim();
+                boolean empty = line.length() == 0;
+                if (empty && previousLineEmpty) {
+                    // Skip line
+                } else {
+                    previousLineEmpty = empty;
+                    output.println(line);
+                }
+            } while (true);
+        }
+    }
+
+    @Override
+    public void execute() throws BuildException {
+
+        if (getProject().getProperty("nb_all") == null) {
+            throw new BuildException("Please specify a nb_all directory.");
+        }
+
+        try {
+            PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(destFile), "utf-8"));
+
+            append(output, preamble);
+
+            Hashtable<String, Object> properties = getProject().getProperties();
+
+            // This excerpt from ModuleListsParser.java
+            Set<String> standardModules = new TreeSet<String>();
 
 Review comment:
   In the nbbuild/build.xml, there's a property "allmodules" that (AFAIK) contains the modules in the selected config. Would be better to just send the value of the property to the task rather than trying to recompute the value again.

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