@Override protected NodeTask newTask(FrontendPluginFactory factory, Config conf, ProxyConfig proxy, Map<String, String> env, String nodeVersion) throws InstallationException { Function<String, String> property = key -> conf.hasPath(key) ? conf.getString(key) : null; factory.getYarnInstaller(proxy) .setYarnVersion(yarnVersion) .setYarnDownloadRoot(conf.getString("yarn.downloadRoot")) .setUserName(property.apply("yarn.username")) .setPassword(property.apply("yarn.password")) .install(); YarnRunner yarn = factory.getYarnRunner(proxy, conf.getString("npm.registryURL")); return (cmd, args) -> { String cmdline = cmd + " " + Arrays.asList(args).stream().collect(Collectors.joining(" ")); yarn.execute(cmdline, env); }; }
private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) throws DownloadException { if (!destination.exists()) { downloadFile(downloadUrl, destination, userName, password); } }
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 YarnRunner downloadYarn(File workingDirectory, ProxyConfig proxyConfig, String npmRegistryUrl, String yarnVersion) { FrontendPluginFactory factory = new FrontendPluginFactory( workingDirectory, workingDirectory); try { factory.getYarnInstaller(proxyConfig).setYarnVersion(yarnVersion) .setYarnDownloadRoot( YarnInstaller.DEFAULT_YARN_DOWNLOAD_ROOT) .install(); } catch (InstallationException e) { throw new IllegalStateException("Failed to download yarn", e); } return factory.getYarnRunner(proxyConfig, validateUrl(npmRegistryUrl)); }
public YarnInstaller getYarnInstaller(ProxyConfig proxy) { return new YarnInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy)); }
@Override public void execute(FrontendPluginFactory factory) throws InstallationException { ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter); Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); if (null != server) { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).setPassword(server.getPassword()) .setUserName(server.getUsername()).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).setUserName(server.getUsername()) .setPassword(server.getPassword()).install(); } else { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).install(); } }
@Override public void execute(FrontendPluginFactory factory) throws InstallationException { ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter); Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); if (null != server) { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).setPassword(server.getPassword()) .setUserName(server.getUsername()).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).setUserName(server.getUsername()) .setPassword(server.getPassword()).install(); } else { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).install(); } }