From 56e6db123150d08c15f1920ed8cc571480161b3c Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Thu, 2 Apr 2015 00:21:00 -0400 Subject: [PATCH] MNG-5795: Maven extensions can not be retrieved from authenticated repositories --- ...DefaultMavenExecutionRequestPopulator.java | 345 ++++++++---------- .../MavenExecutionRequestPopulator.java | 33 +- ...DefaultRepositorySystemSessionFactory.java | 12 + .../SettingsXmlConfigurationProcessor.java | 20 +- 4 files changed, 182 insertions(+), 228 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index edb29ce990..7568fdee09 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -62,7 +62,156 @@ public class DefaultMavenExecutionRequestPopulator this.repositorySystem = repositorySystem; } + @Override + public MavenExecutionRequest populateFromToolchains( MavenExecutionRequest request, PersistedToolchains toolchains ) + throws MavenExecutionRequestPopulationException + { + if ( toolchains != null ) + { + Map> groupedToolchains = new HashMap>( 2 ); + + for ( ToolchainModel model : toolchains.getToolchains() ) + { + if ( !groupedToolchains.containsKey( model.getType() ) ) + { + groupedToolchains.put( model.getType(), new ArrayList() ); + } + + groupedToolchains.get( model.getType() ).add( model ); + } + + request.setToolchains( groupedToolchains ); + } + return request; + } + + @Override + public MavenExecutionRequest populateDefaults( MavenExecutionRequest request ) + throws MavenExecutionRequestPopulationException + { + baseDirectory( request ); + + localRepository( request ); + + populateDefaultPluginGroups( request ); + + injectDefaultRepositories( request ); + + injectDefaultPluginRepositories( request ); + + return request; + } + + // + // + // + + private void populateDefaultPluginGroups( MavenExecutionRequest request ) + { + request.addPluginGroup( "org.apache.maven.plugins" ); + request.addPluginGroup( "org.codehaus.mojo" ); + } + + private void injectDefaultRepositories( MavenExecutionRequest request ) + throws MavenExecutionRequestPopulationException + { + Set definedRepositories = repositorySystem.getRepoIds( request.getRemoteRepositories() ); + + if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) + { + try + { + request.addRemoteRepository( repositorySystem.createDefaultRemoteRepository( request ) ); + } + catch ( Exception e ) + { + throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e ); + } + } + } + + private void injectDefaultPluginRepositories( MavenExecutionRequest request ) + throws MavenExecutionRequestPopulationException + { + Set definedRepositories = repositorySystem.getRepoIds( request.getPluginArtifactRepositories() ); + + if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) + { + try + { + request.addPluginArtifactRepository( repositorySystem.createDefaultRemoteRepository( request ) ); + } + catch ( Exception e ) + { + throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e ); + } + } + } + + private void localRepository( MavenExecutionRequest request ) + throws MavenExecutionRequestPopulationException + { + // ------------------------------------------------------------------------ + // Local Repository + // + // 1. Use a value has been passed in via the configuration + // 2. Use value in the resultant settings + // 3. Use default value + // ------------------------------------------------------------------------ + + if ( request.getLocalRepository() == null ) + { + request.setLocalRepository( createLocalRepository( request ) ); + } + + if ( request.getLocalRepositoryPath() == null ) + { + request.setLocalRepositoryPath( new File( request.getLocalRepository().getBasedir() ).getAbsoluteFile() ); + } + } + + // ------------------------------------------------------------------------ + // Artifact Transfer Mechanism + // ------------------------------------------------------------------------ + + private ArtifactRepository createLocalRepository( MavenExecutionRequest request ) + throws MavenExecutionRequestPopulationException + { + String localRepositoryPath = null; + + if ( request.getLocalRepositoryPath() != null ) + { + localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath(); + } + + if ( StringUtils.isEmpty( localRepositoryPath ) ) + { + localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath(); + } + + try + { + return repositorySystem.createLocalRepository( request, new File( localRepositoryPath ) ); + } + catch ( Exception e ) + { + throw new MavenExecutionRequestPopulationException( "Cannot create local repository.", e ); + } + } + + private void baseDirectory( MavenExecutionRequest request ) + { + if ( request.getBaseDirectory() == null && request.getPom() != null ) + { + request.setBaseDirectory( request.getPom().getAbsoluteFile().getParentFile() ); + } + } + + /*if_not[MAVEN4]*/ + + @Override + @Deprecated public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings ) throws MavenExecutionRequestPopulationException { @@ -162,200 +311,8 @@ public class DefaultMavenExecutionRequestPopulator } return request; - } - - @Override - public MavenExecutionRequest populateFromToolchains( MavenExecutionRequest request, PersistedToolchains toolchains ) - throws MavenExecutionRequestPopulationException - { - if ( toolchains != null ) - { - Map> groupedToolchains = new HashMap>( 2 ); - - for ( ToolchainModel model : toolchains.getToolchains() ) - { - if ( !groupedToolchains.containsKey( model.getType() ) ) - { - groupedToolchains.put( model.getType(), new ArrayList() ); - } - - groupedToolchains.get( model.getType() ).add( model ); - } - - request.setToolchains( groupedToolchains ); - } - return request; - } + } - @Override - public MavenExecutionRequest populateDefaults( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - baseDirectory( request ); + /*end[MAVEN4]*/ - localRepository( request ); - - populateDefaultPluginGroups( request ); - - injectDefaultRepositories( request ); - - injectDefaultPluginRepositories( request ); - - processRepositoriesInSettings( request ); - - return request; - } - - // - // - // - - private void populateDefaultPluginGroups( MavenExecutionRequest request ) - { - request.addPluginGroup( "org.apache.maven.plugins" ); - request.addPluginGroup( "org.codehaus.mojo" ); - } - - private void injectDefaultRepositories( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - Set definedRepositories = repositorySystem.getRepoIds( request.getRemoteRepositories() ); - - if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) - { - try - { - request.addRemoteRepository( repositorySystem.createDefaultRemoteRepository( request ) ); - } - catch ( Exception e ) - { - throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e ); - } - } - } - - private void injectDefaultPluginRepositories( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - Set definedRepositories = repositorySystem.getRepoIds( request.getPluginArtifactRepositories() ); - - if ( !definedRepositories.contains( RepositorySystem.DEFAULT_REMOTE_REPO_ID ) ) - { - try - { - request.addPluginArtifactRepository( repositorySystem.createDefaultRemoteRepository( request ) ); - } - catch ( Exception e ) - { - throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e ); - } - } - } - - private void processRepositoriesInSettings( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - // - // - // - // - // central - // - // http://10.0.1.34:62247/ - // central - // - // - // - // - // true - // http - // localhost - // 62248 - // 10.0.1.34 - // - // - // - // - // it-defaults - // - // - // - // - // it-defaults - // - // - // - // Turns - // - // http://repo1.maven.org/maven2 - // - // to - // - // http://10.0.1.34:62247/ - // - // Not sure why the DefaultMirrorSelector doesn't do this... - // - repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() ); - repositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() ); - } - - private void localRepository( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - // ------------------------------------------------------------------------ - // Local Repository - // - // 1. Use a value has been passed in via the configuration - // 2. Use value in the resultant settings - // 3. Use default value - // ------------------------------------------------------------------------ - - if ( request.getLocalRepository() == null ) - { - request.setLocalRepository( createLocalRepository( request ) ); - } - - if ( request.getLocalRepositoryPath() == null ) - { - request.setLocalRepositoryPath( new File( request.getLocalRepository().getBasedir() ).getAbsoluteFile() ); - } - } - - // ------------------------------------------------------------------------ - // Artifact Transfer Mechanism - // ------------------------------------------------------------------------ - - private ArtifactRepository createLocalRepository( MavenExecutionRequest request ) - throws MavenExecutionRequestPopulationException - { - String localRepositoryPath = null; - - if ( request.getLocalRepositoryPath() != null ) - { - localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath(); - } - - if ( StringUtils.isEmpty( localRepositoryPath ) ) - { - localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath(); - } - - try - { - return repositorySystem.createLocalRepository( request, new File( localRepositoryPath ) ); - } - catch ( Exception e ) - { - throw new MavenExecutionRequestPopulationException( "Cannot create local repository.", e ); - } - } - - private void baseDirectory( MavenExecutionRequest request ) - { - if ( request.getBaseDirectory() == null && request.getPom() != null ) - { - request.setBaseDirectory( request.getPom().getAbsoluteFile().getParentFile() ); - } - } } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java index 9efc01908c..4f254f7a04 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java @@ -29,21 +29,6 @@ import org.apache.maven.toolchain.model.PersistedToolchains; */ public interface MavenExecutionRequestPopulator { - - /** - * Copies the values from the given settings into the specified execution request. This method will replace any - * existing values in the execution request that are controlled by the settings. Hence, it is expected that this - * method is called on a new/empty execution request before the caller mutates it to fit its needs. - * - * @param request The execution request to populate, must not be {@code null}. - * @param settings The settings to copy into the execution request, may be {@code null}. - * @return The populated execution request, never {@code null}. - * @throws MavenExecutionRequestPopulationException If the execution request could not be populated. - */ - @Deprecated - MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings ) - throws MavenExecutionRequestPopulationException; - /** * Copies the values from the given toolchains into the specified execution request. This method will replace any * existing values in the execution request that are controlled by the toolchains. Hence, it is expected that this @@ -68,4 +53,22 @@ public interface MavenExecutionRequestPopulator MavenExecutionRequest populateDefaults( MavenExecutionRequest request ) throws MavenExecutionRequestPopulationException; + /*if_not[MAVEN4]*/ + + /** + * Copies the values from the given settings into the specified execution request. This method will replace any + * existing values in the execution request that are controlled by the settings. Hence, it is expected that this + * method is called on a new/empty execution request before the caller mutates it to fit its needs. + * + * @param request The execution request to populate, must not be {@code null}. + * @param settings The settings to copy into the execution request, may be {@code null}. + * @return The populated execution request, never {@code null}. + * @throws MavenExecutionRequestPopulationException If the execution request could not be populated. + */ + @Deprecated + MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings ) + throws MavenExecutionRequestPopulationException; + + /*end[MAVEN4]*/ + } diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index 6197f0f252..26a8ddae98 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -30,6 +30,7 @@ import javax.inject.Named; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.eventspy.internal.EventSpyDispatcher; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; @@ -91,6 +92,9 @@ public class DefaultRepositorySystemSessionFactory @Inject private EventSpyDispatcher eventSpyDispatcher; + @Inject + MavenRepositorySystem mavenRepositorySystem; + public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request ) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); @@ -226,6 +230,14 @@ public class DefaultRepositorySystemSessionFactory session.setSystemProperties( request.getSystemProperties() ); session.setConfigProperties( configProps ); + mavenRepositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() ); + mavenRepositorySystem.injectProxy( session, request.getRemoteRepositories() ); + mavenRepositorySystem.injectAuthentication( session, request.getRemoteRepositories() ); + + mavenRepositorySystem.injectMirror( request.getPluginArtifactRepositories(), request.getMirrors() ); + mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories() ); + mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories() ); + return session; } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java index 890a6581fd..791a226747 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java @@ -42,9 +42,7 @@ import org.apache.maven.settings.building.SettingsBuilder; import org.apache.maven.settings.building.SettingsBuildingRequest; import org.apache.maven.settings.building.SettingsBuildingResult; import org.apache.maven.settings.building.SettingsProblem; -import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest; import org.apache.maven.settings.crypto.SettingsDecrypter; -import org.apache.maven.settings.crypto.SettingsDecryptionResult; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.slf4j.Logger; @@ -156,25 +154,9 @@ public class SettingsXmlConfigurationProcessor } logger.warn( "" ); } - - DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest(); - decrypt.setProxies( request.getProxies() ); - decrypt.setServers( request.getServers() ); - SettingsDecryptionResult decrypted = settingsDecrypter.decrypt( decrypt ); - - if ( logger.isDebugEnabled() ) - { - for ( SettingsProblem problem : decrypted.getProblems() ) - { - logger.debug( problem.getMessage(), problem.getException() ); - } - } - - request.setProxies( decrypt.getProxies() ); - request.setServers( decrypt.getServers() ); } - public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings ) + private MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings ) throws MavenExecutionRequestPopulationException { if ( settings == null )