diff --git a/frontend-maven-plugin/pom.xml b/frontend-maven-plugin/pom.xml index 210d9c0d..6318511d 100644 --- a/frontend-maven-plugin/pom.xml +++ b/frontend-maven-plugin/pom.xml @@ -55,6 +55,12 @@ plexus-build-api 0.0.7 + + com.google.code.findbugs + jsr305 + 3.0.2 + compile + diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AtlassianUtil.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AtlassianUtil.java new file mode 100644 index 00000000..d4357163 --- /dev/null +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AtlassianUtil.java @@ -0,0 +1,37 @@ +package com.github.eirslett.maven.plugins.frontend.mojo; + +import org.apache.maven.project.MavenProject; + +import javax.annotation.Nonnull; +import javax.naming.OperationNotSupportedException; + +import static java.util.Objects.requireNonNull; + +public class AtlassianUtil { + private AtlassianUtil() throws OperationNotSupportedException { + throw new OperationNotSupportedException("my dude, this is a util class"); + } + + public static boolean isAtlassianProject(@Nonnull MavenProject mavenProject) { + requireNonNull(mavenProject, "mavenProject"); + + // Ordered by likelihood + if (containsAtlassian(mavenProject.getGroupId()) || + containsAtlassian(mavenProject.getVersion()) || // we have forks with original coordinates + containsAtlassian(mavenProject.getArtifactId())) { + return true; + } + + // I don't think I'm missing anything here for forks that have a frontend?? + // AO plugin, Greenhopper, and Ridalabs all have Atlassian group IDs now + // Please take mercy on me and don't be offended if I forgot something + + return false; + } + + private static boolean containsAtlassian(@Nonnull String string) { + requireNonNull(string, "string"); + + return string.toLowerCase().contains("atlassian"); + } +} diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndNpmMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndNpmMojo.java index 1b9511a0..b18bee3a 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndNpmMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndNpmMojo.java @@ -1,6 +1,9 @@ package com.github.eirslett.maven.plugins.frontend.mojo; +import com.github.eirslett.maven.plugins.frontend.lib.ArchiveExtractionException; +import com.github.eirslett.maven.plugins.frontend.lib.DownloadException; import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory; +import com.github.eirslett.maven.plugins.frontend.lib.InstallationException; import com.github.eirslett.maven.plugins.frontend.lib.NPMInstaller; import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionDetector; import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper; @@ -14,7 +17,11 @@ import org.apache.maven.settings.Server; import org.apache.maven.settings.crypto.SettingsDecrypter; +import static com.github.eirslett.maven.plugins.frontend.lib.NPMInstaller.ATLASSIAN_NPM_DOWNLOAD_ROOT; +import static com.github.eirslett.maven.plugins.frontend.lib.NodeInstaller.ATLASSIAN_NODE_DOWNLOAD_ROOT; import static com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper.getDownloadableVersion; +import static com.github.eirslett.maven.plugins.frontend.lib.Utils.isBlank; +import static com.github.eirslett.maven.plugins.frontend.mojo.AtlassianUtil.isAtlassianProject; import static java.util.Objects.isNull; @Mojo(name="install-node-and-npm", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) @@ -29,7 +36,7 @@ public final class InstallNodeAndNpmMojo extends AbstractFrontendMojo { /** * Where to download NPM binary from. Defaults to https://registry.npmjs.org/npm/-/ */ - @Parameter(property = "npmDownloadRoot", required = false, defaultValue = NPMInstaller.DEFAULT_NPM_DOWNLOAD_ROOT) + @Parameter(property = "npmDownloadRoot", required = false) private String npmDownloadRoot; /** @@ -84,11 +91,6 @@ protected boolean skipExecution() { @Override public void execute(FrontendPluginFactory factory) throws Exception { - ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter); - String nodeDownloadRoot = getNodeDownloadRoot(); - String npmDownloadRoot = getNpmDownloadRoot(); - Server server = MojoUtils.decryptServer(serverId, session, decrypter); - String nodeVersion = NodeVersionDetector.getNodeVersion(workingDirectory, this.nodeVersion, this.nodeVersionFile); if (isNull(nodeVersion)) { @@ -101,6 +103,41 @@ public void execute(FrontendPluginFactory factory) throws Exception { String validNodeVersion = getDownloadableVersion(nodeVersion); + final String nodeDownloadRoot = getNodeDownloadRoot(); + final String npmDownloadRoot = getNpmDownloadRoot(); + + if (isAtlassianProject(project) && + isBlank(serverId) && + (isBlank(nodeDownloadRoot) || isBlank(npmDownloadRoot)) + ) { // If they're overridden the settings, they be the boss + getLog().info("Atlassian project detected, going to use the internal mirrors (requires VPN)"); + + serverId = "maven-atlassian-com"; + try { + install(factory, validNodeVersion, + isBlank(nodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : nodeDownloadRoot, + isBlank(npmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : npmDownloadRoot); + return; + } catch (InstallationException exception) { + // Ignore as many filesystem exceptions unrelated to the mirror easily + if (!(exception.getCause() instanceof DownloadException || + exception.getCause() instanceof ArchiveExtractionException)) { + throw exception; + } + getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors"); + getLog().debug("Using internal mirrors failed because: ", exception); + } finally { + serverId = null; + } + } + + install(factory, validNodeVersion, nodeDownloadRoot, npmDownloadRoot); + } + + private void install(FrontendPluginFactory factory, String validNodeVersion, String nodeDownloadRoot, String npmDownloadRoot) throws InstallationException { + ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter); + Server server = MojoUtils.decryptServer(serverId, session, decrypter); + if (null != server) { factory.getNodeInstaller(proxyConfig) .setNodeVersion(validNodeVersion) diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndPnpmMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndPnpmMojo.java index bbeb1f09..866df49b 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndPnpmMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndPnpmMojo.java @@ -1,6 +1,9 @@ package com.github.eirslett.maven.plugins.frontend.mojo; +import com.github.eirslett.maven.plugins.frontend.lib.ArchiveExtractionException; +import com.github.eirslett.maven.plugins.frontend.lib.DownloadException; import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory; +import com.github.eirslett.maven.plugins.frontend.lib.InstallationException; import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionDetector; import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper; import com.github.eirslett.maven.plugins.frontend.lib.PnpmInstaller; @@ -14,7 +17,11 @@ import org.apache.maven.settings.Server; import org.apache.maven.settings.crypto.SettingsDecrypter; +import static com.github.eirslett.maven.plugins.frontend.lib.NPMInstaller.ATLASSIAN_NPM_DOWNLOAD_ROOT; +import static com.github.eirslett.maven.plugins.frontend.lib.NodeInstaller.ATLASSIAN_NODE_DOWNLOAD_ROOT; import static com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper.getDownloadableVersion; +import static com.github.eirslett.maven.plugins.frontend.lib.Utils.isBlank; +import static com.github.eirslett.maven.plugins.frontend.mojo.AtlassianUtil.isAtlassianProject; import static java.util.Objects.isNull; @Mojo(name="install-node-and-pnpm", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true) @@ -29,7 +36,7 @@ public final class InstallNodeAndPnpmMojo extends AbstractFrontendMojo { /** * Where to download pnpm binary from. Defaults to https://registry.npmjs.org/pnpm/-/ */ - @Parameter(property = "pnpmDownloadRoot", required = false, defaultValue = PnpmInstaller.DEFAULT_PNPM_DOWNLOAD_ROOT) + @Parameter(property = "pnpmDownloadRoot", required = false) private String pnpmDownloadRoot; /** @@ -85,16 +92,6 @@ protected boolean skipExecution() { @Override public void execute(FrontendPluginFactory factory) throws Exception { - ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter); - // Use different names to avoid confusion with fields `nodeDownloadRoot` and - // `pnpmDownloadRoot`. - // - // TODO: Remove the `downloadRoot` config (with breaking change) to simplify download root - // resolution. - String resolvedNodeDownloadRoot = getNodeDownloadRoot(); - String resolvedPnpmDownloadRoot = getPnpmDownloadRoot(); - Server server = MojoUtils.decryptServer(serverId, session, decrypter); - String nodeVersion = NodeVersionDetector.getNodeVersion(workingDirectory, this.nodeVersion, this.nodeVersionFile); if (isNull(nodeVersion)) { @@ -107,6 +104,46 @@ public void execute(FrontendPluginFactory factory) throws Exception { String validNodeVersion = getDownloadableVersion(nodeVersion); + // Use different names to avoid confusion with fields `nodeDownloadRoot` and + // `pnpmDownloadRoot`. + // + // TODO: Remove the `downloadRoot` config (with breaking change) to simplify download root + // resolution. + String resolvedNodeDownloadRoot = getNodeDownloadRoot(); + String resolvedPnpmDownloadRoot = getPnpmDownloadRoot(); + + if (isAtlassianProject(project) && + isBlank(serverId) && + (isBlank(resolvedNodeDownloadRoot) || isBlank(resolvedPnpmDownloadRoot)) + ) { // If they're overridden the settings, they be the boss + getLog().info("Atlassian project detected, going to use the internal mirrors (requires VPN)"); + + serverId = "maven-atlassian-com"; + try { + install(factory, validNodeVersion, + isBlank(resolvedNodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : resolvedNodeDownloadRoot, + isBlank(resolvedPnpmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : resolvedPnpmDownloadRoot); + return; + } catch (InstallationException exception) { + // Ignore as many filesystem exceptions unrelated to the mirror easily + if (!(exception.getCause() instanceof DownloadException || + exception.getCause() instanceof ArchiveExtractionException)) { + throw exception; + } + getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors"); + getLog().debug("Using internal mirrors failed because: ", exception); + } finally { + serverId = null; + } + } + + install(factory, validNodeVersion, resolvedNodeDownloadRoot, resolvedPnpmDownloadRoot); + } + + private void install(FrontendPluginFactory factory, String validNodeVersion, String resolvedNodeDownloadRoot, String resolvedPnpmDownloadRoot) throws InstallationException { + ProxyConfig proxyConfig = MojoUtils.getProxyConfig(session, decrypter); + Server server = MojoUtils.decryptServer(serverId, session, decrypter); + if (null != server) { factory.getNodeInstaller(proxyConfig) .setNodeVersion(validNodeVersion) diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndYarnMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndYarnMojo.java index 7284562c..4550e3bc 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndYarnMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndYarnMojo.java @@ -1,10 +1,11 @@ package com.github.eirslett.maven.plugins.frontend.mojo; +import com.github.eirslett.maven.plugins.frontend.lib.ArchiveExtractionException; +import com.github.eirslett.maven.plugins.frontend.lib.DownloadException; import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory; -import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionDetector; +import com.github.eirslett.maven.plugins.frontend.lib.InstallationException; import com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper; import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; -import com.github.eirslett.maven.plugins.frontend.lib.YarnInstaller; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.plugins.annotations.Component; @@ -14,7 +15,12 @@ import org.apache.maven.settings.Server; import org.apache.maven.settings.crypto.SettingsDecrypter; +import static com.github.eirslett.maven.plugins.frontend.lib.NodeInstaller.ATLASSIAN_NODE_DOWNLOAD_ROOT; +import static com.github.eirslett.maven.plugins.frontend.lib.NodeVersionDetector.getNodeVersion; import static com.github.eirslett.maven.plugins.frontend.lib.NodeVersionHelper.getDownloadableVersion; +import static com.github.eirslett.maven.plugins.frontend.lib.Utils.isBlank; +import static com.github.eirslett.maven.plugins.frontend.lib.YarnInstaller.ATLASSIAN_YARN_DOWNLOAD_ROOT; +import static com.github.eirslett.maven.plugins.frontend.mojo.AtlassianUtil.isAtlassianProject; import static com.github.eirslett.maven.plugins.frontend.mojo.YarnUtils.isYarnrcYamlFilePresent; import static java.util.Objects.isNull; @@ -32,8 +38,7 @@ public final class InstallNodeAndYarnMojo extends AbstractFrontendMojo { /** * Where to download Yarn binary from. Defaults to https://github.com/yarnpkg/yarn/releases/download/... */ - @Parameter(property = "yarnDownloadRoot", required = false, - defaultValue = YarnInstaller.DEFAULT_YARN_DOWNLOAD_ROOT) + @Parameter(property = "yarnDownloadRoot", required = false) private String yarnDownloadRoot; /** @@ -80,10 +85,7 @@ protected boolean skipExecution() { @Override public void execute(FrontendPluginFactory factory) throws Exception { - ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter); - Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); - - String nodeVersion = NodeVersionDetector.getNodeVersion(workingDirectory, this.nodeVersion, this.nodeVersionFile); + String nodeVersion = getNodeVersion(workingDirectory, this.nodeVersion, this.nodeVersionFile); if (isNull(nodeVersion)) { throw new LifecycleExecutionException("Node version could not be detected from a file and was not set"); @@ -97,6 +99,47 @@ public void execute(FrontendPluginFactory factory) throws Exception { boolean isYarnYamlFilePresent = isYarnrcYamlFilePresent(this.session, this.workingDirectory); + if (isAtlassianProject(project) && + isBlank(serverId) && + (isBlank(nodeDownloadRoot) || isBlank(yarnDownloadRoot)) + ) { // If they're overridden the settings, they be the boss + getLog().info("Atlassian project detected, going to use the internal mirrors (requires VPN)"); + + serverId = "maven-atlassian-com"; + final String userSetYarnDownloadRoot = yarnDownloadRoot; + if (isBlank(yarnDownloadRoot)) { + yarnDownloadRoot = ATLASSIAN_YARN_DOWNLOAD_ROOT; + } + final String userSetNodeDownloadRoot = nodeDownloadRoot; + if (isBlank(nodeDownloadRoot)) { + nodeDownloadRoot = ATLASSIAN_NODE_DOWNLOAD_ROOT; + } + + try { + install(factory, validNodeVersion, isYarnYamlFilePresent); + return; + } catch (InstallationException exception) { + // Ignore as many filesystem exceptions unrelated to the mirror easily + if (!(exception.getCause() instanceof DownloadException || + exception.getCause() instanceof ArchiveExtractionException)) { + throw exception; + } + getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors"); + getLog().debug("Using internal mirrors failed because: ", exception); + } finally { + nodeDownloadRoot = userSetNodeDownloadRoot; + yarnDownloadRoot = userSetYarnDownloadRoot; + serverId = null; + } + } + + install(factory, validNodeVersion, isYarnYamlFilePresent); + } + + private void install(FrontendPluginFactory factory, String validNodeVersion, boolean isYarnYamlFilePresent) 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(validNodeVersion).setPassword(server.getPassword()) diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractionException.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractionException.java new file mode 100644 index 00000000..f2295fe5 --- /dev/null +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractionException.java @@ -0,0 +1,12 @@ +package com.github.eirslett.maven.plugins.frontend.lib; + +public class ArchiveExtractionException extends Exception { + + ArchiveExtractionException(String message) { + super(message); + } + + ArchiveExtractionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractor.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractor.java index ebc51f23..3a9a17ff 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractor.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/ArchiveExtractor.java @@ -24,17 +24,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -class ArchiveExtractionException extends Exception { - - ArchiveExtractionException(String message) { - super(message); - } - - ArchiveExtractionException(String message, Throwable cause) { - super(message, cause); - } -} - interface ArchiveExtractor { public void extract(String archive, String destinationDirectory) throws ArchiveExtractionException; } diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/DownloadException.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/DownloadException.java new file mode 100644 index 00000000..69afbc7b --- /dev/null +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/DownloadException.java @@ -0,0 +1,10 @@ +package com.github.eirslett.maven.plugins.frontend.lib; + +public final class DownloadException extends Exception { + public DownloadException(String message){ + super(message); + } + DownloadException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/FileDownloader.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/FileDownloader.java index 2d5244a6..4d32fb19 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/FileDownloader.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/FileDownloader.java @@ -29,15 +29,6 @@ import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig.Proxy; -final class DownloadException extends Exception { - public DownloadException(String message){ - super(message); - } - DownloadException(String message, Throwable cause) { - super(message, cause); - } -} - interface FileDownloader { void download(String downloadUrl, String destination, String userName, String password) throws DownloadException; } @@ -69,7 +60,7 @@ public void download(String downloadUrl, String destination, String userName, St if(statusCode != 200){ throw new DownloadException("Got error code "+ statusCode +" from the server."); } - + byte[] data = IOUtils.toByteArray(response.getEntity().getContent()); new File(FilenameUtils.getFullPathNoEndSeparator(destination)).mkdirs(); FileUtils.writeByteArrayToFile(new File(destination), data); diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java index 9df7a255..007752e4 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NPMInstaller.java @@ -14,6 +14,9 @@ public class NPMInstaller { private static final String VERSION = "version"; + public static final String ATLASSIAN_NPM_DOWNLOAD_ROOT = + "https://packages.atlassian.com/artifactory/api/npm/npm-remote/npm/-/"; + public static final String DEFAULT_NPM_DOWNLOAD_ROOT = "https://registry.npmjs.org/npm/-/"; private static final Object LOCK = new Object(); diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java index 5b5c6819..8e8e1d3f 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NodeInstaller.java @@ -14,6 +14,8 @@ public class NodeInstaller { + public static final String ATLASSIAN_NODE_DOWNLOAD_ROOT = "https://packages.atlassian.com/artifactory/nodejs-dist/"; + public static final String INSTALL_PATH = "/node"; private static final Object LOCK = new Object(); diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Platform.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Platform.java index 64d088ba..81886ba7 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Platform.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Platform.java @@ -15,13 +15,13 @@ public static Architecture guess(){ } else if (arch.equals("aarch64")) { return arm64; } else if (arch.equals("s390x")) { - return s390x; + return s390x; } else if (arch.equals("arm")) { - if (version.contains("v7")) { + if (version.contains("v7")) { return armv7l; - } else { - return arm64; - } + } else { + return arm64; + } } else if (arch.equals("ppc64")) { return ppc64; } else if (arch.equals("ppc")) { @@ -39,15 +39,15 @@ public static OS guess() { return osName.contains("Windows") ? OS.Windows : osName.contains("Mac") ? OS.Mac : osName.contains("SunOS") ? OS.SunOS : - osName.toUpperCase().contains("AIX") ? OS.AIX : - OS.Linux; + osName.toUpperCase().contains("AIX") ? OS.AIX : + OS.Linux; } public String getArchiveExtension(){ if(this == OS.Windows){ - return "zip"; + return "zip"; } else { - return "tar.gz"; + return "tar.gz"; } } @@ -88,10 +88,10 @@ public Platform(OS os, Architecture architecture) { } public Platform( - String nodeDownloadRoot, - OS os, - Architecture architecture, - String classifier + String nodeDownloadRoot, + OS os, + Architecture architecture, + String classifier ) { this.nodeDownloadRoot = nodeDownloadRoot; this.os = os; @@ -114,11 +114,11 @@ public static Platform guess(OS os, Architecture architecture, Supplier // We know Alpine is in use if the release file exists, and this is the simplest check. if (os == OS.Linux && checkForAlpine.get()) { return new Platform( - // Currently, musl is Experimental. The download root can be overridden with config - // if this changes and there's not been an update to this project, yet. - // See https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list - "https://unofficial-builds.nodejs.org/download/release/", - os, architecture, "musl"); + // Currently, musl is Experimental. The download root can be overridden with config + // if this changes and there's not been an update to this project, yet. + // See https://github.com/nodejs/node/blob/master/BUILDING.md#platform-list + "https://unofficial-builds.nodejs.org/download/release/", + os, architecture, "musl"); } return new Platform(os, architecture); } @@ -161,7 +161,7 @@ public String getNodeDownloadFilename(String nodeVersion, boolean archiveOnWindo } } else { if (nodeVersion.startsWith("v0.")) { - return nodeVersion + "/node.exe"; + return nodeVersion + "/node.exe"; } else { return nodeVersion+"/win-x86/node.exe"; } diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Utils.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Utils.java index 7ff0b02a..2ea18a61 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Utils.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/Utils.java @@ -1,11 +1,14 @@ package com.github.eirslett.maven.plugins.frontend.lib; +import javax.annotation.Nullable; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -final class Utils { +import static java.util.Objects.isNull; + +public final class Utils { public static List merge(List first, List second) { ArrayList result = new ArrayList(first); result.addAll(second); @@ -34,4 +37,8 @@ public static String implode(String separator, List elements){ public static boolean isRelative(String path) { return !path.startsWith("/") && !path.startsWith("file:") && !path.matches("^[a-zA-Z]:\\\\.*"); } + + public static boolean isBlank(@Nullable String string) { + return isNull(string) || string.trim().isEmpty(); + } } diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java index 2edc035d..a693d0ed 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/YarnInstaller.java @@ -14,6 +14,9 @@ public class YarnInstaller { public static final String INSTALL_PATH = "/node/yarn"; + public static final String ATLASSIAN_YARN_DOWNLOAD_ROOT = + "https://packages.atlassian.com/artifactory/yarn-dist/"; + public static final String DEFAULT_YARN_DOWNLOAD_ROOT = "https://github.com/yarnpkg/yarn/releases/download/";