From b8b148cf8b9a7d6c8430f6fb126a3813328b2ead Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Tue, 1 Sep 2009 19:03:27 +0000 Subject: [PATCH] o Collected repo settings in request git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@810174 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultMavenExecutionRequest.java | 93 ++++++++++++++++--- .../execution/MavenExecutionRequest.java | 18 ++-- .../apache/maven/execution/MavenSession.java | 12 ++- .../maven}/execution/SettingsAdapter.java | 64 +++++++------ ...DefaultMavenExecutionRequestPopulator.java | 39 ++++++-- 5 files changed, 166 insertions(+), 60 deletions(-) rename {maven-embedder/src/main/java/org/apache/maven/embedder => maven-core/src/main/java/org/apache/maven}/execution/SettingsAdapter.java (67%) diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index a37e6df067..b03c7b173c 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -26,6 +26,9 @@ import org.apache.maven.artifact.repository.RepositoryCache; import org.apache.maven.model.Profile; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Proxy; +import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.events.TransferListener; @@ -46,11 +49,11 @@ public class DefaultMavenExecutionRequest private boolean interactiveMode = true; - private List proxies; + private List proxies; - private List servers; + private List servers; - private List mirrors; + private List mirrors; private List profiles; @@ -619,20 +622,20 @@ public class DefaultMavenExecutionRequest // Settings equivalents // ---------------------------------------------------------------------------- - public List getProxies() + public List getProxies() { if ( proxies == null ) { - proxies = new ArrayList(); + proxies = new ArrayList(); } return proxies; } - public MavenExecutionRequest setProxies( List proxies ) + public MavenExecutionRequest setProxies( List proxies ) { if ( proxies != null ) { - this.proxies = new ArrayList( proxies ); + this.proxies = new ArrayList( proxies ); } else { @@ -642,20 +645,40 @@ public class DefaultMavenExecutionRequest return this; } - public List getServers() + public MavenExecutionRequest addProxy( Proxy proxy ) + { + if ( proxy == null ) + { + throw new IllegalArgumentException( "proxy missing" ); + } + + for ( Proxy p : getProxies() ) + { + if ( p.getId() != null && p.getId().equals( proxy.getId() ) ) + { + return this; + } + } + + getProxies().add( proxy ); + + return this; + } + + public List getServers() { if ( servers == null ) { - servers = new ArrayList(); + servers = new ArrayList(); } return servers; } - public MavenExecutionRequest setServers( List servers ) + public MavenExecutionRequest setServers( List servers ) { if ( servers != null ) { - this.servers = new ArrayList( servers ); + this.servers = new ArrayList( servers ); } else { @@ -665,20 +688,40 @@ public class DefaultMavenExecutionRequest return this; } - public List getMirrors() + public MavenExecutionRequest addServer( Server server ) + { + if ( server == null ) + { + throw new IllegalArgumentException( "server missing" ); + } + + for ( Server p : getServers() ) + { + if ( p.getId() != null && p.getId().equals( server.getId() ) ) + { + return this; + } + } + + getServers().add( server ); + + return this; + } + + public List getMirrors() { if ( mirrors == null ) { - mirrors = new ArrayList(); + mirrors = new ArrayList(); } return mirrors; } - public MavenExecutionRequest setMirrors( List mirrors ) + public MavenExecutionRequest setMirrors( List mirrors ) { if ( mirrors != null ) { - this.mirrors = new ArrayList( mirrors ); + this.mirrors = new ArrayList( mirrors ); } else { @@ -688,6 +731,26 @@ public class DefaultMavenExecutionRequest return this; } + public MavenExecutionRequest addMirror( Mirror mirror ) + { + if ( mirror == null ) + { + throw new IllegalArgumentException( "mirror missing" ); + } + + for ( Mirror p : getMirrors() ) + { + if ( p.getId() != null && p.getId().equals( mirror.getId() ) ) + { + return this; + } + } + + getMirrors().add( mirror ); + + return this; + } + public List getProfiles() { if ( profiles == null ) diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index 6d9945217e..dc779cf57d 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -29,6 +29,9 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.RepositoryCache; import org.apache.maven.model.Profile; import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Proxy; +import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.wagon.events.TransferListener; import org.codehaus.plexus.logging.Logger; @@ -207,16 +210,19 @@ public interface MavenExecutionRequest List getInactiveProfiles(); // Proxies - List getProxies(); - MavenExecutionRequest setProxies( List proxies ); + List getProxies(); + MavenExecutionRequest setProxies( List proxies ); + MavenExecutionRequest addProxy( Proxy proxy ); // Servers - List getServers(); - MavenExecutionRequest setServers( List servers ); + List getServers(); + MavenExecutionRequest setServers( List servers ); + MavenExecutionRequest addServer( Server server ); // Mirrors - List getMirrors(); - MavenExecutionRequest setMirrors( List mirrors ); + List getMirrors(); + MavenExecutionRequest setMirrors( List mirrors ); + MavenExecutionRequest addMirror( Mirror mirror ); // Plugin groups List getPluginGroups(); diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index fe98079709..33b855fe8a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -48,6 +48,8 @@ public class MavenSession private MavenExecutionResult result; + private final Settings settings; + private Properties executionProperties; private MavenProject currentProject; @@ -76,7 +78,8 @@ public class MavenSession this.container = container; this.request = request; this.result = result; - setProjects( projects ); + this.settings = new SettingsAdapter( request ); + setProjects( projects ); } public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result ) @@ -84,6 +87,7 @@ public class MavenSession this.container = container; this.request = request; this.result = result; + this.settings = new SettingsAdapter( request ); } public void setProjects( List projects ) @@ -118,14 +122,14 @@ public class MavenSession } @Deprecated - public List lookupList( String role ) + public List lookupList( String role ) throws ComponentLookupException { return container.lookupList( role ); } @Deprecated - public Map lookupMap( String role ) + public Map lookupMap( String role ) throws ComponentLookupException { return container.lookupMap( role ); @@ -187,7 +191,7 @@ public class MavenSession public Settings getSettings() { - return request.getSettings(); + return settings; } public List getProjects() diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/SettingsAdapter.java b/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java similarity index 67% rename from maven-embedder/src/main/java/org/apache/maven/embedder/execution/SettingsAdapter.java rename to maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java index 1cd5b43c05..4c5e21871c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/SettingsAdapter.java +++ b/maven-core/src/main/java/org/apache/maven/execution/SettingsAdapter.java @@ -1,4 +1,4 @@ -package org.apache.maven.embedder.execution; +package org.apache.maven.execution; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -21,8 +21,11 @@ package org.apache.maven.embedder.execution; import java.util.List; -import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Profile; +import org.apache.maven.settings.Proxy; import org.apache.maven.settings.RuntimeInfo; +import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; /** @@ -33,74 +36,83 @@ import org.apache.maven.settings.Settings; * * @author Jason van Zyl */ -public class SettingsAdapter +class SettingsAdapter extends Settings { + private MavenExecutionRequest request; - private Settings settings; + private RuntimeInfo runtimeInfo; - - public SettingsAdapter( MavenExecutionRequest request, Settings settings ) + + public SettingsAdapter( MavenExecutionRequest request ) { this.request = request; - this.settings = settings; this.runtimeInfo = new RuntimeInfo( request.getUserSettingsFile() ); } + @Override public String getLocalRepository() { if ( request.getLocalRepositoryPath() != null ) { return request.getLocalRepositoryPath().getAbsolutePath(); } - - return settings.getLocalRepository(); + + return null; } + @Override public boolean isInteractiveMode() - { - return request.isInteractiveMode(); + { + return request.isInteractiveMode(); } + @Override public boolean isOffline() { return request.isOffline(); } - // These we are not setting in the execution request currently - - public List getProxies() + @Override + public List getProxies() { - return settings.getProxies(); + return request.getProxies(); } - public List getServers() + @Override + public List getServers() { - return settings.getServers(); + return request.getServers(); } - public List getMirrors() + @Override + public List getMirrors() { - return settings.getMirrors(); + return request.getMirrors(); } - public List getProfiles() + @Override + public List getProfiles() { - return settings.getProfiles(); + return request.getSettings().getProfiles(); } - public List getActiveProfiles() + @Override + public List getActiveProfiles() { - return settings.getActiveProfiles(); + return request.getActiveProfiles(); } - public List getPluginGroups() + @Override + public List getPluginGroups() { - return settings.getPluginGroups(); + return request.getPluginGroups(); } - + + @Override public RuntimeInfo getRuntimeInfo() { return runtimeInfo; } + } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 2ef60e5883..b5c4d62fc6 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -101,8 +101,6 @@ public class DefaultMavenExecutionRequestPopulator populateDefaultPluginGroups( request ); - List settingsProfiles = settings.getProfiles(); - // We just need to keep track of what profiles are being activated by the settings. We don't need to process // them here. This should be taken care of by the project builder. // @@ -111,6 +109,8 @@ public class DefaultMavenExecutionRequestPopulator // We only need to take the profiles and make sure they are available when the calculation of the active profiles // is determined. // + List settingsProfiles = settings.getProfiles(); + if ( ( settingsProfiles != null ) && !settingsProfiles.isEmpty() ) { for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() ) @@ -194,30 +194,51 @@ public class DefaultMavenExecutionRequestPopulator // // - Proxy proxy = settings.getActiveProxy(); + Proxy activeProxy = settings.getActiveProxy(); - if ( proxy != null ) + if ( activeProxy != null ) { - if ( proxy.getHost() == null ) + if ( activeProxy.getHost() == null ) { throw new MavenEmbedderException( "Proxy in settings.xml has no host" ); } + String password = decrypt( activeProxy.getPassword(), "password for proxy " + activeProxy.getId() ); + + repositorySystem.addProxy( activeProxy.getProtocol(), activeProxy.getHost(), activeProxy.getPort(), + activeProxy.getUsername(), password, activeProxy.getNonProxyHosts() ); + } + + for ( Proxy proxy : settings.getProxies() ) + { + proxy = proxy.clone(); + String password = decrypt( proxy.getPassword(), "password for proxy " + proxy.getId() ); - repositorySystem.addProxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), proxy.getUsername(), - password, proxy.getNonProxyHosts() ); + proxy.setPassword( password ); + + request.addProxy( proxy ); } for ( Server server : settings.getServers() ) { + server = server.clone(); + String password = decrypt( server.getPassword(), "password for server " + server.getId() ); + server.setPassword( password ); + + request.addServer( server ); + repositorySystem.addAuthenticationForArtifactRepository( server.getId(), server.getUsername(), password ); } for ( Mirror mirror : settings.getMirrors() ) { + mirror = mirror.clone(); + + request.addMirror( mirror ); + repositorySystem.addMirror( mirror.getId(), mirror.getMirrorOf(), mirror.getUrl() ); } @@ -294,11 +315,11 @@ public class DefaultMavenExecutionRequestPopulator { Settings settings = settingsBuilder.buildSettings( request ); - request.setSettings( new SettingsAdapter( request, settings ) ); + request.setSettings( settings ); } catch ( Exception e ) { - request.setSettings( new SettingsAdapter( request, new Settings() ) ); + request.setSettings( new Settings() ); } } }