public static Platform guess(){ OS os = OS.guess(); Architecture architecture = Architecture.guess(); return new Platform(os,architecture); }
public String getNodeClassifier() { return this.getCodename() + "-" + this.architecture.name(); } }
public String getNodeDownloadFilename(String nodeVersion, boolean archiveOnWindows) { if(isWindows() && !archiveOnWindows) { if(architecture == Architecture.x64){ if (nodeVersion.startsWith("v0.")) { return nodeVersion+"/x64/node.exe"; } else { return nodeVersion+"/win-x64/node.exe"; } } else { if (nodeVersion.startsWith("v0.")) { return nodeVersion + "/node.exe"; } else { return nodeVersion+"/win-x86/node.exe"; } } } else { return nodeVersion + "/" + getLongNodeFilename(nodeVersion, archiveOnWindows) + "." + os.getArchiveExtension(); } }
public String getLongNodeFilename(String nodeVersion, boolean archiveOnWindows) { if(isWindows() && !archiveOnWindows){ return "node.exe"; } else { return "node-" + nodeVersion + "-" + this.getNodeClassifier(); } }
private void installNodeWithNpmForWindows() throws InstallationException { try { final String longNodeFilename = this.config.getPlatform().getLongNodeFilename(this.nodeVersion, true); String downloadUrl = this.nodeDownloadRoot + this.config.getPlatform().getNodeDownloadFilename(this.nodeVersion, true); String classifier = this.config.getPlatform().getNodeClassifier(); this.config.getPlatform().getArchiveExtension());
private void installNodeForWindows() throws InstallationException { final String downloadUrl = this.nodeDownloadRoot + this.config.getPlatform().getNodeDownloadFilename(this.nodeVersion, false); try { File destinationDirectory = getInstallDirectory(); File destination = new File(destinationDirectory, "node.exe"); String classifier = this.config.getPlatform().getNodeClassifier(); CacheDescriptor cacheDescriptor = new CacheDescriptor("node", this.nodeVersion, classifier, "exe"); File binary = this.config.getCacheResolver().resolve(cacheDescriptor); downloadFileIfMissing(downloadUrl, binary, this.userName, this.password); this.logger.info("Copying node binary from {} to {}", binary, destination); FileUtils.copyFile(binary, destination); this.logger.info("Installed node locally."); } catch (DownloadException e) { throw new InstallationException("Could not download Node.js from: " + downloadUrl, e); } catch (IOException e) { throw new InstallationException("Could not install Node.js", e); } }
private Map<String, String> createEnvironment(List<String> paths, Platform platform, Map<String, String> additionalEnvironment) { final Map<String, String> environment = new HashMap<>(System.getenv()); String pathVarName = "PATH"; String pathVarValue = environment.get(pathVarName); if (platform.isWindows()) { for (Map.Entry<String, String> entry : environment.entrySet()) { if ("PATH".equalsIgnoreCase(entry.getKey())) { pathVarName = entry.getKey(); pathVarValue = entry.getValue(); } } } StringBuilder pathBuilder = new StringBuilder(); if (pathVarValue != null) { pathBuilder.append(pathVarValue).append(File.pathSeparator); } for (String path : paths) { pathBuilder.insert(0, File.pathSeparator).insert(0, path); } environment.put(pathVarName, pathBuilder.toString()); if (additionalEnvironment != null) { environment.putAll(additionalEnvironment); } return environment; }
/** * Get the platform in which the plugin is executed. * * @return Platform platform */ @Override public Platform getPlatform() { return Platform.guess(); } }
private void installNodeDefault() throws InstallationException { try { final String longNodeFilename = this.config.getPlatform().getLongNodeFilename(this.nodeVersion, false); String downloadUrl = this.nodeDownloadRoot + this.config.getPlatform().getNodeDownloadFilename(this.nodeVersion, false); String classifier = this.config.getPlatform().getNodeClassifier(); this.config.getPlatform().getArchiveExtension());
@Override public File getYarnPath() { String yarnExecutable = getPlatform().isWindows() ? YARN_WINDOWS : YARN_DEFAULT; return new File(installConfig.getInstallDirectory() + yarnExecutable); }
/** * Get the platform in which the plugin is executed. * * @return Platform platform */ @Override public Platform getPlatform() { return Platform.guess(); } }
@Override public File getNodePath() { String nodeExecutable = getPlatform().isWindows() ? NODE_WINDOWS : NODE_DEFAULT; return new File(installConfig.getInstallDirectory() + nodeExecutable); }
public void install() throws InstallationException { // use static lock object for a synchronized block synchronized (LOCK) { if (this.nodeDownloadRoot == null || this.nodeDownloadRoot.isEmpty()) { this.nodeDownloadRoot = DEFAULT_NODEJS_DOWNLOAD_ROOT; } if (!nodeIsAlreadyInstalled()) { this.logger.info("Installing node version {}", this.nodeVersion); if (!this.nodeVersion.startsWith("v")) { this.logger.warn("Node version does not start with naming convention 'v'."); } if (this.config.getPlatform().isWindows()) { if (npmProvided()) { installNodeWithNpmForWindows(); } else { installNodeForWindows(); } } else { installNodeDefault(); } } } }