Skip to content

Commit

Permalink
Merge pull request #8431 from famod/issue-2219-mvn-wrapper-proxy
Browse files Browse the repository at this point in the history
CreateProjectMojo: set proxy before mvn wrapper download
  • Loading branch information
aloubyansky authored Apr 8, 2020
2 parents ea9c621 + e63db1c commit 0b83824
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.settings.Proxy;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -270,6 +271,8 @@ private void createMavenWrapper(File createdPomFile, Properties props) {
newExecutionRequest, session.getResult());
newSession.setCurrentProject(newProject);

setProxySystemPropertiesFromSession();

executeMojo(
plugin(
groupId("io.takari"),
Expand All @@ -288,6 +291,27 @@ private void createMavenWrapper(File createdPomFile, Properties props) {
}
}

private void setProxySystemPropertiesFromSession() {
List<Proxy> proxiesFromSession = session.getRequest().getProxies();
// - takari maven uses https to download the maven wrapper
// - don't do anything if proxy system property is already set
if (!proxiesFromSession.isEmpty() && System.getProperty("https.proxyHost") == null) {

// use the first active proxy for setting the system properties
proxiesFromSession.stream()
.filter(Proxy::isActive)
.findFirst()
.ifPresent(proxy -> {
// note: a http proxy _is_ usable as https.proxyHost
System.setProperty("https.proxyHost", proxy.getHost());
System.setProperty("https.proxyPort", String.valueOf(proxy.getPort()));
if (proxy.getNonProxyHosts() != null) {
System.setProperty("http.nonProxyHosts", proxy.getNonProxyHosts());
}
});
}
}

private void askTheUserForMissingValues() throws MojoExecutionException {

// If the user has disabled the interactive mode or if the user has specified the artifactId, disable the
Expand Down

0 comments on commit 0b83824

Please sign in to comment.