diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java index 2644835b..68c1ab83 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/AbstractFrontendMojo.java @@ -1,6 +1,8 @@ package com.github.eirslett.maven.plugins.frontend.mojo; import java.io.File; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import org.apache.maven.plugin.AbstractMojo; @@ -9,6 +11,8 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Server; +import org.apache.maven.shared.utils.xml.Xpp3Dom; import org.eclipse.aether.RepositorySystemSession; import com.github.eirslett.maven.plugins.frontend.lib.FrontendException; @@ -106,5 +110,33 @@ public void execute() throws MojoFailureException { getLog().info("Skipping execution."); } } + + /** + * Provides the HTTP-Headers from the server section of settings.xml. + * + * @param server + * the <server> entry from the settings.xml + */ + protected Map getHttpHeaders(Server server) { + if (server == null || !(server.getConfiguration() instanceof Xpp3Dom)) { + return Collections.emptyMap(); + } + + Xpp3Dom configuration = (Xpp3Dom) server.getConfiguration(); + + Map result = new HashMap<>(); + + Xpp3Dom httpHeaders = configuration.getChild("httpHeaders"); + if (httpHeaders != null) { + for (Xpp3Dom property : httpHeaders.getChildren("property")) { + Xpp3Dom name = property.getChild("name"); + Xpp3Dom value = property.getChild("value"); + if (name != null && value != null) { + result.put(name.getValue(), value.getValue()); + } + } + } + return result; + } } diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallBunMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallBunMojo.java index 005c800e..a6f2d6c9 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallBunMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallBunMojo.java @@ -50,7 +50,7 @@ public void execute(FrontendPluginFactory factory) throws InstallationException Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter); if (null != server) { factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).setUserName(server.getUsername()) - .setPassword(server.getPassword()).install(); + .setPassword(server.getPassword()).setHttpHeaders(getHttpHeaders(server)).install(); } else { factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).install(); } diff --git a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndCorepackMojo.java b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndCorepackMojo.java index a8873261..e628f12f 100644 --- a/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndCorepackMojo.java +++ b/frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndCorepackMojo.java @@ -5,6 +5,9 @@ import com.github.eirslett.maven.plugins.frontend.lib.InstallationException; import com.github.eirslett.maven.plugins.frontend.lib.NodeInstaller; import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; + +import java.util.Map; + import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -88,8 +91,15 @@ public void execute(FrontendPluginFactory factory) throws InstallationException // If pplicable, configure authentication details Server server = MojoUtils.decryptServer(serverId, session, decrypter); if (null != server) { - nodeInstaller.setUserName(server.getUsername()).setPassword(server.getPassword()); - corepackInstaller.setUserName(server.getUsername()).setPassword(server.getPassword()); + Map httpHeaders = getHttpHeaders(server); + nodeInstaller + .setUserName(server.getUsername()) + .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders); + corepackInstaller + .setUserName(server.getUsername()) + .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders); } // Perform the installation 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 c80b3c0a..186adbb4 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 @@ -4,6 +4,9 @@ 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.ProxyConfig; + +import java.util.Map; + import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -78,12 +81,14 @@ public void execute(FrontendPluginFactory factory) throws InstallationException String npmDownloadRoot = getNpmDownloadRoot(); Server server = MojoUtils.decryptServer(serverId, session, decrypter); if (null != server) { - factory.getNodeInstaller(proxyConfig) + Map httpHeaders = getHttpHeaders(server); + factory.getNodeInstaller(proxyConfig) .setNodeVersion(nodeVersion) .setNodeDownloadRoot(nodeDownloadRoot) .setNpmVersion(npmVersion) .setUserName(server.getUsername()) .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders) .install(); factory.getNPMInstaller(proxyConfig) .setNodeVersion(nodeVersion) @@ -91,6 +96,7 @@ public void execute(FrontendPluginFactory factory) throws InstallationException .setNpmDownloadRoot(npmDownloadRoot) .setUserName(server.getUsername()) .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders) .install(); } else { factory.getNodeInstaller(proxyConfig) 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 80f48e16..66c1a5cd 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 @@ -4,6 +4,9 @@ import com.github.eirslett.maven.plugins.frontend.lib.InstallationException; import com.github.eirslett.maven.plugins.frontend.lib.PnpmInstaller; import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; + +import java.util.Map; + import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -84,17 +87,20 @@ public void execute(FrontendPluginFactory factory) throws InstallationException String resolvedPnpmDownloadRoot = getPnpmDownloadRoot(); Server server = MojoUtils.decryptServer(serverId, session, decrypter); if (null != server) { + Map httpHeaders = getHttpHeaders(server); factory.getNodeInstaller(proxyConfig) .setNodeVersion(nodeVersion) .setNodeDownloadRoot(resolvedNodeDownloadRoot) .setUserName(server.getUsername()) .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders) .install(); factory.getPnpmInstaller(proxyConfig) .setPnpmVersion(pnpmVersion) .setPnpmDownloadRoot(resolvedPnpmDownloadRoot) .setUserName(server.getUsername()) .setPassword(server.getPassword()) + .setHttpHeaders(httpHeaders) .install(); } else { factory.getNodeInstaller(proxyConfig) 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 d8a7a75c..5cd15ff5 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 @@ -2,8 +2,7 @@ import static com.github.eirslett.maven.plugins.frontend.mojo.YarnUtils.isYarnrcYamlFilePresent; -import java.io.File; -import java.util.stream.Stream; +import java.util.Map; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -79,12 +78,14 @@ public void execute(FrontendPluginFactory factory) throws InstallationException boolean isYarnYamlFilePresent = isYarnrcYamlFilePresent(this.session, this.workingDirectory); if (null != server) { + Map httpHeaders = getHttpHeaders(server); factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) - .setNodeVersion(this.nodeVersion).setPassword(server.getPassword()) - .setUserName(server.getUsername()).install(); + .setNodeVersion(this.nodeVersion).setUserName(server.getUsername()) + .setPassword(server.getPassword()).setHttpHeaders(httpHeaders).install(); factory.getYarnInstaller(proxyConfig).setYarnDownloadRoot(this.yarnDownloadRoot) .setYarnVersion(this.yarnVersion).setUserName(server.getUsername()) - .setPassword(server.getPassword()).setIsYarnBerry(isYarnYamlFilePresent).install(); + .setPassword(server.getPassword()).setHttpHeaders(httpHeaders) + .setIsYarnBerry(isYarnYamlFilePresent).install(); } else { factory.getNodeInstaller(proxyConfig).setNodeDownloadRoot(this.nodeDownloadRoot) .setNodeVersion(this.nodeVersion).install(); diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunInstaller.java index cd5a34e4..7729265b 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/BunInstaller.java @@ -11,6 +11,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Arrays; +import java.util.Map; public class BunInstaller { @@ -22,6 +23,8 @@ public class BunInstaller { private String bunVersion, userName, password; + private Map httpHeaders; + private final Logger logger; private final InstallConfig config; @@ -52,6 +55,11 @@ public BunInstaller setPassword(String password) { return this; } + public BunInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } + public void install() throws InstallationException { // use static lock object for a synchronized block synchronized (LOCK) { @@ -105,7 +113,7 @@ private void installBunDefault() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, this.httpHeaders); File installDirectory = getInstallDirectory(); @@ -201,16 +209,16 @@ private void extractFile(File archive, File destinationDirectory) throws Archive this.archiveExtractor.extract(archive.getPath(), destinationDirectory.getPath()); } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) + private void downloadFile(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { this.logger.info("Downloading {} to {}", downloadUrl, destination); - this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } } diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/CorepackInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/CorepackInstaller.java index ce7fa8c8..310475ce 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/CorepackInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/CorepackInstaller.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; +import java.util.Map; public class CorepackInstaller { @@ -20,6 +21,8 @@ public class CorepackInstaller { private String corepackVersion, corepackDownloadRoot, userName, password; + private Map httpHeaders; + private final Logger logger; private final InstallConfig config; @@ -59,6 +62,11 @@ public CorepackInstaller setPassword(String password) { return this; } + public CorepackInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } + public void install() throws InstallationException { // use static lock object for a synchronized block synchronized (LOCK) { @@ -120,7 +128,7 @@ private void installCorepack() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, this.httpHeaders); File installDirectory = getNodeInstallDirectory(); File nodeModulesDirectory = new File(installDirectory, "node_modules"); @@ -261,16 +269,16 @@ private void extractFile(File archive, File destinationDirectory) throws Archive this.archiveExtractor.extract(archive.getPath(), destinationDirectory.getPath()); } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) + private void downloadFile(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { this.logger.info("Downloading {} to {}", downloadUrl, destination); - this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } } 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..1a702103 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 @@ -5,6 +5,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.commons.io.FileUtils; @@ -39,7 +40,7 @@ public DownloadException(String message){ } interface FileDownloader { - void download(String downloadUrl, String destination, String userName, String password) throws DownloadException; + void download(String downloadUrl, String destination, String userName, String password, Map header) throws DownloadException; } final class DefaultFileDownloader implements FileDownloader { @@ -52,7 +53,7 @@ public DefaultFileDownloader(ProxyConfig proxyConfig){ } @Override - public void download(String downloadUrl, String destination, String userName, String password) throws DownloadException { + public void download(String downloadUrl, String destination, String userName, String password, Map httpHeaders) throws DownloadException { // force tls to 1.2 since github removed weak cryptographic standards // https://blog.github.com/2018-02-02-weak-cryptographic-standards-removal-notice/ System.setProperty("https.protocols", "TLSv1.2"); @@ -64,7 +65,7 @@ public void download(String downloadUrl, String destination, String userName, St FileUtils.copyFile(new File(downloadURI), new File(destination)); } else { - CloseableHttpResponse response = execute(fixedDownloadUrl, userName, password); + CloseableHttpResponse response = execute(fixedDownloadUrl, userName, password, httpHeaders); int statusCode = response.getStatusLine().getStatusCode(); if(statusCode != 200){ throw new DownloadException("Got error code "+ statusCode +" from the server."); @@ -79,7 +80,7 @@ public void download(String downloadUrl, String destination, String userName, St } } - private CloseableHttpResponse execute(String requestUrl, String userName, String password) throws IOException { + private CloseableHttpResponse execute(String requestUrl, String userName, String password, Map httpHeaders) throws IOException { final HttpGet request = new HttpGet(requestUrl); final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); @@ -100,6 +101,13 @@ private CloseableHttpResponse execute(String requestUrl, String userName, String } else { LOGGER.info("No proxy was configured, downloading directly"); } + + if (httpHeaders != null) { + for (Map.Entry header : httpHeaders.entrySet()) { + LOGGER.info("Using HTTP-Header (" + header.getKey() + ") from settings.xml"); + request.addHeader(header.getKey(), header.getValue()); + } + } if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) { LOGGER.info("Using credentials (" + userName + ") from settings.xml"); 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..390e9e4a 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 @@ -6,6 +6,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; + import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,6 +22,8 @@ public class NPMInstaller { private String nodeVersion, npmVersion, npmDownloadRoot, userName, password; + private Map httpHeaders; + private final Logger logger; private final InstallConfig config; @@ -60,6 +64,11 @@ public NPMInstaller setPassword(String password) { return this; } + public NPMInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } + private boolean npmProvided() throws InstallationException { if ("provided".equals(this.npmVersion)) { if (Integer.parseInt(this.nodeVersion.replace("v", "").split("[.]")[0]) < 4) { @@ -122,7 +131,7 @@ private void installNpm() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, this.httpHeaders); File installDirectory = getNodeInstallDirectory(); File nodeModulesDirectory = new File(installDirectory, "node_modules"); @@ -218,16 +227,16 @@ private void extractFile(File archive, File destinationDirectory) throws Archive this.archiveExtractor.extract(archive.getPath(), destinationDirectory.getPath()); } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) + private void downloadFile(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { this.logger.info("Downloading {} to {}", downloadUrl, destination); - this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } } 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..e81fa9e4 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 @@ -7,6 +7,7 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Arrays; +import java.util.Map; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; @@ -19,6 +20,8 @@ public class NodeInstaller { private static final Object LOCK = new Object(); private String npmVersion, nodeVersion, nodeDownloadRoot, userName, password; + + private Map httpHeaders; private final Logger logger; @@ -59,6 +62,11 @@ public NodeInstaller setPassword(String password) { this.password = password; return this; } + + public NodeInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } private boolean npmProvided() throws InstallationException { if (this.npmVersion != null) { @@ -138,7 +146,7 @@ private void installNodeDefault() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, this.httpHeaders); try { extractFile(archive, tmpDirectory); @@ -226,7 +234,7 @@ private void installNodeWithNpmForWindows() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, this.httpHeaders); extractFile(archive, tmpDirectory); @@ -282,7 +290,7 @@ private void installNodeForWindows() throws InstallationException { File binary = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, binary, this.userName, this.password); + downloadFileIfMissing(downloadUrl, binary, this.userName, this.password, this.httpHeaders); this.logger.info("Copying node binary from {} to {}", binary, destination); FileUtils.copyFile(binary, destination); @@ -325,16 +333,16 @@ private void extractFile(File archive, File destinationDirectory) throws Archive this.archiveExtractor.extract(archive.getPath(), destinationDirectory.getPath()); } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) - throws DownloadException { + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, + Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) - throws DownloadException { + private void downloadFile(String downloadUrl, File destination, String userName, String password, + Map httpHeaders) throws DownloadException { this.logger.info("Downloading {} to {}", downloadUrl, destination); - this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } } diff --git a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PnpmInstaller.java b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PnpmInstaller.java index 1cf0e52d..2509daef 100644 --- a/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PnpmInstaller.java +++ b/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/PnpmInstaller.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; +import java.util.Map; public class PnpmInstaller { @@ -19,6 +20,8 @@ public class PnpmInstaller { private static final Object LOCK = new Object(); private String pnpmVersion, pnpmDownloadRoot, userName, password; + + private Map httpHeaders; private final Logger logger; @@ -59,6 +62,11 @@ public PnpmInstaller setPassword(String password) { return this; } + public PnpmInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } + public void install() throws InstallationException { // use static lock object for a synchronized block synchronized (LOCK) { @@ -115,7 +123,7 @@ private void installPnpm() throws InstallationException { File archive = this.config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, this.userName, this.password); + downloadFileIfMissing(downloadUrl, archive, this.userName, this.password, httpHeaders); File installDirectory = getNodeInstallDirectory(); File nodeModulesDirectory = new File(installDirectory, "node_modules"); @@ -256,16 +264,16 @@ private void extractFile(File archive, File destinationDirectory) throws Archive this.archiveExtractor.extract(archive.getPath(), destinationDirectory.getPath()); } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) + private void downloadFile(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { this.logger.info("Downloading {} to {}", downloadUrl, destination); - this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + this.fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } } 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..600508cf 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 @@ -5,6 +5,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; +import java.util.Map; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; @@ -22,6 +23,8 @@ public class YarnInstaller { private static final String YARN_ROOT_DIRECTORY = "dist"; private String yarnVersion, yarnDownloadRoot, userName, password; + + private Map httpHeaders; private boolean isYarnBerry; @@ -65,6 +68,11 @@ public YarnInstaller setPassword(String password) { return this; } + public YarnInstaller setHttpHeaders(Map httpHeaders) { + this.httpHeaders = httpHeaders; + return this; + } + public void install() throws InstallationException { // use static lock object for a synchronized block synchronized (LOCK) { @@ -121,7 +129,7 @@ private void installYarn() throws InstallationException { File archive = config.getCacheResolver().resolve(cacheDescriptor); - downloadFileIfMissing(downloadUrl, archive, userName, password); + downloadFileIfMissing(downloadUrl, archive, userName, password, httpHeaders); File installDirectory = getInstallDirectory(); @@ -193,16 +201,16 @@ private void ensureCorrectYarnRootDirectory(File installDirectory, String yarnVe } } - private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password) + private void downloadFileIfMissing(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { if (!destination.exists()) { - downloadFile(downloadUrl, destination, userName, password); + downloadFile(downloadUrl, destination, userName, password, httpHeaders); } } - private void downloadFile(String downloadUrl, File destination, String userName, String password) + private void downloadFile(String downloadUrl, File destination, String userName, String password, Map httpHeaders) throws DownloadException { logger.info("Downloading {} to {}", downloadUrl, destination); - fileDownloader.download(downloadUrl, destination.getPath(), userName, password); + fileDownloader.download(downloadUrl, destination.getPath(), userName, password, httpHeaders); } }