Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into GH-2588
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Jan 18, 2024
2 parents ce20bc7 + d3ba9f4 commit 71c35b8
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class N4JSGlobals {
* </ul>
* If it contains fewer than three version segments, all numbers for the remaining segments are deemed compatible.
*/
public static final String NODE_VERSION = "20.3";
public static final String NODE_VERSION = "20.10";

/** URL of the public npm registry. */
public static final String NPMJS_URL = "https://registry.npmjs.org/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public ProcessResult yarnRun(Path workingDir, String... options) {
});
}

/** see {@link TestProcessExecuter#pnpmRun(Path, Map, String[])} */
public ProcessResult pnpmRun(Path workingDir, String... options) {
return withoutCorruptingGlobalState(() -> {
return getExProcessExecuter().pnpmRun(workingDir, environment, options);
});
}

/** see {@link TestProcessExecuter#gitRun(Path, Map, String[])} */
public ProcessResult gitRun(Path workingDir, String... options) {
return withoutCorruptingGlobalState(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public ProcessBuilder yarnRun(Path workingDirectory, Map<String, String> environ
return createProcessBuilder(workingDirectory, cmd, environment);
}

/** @return a process: {@code pnpm install} */
public ProcessBuilder pnpmRun(Path workingDirectory, Map<String, String> environment, String[] options) {
final String[] cmd = createCommandPnpmRun(environment, options);
return createProcessBuilder(workingDirectory, cmd, environment);
}

/** @return a process: {@code git OPTIONS} */
public ProcessBuilder gitRun(Path workingDirectory, Map<String, String> environment, String[] options) {
final String[] cmd = createCommandGitRun(environment, options);
Expand Down Expand Up @@ -110,6 +116,16 @@ private String[] createCommandYarnRun(Map<String, String> output_env, String[] o
return cmd.toArray(new String[0]);
}

private String[] createCommandPnpmRun(Map<String, String> output_env, String[] options) {
List<String> cmd = getCommands(output_env, binariesLocatorHelper.getPnpmBinary(), options);

// yarn will invoke node, so node must be on the path:
Path nodePath = binariesLocatorHelper.getNodeBinary().toAbsolutePath().getParent();
prependToPathString(output_env, nodePath);

return cmd.toArray(new String[0]);
}

private String[] createCommandGitRun(Map<String, String> output_env, String[] options) {
List<String> cmd = getCommands(output_env, binariesLocatorHelper.getGitBinary(), options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public ProcessResult yarnRun(Path workingDir, Map<String, String> environment, S
return joinProcess("yarn", () -> testProcessBuilder.yarnRun(workingDir, environment, options));
}

/** Runs pnpm OPTIONS in the given {@code workingDir} */
public ProcessResult pnpmRun(Path workingDir, Map<String, String> environment, String... options) {
return joinProcess("pnpm", () -> testProcessBuilder.pnpmRun(workingDir, environment, options));
}

/** Runs git OPTIONS in the given {@code workingDir} */
public ProcessResult gitRun(Path workingDir, Map<String, String> environment, String... options) {
return joinProcess("git", () -> testProcessBuilder.gitRun(workingDir, environment, options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public final class BinariesConstants {
*/
public static final String DEFAULT_YARN_PATH_VM_ARG = "org.eclipse.n4js.defaultYarnPath";

/**
* Default pnpm path, similar to {@code DEFAULT_NODE_PATH_VM_ARG}
*/
public static final String DEFAULT_PNPM_PATH_VM_ARG = "org.eclipse.n4js.defaultPnpmPath";

/**
* Default git path, similar to {@code DEFAULT_NODE_PATH_VM_ARG}
*/
Expand Down Expand Up @@ -87,6 +92,16 @@ public final class BinariesConstants {
*/
public static final String YARN_PATH_ENV = "YARN_PATH";

/**
* Jenkins environment variable for the {@code pnpm} binary path. Points to the actual binary (with an absolute
* path) instead of pointing to the folder containing the binary.
*
* <p>
* Even if it is available the {@link #DEFAULT_PNPM_PATH_VM_ARG <code>org.eclipse.n4js.defaultPnpmPath</code>} VM
* argument might override this configuration.
*/
public static final String PNPM_PATH_ENV = "PNPM_PATH";

/**
* Jenkins environment variable for the {@code git} binary path. Points to the actual binary (with an absolute path)
* instead of pointing to the folder containing the binary.
Expand Down Expand Up @@ -131,6 +146,18 @@ public final class BinariesConstants {
? new File("C:" + separator + "Program Files" + separator + "yarn").getAbsolutePath()
: new File(separator + "usr" + File.separator + "local" + separator + "bin").getAbsolutePath();

/**
* The (fallback) built-in default {@code pnpm} path if the above VM or ENV property is not specified.
*
* <ul>
* <li>On Windows systems: {@code C:\Program Files\pnpm}</li>
* <li>On Unix systems: {@code /usr/local/bin}</li>
* </ul>
*/
public static final String BUILT_IN_DEFAULT_PNPM_PATH = isWindows()
? new File("C:" + separator + "Program Files" + separator + "pnpm").getAbsolutePath()
: new File(separator + "usr" + File.separator + "local" + separator + "bin").getAbsolutePath();

/**
* The (fallback) built-in default {@code git} path if the above VM or ENV property is not specified.
*
Expand Down Expand Up @@ -179,6 +206,8 @@ public final class BinariesConstants {
public static final String YARN_LABEL = "Yarn";
/** The {@code yarn} binary name without file extension. */
public static final String YARN_BINARY_NAME = "yarn";
/** The {@code pnpm} binary name without file extension. */
public static final String PNPM_BINARY_NAME = "pnpm";
/** The {@code git} binary name without file extension. */
public static final String GIT_BINARY_NAME = "git";
/** The minimum {@code yarn} version. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class BinariesLocatorHelper {
private Path memoizedNodePath = null;
private Path memoizedNpmPath = null;
private Path memoizedYarnPath = null;
private Path memoizedPnpmPath = null;
private Path memoizedGitPath = null;

/** Returns the path to the Java binary. */
Expand Down Expand Up @@ -89,6 +90,14 @@ public Path getYarnBinary() {
return memoizedYarnPath;
}

/** Returns the path to the pnpm binary. */
public Path getPnpmBinary() {
if (memoizedPnpmPath == null) {
memoizedPnpmPath = findPnpmPath().resolve(BinariesConstants.PNPM_BINARY_NAME);
}
return memoizedPnpmPath;
}

/** Returns the path to the yarn binary. */
public Path getGitBinary() {
if (memoizedGitPath == null) {
Expand Down Expand Up @@ -229,6 +238,63 @@ private Path findYarnPath() {
return yarnPathCandidate;
}

/**
* Like {@link #findNodePath()}, but for the pnpm binary.
*
* @return string with absolute path to the binary
*/
private Path findPnpmPath() {
Path pnpmPathCandidate = null;

// 1. lookup by DEFAULT_YARN_PATH_VM_ARG
pnpmPathCandidate = resolveFolderContaingBinary(
tryGetEnvOrSystemVariable(BinariesConstants.DEFAULT_PNPM_PATH_VM_ARG));
if (pnpmPathCandidate != null) {
info("User specified default pnpm path will be used: '" + pnpmPathCandidate
+ ".' based on the '" + BinariesConstants.DEFAULT_PNPM_PATH_VM_ARG + "' VM argument.");
return pnpmPathCandidate;
}
debug("Could not resolve pnpm path from '" + BinariesConstants.DEFAULT_PNPM_PATH_VM_ARG
+ "' VM argument.");

// 2. lookup by YARN_PATH_ENV
pnpmPathCandidate = resolveFolderContaingBinary(
tryGetEnvOrSystemVariable(BinariesConstants.PNPM_PATH_ENV));
if (pnpmPathCandidate != null) {
info("User specified default pnpm path will be used: '" + pnpmPathCandidate
+ ".' based on the '" + BinariesConstants.PNPM_PATH_ENV + "' environment argument.");
return pnpmPathCandidate;
}
debug("Could not resolve pnpm path from '" + BinariesConstants.PNPM_PATH_ENV);

// 3. lookup by PATH
pnpmPathCandidate = resolveFolderContaingBinary(
ExecutableLookupUtil.findInPath(BinariesConstants.PNPM_BINARY_NAME));
if (pnpmPathCandidate != null) {
info("Obtained pnpm path will be used: '" + pnpmPathCandidate
+ ".' based on the OS PATH.");
return pnpmPathCandidate;
}
debug("Could not resolve pnpm path from OS PATH variable.");

// 4. lookup by OS query
pnpmPathCandidate = resolveFolderContaingBinary(
lookForBinary(BinariesConstants.PNPM_BINARY_NAME));
if (pnpmPathCandidate != null) {
info("Obtained pnpm path will be used: '" + pnpmPathCandidate
+ ".' based on the OS dynamic lookup.");
return pnpmPathCandidate;

}
debug("Could not resolve pnpm path from OS dynamic lookup.");

// 5. use default, whether it is correct or not.
info("Could not resolve pnpm path. Falling back to default path: " + pnpmPathCandidate);
pnpmPathCandidate = new File(BinariesConstants.BUILT_IN_DEFAULT_PNPM_PATH).toPath();

return pnpmPathCandidate;
}

/**
* Like {@link #findNodePath()}, but for the git binary.
*
Expand Down

0 comments on commit 71c35b8

Please sign in to comment.