private static String taskToString(String taskName, List<String> arguments) { List<String> clonedArguments = new ArrayList<String>(arguments); for (int i = 0; i < clonedArguments.size(); i++) { final String s = clonedArguments.get(i); final boolean maskMavenProxyPassword = s.contains("proxy="); if (maskMavenProxyPassword) { final String bestEffortMaskedPassword = maskPassword(s); clonedArguments.set(i, bestEffortMaskedPassword); } } return "'" + taskName + " " + implode(" ", clonedArguments) + "'"; }
private String getAbsoluteTaskLocation() { String location = normalize(taskLocation); if (Utils.isRelative(taskLocation)) { File taskFile = new File(config.getWorkingDirectory(), location); if (!taskFile.exists()) { taskFile = new File(config.getInstallDirectory(), location); } location = taskFile.getAbsolutePath(); } return location; }
public static List<String> prepend(String first, List<String> list){ return merge(Arrays.asList(first), list); }
public YarnExecutor(YarnExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment) { final String yarn = config.getYarnPath().getAbsolutePath(); List<String> localPaths = new ArrayList<>(); localPaths.add(config.getYarnPath().getParent()); localPaths.add(config.getNodePath().getParent()); executor = new ProcessExecutor(config.getWorkingDirectory(), localPaths, Utils.prepend(yarn, arguments), config.getPlatform(), additionalEnvironment); }
@Override public File getNpmPath() { return new File(installConfig.getInstallDirectory() + Utils.normalize(NPM)); }
public NodeExecutor(NodeExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment){ final String node = config.getNodePath().getAbsolutePath(); List<String> localPaths = new ArrayList<String>(); localPaths.add(config.getNodePath().getParent()); this.executor = new ProcessExecutor( config.getWorkingDirectory(), localPaths, Utils.prepend(node, arguments), config.getPlatform(), additionalEnvironment); }
private boolean npmIsAlreadyInstalled() { try { final File npmPackageJson = new File( this.config.getInstallDirectory() + Utils.normalize("/node/node_modules/npm/package.json")); if (npmPackageJson.exists()) { HashMap<String, Object> data = new ObjectMapper().readValue(npmPackageJson, HashMap.class); if (data.containsKey(VERSION)) { final String foundNpmVersion = data.get(VERSION).toString(); if (foundNpmVersion.equals(this.npmVersion)) { this.logger.info("NPM {} is already installed.", foundNpmVersion); return true; } else { this.logger.info("NPM {} was installed, but we need version {}", foundNpmVersion, this.npmVersion); return false; } } else { this.logger.info("Could not read NPM version from package.json"); return false; } } else { return false; } } catch (IOException ex) { throw new RuntimeException("Could not read package.json", ex); } }
public final void execute(String args, Map<String, String> environment) throws TaskRunnerException { final String absoluteTaskLocation = getAbsoluteTaskLocation(); final List<String> arguments = getArguments(args); logger.info("Running " + taskToString(taskName, arguments) + " in " + config.getWorkingDirectory()); try { final int result = new NodeExecutor(config, prepend(absoluteTaskLocation, arguments), environment).executeAndRedirectOutput(logger); if (result != 0) { throw new TaskRunnerException(taskToString(taskName, arguments) + " failed. (error code " + result + ")"); } } catch (ProcessExecutionException e) { throw new TaskRunnerException(taskToString(taskName, arguments) + " failed.", e); } }
private static String taskToString(String taskName, List<String> arguments) { List<String> clonedArguments = new ArrayList<>(arguments); for (int i = 0; i < clonedArguments.size(); i++) { final String s = clonedArguments.get(i); final boolean maskMavenProxyPassword = s.contains("proxy="); if (maskMavenProxyPassword) { final String bestEffortMaskedPassword = maskPassword(s); clonedArguments.set(i, bestEffortMaskedPassword); } } return "'" + taskName + " " + implode(" ", clonedArguments) + "'"; }