return result;
}
public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setCache( request.getRepositoryCache() );
Map<Object, Object> configProps = new LinkedHashMap<Object, Object>();
configProps.put( ConfigurationProperties.USER_AGENT, getUserAgent() );
configProps.put( ConfigurationProperties.INTERACTIVE, Boolean.valueOf( request.isInteractiveMode() ) );
configProps.putAll( request.getSystemProperties() );
configProps.putAll( request.getUserProperties() );
session.setOffline( request.isOffline() );
session.setChecksumPolicy( request.getGlobalChecksumPolicy() );
if ( request.isNoSnapshotUpdates() )
{
session.setUpdatePolicy( RepositoryPolicy.UPDATE_POLICY_NEVER );
}
else if ( request.isUpdateSnapshots() )
{
session.setUpdatePolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
}
else
{
session.setUpdatePolicy( null );
}
int errorPolicy = 0;
errorPolicy |= request.isCacheNotFound() ? ResolutionErrorPolicy.CACHE_NOT_FOUND : 0;
errorPolicy |= request.isCacheTransferError() ? ResolutionErrorPolicy.CACHE_TRANSFER_ERROR : 0;
session.setResolutionErrorPolicy( new SimpleResolutionErrorPolicy( errorPolicy, errorPolicy
| ResolutionErrorPolicy.CACHE_NOT_FOUND ) );
session.setArtifactTypeRegistry( RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ) );
LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );
if ( request.isUseLegacyLocalRepository() )
{
logger.warn( "Disabling enhanced local repository: using legacy is stronlgy discouraged to ensure build reproducibility." );
try
{
session.setLocalRepositoryManager( simpleLocalRepositoryManagerFactory.newInstance( session, localRepo ) );
}
catch ( NoLocalRepositoryManagerException e )
{
logger.warn( "Failed to configure legacy local repository: back to default" );
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}
}
else
{
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) );
}
if ( request.getWorkspaceReader() != null )
{
session.setWorkspaceReader( request.getWorkspaceReader() );
}
else
{
session.setWorkspaceReader( workspaceRepository );
}
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() );
}
}
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
for ( Mirror mirror : request.getMirrors() )
{
mirrorSelector.add( mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(),
mirror.getMirrorOfLayouts() );
}
session.setMirrorSelector( mirrorSelector );
DefaultProxySelector proxySelector = new DefaultProxySelector();
for ( Proxy proxy : decrypted.getProxies() )
{
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername( proxy.getUsername() ).addPassword( proxy.getPassword() );
proxySelector.add( new org.eclipse.aether.repository.Proxy( proxy.getProtocol(), proxy.getHost(),
proxy.getPort(), authBuilder.build() ),
proxy.getNonProxyHosts() );
}
session.setProxySelector( proxySelector );
DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
for ( Server server : decrypted.getServers() )
{
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername( server.getUsername() ).addPassword( server.getPassword() );
authBuilder.addPrivateKey( server.getPrivateKey(), server.getPassphrase() );
authSelector.add( server.getId(), authBuilder.build() );
if ( server.getConfiguration() != null )
{
Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
for ( int i = dom.getChildCount() - 1; i >= 0; i-- )
{
Xpp3Dom child = dom.getChild( i );
if ( "wagonProvider".equals( child.getName() ) )
{
dom.removeChild( i );
}
}
XmlPlexusConfiguration config = new XmlPlexusConfiguration( dom );
configProps.put( "aether.connector.wagon.config." + server.getId(), config );
}
configProps.put( "aether.connector.perms.fileMode." + server.getId(), server.getFilePermissions() );
configProps.put( "aether.connector.perms.dirMode." + server.getId(), server.getDirectoryPermissions() );
}
session.setAuthenticationSelector( authSelector );
session.setTransferListener( request.getTransferListener() );
session.setRepositoryListener( eventSpyDispatcher.chainListener( new LoggingRepositoryListener( logger ) ) );
session.setUserProperties( request.getUserProperties() );
session.setSystemProperties( request.getSystemProperties() );
session.setConfigProperties( configProps );
return session;
}