matthiasblaesing commented on a change in pull request #1845: Adding 
LICENSE/NOTICE for the VisualStudio Code extension for Java
URL: https://github.com/apache/netbeans/pull/1845#discussion_r363100600
 
 

 ##########
 File path: 
nbbuild/misc/prepare-bundles/src/main/java/org/netbeans/prepare/bundles/PrepareBundles.java
 ##########
 @@ -0,0 +1,295 @@
+/*
+ * 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.prepare.bundles;
+
+import com.google.gson.Gson;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.UncheckedIOException;
+import java.io.Writer;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileVisitOption;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.jar.JarOutputStream;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+
+/**
+ * Prepare bundles and license files for a group of node modules.
+ */
+public class PrepareBundles {
+
+    private static final String[] LICENSE_FILE_NAMES = {
+        "license",
+        "License",
+        "LICENSE",
+        "LICENSE.txt",
+        "LICENSE-MIT.txt",
+        "license.txt",
+        "License.txt",
+        "LICENSE.md",
+        "license.md"
+    };
+    private static final String nl = System.getProperty("line.separator");
+
+    public static void main(String... args) throws IOException, 
InterruptedException, NoSuchAlgorithmException {
+        if (args.length != 2) {
+            throw new IllegalStateException("Requires two parameters: location 
of the bundles directory, and the location of the NetBeans checkout.");
+        }
+
+        Path targetDir = Paths.get(args[0]);
+        Path packagesDir = targetDir.resolve("package");
+        new ProcessBuilder("npm", 
"install").directory(packagesDir.toFile()).inheritIO().start().waitFor();
+        Path bundlesDir = targetDir.resolve("bundles");
+        Files.createDirectories(bundlesDir);
+        try (DirectoryStream<Path> ds = Files.newDirectoryStream(bundlesDir)) {
+            for (Path bundle : ds) {
+                Files.delete(bundle);
+            }
+        }
+
+        Path licensesDir = targetDir.resolve("licenses");
+
+        Files.createDirectories(licensesDir);
+        try (DirectoryStream<Path> ds = Files.newDirectoryStream(licensesDir)) 
{
+            for (Path license : ds) {
+                Files.delete(license);
+            }
+        }
+
+        Path externalDir = targetDir.resolve("external");
+        Files.createDirectories(externalDir);
+        try (DirectoryStream<Path> ds = Files.newDirectoryStream(externalDir)) 
{
+            for (Path external : ds) {
+                Files.delete(external);
+            }
+        }
+
+        Map<List<String>, LicenseUses> tokens2Projects = new HashMap<>();
+        Map<String, LicenseDescription> project2License = new HashMap<>();
+        Map<String, String> project2Notice = new HashMap<>();
+        try (DirectoryStream<Path> ds = 
Files.newDirectoryStream(packagesDir.resolve("node_modules"));
+             Writer binariesList = new 
OutputStreamWriter(Files.newOutputStream(bundlesDir.resolve("binaries-list")), 
"UTF-8")) {
+            for (Path module : ds) {
+                if (".bin".equals(module.getFileName().toString())) continue;
+                if ("@types".equals(module.getFileName().toString())) continue;
+                Path packageJson = module.resolve("package.json");
+
+                if (!Files.isReadable(packageJson)) {
+                    throw new IllegalStateException("Cannot find package.json 
for: " + module.getFileName());
+                }
+
+                String packageJsonText = readString(packageJson);
+                Map<String, Object> packageJsonData = new 
Gson().fromJson(packageJsonText, HashMap.class);
+                String name = (String) packageJsonData.get("name");
+                String version = (String) packageJsonData.get("version");
+                String description = (String) 
packageJsonData.get("description");
+                String homepage = (String) packageJsonData.get("homepage");
+                String licenseKey = (String) packageJsonData.get("license");
+
+                String licenseText = null;
+
+                for (String l : LICENSE_FILE_NAMES) {
+                    if (Files.isReadable(module.resolve(l))) {
+                        licenseText = readString(module.resolve(l));
+                        break;
+                    }
+                }
+
+                if (licenseText == null) {
+                    String hardcodedLicenseName = name + "-" + version + 
"-license";
+                    URL hardcodedLicense = 
PrepareBundles.class.getResource(hardcodedLicenseName);
+                    if (hardcodedLicense == null ){
+                        throw new IllegalStateException("Cannot find license 
for: " + module.getFileName());
+                    }
+                    StringBuilder licenseTextBuffer = new StringBuilder();
+                    try (InputStream in = hardcodedLicense.openStream();
+                         Reader r = new InputStreamReader(in, 
StandardCharsets.UTF_8)) {
+                        int read;
+                        while ((read = r.read()) != (-1)) {
+                            licenseTextBuffer.append((char) read);
+                        }
+                    }
+                    licenseText = licenseTextBuffer.toString();
+                }
+                
+                Path thirdpartynoticestxt = 
module.resolve("thirdpartynotices.txt");
+
+                if (Files.isReadable(thirdpartynoticestxt)) {
+                    licenseText = "Parts of this work are licensed:\n" +
+                                  licenseText +
+                                  "\n\n" +
+                                  "Parts of this work are licensed:\n" +
+                                  readString(thirdpartynoticestxt);
+                } else {
+                    licenseText = licenseText;
+                }
+
+                Path noticestxt = module.resolve("CopyrightNotice.txt");
 
 Review comment:
   This seems to be problematic. One sample I found from a quick look at the 
generated NOTICE file was this:
   
   ```
   /*! 
*****************************************************************************
   Copyright (c) Microsoft Corporation. All rights reserved. 
   Licensed 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  
    
   THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS 
OF ANY
   KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
   WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
   MERCHANTABLITY OR NON-INFRINGEMENT. 
    
   See the Apache Version 2.0 License for specific language governing 
permissions
   and limitations under the License.
   
***************************************************************************** */
   ```
   
   The author did not understand the purpose of the NOTICE file and if we'd 
integrate this file by hand, I'd request it to be completely removed, as 
nothing of the text has a place in the NOTICE file.
   
   I admit though, that it is difficult to detect and override. Maybe notices 
should only done by hand?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to