mirror of https://github.com/apache/maven.git
MNG-5795: Maven extensions can not be retrieved from authenticated repositories
This commit is contained in:
parent
f78742f3ea
commit
56e6db1231
|
@ -62,7 +62,156 @@ public class DefaultMavenExecutionRequestPopulator
|
|||
this.repositorySystem = repositorySystem;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MavenExecutionRequest populateFromToolchains( MavenExecutionRequest request, PersistedToolchains toolchains )
|
||||
throws MavenExecutionRequestPopulationException
|
||||
{
|
||||
if ( toolchains != null )
|
||||
{
|
||||
Map<String, List<ToolchainModel>> groupedToolchains = new HashMap<String, List<ToolchainModel>>( 2 );
|
||||
|
||||
for ( ToolchainModel model : toolchains.getToolchains() )
|
||||
{
|
||||
if ( !groupedToolchains.containsKey( model.getType() ) )
|
||||
{
|
||||
groupedToolchains.put( model.getType(), new ArrayList<ToolchainModel>() );
|
||||
}
|
||||
|
||||
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<String> 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<String> 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<String, List<ToolchainModel>> groupedToolchains = new HashMap<String, List<ToolchainModel>>( 2 );
|
||||
|
||||
for ( ToolchainModel model : toolchains.getToolchains() )
|
||||
{
|
||||
if ( !groupedToolchains.containsKey( model.getType() ) )
|
||||
{
|
||||
groupedToolchains.put( model.getType(), new ArrayList<ToolchainModel>() );
|
||||
}
|
||||
|
||||
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<String> 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<String> 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
|
||||
{
|
||||
//
|
||||
// <settings>
|
||||
// <mirrors>
|
||||
// <mirror>
|
||||
// <id>central</id>
|
||||
// <!-- NOTE: We need to try and use the proper host name/ip as Java generally ignores proxies for
|
||||
// "localhost" -->
|
||||
// <url>http://10.0.1.34:62247/</url>
|
||||
// <mirrorOf>central</mirrorOf>
|
||||
// </mirror>
|
||||
// </mirrors>
|
||||
// <proxies>
|
||||
// <proxy>
|
||||
// <active>true</active>
|
||||
// <protocol>http</protocol>
|
||||
// <host>localhost</host>
|
||||
// <port>62248</port>
|
||||
// <nonProxyHosts>10.0.1.34</nonProxyHosts>
|
||||
// </proxy>
|
||||
// </proxies>
|
||||
// <profiles>
|
||||
// <profile>
|
||||
// <id>it-defaults</id>
|
||||
// <!-- disable central override and use built-in values -->
|
||||
// </profile>
|
||||
// </profiles>
|
||||
// <activeProfiles>
|
||||
// <activeProfile>it-defaults</activeProfile>
|
||||
// </activeProfiles>
|
||||
// </settings>
|
||||
//
|
||||
// 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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]*/
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in New Issue