Skip to content

Commit

Permalink
Fix eclipse-wildwebdeveloper#1247 - Maven build use node from PATH on…
Browse files Browse the repository at this point in the history
… mac os
  • Loading branch information
zulus committed Sep 24, 2023
1 parent bd4d902 commit 4bbd4a0
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 12 deletions.
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.wildwebdeveloper.embedder.node.feature"
label="%name"
version="1.0.6.qualifier"
version="1.0.7.qualifier"
provider-name="Eclipse Wild Web Developer project"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper.embedder.node.feature/pom.xml
Expand Up @@ -7,7 +7,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>eclipse-feature</packaging>
<version>1.0.6-SNAPSHOT</version>
<version>1.0.7-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper.embedder.node/pom.xml
Expand Up @@ -7,7 +7,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>eclipse-plugin</packaging>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>

<build>
<plugins>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> commands)
{
List<String> 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<String> commands)
{
List<String> tmp = new ArrayList<>();


tmp.add(getNpmJSLocation().getAbsolutePath());
tmp.addAll(commands);

return prepareNodeProcessBuilder(tmp);
}

public static File which(String program) {
Properties properties = getNodeJsInfoProperties();
Expand Down
Expand Up @@ -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()
Expand Down
Expand Up @@ -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()
Expand Down
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.wildwebdeveloper/pom.xml
Expand Up @@ -180,6 +180,7 @@
<arg>pack</arg>
<arg>--no-bin-links</arg>
<arg>--ignore-scripts</arg>
<arg>--install-strategy=hoisted</arg>
<arg>vscode/VSCode-linux-x64/resources/app/extensions/html-language-features/server</arg>
<arg>vscode/VSCode-linux-x64/resources/app/extensions/css-language-features/server</arg>
<arg>vscode/VSCode-linux-x64/resources/app/extensions/json-language-features/server</arg>
Expand All @@ -204,6 +205,7 @@
<arg>--only=prod</arg>
<arg>--no-bin-links</arg>
<arg>--ignore-scripts</arg>
<arg>--install-strategy=hoisted</arg>
<!-- The actual verions for the LS and other dependency NPM Modules are to be set in './package.json file',
which is used to install the dependencies -->
</arguments>
Expand Down
Expand Up @@ -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<String> 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);
Expand Down

0 comments on commit 4bbd4a0

Please sign in to comment.