You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/01/17 15:46:24 UTC
maven git commit: [MNG-5754] Toolchains should be read during
initialization MavenExecutionRequest has been extended with toolchains,
which is filled by MavenCli Interfaces have been extended with new methods,
assuming only Maven provides implementations
Repository: maven
Updated Branches:
refs/heads/master 99f763dec -> f75008743
[MNG-5754] Toolchains should be read during initialization
MavenExecutionRequest has been extended with toolchains, which is filled by MavenCli
Interfaces have been extended with new methods, assuming only Maven provides implementations
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/f7500874
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/f7500874
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/f7500874
Branch: refs/heads/master
Commit: f75008743b2c0fa19ca83c46535c24bb5e2c9215
Parents: 99f763d
Author: Robert Scholte <rf...@codehaus.org>
Authored: Sat Jan 17 15:45:53 2015 +0100
Committer: Robert Scholte <rf...@codehaus.org>
Committed: Sat Jan 17 15:45:53 2015 +0100
----------------------------------------------------------------------
.../execution/DefaultMavenExecutionRequest.java | 22 +++++++
.../DefaultMavenExecutionRequestPopulator.java | 29 ++++++++++
.../maven/execution/MavenExecutionRequest.java | 17 ++++++
.../MavenExecutionRequestPopulator.java | 15 +++++
.../java/org/apache/maven/cli/MavenCli.java | 60 ++++++++++++++++++--
5 files changed, 138 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/f7500874/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
index b417900..d88024d 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java
@@ -22,7 +22,9 @@ package org.apache.maven.execution;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -32,6 +34,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
+import org.apache.maven.toolchain.model.ToolchainModel;
import org.eclipse.aether.DefaultRepositoryCache;
import org.eclipse.aether.RepositoryCache;
import org.eclipse.aether.repository.WorkspaceReader;
@@ -139,6 +142,8 @@ public class DefaultMavenExecutionRequest
private int degreeOfConcurrency = 1;
private String builderId = "singlethreaded";
+
+ private Map<String, List<ToolchainModel>> toolchains;
/**
* Suppress SNAPSHOT updates.
@@ -1127,4 +1132,21 @@ public class DefaultMavenExecutionRequest
{
return builderId;
}
+
+ @Override
+ public Map<String, List<ToolchainModel>> getToolchains()
+ {
+ if ( toolchains == null )
+ {
+ toolchains = new HashMap<String, List<ToolchainModel>>();
+ }
+ return toolchains;
+ }
+
+ @Override
+ public MavenExecutionRequest setToolchains( Map<String, List<ToolchainModel>> toolchains )
+ {
+ this.toolchains = toolchains;
+ return this;
+ }
}
http://git-wip-us.apache.org/repos/asf/maven/blob/f7500874/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java
----------------------------------------------------------------------
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 de5fa69..4d79e14 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
@@ -20,8 +20,11 @@ package org.apache.maven.execution;
*/
import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.InvalidRepositoryException;
@@ -34,6 +37,8 @@ import org.apache.maven.settings.Repository;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsUtils;
+import org.apache.maven.toolchain.model.PersistedToolchains;
+import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.StringUtils;
@@ -46,6 +51,7 @@ public class DefaultMavenExecutionRequestPopulator
@Requirement
private RepositorySystem repositorySystem;
+ @Override
public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings )
throws MavenExecutionRequestPopulationException
{
@@ -134,6 +140,29 @@ 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;
+ }
+
private void populateDefaultPluginGroups( MavenExecutionRequest request )
{
request.addPluginGroup( "org.apache.maven.plugins" );
http://git-wip-us.apache.org/repos/asf/maven/blob/f7500874/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
index 7daac89..15e2082 100644
--- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java
@@ -22,6 +22,7 @@ package org.apache.maven.execution;
import java.io.File;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -31,6 +32,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
+import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.aether.RepositoryCache;
import org.eclipse.aether.repository.WorkspaceReader;
@@ -394,4 +396,19 @@ public interface MavenExecutionRequest
*/
String getBuilderId();
+ /**
+ *
+ * @param toolchains all toolchains grouped by type
+ * @return this request
+ * @since 3.2.6
+ */
+ MavenExecutionRequest setToolchains( Map<String, List<ToolchainModel>> toolchains );
+
+ /**
+ *
+ * @return all toolchains grouped by type, never {@code null}
+ * @since 3.2.6
+ */
+ Map<String, List<ToolchainModel>> getToolchains();
+
}
http://git-wip-us.apache.org/repos/asf/maven/blob/f7500874/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java
----------------------------------------------------------------------
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 7c20cb8..8eb805c 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
@@ -20,6 +20,7 @@ package org.apache.maven.execution;
*/
import org.apache.maven.settings.Settings;
+import org.apache.maven.toolchain.model.PersistedToolchains;
/**
* Assists in populating an execution request for invocation of Maven.
@@ -43,6 +44,20 @@ public interface MavenExecutionRequestPopulator
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
+ * 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 toolchains The toolchains 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.
+ * @since 3.2.6
+ */
+ MavenExecutionRequest populateFromToolchains( MavenExecutionRequest request, PersistedToolchains toolchains )
+ throws MavenExecutionRequestPopulationException;
+
+ /**
* Injects default values like plugin groups or repositories into the specified execution request.
*
* @param request The execution request to populate, must not be {@code null}.
http://git-wip-us.apache.org/repos/asf/maven/blob/f7500874/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 c7b0485..13108f2 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
@@ -37,6 +37,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.building.FileSource;
+import org.apache.maven.building.Problem;
import org.apache.maven.building.Source;
import org.apache.maven.cli.event.DefaultEventSpyContext;
import org.apache.maven.cli.event.ExecutionEventLogger;
@@ -66,7 +68,11 @@ 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.toolchain.MisconfiguredToolchainException;
+import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest;
import org.apache.maven.toolchain.building.ToolchainsBuilder;
+import org.apache.maven.toolchain.building.ToolchainsBuildingException;
+import org.apache.maven.toolchain.building.ToolchainsBuildingResult;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
@@ -445,6 +451,8 @@ public class MavenCli
settingsBuilder = container.lookup( SettingsBuilder.class );
+ toolchainsBuilder = container.lookup( ToolchainsBuilder.class );
+
dispatcher = (DefaultSecDispatcher) container.lookup( SecDispatcher.class, "maven" );
return container;
@@ -837,18 +845,60 @@ public class MavenCli
cliRequest.request.setGlobalToolchainsFile( globalToolchainsFile );
cliRequest.request.setUserToolchainsFile( userToolchainsFile );
-
- // Unlike settings, the toolchains aren't built here.
- // That's done by the maven-toolchains-plugin, by calling it from the project with the proper configuration
+
+ DefaultToolchainsBuildingRequest toolchainsRequest = new DefaultToolchainsBuildingRequest();
+ if ( globalToolchainsFile.isFile() )
+ {
+ toolchainsRequest.setGlobalToolchainsSource( new FileSource( globalToolchainsFile ) );
+ }
+ if ( userToolchainsFile.isFile() )
+ {
+ toolchainsRequest.setUserToolchainsSource( new FileSource( userToolchainsFile ) );
+ }
+
+ eventSpyDispatcher.onEvent( toolchainsRequest );
+
+ slf4jLogger.debug( "Reading global toolchains from "
+ + getLocation( toolchainsRequest.getGlobalToolchainsSource(), globalToolchainsFile ) );
+ slf4jLogger.debug( "Reading user toolchains from "
+ + getLocation( toolchainsRequest.getUserToolchainsSource(), userToolchainsFile ) );
+
+ ToolchainsBuildingResult toolchainsResult;
+ try
+ {
+ toolchainsResult = toolchainsBuilder.build( toolchainsRequest );
+ }
+ catch ( ToolchainsBuildingException e )
+ {
+ throw new MisconfiguredToolchainException( e.getMessage(), e );
+ }
+
+ eventSpyDispatcher.onEvent( toolchainsRequest );
+
+ executionRequestPopulator.populateFromToolchains( cliRequest.request,
+ toolchainsResult.getEffectiveToolchains() );
+
+ if ( !toolchainsResult.getProblems().isEmpty() && slf4jLogger.isWarnEnabled() )
+ {
+ slf4jLogger.warn( "" );
+ slf4jLogger.warn( "Some problems were encountered while building the effective toolchains" );
+
+ for ( Problem problem : toolchainsResult.getProblems() )
+ {
+ slf4jLogger.warn( problem.getMessage() + " @ " + problem.getLocation() );
+ }
+
+ slf4jLogger.warn( "" );
+ }
}
- private Object getLocation( Source source, File file )
+ private Object getLocation( Source source, File defaultLocation )
{
if ( source != null )
{
return source.getLocation();
}
- return file;
+ return defaultLocation;
}
private MavenExecutionRequest populateRequest( CliRequest cliRequest )