[MSHARED-248] Add option for toolchains
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1392534 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 9e5a0dc..9fa70ab 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvocationRequest.java
@@ -71,6 +71,8 @@
private File userSettings;
private File globalSettings;
+
+ private File toolchains;
private String globalChecksumPolicy;
@@ -322,6 +324,17 @@
return this;
}
+ public File getToolchainsFile()
+ {
+ return toolchains;
+ }
+
+ public InvocationRequest setToolchainsFile( File toolchains )
+ {
+ this.toolchains = toolchains;
+ 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 9d0a81a..8a2d434 100644
--- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
+++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java
@@ -250,8 +250,17 @@
*
* @return The path to the global settings for the Maven invocation or <code>null</code> to load the global settings
* from the default location.
+ * @since 2.0.12
*/
File getGlobalSettingsFile();
+
+ /**
+ * Gets the path to the custom toolchains file
+ *
+ * @return The path to the custom toolchains file or <code>null</code> to load the toolchains from the default location
+ * @since 2.0.12
+ */
+ File getToolchainsFile();
/**
* Gets the checksum mode of the Maven invocation.
@@ -514,10 +523,20 @@
* @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.
+ * @since 2.0.12
*/
InvocationRequest setGlobalSettingsFile( File globalSettings );
/**
+ * Sets the alternate path for the user toolchains file
+ * Equivalent of {@code -t} or {@code --toolchains}
+ *
+ * @param toolchains the alternate path for the user toolchains file
+ * @return This invocation request
+ * @since 2.0.12
+ */
+ InvocationRequest setToolchainsFile( File toolchains );
+ /**
* 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 62a81b0..b4be1c0 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -94,6 +94,8 @@
setSettingsLocation( request, cli );
+ setToolchainsLocation( request, cli );
+
setProperties( request, cli );
setProfiles( request, cli );
@@ -101,7 +103,7 @@
setGoals( request, cli );
setThreads( request, cli );
-
+
return cli;
}
@@ -167,6 +169,28 @@
}
}
+
+ protected void setToolchainsLocation( InvocationRequest request, Commandline cli )
+ {
+ File toolchainsFile = request.getToolchainsFile();
+
+ if ( toolchainsFile != null )
+ {
+ try
+ {
+ File canSet = toolchainsFile.getCanonicalFile();
+ toolchainsFile = canSet;
+ }
+ catch ( IOException e )
+ {
+ logger.debug( "Failed to canonicalize toolchains path: " + toolchainsFile.getAbsolutePath()
+ + ". Using as-is.", e );
+ }
+
+ cli.createArg().setValue( "-t" );
+ cli.createArg().setValue( toolchainsFile.getPath() );
+ }
+ }
protected void setShellEnvironment( InvocationRequest request, Commandline cli )
throws CommandLineConfigurationException
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 5786b6f..8438e4f 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -839,6 +839,33 @@
assertArgumentsPresent( cli, args );
}
+ public void testShouldSpecifyCustomToolchainsLocationFromRequest()
+ throws Exception
+ {
+ logTestStart();
+
+ File tmpDir = getTempDir();
+ File base = new File( tmpDir, "invoker-tests" );
+
+ toDelete.add( base );
+
+ File projectDir = new File( base, "custom-toolchains" ).getCanonicalFile();
+
+ projectDir.mkdirs();
+
+ File toolchainsFile = createDummyFile( projectDir, "toolchains.xml" );
+
+ Commandline cli = new Commandline();
+
+ TestCommandLineBuilder tcb = new TestCommandLineBuilder();
+ tcb.setToolchainsLocation( newRequest().setToolchainsFile( toolchainsFile ), cli );
+
+ Set<String> args = new HashSet<String>();
+ args.add( "-t" );
+ args.add( toolchainsFile.getCanonicalPath() );
+
+ assertArgumentsPresent( cli, args );
+ }
public void testShouldSpecifyCustomPropertyFromRequest()
throws IOException
{