@Override public File getInstallDirectory() { return installConfig.getInstallDirectory(); }
@Override public Platform getPlatform() { return installConfig.getPlatform(); } }
@Override public File getWorkingDirectory() { return installConfig.getWorkingDirectory(); }
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); } }
File archive = this.config.getCacheResolver().resolve(cacheDescriptor);
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()); File archive = this.config.getCacheResolver().resolve(cacheDescriptor);
private void installYarn() throws InstallationException { try { logger.info("Installing Yarn version {}", yarnVersion); String downloadUrl = yarnDownloadRoot + yarnVersion; String extension = "tar.gz"; String fileending = "/yarn-" + yarnVersion + "." + extension; downloadUrl += fileending; CacheDescriptor cacheDescriptor = new CacheDescriptor("yarn", yarnVersion, extension); File archive = config.getCacheResolver().resolve(cacheDescriptor); downloadFileIfMissing(downloadUrl, archive, userName, password); File installDirectory = getInstallDirectory(); // We need to delete the existing yarn directory first so we clean out any old files, and // so we can rename the package directory below. try { if (installDirectory.isDirectory()) { FileUtils.deleteDirectory(installDirectory); } } catch (IOException e) { logger.warn("Failed to delete existing Yarn installation."); } extractFile(archive, installDirectory); ensureCorrectYarnRootDirectory(installDirectory, yarnVersion); logger.info("Installed Yarn locally."); } catch (DownloadException e) { throw new InstallationException("Could not download Yarn", e); } catch (ArchiveExtractionException | IOException e) { throw new InstallationException("Could not extract the Yarn archive", e); } }
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()); File archive = this.config.getCacheResolver().resolve(cacheDescriptor);
private File getInstallDirectory() { File installDirectory = new File(config.getInstallDirectory(), INSTALL_PATH); if (!installDirectory.exists()) { logger.debug("Creating install directory {}", installDirectory); installDirectory.mkdirs(); } return installDirectory; }
@Override public Platform getPlatform() { return installConfig.getPlatform(); } }
@Override public File getWorkingDirectory() { return installConfig.getWorkingDirectory(); }
private File getInstallDirectory() { File installDirectory = new File(this.config.getInstallDirectory(), INSTALL_PATH); if (!installDirectory.exists()) { this.logger.debug("Creating install directory {}", installDirectory); installDirectory.mkdirs(); } return installDirectory; }
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(); } } } }
private File getNodeInstallDirectory() { File installDirectory = new File(this.config.getInstallDirectory(), NodeInstaller.INSTALL_PATH); if (!installDirectory.exists()) { this.logger.debug("Creating install directory {}", installDirectory); installDirectory.mkdirs(); } return installDirectory; }
@Override public File getNpmPath() { return new File(installConfig.getInstallDirectory() + Utils.normalize(NPM)); }
@Override public File getNodePath() { String nodeExecutable = getPlatform().isWindows() ? NODE_WINDOWS : NODE_DEFAULT; return new File(installConfig.getInstallDirectory() + nodeExecutable); }
@Override public File getYarnPath() { String yarnExecutable = getPlatform().isWindows() ? YARN_WINDOWS : YARN_DEFAULT; return new File(installConfig.getInstallDirectory() + yarnExecutable); }
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); } }