maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ifedore...@apache.org
Subject [7/8] maven git commit: extracted RepositorySystemSessionFactory from DefaultMaven
Date Fri, 20 Feb 2015 19:07:32 GMT
extracted RepositorySystemSessionFactory from DefaultMaven

Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/5f150940
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/5f150940
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/5f150940

Branch: refs/heads/master
Commit: 5f150940c105d517108616aa184a5d276985376f
Parents: 586e65f
Author: Igor Fedorenko <ifedorenko@apache.org>
Authored: Mon Feb 9 16:56:33 2015 -0500
Committer: Igor Fedorenko <ifedorenko@apache.org>
Committed: Fri Feb 20 10:26:15 2015 -0500

----------------------------------------------------------------------
 .../java/org/apache/maven/DefaultMaven.java     | 210 +--------------
 .../apache/maven/LoggingRepositoryListener.java | 141 ----------
 .../DefaultRepositorySystemSessionFactory.java  | 259 +++++++++++++++++++
 .../aether/LoggingRepositoryListener.java       | 141 ++++++++++
 4 files changed, 404 insertions(+), 347 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/5f150940/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index ee82c1d..83d6f4f 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -20,8 +20,6 @@ package org.apache.maven;
  */
 
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -33,17 +31,15 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 
 import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.eventspy.internal.EventSpyDispatcher;
 import org.apache.maven.execution.DefaultMavenExecutionResult;
 import org.apache.maven.execution.ExecutionEvent;
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionResult;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.execution.ProjectDependencyGraph;
+import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
 import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
 import org.apache.maven.lifecycle.internal.LifecycleStarter;
 import org.apache.maven.model.Plugin;
@@ -58,41 +54,18 @@ import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingResult;
 import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
 import org.apache.maven.session.scope.internal.SessionScope;
-import org.apache.maven.settings.Mirror;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-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.PlexusContainer;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
 import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.dag.CycleDetectedException;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.eclipse.aether.ConfigurationProperties;
 import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
-import org.eclipse.aether.repository.RepositoryPolicy;
 import org.eclipse.aether.repository.WorkspaceReader;
-import org.eclipse.aether.resolution.ResolutionErrorPolicy;
-import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
-import org.eclipse.aether.util.repository.AuthenticationBuilder;
 import org.eclipse.aether.util.repository.ChainedWorkspaceReader;
-import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
-import org.eclipse.aether.util.repository.DefaultMirrorSelector;
-import org.eclipse.aether.util.repository.DefaultProxySelector;
-import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
 
 /**
  * @author Jason van Zyl
@@ -118,28 +91,13 @@ public class DefaultMaven
     private ExecutionEventCatapult eventCatapult;
 
     @Requirement
-    private ArtifactHandlerManager artifactHandlerManager;
-
-    @Requirement( optional = true, hint = "ide" )
-    private WorkspaceReader workspaceRepository;
-
-    @Requirement
-    private RepositorySystem repoSystem;
-
-    @Requirement( optional = true, hint = "simple" )
-    private LocalRepositoryManagerFactory simpleLocalRepoMgrFactory;
-
-    @Requirement
-    private SettingsDecrypter settingsDecrypter;
-
-    @Requirement
     private LegacySupport legacySupport;
 
     @Requirement
-    private EventSpyDispatcher eventSpyDispatcher;
+    private SessionScope sessionScope;
 
     @Requirement
-    private SessionScope sessionScope;
+    private DefaultRepositorySystemSessionFactory repositorySessionFactory;
 
     @Override
     public MavenExecutionResult execute( MavenExecutionRequest request )
@@ -393,167 +351,7 @@ public class DefaultMaven
 
     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, 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 strongly discouraged
to ensure"
-                + " build reproducibility." );
-            try
-            {
-                session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.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;
-    }
-
-    private String getUserAgent()
-    {
-        return "Apache-Maven/" + getMavenVersion() + " (Java " + System.getProperty( "java.version"
) + "; "
-            + System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" )
+ ")";
-    }
-
-    private String getMavenVersion()
-    {
-        Properties props = new Properties();
-
-        InputStream is = getClass().getResourceAsStream( "/META-INF/maven/org.apache.maven/maven-core/pom.properties"
);
-        if ( is != null )
-        {
-            try
-            {
-                props.load( is );
-            }
-            catch ( IOException e )
-            {
-                logger.debug( "Failed to read Maven version", e );
-            }
-            IOUtil.close( is );
-        }
-
-        return props.getProperty( "version", "unknown-version" );
+        return repositorySessionFactory.newRepositorySession( request );
     }
 
     private void validateLocalRepository( MavenExecutionRequest request )

http://git-wip-us.apache.org/repos/asf/maven/blob/5f150940/maven-core/src/main/java/org/apache/maven/LoggingRepositoryListener.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/LoggingRepositoryListener.java b/maven-core/src/main/java/org/apache/maven/LoggingRepositoryListener.java
deleted file mode 100644
index d176b9d..0000000
--- a/maven-core/src/main/java/org/apache/maven/LoggingRepositoryListener.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package org.apache.maven;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.FileNotFoundException;
-
-import org.codehaus.plexus.logging.Logger;
-import org.eclipse.aether.AbstractRepositoryListener;
-import org.eclipse.aether.RepositoryEvent;
-import org.eclipse.aether.transfer.MetadataNotFoundException;
-
-/**
- * @author Benjamin Bentmann
- */
-class LoggingRepositoryListener
-    extends AbstractRepositoryListener
-{
-
-    private final Logger logger;
-
-    public LoggingRepositoryListener( Logger logger )
-    {
-        this.logger = logger;
-    }
-
-    @Override
-    public void artifactInstalling( RepositoryEvent event )
-    {
-        logger.info( "Installing " + event.getArtifact().getFile() + " to " + event.getFile()
);
-    }
-
-    @Override
-    public void metadataInstalling( RepositoryEvent event )
-    {
-        logger.debug( "Installing " + event.getMetadata() + " to " + event.getFile() );
-    }
-
-    @Override
-    public void metadataResolved( RepositoryEvent event )
-    {
-        Exception e = event.getException();
-        if ( e != null )
-        {
-            if ( e instanceof MetadataNotFoundException )
-            {
-                logger.debug( e.getMessage() );
-            }
-            else if ( logger.isDebugEnabled() )
-            {
-                logger.warn( e.getMessage(), e );
-            }
-            else
-            {
-                logger.warn( e.getMessage() );
-            }
-        }
-    }
-
-    @Override
-    public void metadataInvalid( RepositoryEvent event )
-    {
-        Exception exception = event.getException();
-
-        StringBuilder buffer = new StringBuilder( 256 );
-        buffer.append( "The metadata " );
-        if ( event.getMetadata().getFile() != null )
-        {
-            buffer.append( event.getMetadata().getFile() );
-        }
-        else
-        {
-            buffer.append( event.getMetadata() );
-        }
-
-        if ( exception instanceof FileNotFoundException )
-        {
-            buffer.append( " is inaccessible" );
-        }
-        else
-        {
-            buffer.append( " is invalid" );
-        }
-
-        if ( exception != null )
-        {
-            buffer.append( ": " );
-            buffer.append( exception.getMessage() );
-        }
-
-        if ( logger.isDebugEnabled() )
-        {
-            logger.warn( buffer.toString(), exception );
-        }
-        else
-        {
-            logger.warn( buffer.toString() );
-        }
-    }
-
-    @Override
-    public void artifactDescriptorInvalid( RepositoryEvent event )
-    {
-        StringBuilder buffer = new StringBuilder( 256 );
-        buffer.append( "The POM for " );
-        buffer.append( event.getArtifact() );
-        buffer.append( " is invalid, transitive dependencies (if any) will not be available"
);
-
-        if ( logger.isDebugEnabled() )
-        {
-            logger.warn( buffer + ": " + event.getException().getMessage() );
-        }
-        else
-        {
-            logger.warn( buffer + ", enable debug logging for more details" );
-        }
-    }
-
-    @Override
-    public void artifactDescriptorMissing( RepositoryEvent event )
-    {
-        logger.warn( "The POM for " + event.getArtifact() + " is missing, no dependency information
available" );
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/maven/blob/5f150940/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..d049caf
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -0,0 +1,259 @@
+package org.apache.maven.internal.aether;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.eventspy.internal.EventSpyDispatcher;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.settings.Mirror;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Server;
+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.configuration.xml.XmlPlexusConfiguration;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.aether.ConfigurationProperties;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
+import org.eclipse.aether.repository.RepositoryPolicy;
+import org.eclipse.aether.repository.WorkspaceReader;
+import org.eclipse.aether.resolution.ResolutionErrorPolicy;
+import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
+import org.eclipse.aether.util.repository.AuthenticationBuilder;
+import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
+import org.eclipse.aether.util.repository.DefaultMirrorSelector;
+import org.eclipse.aether.util.repository.DefaultProxySelector;
+import org.eclipse.aether.util.repository.SimpleResolutionErrorPolicy;
+import org.eclipse.sisu.Nullable;
+
+/**
+ * @since 3.2.6
+ */
+@Named
+public class DefaultRepositorySystemSessionFactory
+{
+    @Inject
+    private Logger logger;
+
+    @Inject
+    private ArtifactHandlerManager artifactHandlerManager;
+
+    @Inject
+    private RepositorySystem repoSystem;
+
+    @Inject
+    @Nullable
+    @Named( "simple" )
+    private LocalRepositoryManagerFactory simpleLocalRepoMgrFactory;
+
+    @Inject
+    @Nullable
+    @Named( "ide" )
+    private WorkspaceReader workspaceRepository;
+
+    @Inject
+    private SettingsDecrypter settingsDecrypter;
+
+    @Inject
+    private EventSpyDispatcher eventSpyDispatcher;
+
+    public DefaultRepositorySystemSession 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, 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 strongly discouraged
to ensure"
+                + " build reproducibility." );
+            try
+            {
+                session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.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;
+    }
+
+    private String getUserAgent()
+    {
+        return "Apache-Maven/" + getMavenVersion() + " (Java " + System.getProperty( "java.version"
) + "; "
+            + System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" )
+ ")";
+    }
+
+    private String getMavenVersion()
+    {
+        Properties props = new Properties();
+
+        InputStream is = getClass().getResourceAsStream( "/META-INF/maven/org.apache.maven/maven-core/pom.properties"
);
+        if ( is != null )
+        {
+            try
+            {
+                props.load( is );
+            }
+            catch ( IOException e )
+            {
+                logger.debug( "Failed to read Maven version", e );
+            }
+            IOUtil.close( is );
+        }
+
+        return props.getProperty( "version", "unknown-version" );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/5f150940/maven-core/src/main/java/org/apache/maven/internal/aether/LoggingRepositoryListener.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/LoggingRepositoryListener.java
b/maven-core/src/main/java/org/apache/maven/internal/aether/LoggingRepositoryListener.java
new file mode 100644
index 0000000..7b67c3b
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/LoggingRepositoryListener.java
@@ -0,0 +1,141 @@
+package org.apache.maven.internal.aether;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.FileNotFoundException;
+
+import org.codehaus.plexus.logging.Logger;
+import org.eclipse.aether.AbstractRepositoryListener;
+import org.eclipse.aether.RepositoryEvent;
+import org.eclipse.aether.transfer.MetadataNotFoundException;
+
+/**
+ * @author Benjamin Bentmann
+ */
+class LoggingRepositoryListener
+    extends AbstractRepositoryListener
+{
+
+    private final Logger logger;
+
+    public LoggingRepositoryListener( Logger logger )
+    {
+        this.logger = logger;
+    }
+
+    @Override
+    public void artifactInstalling( RepositoryEvent event )
+    {
+        logger.info( "Installing " + event.getArtifact().getFile() + " to " + event.getFile()
);
+    }
+
+    @Override
+    public void metadataInstalling( RepositoryEvent event )
+    {
+        logger.debug( "Installing " + event.getMetadata() + " to " + event.getFile() );
+    }
+
+    @Override
+    public void metadataResolved( RepositoryEvent event )
+    {
+        Exception e = event.getException();
+        if ( e != null )
+        {
+            if ( e instanceof MetadataNotFoundException )
+            {
+                logger.debug( e.getMessage() );
+            }
+            else if ( logger.isDebugEnabled() )
+            {
+                logger.warn( e.getMessage(), e );
+            }
+            else
+            {
+                logger.warn( e.getMessage() );
+            }
+        }
+    }
+
+    @Override
+    public void metadataInvalid( RepositoryEvent event )
+    {
+        Exception exception = event.getException();
+
+        StringBuilder buffer = new StringBuilder( 256 );
+        buffer.append( "The metadata " );
+        if ( event.getMetadata().getFile() != null )
+        {
+            buffer.append( event.getMetadata().getFile() );
+        }
+        else
+        {
+            buffer.append( event.getMetadata() );
+        }
+
+        if ( exception instanceof FileNotFoundException )
+        {
+            buffer.append( " is inaccessible" );
+        }
+        else
+        {
+            buffer.append( " is invalid" );
+        }
+
+        if ( exception != null )
+        {
+            buffer.append( ": " );
+            buffer.append( exception.getMessage() );
+        }
+
+        if ( logger.isDebugEnabled() )
+        {
+            logger.warn( buffer.toString(), exception );
+        }
+        else
+        {
+            logger.warn( buffer.toString() );
+        }
+    }
+
+    @Override
+    public void artifactDescriptorInvalid( RepositoryEvent event )
+    {
+        StringBuilder buffer = new StringBuilder( 256 );
+        buffer.append( "The POM for " );
+        buffer.append( event.getArtifact() );
+        buffer.append( " is invalid, transitive dependencies (if any) will not be available"
);
+
+        if ( logger.isDebugEnabled() )
+        {
+            logger.warn( buffer + ": " + event.getException().getMessage() );
+        }
+        else
+        {
+            logger.warn( buffer + ", enable debug logging for more details" );
+        }
+    }
+
+    @Override
+    public void artifactDescriptorMissing( RepositoryEvent event )
+    {
+        logger.warn( "The POM for " + event.getArtifact() + " is missing, no dependency information
available" );
+    }
+
+}


Mime
View raw message