[MSHARED-247] Add option for global-settings
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1392525 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
index 6b55502..9e5a0dc 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
@@ -70,6 +70,8 @@
private File userSettings;
+ private File globalSettings;
+
private String globalChecksumPolicy;
private String pomFilename;
@@ -302,13 +304,24 @@
{
return userSettings;
}
-
+
public InvocationRequest setUserSettingsFile( File userSettings )
{
this.userSettings = userSettings;
return this;
}
+ public File getGlobalSettingsFile()
+ {
+ return globalSettings;
+ }
+
+ public InvocationRequest setGlobalSettingsFile( File globalSettings )
+ {
+ this.globalSettings = globalSettings;
+ return this;
+ }
+
public String getGlobalChecksumPolicy()
{
return globalChecksumPolicy;
diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
index ed33d16..9d0a81a 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
@@ -246,6 +246,14 @@
File getUserSettingsFile();
/**
+ * Gets the path to the global settings for the Maven invocation.
+ *
+ * @return The path to the global settings for the Maven invocation or <code>null</code> to load the global settings
+ * from the default location.
+ */
+ File getGlobalSettingsFile();
+
+ /**
* Gets the checksum mode of the Maven invocation.
*
* @return The checksum mode, one of {@link #CHECKSUM_POLICY_WARN} and {@link #CHECKSUM_POLICY_FAIL}.
@@ -501,6 +509,15 @@
InvocationRequest setUserSettingsFile( File userSettings );
/**
+ * Sets the path to the global settings for the Maven invocation.
+ *
+ * @param globalSettings The path to the global settings for the Maven invocation, may be <code>null</code> to load
+ * the global settings from the default location.
+ * @return This invocation request.
+ */
+ InvocationRequest setGlobalSettingsFile( File globalSettings );
+
+ /**
* Sets the checksum mode of the Maven invocation.
*
* @param globalChecksumPolicy The checksum mode, must be one of {@link #CHECKSUM_POLICY_WARN} and
diff --git a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
index 8e98b17..62a81b0 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -146,6 +146,26 @@
cli.createArg().setValue( "-s" );
cli.createArg().setValue( userSettingsFile.getPath() );
}
+
+ File globalSettingsFile = request.getGlobalSettingsFile();
+
+ if ( globalSettingsFile != null )
+ {
+ try
+ {
+ File canSet = globalSettingsFile.getCanonicalFile();
+ globalSettingsFile = canSet;
+ }
+ catch ( IOException e )
+ {
+ logger.debug( "Failed to canonicalize global settings path: " + globalSettingsFile.getAbsolutePath()
+ + ". Using as-is.", e );
+ }
+
+ cli.createArg().setValue( "-gs" );
+ cli.createArg().setValue( globalSettingsFile.getPath() );
+ }
+
}
protected void setShellEnvironment( InvocationRequest request, Commandline cli )
diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
index f71f5dc..5786b6f 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -783,7 +783,7 @@
assertArgumentsPresent( cli, args );
}
- public void testShouldSpecifyCustomSettingsLocationFromRequest()
+ public void testShouldSpecifyCustomUserSettingsLocationFromRequest()
throws Exception
{
logTestStart();
@@ -810,6 +810,34 @@
assertArgumentsPresent( cli, args );
}
+
+ public void testShouldSpecifyCustomGlobalSettingsLocationFromRequest()
+ throws Exception
+ {
+ logTestStart();
+
+ File tmpDir = getTempDir();
+ File base = new File( tmpDir, "invoker-tests" );
+
+ toDelete.add( base );
+
+ File projectDir = new File( base, "custom-settings" ).getCanonicalFile();
+
+ projectDir.mkdirs();
+
+ File settingsFile = createDummyFile( projectDir, "settings.xml" );
+
+ Commandline cli = new Commandline();
+
+ TestCommandLineBuilder tcb = new TestCommandLineBuilder();
+ tcb.setSettingsLocation( newRequest().setGlobalSettingsFile( settingsFile ), cli );
+
+ Set<String> args = new HashSet<String>();
+ args.add( "-gs" );
+ args.add( settingsFile.getCanonicalPath() );
+
+ assertArgumentsPresent( cli, args );
+ }
public void testShouldSpecifyCustomPropertyFromRequest()
throws IOException