From 21410264a4f8cda58e286158ab21fb53e3d450a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Paku=C5=82a?= Date: Sun, 24 Sep 2023 19:30:49 +0200 Subject: [PATCH] Fix #1247 - Maven build use node from PATH on mac os --- .../feature.xml | 2 +- .../pom.xml | 2 +- .../META-INF/MANIFEST.MF | 2 +- .../pom.xml | 2 +- .../embedder/node/NodeJSManager.java | 61 ++++++++++++++++++- .../wildwebdeveloper/tests/TestAngular.java | 4 +- .../wildwebdeveloper/tests/TestESLint.java | 4 +- .../wildwebdeveloper/tests/TestVue.java | 4 +- org.eclipse.wildwebdeveloper/pom.xml | 1 + .../debug/npm/NpmLaunchDelegate.java | 2 +- 10 files changed, 72 insertions(+), 12 deletions(-) diff --git a/org.eclipse.wildwebdeveloper.embedder.node.feature/feature.xml b/org.eclipse.wildwebdeveloper.embedder.node.feature/feature.xml index f2e93554e2..53072cc33c 100644 --- a/org.eclipse.wildwebdeveloper.embedder.node.feature/feature.xml +++ b/org.eclipse.wildwebdeveloper.embedder.node.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.wildwebdeveloper.embedder.node.feature/pom.xml b/org.eclipse.wildwebdeveloper.embedder.node.feature/pom.xml index bd9e47e2c9..1de50d6740 100644 --- a/org.eclipse.wildwebdeveloper.embedder.node.feature/pom.xml +++ b/org.eclipse.wildwebdeveloper.embedder.node.feature/pom.xml @@ -7,7 +7,7 @@ 1.0.0-SNAPSHOT eclipse-feature - 1.0.6-SNAPSHOT + 1.0.7-SNAPSHOT diff --git a/org.eclipse.wildwebdeveloper.embedder.node/META-INF/MANIFEST.MF b/org.eclipse.wildwebdeveloper.embedder.node/META-INF/MANIFEST.MF index b82114c301..1406abc91b 100644 --- a/org.eclipse.wildwebdeveloper.embedder.node/META-INF/MANIFEST.MF +++ b/org.eclipse.wildwebdeveloper.embedder.node/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Manager for embedded Node.js Bundle-SymbolicName: org.eclipse.wildwebdeveloper.embedder.node -Bundle-Version: 1.0.2.qualifier +Bundle-Version: 1.0.3.qualifier Bundle-Vendor: Eclipse Wild Web Developer Automatic-Module-Name: org.eclipse.wildwebdeveloper.embedder.node Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/org.eclipse.wildwebdeveloper.embedder.node/pom.xml b/org.eclipse.wildwebdeveloper.embedder.node/pom.xml index 596bf60545..6c2865ad4a 100644 --- a/org.eclipse.wildwebdeveloper.embedder.node/pom.xml +++ b/org.eclipse.wildwebdeveloper.embedder.node/pom.xml @@ -7,7 +7,7 @@ 1.0.0-SNAPSHOT eclipse-plugin - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT diff --git a/org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node/NodeJSManager.java b/org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node/NodeJSManager.java index 92d7dadfed..5cd2858fed 100644 --- a/org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node/NodeJSManager.java +++ b/org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node/NodeJSManager.java @@ -22,6 +22,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import org.eclipse.core.internal.runtime.InternalPlatform; @@ -117,12 +120,68 @@ public static File getNpmLocation() { File nodeJsLocation = getNodeJsLocation(); if (nodeJsLocation != null) { File res = new File(nodeJsLocation.getParentFile(), npmFileName); - if (res.canExecute()) { + if (res.exists()) { return res; } } return which(npmFileName); } + + public static File getNpmJSLocation() { + + try { + File npmLocation = getNpmLocation().getCanonicalFile(); + if (npmLocation.getAbsolutePath().endsWith(".js")) { + return npmLocation; + } + String path = "node_modules/npm/bin/npm-cli.js"; + if (new File(npmLocation.getParentFile(), "node_modules").exists()) { + return new File(npmLocation.getParentFile(), path); + } + File target = new File( npmLocation.getParentFile().getParentFile(), path); + if (target.exists()) { + return target; + } + + + return new File( npmLocation.getParentFile(), "lib/cli.js"); + } catch (IOException e) { + } + + return null; + + + } + + public static ProcessBuilder prepareNodeProcessBuilder(String... commands) + { + return prepareNodeProcessBuilder(Arrays.asList(commands)); + } + + public static ProcessBuilder prepareNodeProcessBuilder(List commands) + { + List tmp = new ArrayList<>(); + tmp.add(getNodeJsLocation().getAbsolutePath()); + tmp.addAll(commands); + + return new ProcessBuilder(tmp); + } + + public static ProcessBuilder prepareNPMProcessBuilder(String... commands) + { + return prepareNPMProcessBuilder(Arrays.asList(commands)); + } + + public static ProcessBuilder prepareNPMProcessBuilder(List commands) + { + List tmp = new ArrayList<>(); + + + tmp.add(getNpmJSLocation().getAbsolutePath()); + tmp.addAll(commands); + + return prepareNodeProcessBuilder(tmp); + } public static File which(String program) { Properties properties = getNodeJsInfoProperties(); diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestAngular.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestAngular.java index 3aab21028e..cada34c1ec 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestAngular.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestAngular.java @@ -51,8 +51,8 @@ public static void setUp() throws Exception { AllCleanRule.enableLogging(); project = Utils.provisionTestProject("angular-app"); - ProcessBuilder builder = new ProcessBuilder(NodeJSManager.getNpmLocation().getAbsolutePath(), "install", - "--no-bin-links", "--ignore-scripts").directory(project.getLocation().toFile()); + ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") + .directory(project.getLocation().toFile()); Process process = builder.start(); System.out.println(builder.command().toString()); String result = new BufferedReader(new InputStreamReader(process.getErrorStream())).lines() diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java index a634b6174e..d2ee71f605 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestESLint.java @@ -78,8 +78,8 @@ public static void setUpProject() throws Exception { try (InputStream eslintRc = TestESLint.class.getResourceAsStream("/testProjects/eslint/ESLintProj.js")) { Files.copy(eslintRc, new File(projectDirectory, "ESLintProj.tsx").toPath()); } - ProcessBuilder builder = new ProcessBuilder(NodeJSManager.getNpmLocation().getAbsolutePath(), "install", - "--no-bin-links", "--ignore-scripts").directory(projectDirectory); + ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") + .directory(projectDirectory); Process dependencyInstaller = builder.start(); System.out.println(builder.command().toString()); String result = new BufferedReader(new InputStreamReader(dependencyInstaller.getErrorStream())).lines() diff --git a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java index acf32e23df..161d110381 100644 --- a/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java +++ b/org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestVue.java @@ -55,8 +55,8 @@ public static void setUp() throws Exception { AllCleanRule.enableLogging(); project = Utils.provisionTestProject("vue-app"); - ProcessBuilder builder = new ProcessBuilder(NodeJSManager.getNpmLocation().getAbsolutePath(), "install", - "--no-bin-links", "--ignore-scripts").directory(project.getLocation().toFile()); + ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") + .directory(project.getLocation().toFile()); Process process = builder.start(); System.out.println(builder.command().toString()); String result = new BufferedReader(new InputStreamReader(process.getErrorStream())).lines() diff --git a/org.eclipse.wildwebdeveloper/pom.xml b/org.eclipse.wildwebdeveloper/pom.xml index e16ffedcfe..2bcd265ff0 100644 --- a/org.eclipse.wildwebdeveloper/pom.xml +++ b/org.eclipse.wildwebdeveloper/pom.xml @@ -193,6 +193,7 @@ pack --no-bin-links --ignore-scripts + --install-strategy=hoisted vscode/VSCode-linux-x64/resources/app/extensions/html-language-features/server vscode/VSCode-linux-x64/resources/app/extensions/css-language-features/server vscode/VSCode-linux-x64/resources/app/extensions/json-language-features/server diff --git a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/npm/NpmLaunchDelegate.java b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/npm/NpmLaunchDelegate.java index 97e3186cc7..37bd41e66d 100644 --- a/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/npm/NpmLaunchDelegate.java +++ b/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/debug/npm/NpmLaunchDelegate.java @@ -63,7 +63,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun final String argumentString = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(configuration.getAttribute(ARGUMENTS, "No NPM argument set") //$NON-NLS-1$ .trim()); List arguments = new ArrayList<>(); - arguments.add(NodeJSManager.getNpmLocation().getAbsolutePath()); + arguments.addAll(NodeJSManager.prepareNPMProcessBuilder().command()); arguments.addAll(Arrays.asList(argumentString.split(" "))); //$NON-NLS-1$ monitor.beginTask(argumentString + ' ' + packageJSON.getAbsolutePath(), 2); monitor.worked(1);