You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by if...@apache.org on 2015/02/06 03:11:35 UTC
[1/2] maven git commit: MNG-5762 populate plugin repositories in
ExecutionRequestPopulator
Repository: maven
Updated Branches:
refs/heads/project-basedir b71b3ed93 -> 888109c68 (forced update)
MNG-5762 populate plugin repositories in ExecutionRequestPopulator
Signed-off-by: Igor Fedorenko <if...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/d745f8c4
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/d745f8c4
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/d745f8c4
Branch: refs/heads/project-basedir
Commit: d745f8c47506bd93d4ae9eca830db50ad40ba61d
Parents: 3c63c3b
Author: Igor Fedorenko <if...@apache.org>
Authored: Wed Feb 4 22:11:30 2015 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Wed Feb 4 22:26:16 2015 -0500
----------------------------------------------------------------------
.../DefaultMavenExecutionRequestPopulator.java | 29 +++++++--
...faultMavenExecutionRequestPopulatorTest.java | 62 ++++++++++++++++++++
2 files changed, 86 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/d745f8c4/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 4d79e14..bb794ee 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
@@ -27,6 +27,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Named;
+
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.bridge.MavenRepositorySystem;
@@ -39,17 +42,20 @@ 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;
-@Component( role = MavenExecutionRequestPopulator.class )
+@Named
public class DefaultMavenExecutionRequestPopulator
implements MavenExecutionRequestPopulator
{
- @Requirement
- private RepositorySystem repositorySystem;
+ private final RepositorySystem repositorySystem;
+
+ @Inject
+ public DefaultMavenExecutionRequestPopulator( RepositorySystem repositorySystem )
+ {
+ this.repositorySystem = repositorySystem;
+ }
@Override
public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings )
@@ -134,6 +140,19 @@ public class DefaultMavenExecutionRequestPopulator
// 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
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/maven/blob/d745f8c4/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
----------------------------------------------------------------------
diff --git a/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
new file mode 100644
index 0000000..5019c7f
--- /dev/null
+++ b/maven-core/src/test/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulatorTest.java
@@ -0,0 +1,62 @@
+package org.apache.maven.execution;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.TestRepositorySystem;
+import org.apache.maven.settings.Profile;
+import org.apache.maven.settings.Repository;
+import org.apache.maven.settings.Settings;
+
+/*
+ * 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.
+ */
+
+public class DefaultMavenExecutionRequestPopulatorTest
+ extends TestCase
+{
+ DefaultMavenExecutionRequestPopulator testee =
+ new DefaultMavenExecutionRequestPopulator( new TestRepositorySystem() );
+
+ public void testPluginRepositoryInjection()
+ throws Exception
+ {
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+
+ Repository r = new Repository();
+ r.setId( "test" );
+ r.setUrl( "file:///test" );
+
+ Profile p = new Profile();
+ p.setId( "test" );
+ p.addPluginRepository( r );
+
+ Settings settings = new Settings();
+ settings.addProfile( p );
+ settings.addActiveProfile( p.getId() );
+
+ testee.populateFromSettings( request, settings );
+
+ List<ArtifactRepository> repositories = request.getPluginArtifactRepositories();
+ assertEquals( 1, repositories.size() );
+ assertEquals( r.getId(), repositories.get( 0 ).getId() );
+ assertEquals( r.getUrl(), repositories.get( 0 ).getUrl() );
+ }
+}
[2/2] maven git commit: .mvn/ for project specific jvm options and
maven parameters
Posted by if...@apache.org.
.mvn/ for project specific jvm options and maven parameters
Signed-off-by: Igor Fedorenko <if...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/888109c6
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/888109c6
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/888109c6
Branch: refs/heads/project-basedir
Commit: 888109c686d9eaaa70774486d3682abd074d7dcb
Parents: d745f8c
Author: Igor Fedorenko <if...@apache.org>
Authored: Mon Jan 26 14:22:05 2015 -0500
Committer: Igor Fedorenko <if...@apache.org>
Committed: Thu Feb 5 14:27:47 2015 -0500
----------------------------------------------------------------------
apache-maven/src/bin/.gitattributes | 1 +
apache-maven/src/bin/mvn | 8 ++-
apache-maven/src/bin/mvn-common.sh | 43 +++++++++++++
apache-maven/src/bin/mvnDebug | 8 ++-
apache-maven/src/bin/mvnyjp | 23 ++++---
apache-maven/src/main/assembly/bin.xml | 1 +
.../execution/DefaultMavenExecutionRequest.java | 14 ++++
.../maven/execution/MavenExecutionRequest.java | 9 +++
.../java/org/apache/maven/cli/MavenCli.java | 68 +++++++++++++++++++-
.../java/org/apache/maven/cli/MavenCliTest.java | 58 +++++++++++++++++
.../projects/config-illegal/.mvn/maven.config | 1 +
.../src/test/projects/config/.mvn/maven.config | 2 +
12 files changed, 217 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/bin/.gitattributes
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/.gitattributes b/apache-maven/src/bin/.gitattributes
index cc7533f..90eeece 100644
--- a/apache-maven/src/bin/.gitattributes
+++ b/apache-maven/src/bin/.gitattributes
@@ -1,3 +1,4 @@
mvn eol=lf crlf=input
mvnDebug eol=lf crlf=input
mvnyjp eol=lf crlf=input
+mvn-common.sh eol=lf crlf=input
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/bin/mvn
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
index 1ed3024..f745f4e 100755
--- a/apache-maven/src/bin/mvn
+++ b/apache-maven/src/bin/mvn
@@ -189,14 +189,18 @@ if $cygwin; then
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
+. "$M2_HOME/bin/mvn-common.sh"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
-MAVEN_CMD_LINE_ARGS="$@"
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
- "-Dmaven.home=${M2_HOME}" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/bin/mvn-common.sh
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvn-common.sh b/apache-maven/src/bin/mvn-common.sh
new file mode 100755
index 0000000..b39741b
--- /dev/null
+++ b/apache-maven/src/bin/mvn-common.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# 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.
+# ----------------------------------------------------------------------------
+
+# TODO ideally, this should contain all logic common to mvn* shell scripts
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+ local basedir=$(pwd)
+ local wdir=$(pwd)
+ while [ "$wdir" != '/' ] ; do
+ wdir=$(cd $wdir/..; pwd)
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/bin/mvnDebug
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvnDebug b/apache-maven/src/bin/mvnDebug
index 291f81f..287d20b 100755
--- a/apache-maven/src/bin/mvnDebug
+++ b/apache-maven/src/bin/mvnDebug
@@ -193,9 +193,13 @@ if $cygwin; then
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi
+. "$M2_HOME/bin/mvn-common.sh"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
-MAVEN_CMD_LINE_ARGS="$@"
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
exec "$JAVACMD" \
@@ -203,5 +207,5 @@ exec "$JAVACMD" \
$MAVEN_DEBUG_OPTS \
-classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
- "-Dmaven.home=${M2_HOME}" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/bin/mvnyjp
----------------------------------------------------------------------
diff --git a/apache-maven/src/bin/mvnyjp b/apache-maven/src/bin/mvnyjp
index faf3412..6d5f555 100755
--- a/apache-maven/src/bin/mvnyjp
+++ b/apache-maven/src/bin/mvnyjp
@@ -34,14 +34,6 @@
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
-QUOTED_ARGS=""
-while [ "$1" != "" ] ; do
-
- QUOTED_ARGS="$QUOTED_ARGS \"$1\""
- shift
-
-done
-
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
@@ -204,11 +196,18 @@ fi
MAVEN_OPTS="-agentpath:$YJPLIB=onexit=snapshot,onexit=memory,tracing,onlylocal $MAVEN_OPTS"
+. "$M2_HOME/bin/mvn-common.sh"
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
- "-Dmaven.home=${M2_HOME}" \
- ${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS
-
-
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.projectBasedir=${MAVEN_PROJECTBASEDIR}" \
+ ${CLASSWORLDS_LAUNCHER} "$@"
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/apache-maven/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/apache-maven/src/main/assembly/bin.xml b/apache-maven/src/main/assembly/bin.xml
index b2aa900..6b862f8 100644
--- a/apache-maven/src/main/assembly/bin.xml
+++ b/apache-maven/src/main/assembly/bin.xml
@@ -74,6 +74,7 @@ under the License.
<outputDirectory>bin</outputDirectory>
<includes>
<include>m2</include>
+ <include>mvn-common.sh</include>
<include>mvn</include>
<include>mvnDebug</include>
<!-- This is so that CI systems can periodically run the profiler -->
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/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 d88024d..f4439b1 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
@@ -93,6 +93,8 @@ public class DefaultMavenExecutionRequest
// Request
// ----------------------------------------------------------------------------
+ private File projectBasedir;
+
private File basedir;
private List<String> goals;
@@ -1149,4 +1151,16 @@ public class DefaultMavenExecutionRequest
this.toolchains = toolchains;
return this;
}
+
+ @Override
+ public void setProjectBaseDirectory( File directory )
+ {
+ this.projectBasedir = directory;
+ }
+
+ @Override
+ public File getProjectBaseDirectory()
+ {
+ return projectBasedir;
+ }
}
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/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 15e2082..0591440 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
@@ -411,4 +411,13 @@ public interface MavenExecutionRequest
*/
Map<String, List<ToolchainModel>> getToolchains();
+ /**
+ * @since 3.2.6
+ */
+ void setProjectBaseDirectory( File file );
+
+ /**
+ * @since 3.2.6
+ */
+ File getProjectBaseDirectory();
}
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/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 5b7bd7f..dbaab7c 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,12 +19,17 @@ package org.apache.maven.cli;
* under the License.
*/
+import java.io.BufferedReader;
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.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -105,6 +110,8 @@ public class MavenCli
public static final String THREADS_DEPRECATED = "maven.threads.experimental";
+ public static final String PROJECT_BASEDIR = "maven.projectBasedir";
+
@SuppressWarnings( "checkstyle:constantname" )
public static final String userHome = System.getProperty( "user.home" );
@@ -256,13 +263,27 @@ public class MavenCli
}
}
- private void initialize( CliRequest cliRequest )
+ void initialize( CliRequest cliRequest )
{
if ( cliRequest.workingDirectory == null )
{
cliRequest.workingDirectory = System.getProperty( "user.dir" );
}
+ if ( cliRequest.projectBaseDirectory == null )
+ {
+ String basedirProperty = System.getProperty( PROJECT_BASEDIR );
+ File basedir = basedirProperty != null ? new File( basedirProperty ) : new File( "" );
+ try
+ {
+ cliRequest.projectBaseDirectory = basedir.getCanonicalFile();
+ }
+ catch ( IOException e )
+ {
+ cliRequest.projectBaseDirectory = basedir.getAbsoluteFile();
+ }
+ }
+
//
// Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative
// Windows paths.
@@ -275,7 +296,7 @@ public class MavenCli
}
}
- private void cli( CliRequest cliRequest )
+ void cli( CliRequest cliRequest )
throws Exception
{
//
@@ -286,9 +307,48 @@ public class MavenCli
CLIManager cliManager = new CLIManager();
+ List<String> args = new ArrayList<String>();
+
+ try
+ {
+ File configFile = new File( cliRequest.projectBaseDirectory, ".mvn/maven.config" );
+
+ if ( configFile.isFile() )
+ {
+ BufferedReader r =
+ new BufferedReader( new InputStreamReader( new FileInputStream( configFile ), "UTF-8" ) );
+ try
+ {
+ String str;
+ while ( ( str = r.readLine() ) != null )
+ {
+ args.add( str );
+ }
+ }
+ finally
+ {
+ r.close();
+ }
+
+ CommandLine config = cliManager.parse( args.toArray( new String[args.size()] ) );
+ List<?> unrecongized = config.getArgList();
+ if ( !unrecongized.isEmpty() )
+ {
+ throw new ParseException( "Unrecognized maven.config entries: " + unrecongized );
+ }
+ }
+ }
+ catch ( ParseException e )
+ {
+ System.err.println( "Unable to parse maven.config: " + e.getMessage() );
+ cliManager.displayHelp( System.out );
+ throw e;
+ }
+
try
{
- cliRequest.commandLine = cliManager.parse( cliRequest.args );
+ args.addAll( 0, Arrays.asList( cliRequest.args ) );
+ cliRequest.commandLine = cliManager.parse( args.toArray( new String[args.size()] ) );
}
catch ( ParseException e )
{
@@ -1070,6 +1130,7 @@ public class MavenCli
.setUpdateSnapshots( updateSnapshots ) // default: false
.setNoSnapshotUpdates( noSnapshotUpdates ) // default: false
.setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn
+ .setProjectBaseDirectory( cliRequest.projectBaseDirectory )
;
if ( alternatePomFile != null )
@@ -1319,6 +1380,7 @@ public class MavenCli
CommandLine commandLine;
ClassWorld classWorld;
String workingDirectory;
+ File projectBaseDirectory;
boolean debug;
boolean quiet;
boolean showErrors = true;
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
index 6e06cc5..c1b6c03 100644
--- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
+++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
@@ -19,16 +19,39 @@ package org.apache.maven.cli;
* under the License.
*/
+import java.io.File;
+
import junit.framework.TestCase;
+import org.apache.commons.cli.ParseException;
+import org.apache.maven.cli.MavenCli.CliRequest;
+
public class MavenCliTest
extends TestCase
{
private MavenCli cli;
+ private String origBasedir;
+
protected void setUp()
{
cli = new MavenCli();
+ origBasedir = System.getProperty( MavenCli.PROJECT_BASEDIR );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ if ( origBasedir != null )
+ {
+ System.setProperty( MavenCli.PROJECT_BASEDIR, origBasedir );
+ }
+ else
+ {
+ System.getProperties().remove( MavenCli.PROJECT_BASEDIR );
+ }
+ super.tearDown();
}
public void testCalculateDegreeOfConcurrencyWithCoreMultiplier()
@@ -49,4 +72,39 @@ public class MavenCliTest
// carry on
}
}
+
+ public void testMavenConfig()
+ throws Exception
+ {
+ System.setProperty( MavenCli.PROJECT_BASEDIR, new File( "src/test/projects/config" ).getCanonicalPath() );
+ CliRequest request = new CliRequest( new String[0], null );
+
+ // read .mvn/maven.config
+ cli.initialize( request );
+ cli.cli( request );
+ assertEquals( "multithreaded", request.commandLine.getOptionValue( "builder" ) );
+
+ // override from command line
+ request = new CliRequest( new String[] { "--builder", "foobar" }, null );
+ cli.cli( request );
+ assertEquals( "foobar", request.commandLine.getOptionValue( "builder" ) );
+ }
+
+ public void testMavenConfigInvalid()
+ throws Exception
+ {
+ System.setProperty( MavenCli.PROJECT_BASEDIR, new File( "src/test/projects/config-illegal" ).getCanonicalPath() );
+ CliRequest request = new CliRequest( new String[0], null );
+
+ cli.initialize( request );
+ try
+ {
+ cli.cli( request );
+ fail();
+ }
+ catch ( ParseException expected )
+ {
+
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
new file mode 100644
index 0000000..8541464
--- /dev/null
+++ b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
@@ -0,0 +1 @@
+deploy
http://git-wip-us.apache.org/repos/asf/maven/blob/888109c6/maven-embedder/src/test/projects/config/.mvn/maven.config
----------------------------------------------------------------------
diff --git a/maven-embedder/src/test/projects/config/.mvn/maven.config b/maven-embedder/src/test/projects/config/.mvn/maven.config
new file mode 100644
index 0000000..bf41c83
--- /dev/null
+++ b/maven-embedder/src/test/projects/config/.mvn/maven.config
@@ -0,0 +1,2 @@
+--builder
+multithreaded