maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From schu...@apache.org
Subject [3/4] maven git commit: [MNG-5984] Maven core extension resolution ignores repositories from activeByDefault profiles in settings.xml
Date Wed, 08 Mar 2017 18:43:02 GMT
[MNG-5984] Maven core extension resolution ignores repositories from activeByDefault profiles
in settings.xml


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

Branch: refs/heads/MNG-5984
Commit: 10782f6c762c7a2a21328c6326b5e569a768d982
Parents: 34afec6
Author: Christian Schulte <schulte@apache.org>
Authored: Thu Feb 25 19:46:13 2016 +0100
Committer: Christian Schulte <schulte@apache.org>
Committed: Wed Mar 8 19:42:44 2017 +0100

----------------------------------------------------------------------
 .../apache/maven/settings/SettingsUtils.java    |   2 +-
 .../java/org/apache/maven/cli/MavenCli.java     | 158 ++++++++++++++++---
 .../SettingsXmlConfigurationProcessor.java      |  65 ++------
 3 files changed, 152 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/10782f6c/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
index 8da696e..16ccdb6 100644
--- a/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
+++ b/maven-core/src/main/java/org/apache/maven/settings/SettingsUtils.java
@@ -139,7 +139,7 @@ public final class SettingsUtils
 
         profile.setId( settingsProfile.getId() );
 
-        profile.setSource( "settings.xml" );
+        profile.setSource( org.apache.maven.model.Profile.SOURCE_SETTINGS );
 
         Activation settingsActivation = settingsProfile.getActivation();
 

http://git-wip-us.apache.org/repos/asf/maven/blob/10782f6c/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 8d38ab0..27f86d8 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -19,6 +19,28 @@ package org.apache.maven.cli;
  * under the License.
  */
 
+import java.io.BufferedInputStream;
+import java.io.Console;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 import com.google.inject.AbstractModule;
@@ -28,6 +50,8 @@ import org.apache.commons.cli.UnrecognizedOptionException;
 import org.apache.maven.BuildAbort;
 import org.apache.maven.InternalErrorException;
 import org.apache.maven.Maven;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.building.FileSource;
 import org.apache.maven.building.Problem;
 import org.apache.maven.building.Source;
@@ -58,7 +82,15 @@ import org.apache.maven.execution.MavenExecutionResult;
 import org.apache.maven.extension.internal.CoreExports;
 import org.apache.maven.extension.internal.CoreExtensionEntry;
 import org.apache.maven.lifecycle.LifecycleExecutionException;
+import org.apache.maven.model.Profile;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.building.DefaultModelProblem;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.ModelProblemCollector;
+import org.apache.maven.model.building.ModelProblemCollectorRequest;
 import org.apache.maven.model.building.ModelProcessor;
+import org.apache.maven.model.profile.DefaultProfileActivationContext;
+import org.apache.maven.model.profile.ProfileSelector;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.properties.internal.EnvironmentUtils;
 import org.apache.maven.properties.internal.SystemProperties;
@@ -89,28 +121,6 @@ import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
 import org.sonatype.plexus.components.sec.dispatcher.SecUtil;
 import org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity;
 
-import java.io.BufferedInputStream;
-import java.io.Console;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
 
 // TODO push all common bits back to plexus cli and prepare for transition to Guice. We don't
need 50 ways to make CLIs
@@ -177,6 +187,8 @@ public class MavenCli
 
     private Map<String, ConfigurationProcessor> configurationProcessors;
 
+    private ProfileSelector profileSelector;
+
     public MavenCli()
     {
         this( null );
@@ -299,6 +311,7 @@ public class MavenCli
             populateRequest( cliRequest );
             encryption( cliRequest );
             repository( cliRequest );
+            profiles( cliRequest );
             return execute( cliRequest );
         }
         catch ( ExitException e )
@@ -642,6 +655,8 @@ public class MavenCli
 
         dispatcher = (DefaultSecDispatcher) container.lookup( SecDispatcher.class, "maven"
);
 
+        profileSelector = container.lookup( ProfileSelector.class );
+
         return container;
     }
 
@@ -705,6 +720,10 @@ public class MavenCli
 
                 request = executionRequestPopulator.populateDefaults( request );
 
+                profileSelector = container.lookup( ProfileSelector.class );
+
+                profiles( request );
+
                 BootstrapCoreExtensionManager resolver = container.lookup( BootstrapCoreExtensionManager.class
);
 
                 return resolver.loadCoreExtensions( request, providedArtifacts, extensions
);
@@ -894,13 +913,104 @@ public class MavenCli
     private void repository( CliRequest cliRequest )
         throws Exception
     {
-        if ( cliRequest.commandLine.hasOption( CLIManager.LEGACY_LOCAL_REPOSITORY ) || Boolean.getBoolean(
-            "maven.legacyLocalRepo" ) )
+        if ( cliRequest.commandLine.hasOption( CLIManager.LEGACY_LOCAL_REPOSITORY )
+                 || Boolean.getBoolean( "maven.legacyLocalRepo" ) )
         {
             cliRequest.request.setUseLegacyLocalRepository( true );
         }
     }
 
+    private void profiles( final CliRequest request )
+    {
+        this.profiles( request.getRequest() );
+    }
+
+    private void profiles( final MavenExecutionRequest request )
+    {
+        // Adds repositories from profiles.
+        final DefaultProfileActivationContext profileActivationContext = new DefaultProfileActivationContext();
+        profileActivationContext.setActiveProfileIds( request.getActiveProfiles() );
+        profileActivationContext.setInactiveProfileIds( request.getInactiveProfiles() );
+        profileActivationContext.setSystemProperties( request.getSystemProperties() );
+        profileActivationContext.setUserProperties( request.getUserProperties() );
+        profileActivationContext.setProjectDirectory( request.getPom() != null
+                                                          ? request.getPom().getParentFile()
+                                                          : null );
+
+        final List<ModelProblem> modelProblems = new ArrayList<>();
+        final List<Profile> activeProfiles =
+            this.profileSelector.getActiveProfiles( request.getProfiles(), profileActivationContext,
+                                                    new ModelProblemCollector()
+                                                    {
+
+                                                        @Override
+                                                        public void add( final ModelProblemCollectorRequest
req )
+                                                        {
+                                                            modelProblems.add( new DefaultModelProblem(
+                                                                    req.getMessage(), req.getSeverity(),
+                                                                    req.getVersion(), Profile.SOURCE_SETTINGS,
-1, -1,
+                                                                    null, req.getException()
) );
+
+                                                        }
+
+                                                    } );
+
+        if ( !modelProblems.isEmpty() )
+        {
+            slf4jLogger.warn( "" );
+            slf4jLogger.warn( "Some problems were encountered while processing profiles"
);
+
+            for ( final ModelProblem problem : modelProblems )
+            {
+                slf4jLogger.warn( problem.getMessage(), problem.getException() );
+            }
+
+            slf4jLogger.warn( "" );
+        }
+
+        if ( !activeProfiles.isEmpty() )
+        {
+            for ( final Profile profile : activeProfiles )
+            {
+                final List<Repository> remoteRepositories = profile.getRepositories();
+
+                for ( final Repository remoteRepository : remoteRepositories )
+                {
+                    try
+                    {
+                        request.addRemoteRepository(
+                            MavenRepositorySystem.buildArtifactRepository( remoteRepository
) );
+
+                    }
+                    catch ( final InvalidRepositoryException e )
+                    {
+                        slf4jLogger.warn( String.format( "Failure adding repository '%s'
from profile '%s'.",
+                                                         remoteRepository.getId(), profile.getId()
), e );
+
+                    }
+                }
+
+                final List<Repository> pluginRepositories = profile.getPluginRepositories();
+
+                for ( final Repository pluginRepository : pluginRepositories )
+                {
+                    try
+                    {
+                        request.addPluginArtifactRepository(
+                            MavenRepositorySystem.buildArtifactRepository( pluginRepository
) );
+
+                    }
+                    catch ( InvalidRepositoryException e )
+                    {
+                        slf4jLogger.warn( String.format( "Failure adding plugin repository
'%s' from profile '%s'.",
+                                                         pluginRepository.getId(), profile.getId()
), e );
+
+                    }
+                }
+            }
+        }
+    }
+
     private int execute( CliRequest cliRequest )
         throws MavenExecutionRequestPopulationException
     {

http://git-wip-us.apache.org/repos/asf/maven/blob/10782f6c/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java
----------------------------------------------------------------------
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 d9a6954..1008d4e 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
@@ -21,11 +21,8 @@ package org.apache.maven.cli.configuration;
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.util.List;
 
 import org.apache.commons.cli.CommandLine;
-import org.apache.maven.artifact.InvalidRepositoryException;
-import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.building.Source;
 import org.apache.maven.cli.CLIManager;
 import org.apache.maven.cli.CliRequest;
@@ -33,7 +30,6 @@ import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionRequestPopulationException;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Repository;
 import org.apache.maven.settings.Server;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.settings.SettingsUtils;
@@ -42,7 +38,6 @@ 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.SettingsDecrypter;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.slf4j.Logger;
@@ -51,6 +46,7 @@ import org.slf4j.Logger;
 public class SettingsXmlConfigurationProcessor
     implements ConfigurationProcessor
 {
+
     public static final String HINT = "settings";
 
     public static final String USER_HOME = System.getProperty( "user.home" );
@@ -68,9 +64,6 @@ public class SettingsXmlConfigurationProcessor
     @Requirement
     private SettingsBuilder settingsBuilder;
 
-    @Requirement
-    private SettingsDecrypter settingsDecrypter;
-
     @Override
     public void process( CliRequest cliRequest )
         throws Exception
@@ -88,8 +81,9 @@ public class SettingsXmlConfigurationProcessor
 
             if ( !userSettingsFile.isFile() )
             {
-                throw new FileNotFoundException( "The specified user settings file does not
exist: "
-                    + userSettingsFile );
+                throw new FileNotFoundException( String.format( "The specified user settings
file does not exist: %s",
+                                                                userSettingsFile ) );
+
             }
         }
         else
@@ -106,8 +100,9 @@ public class SettingsXmlConfigurationProcessor
 
             if ( !globalSettingsFile.isFile() )
             {
-                throw new FileNotFoundException( "The specified global settings file does
not exist: "
-                    + globalSettingsFile );
+                throw new FileNotFoundException( String.format( "The specified global settings
file does not exist: %s",
+                                                                globalSettingsFile ) );
+
             }
         }
         else
@@ -129,10 +124,13 @@ public class SettingsXmlConfigurationProcessor
             request.getEventSpyDispatcher().onEvent( settingsRequest );
         }
 
-        logger.debug( "Reading global settings from "
-            + getLocation( settingsRequest.getGlobalSettingsSource(), settingsRequest.getGlobalSettingsFile()
) );
-        logger.debug( "Reading user settings from "
-            + getLocation( settingsRequest.getUserSettingsSource(), settingsRequest.getUserSettingsFile()
) );
+        logger.debug( String.format( "Reading global settings from %s",
+                                     getLocation( settingsRequest.getGlobalSettingsSource(),
+                                                  settingsRequest.getGlobalSettingsFile()
) ) );
+
+        logger.debug( String.format( "Reading user settings from %s",
+                                     getLocation( settingsRequest.getUserSettingsSource(),
+                                                  settingsRequest.getUserSettingsFile() )
) );
 
         SettingsBuildingResult settingsResult = settingsBuilder.build( settingsRequest );
 
@@ -218,43 +216,13 @@ public class SettingsXmlConfigurationProcessor
             request.addMirror( mirror );
         }
 
-        request.setActiveProfiles( settings.getActiveProfiles() );
+        request.addActiveProfiles( settings.getActiveProfiles() );
 
         for ( org.apache.maven.settings.Profile rawProfile : settings.getProfiles() )
         {
             request.addProfile( SettingsUtils.convertFromSettingsProfile( rawProfile ) );
-
-            if ( settings.getActiveProfiles().contains( rawProfile.getId() ) )
-            {
-                List<Repository> remoteRepositories = rawProfile.getRepositories();
-                for ( Repository remoteRepository : remoteRepositories )
-                {
-                    try
-                    {
-                        request.addRemoteRepository( 
-                            MavenRepositorySystem.buildArtifactRepository( remoteRepository
) );
-                    }
-                    catch ( InvalidRepositoryException e )
-                    {
-                        // do nothing for now
-                    }
-                }
-                
-                List<Repository> pluginRepositories = rawProfile.getPluginRepositories();
-                for ( Repository pluginRepository : pluginRepositories )
-                {
-                    try
-                    {
-                        request.addPluginArtifactRepository( 
-                            MavenRepositorySystem.buildArtifactRepository( pluginRepository
) );
-                    }
-                    catch ( InvalidRepositoryException e )
-                    {
-                        // do nothing for now
-                    }
-                }                
-            }
         }
+
         return request;
     }
 
@@ -287,4 +255,5 @@ public class SettingsXmlConfigurationProcessor
             return new File( workingDirectory, file.getPath() ).getAbsoluteFile();
         }
     }
+
 }


Mime
View raw message