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

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


The following commit(s) were added to refs/heads/master by this push:
     new ec7cbe3c62 External Code Formatters added into NBLS. (#4176)
ec7cbe3c62 is described below

commit ec7cbe3c6279692f1754cbc5fd78cc7c85b7b8fd
Author: Dusan Balek <[email protected]>
AuthorDate: Tue Jun 7 08:46:34 2022 +0200

    External Code Formatters added into NBLS. (#4176)
---
 .travis.yml                                        |   2 +-
 java/java.lsp.server/build.xml                     |   4 +-
 java/java.lsp.server/vscode/package-lock.json      |  77 ++++----
 java/java.lsp.server/vscode/package.json           |  19 +-
 .../netbeans/prepare/bundles/PrepareBundles.java   | 195 +++++++++++----------
 5 files changed, 150 insertions(+), 147 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index d654370c08..2574ca3440 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -659,7 +659,7 @@ matrix:
             - nbbuild/travis/ant.sh $OPTS clean
             - nbbuild/travis/ant.sh $OPTS build
           script:
-            - (cd java/java.lsp.server; ant build-vscode-ext 
-D3rdparty.modules=.*nbjavac.*)
+            - (cd java/java.lsp.server; ant build-vscode-ext 
-D3rdparty.modules=.*externalcodeformatter.*)
             - (cd java/java.lsp.server; ant test-vscode-ext)
 
         - name: "GraalVM Tests (latest)"
diff --git a/java/java.lsp.server/build.xml b/java/java.lsp.server/build.xml
index 57daa8246c..29bea31dcd 100644
--- a/java/java.lsp.server/build.xml
+++ b/java/java.lsp.server/build.xml
@@ -42,8 +42,8 @@
         <chmod file="${lsp.build.dir}/platform/lib/nbexec" perm="u+x"/>
         <chmod file="${lsp.build.dir}/java/maven/bin/mvn" perm="u+x" />
 
-        <property name="3rdparty.modules" value=".*nbjavac.*"/>
-        <autoupdate todir="${lsp.build.dir}/extra" 
updatecenter="file://${nb_all}/nb/updatecenters/build/classes/org/netbeans/modules/updatecenters/resources/3rdparty-catalog.xml">
+        <property name="3rdparty.modules" value=".*externalcodeformatter.*"/>
+        <autoupdate todir="${lsp.build.dir}/extra" 
updatecenter="https://netbeans.apache.org/nb/plugins/14/catalog.xml.gz";>
             <modules includes="${3rdparty.modules}"/>
         </autoupdate>
     </target>
diff --git a/java/java.lsp.server/vscode/package-lock.json 
b/java/java.lsp.server/vscode/package-lock.json
index 437b976520..ed049ec05e 100644
--- a/java/java.lsp.server/vscode/package-lock.json
+++ b/java/java.lsp.server/vscode/package-lock.json
@@ -9,8 +9,8 @@
                        "version": "0.1.0",
                        "license": "Apache 2.0",
                        "dependencies": {
+                               "@vscode/debugadapter": "1.55.1",
                                "jsonc-parser": "3.0.0",
-                               "vscode-debugadapter": "1.51.0",
                                "vscode-languageclient": "8.0.1"
                        },
                        "devDependencies": {
@@ -69,6 +69,22 @@
                        "dev": true,
                        "license": "ISC"
                },
+               "node_modules/@vscode/debugadapter": {
+                       "version": "1.55.1",
+                       "resolved": 
"https://registry.npmjs.org/@vscode/debugadapter/-/debugadapter-1.55.1.tgz";,
+                       "integrity": 
"sha512-UeiEpSVNZSeRvLWluaJ+Qo2el/QD2o3t7JSQBu/0TEG3s98Ib3ihYaFk5uGugmITNTSBClMMs7UXieACRcOFlA==",
+                       "dependencies": {
+                               "@vscode/debugprotocol": "1.55.1"
+                       },
+                       "engines": {
+                               "node": ">=14"
+                       }
+               },
+               "node_modules/@vscode/debugprotocol": {
+                       "version": "1.55.1",
+                       "resolved": 
"https://registry.npmjs.org/@vscode/debugprotocol/-/debugprotocol-1.55.1.tgz";,
+                       "integrity": 
"sha512-tEOY1KxSACd77JFfoipYvLZdVdrTnXBiVgS7zKDmAQxxmVsKPERB6HOXDijoWi1wUjFx+K7plXCtweX+k5Fc/g=="
+               },
                "node_modules/agent-base": {
                        "version": "4.3.0",
                        "dev": true,
@@ -639,17 +655,6 @@
                                "node": "*"
                        }
                },
-               "node_modules/mkdirp": {
-                       "version": "1.0.4",
-                       "resolved": 
"https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz";,
-                       "integrity": 
"sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
-                       "bin": {
-                               "mkdirp": "bin/cmd.js"
-                       },
-                       "engines": {
-                               "node": ">=10"
-                       }
-               },
                "node_modules/mocha": {
                        "version": "9.2.0",
                        "dev": true,
@@ -951,22 +956,6 @@
                                "node": ">=4.2.0"
                        }
                },
-               "node_modules/vscode-debugadapter": {
-                       "version": "1.51.0",
-                       "resolved": 
"https://registry.npmjs.org/vscode-debugadapter/-/vscode-debugadapter-1.51.0.tgz";,
-                       "integrity": 
"sha512-mObaXD5/FH/z6aL2GDuyCLbnwLsYRCAJWgFid01vKW9Y5Si8OvINK+Tn+Yl/lRUbetjNuZW3j1euMEz6z8Yzqg==",
-                       "deprecated": "This package has been renamed to 
@vscode/debugadapter, please update to the new name",
-                       "dependencies": {
-                               "mkdirp": "^1.0.4",
-                               "vscode-debugprotocol": "1.51.0"
-                       }
-               },
-               "node_modules/vscode-debugprotocol": {
-                       "version": "1.51.0",
-                       "resolved": 
"https://registry.npmjs.org/vscode-debugprotocol/-/vscode-debugprotocol-1.51.0.tgz";,
-                       "integrity": 
"sha512-dzKWTMMyebIMPF1VYMuuQj7gGFq7guR8AFya0mKacu+ayptJfaRuM0mdHCqiOth4FnRP8mPhEroFPx6Ift8wHA==",
-                       "deprecated": "This package has been renamed to 
@vscode/debugprotocol, please update to the new name"
-               },
                "node_modules/vscode-jsonrpc": {
                        "version": "8.0.1",
                        "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz";,
@@ -1153,6 +1142,19 @@
                        "version": "1.1.2",
                        "dev": true
                },
+               "@vscode/debugadapter": {
+                       "version": "1.55.1",
+                       "resolved": 
"https://registry.npmjs.org/@vscode/debugadapter/-/debugadapter-1.55.1.tgz";,
+                       "integrity": 
"sha512-UeiEpSVNZSeRvLWluaJ+Qo2el/QD2o3t7JSQBu/0TEG3s98Ib3ihYaFk5uGugmITNTSBClMMs7UXieACRcOFlA==",
+                       "requires": {
+                               "@vscode/debugprotocol": "1.55.1"
+                       }
+               },
+               "@vscode/debugprotocol": {
+                       "version": "1.55.1",
+                       "resolved": 
"https://registry.npmjs.org/@vscode/debugprotocol/-/debugprotocol-1.55.1.tgz";,
+                       "integrity": 
"sha512-tEOY1KxSACd77JFfoipYvLZdVdrTnXBiVgS7zKDmAQxxmVsKPERB6HOXDijoWi1wUjFx+K7plXCtweX+k5Fc/g=="
+               },
                "agent-base": {
                        "version": "4.3.0",
                        "dev": true,
@@ -1500,11 +1502,6 @@
                                "brace-expansion": "^1.1.7"
                        }
                },
-               "mkdirp": {
-                       "version": "1.0.4",
-                       "resolved": 
"https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz";,
-                       "integrity": 
"sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
-               },
                "mocha": {
                        "version": "9.2.0",
                        "dev": true,
@@ -1682,20 +1679,6 @@
                        "integrity": 
"sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==",
                        "dev": true
                },
-               "vscode-debugadapter": {
-                       "version": "1.51.0",
-                       "resolved": 
"https://registry.npmjs.org/vscode-debugadapter/-/vscode-debugadapter-1.51.0.tgz";,
-                       "integrity": 
"sha512-mObaXD5/FH/z6aL2GDuyCLbnwLsYRCAJWgFid01vKW9Y5Si8OvINK+Tn+Yl/lRUbetjNuZW3j1euMEz6z8Yzqg==",
-                       "requires": {
-                               "mkdirp": "^1.0.4",
-                               "vscode-debugprotocol": "1.51.0"
-                       }
-               },
-               "vscode-debugprotocol": {
-                       "version": "1.51.0",
-                       "resolved": 
"https://registry.npmjs.org/vscode-debugprotocol/-/vscode-debugprotocol-1.51.0.tgz";,
-                       "integrity": 
"sha512-dzKWTMMyebIMPF1VYMuuQj7gGFq7guR8AFya0mKacu+ayptJfaRuM0mdHCqiOth4FnRP8mPhEroFPx6Ift8wHA=="
-               },
                "vscode-jsonrpc": {
                        "version": "8.0.1",
                        "resolved": 
"https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz";,
diff --git a/java/java.lsp.server/vscode/package.json 
b/java/java.lsp.server/vscode/package.json
index 3e88a1d4ba..54be2ad281 100644
--- a/java/java.lsp.server/vscode/package.json
+++ b/java/java.lsp.server/vscode/package.json
@@ -140,6 +140,23 @@
                                        "default": 100,
                                        "description": "Timeout (in 
milliseconds) for loading Javadoc in code completion (-1 for unlimited)"
                                },
+                               "netbeans.format.codeFormatter": {
+                                       "type": "string",
+                                       "enum": [
+                                               "NetBeans",
+                                               "Eclipse",
+                                               "Google",
+                                               "Spring"
+                                       ],
+                                       "enumDescriptions": [
+                                               "Internal NetBeans Code 
Formatter",
+                                               "Eclipse Code Formatter",
+                                               "Goolge Code Formatter",
+                                               "Spring Code Formatter"
+                                       ],
+                                       "description": "Code formatter to use",
+                                       "default": "NetBeans"
+                               },
                                "netbeans.format.settingsPath": {
                                        "type": "string",
                                        "description": "Path to the file 
containing exported formatter settings",
@@ -835,7 +852,7 @@
        },
        "dependencies": {
                "jsonc-parser": "3.0.0",
-               "vscode-debugadapter": "1.51.0",
+               "@vscode/debugadapter": "1.55.1",
                "vscode-languageclient": "8.0.1"
        }
 }
diff --git 
a/nbbuild/misc/prepare-bundles/src/main/java/org/netbeans/prepare/bundles/PrepareBundles.java
 
b/nbbuild/misc/prepare-bundles/src/main/java/org/netbeans/prepare/bundles/PrepareBundles.java
index 78f88f3658..f8f0c21d63 100644
--- 
a/nbbuild/misc/prepare-bundles/src/main/java/org/netbeans/prepare/bundles/PrepareBundles.java
+++ 
b/nbbuild/misc/prepare-bundles/src/main/java/org/netbeans/prepare/bundles/PrepareBundles.java
@@ -19,6 +19,7 @@
 package org.netbeans.prepare.bundles;
 
 import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -104,107 +105,18 @@ public class PrepareBundles {
                 if (".bin".equals(module.getFileName().toString())) continue;
                 if 
(".package-lock.json".equals(module.getFileName().toString())) continue;
                 if ("@types".equals(module.getFileName().toString())) continue;
-                if ("@ungap".equals(module.getFileName().toString())) {
-                    module = module.resolve("promise-all-settled");
-                }
-                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 = packageJsonData.get("license").toString();
-
-                String licenseText = null;
-
-                try (DirectoryStream<Path> insideModule = 
Files.newDirectoryStream(module)) {
-                    for (Path licenseCandidate : insideModule) {
-                        String fileName = 
licenseCandidate.getFileName().toString();
-
-                        if (LICENSE_FILE_NAMES.stream().anyMatch(p -> 
p.matcher(fileName).matches())) {
-                            licenseText = 
readString(module.resolve(licenseCandidate));
-                            break;
-                        }
-                    }
-                }
-
-                String hardcodedLicenseName = name + "-" + version + 
"-license";
-                URL hardcodedLicense = 
PrepareBundles.class.getResource(hardcodedLicenseName);
-                if (hardcodedLicense != null ){
-                    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);
+                if ("@vscode".equals(module.getFileName().toString())) {
+                    try (DirectoryStream<Path> sds = 
Files.newDirectoryStream(module)) {
+                        for (Path sModule : sds) {
+                            checkModule(sModule, sb, tokens2Projects, 
project2License, bundlesDir, targetDir, externalDir, binariesList);
                         }
                     }
-                    licenseText = licenseTextBuffer.toString();
-                } else if (licenseText == null) {
-                    sb.append("Cannot find license for: ").
-                        append(module.getFileName()).
-                        append(" in ").
-                        append(hardcodedLicenseName).
-                        append("\n");
                     continue;
                 }
-
-                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);
-                }
-
-                //fill project2Notice here if needed
-
-                List<String> tokens = licenseTextToTokens(licenseText);
-                String licenseTextFin = licenseText;
-
-                tokens2Projects.computeIfAbsent(tokens, t -> new 
LicenseUses(licenseKey, 
licenseTextFin)).projects.add(module.getFileName().toString());
-                project2License.put(module.getFileName().toString(), new 
LicenseDescription(name, version, description, homepage, licenseKey, 
licenseText));
-
-                Path bundle = bundlesDir.resolve(module.getFileName() + "-" + 
version + ".zip");
-                try (JarOutputStream out = new 
JarOutputStream(Files.newOutputStream(bundle));
-                    Stream<Path> files = Files.walk(module, 
FileVisitOption.FOLLOW_LINKS)) {
-                    Path moduleFinal = module;
-                    files.forEach(p -> {
-                        if (p == moduleFinal) return ;
-                        try {
-                            String relative = 
moduleFinal.getParent().relativize(p).toString();
-                            boolean isDir = Files.isDirectory(p);
-                            ZipEntry ze = new ZipEntry(relative + (isDir ? "/" 
: ""));
-                            out.putNextEntry(ze);
-                            if (!isDir) {
-                                if (relative.equals("package.json")) {
-                                    
out.write(packageJsonText.replace(targetDir.toString(), "").getBytes("UTF-8"));
-                                } else {
-                                    Files.copy(p, out);
-                                }
-                            }
-                        } catch (IOException ex) {
-                            throw new UncheckedIOException(ex);
-                        }
-                    });
-                }
-                MessageDigest md = MessageDigest.getInstance("SHA1");
-                md.update(Files.readAllBytes(bundle));
-                StringBuilder hash = new StringBuilder();
-                for (byte b : md.digest()) {
-                    hash.append(String.format("%02X", b));
+                if ("@ungap".equals(module.getFileName().toString())) {
+                    module = module.resolve("promise-all-settled");
                 }
-                Path external = externalDir.resolve(hash + "-" + 
bundle.getFileName());
-                Files.copy(bundle, external);
-                binariesList.write(hash + " " + 
bundle.getFileName().toString() + nl);
+                checkModule(module, sb, tokens2Projects, project2License, 
bundlesDir, targetDir, externalDir, binariesList);
             }
         }
         if (sb.length() > 0) {
@@ -259,6 +171,97 @@ public class PrepareBundles {
 
     }
 
+    private static void checkModule(Path module, StringBuilder sb, 
Map<List<String>, LicenseUses> tokens2Projects, Map<String, LicenseDescription> 
project2License, Path bundlesDir, Path targetDir, Path externalDir, final 
Writer binariesList) throws NoSuchAlgorithmException, IOException, 
IllegalStateException, JsonSyntaxException {
+        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 = packageJsonData.get("license").toString();
+        String licenseText = null;
+        try (DirectoryStream<Path> insideModule = 
Files.newDirectoryStream(module)) {
+            for (Path licenseCandidate : insideModule) {
+                String fileName = licenseCandidate.getFileName().toString();
+                
+                if (LICENSE_FILE_NAMES.stream().anyMatch(p -> 
p.matcher(fileName).matches())) {
+                    licenseText = readString(module.resolve(licenseCandidate));
+                    break;
+                }
+            }
+        }
+        String hardcodedLicenseName = name + "-" + version + "-license";
+        URL hardcodedLicense = 
PrepareBundles.class.getResource(hardcodedLicenseName);
+        if (hardcodedLicense != null) {
+            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();
+        } else if (licenseText == null) {
+            sb.append("Cannot find license for: ").
+                    append(module.getFileName()).
+                    append(" in ").
+                    append(hardcodedLicenseName).
+                    append("\n");
+            return;
+        }
+        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);
+        }
+        //fill project2Notice here if needed
+        
+        List<String> tokens = licenseTextToTokens(licenseText);
+        String licenseTextFin = licenseText;
+        tokens2Projects.computeIfAbsent(tokens, t -> new 
LicenseUses(licenseKey, 
licenseTextFin)).projects.add(module.getFileName().toString());
+        project2License.put(module.getFileName().toString(), new 
LicenseDescription(name, version, description, homepage, licenseKey, 
licenseText));
+        Path bundle = bundlesDir.resolve(module.getFileName() + "-" + version 
+ ".zip");
+        try (JarOutputStream out = new 
JarOutputStream(Files.newOutputStream(bundle));
+                Stream<Path> files = Files.walk(module, 
FileVisitOption.FOLLOW_LINKS)) {
+            Path moduleFinal = module;
+            files.forEach(p -> {
+                if (p == moduleFinal) return ;
+                try {
+                    String relative = 
moduleFinal.getParent().relativize(p).toString();
+                    boolean isDir = Files.isDirectory(p);
+                    ZipEntry ze = new ZipEntry(relative + (isDir ? "/" : ""));
+                    out.putNextEntry(ze);
+                    if (!isDir) {
+                        if (relative.equals("package.json")) {
+                            
out.write(packageJsonText.replace(targetDir.toString(), "").getBytes("UTF-8"));
+                        } else {
+                            Files.copy(p, out);
+                        }
+                    }
+                } catch (IOException ex) {
+                    throw new UncheckedIOException(ex);
+                }
+            });
+        }
+        MessageDigest md = MessageDigest.getInstance("SHA1");
+        md.update(Files.readAllBytes(bundle));
+        StringBuilder hash = new StringBuilder();
+        for (byte b : md.digest()) {
+            hash.append(String.format("%02X", b));
+        }
+        Path external = externalDir.resolve(hash + "-" + bundle.getFileName());
+        Files.copy(bundle, external);
+        binariesList.write(hash + " " + bundle.getFileName().toString() + nl);
+    }
+
     private static String readString(Path p) throws IOException {
         return new String(Files.readAllBytes(p), StandardCharsets.UTF_8);
     }


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