[MSHARED-251] Option to change from mvn executable to mvnDebug executable

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1395172 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
index a6246fc..6f34b6f 100644
--- a/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
+++ b/src/main/java/org/apache/maven/shared/invoker/DefaultInvoker.java
@@ -50,6 +50,8 @@
 
     private File mavenHome;
 
+    private File mavenExecutable;
+
     private InvocationOutputHandler outputHandler = DEFAULT_OUTPUT_HANDLER;
 
     private InputStream inputStream;
@@ -78,6 +80,13 @@
         {
             cliBuilder.setMavenHome( getMavenHome() );
         }
+        
+        File mavenExecutable = getMavenExecutable();
+        if ( mavenExecutable != null )
+        {
+            cliBuilder.setMavenExecutable( mavenExecutable );
+        }
+        
 
         File workingDirectory = getWorkingDirectory();
         if ( workingDirectory != null )
@@ -197,6 +206,17 @@
         return this;
     }
 
+    public File getMavenExecutable()
+    {
+        return mavenExecutable;
+    }
+
+    public Invoker setMavenExecutable( File mavenExecutable )
+    {
+        this.mavenExecutable = mavenExecutable;
+        return this;
+    }
+
     public Invoker setErrorHandler( InvocationOutputHandler errorHandler )
     {
         this.errorHandler = errorHandler;
diff --git a/src/main/java/org/apache/maven/shared/invoker/Invoker.java b/src/main/java/org/apache/maven/shared/invoker/Invoker.java
index 6c1b2f7..a663837 100644
--- a/src/main/java/org/apache/maven/shared/invoker/Invoker.java
+++ b/src/main/java/org/apache/maven/shared/invoker/Invoker.java
@@ -96,6 +96,21 @@
     Invoker setMavenHome( File mavenHome );
 
     /**
+     * Get the customized File of the Maven executable.
+     * 
+     * @return the custom Maven executable, otherwise {@code null} 
+     */
+    File getMavenExecutable();
+
+    /**
+     * {@code mavenExecutable} can either be a file relative to ${maven.home}/bin/ or an absolute file.
+     * 
+     * @param mavenExecutable the executable
+     * @return This invoker instance
+     */
+    Invoker setMavenExecutable( File mavenExecutable );
+
+    /**
      * Sets the path to the base directory of the local repository to use for the Maven invocation.
      * 
      * @param localRepositoryDirectory The path to the base directory of the local repository or <code>null</code> to
@@ -147,5 +162,4 @@
      * @return This invoker instance.
      */
     Invoker setErrorHandler( InvocationOutputHandler errorHandler );
-
 }
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 abf6482..a32aa47 100644
--- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
@@ -47,7 +47,7 @@
 
     private File mavenHome;
 
-    private File mvnCommand;
+    private File mavenExecutable;
 
     private Properties systemEnvVars;
 
@@ -564,34 +564,41 @@
 
         logger.debug( "Using ${maven.home} of: \'" + mavenHome + "\'." );
 
-        if ( mvnCommand == null )
+        if ( mavenExecutable == null || !mavenExecutable.isAbsolute() )
         {
-            if ( Os.isFamily( "windows" ) )
+            String executable;
+            if( mavenExecutable != null )
             {
-                mvnCommand = new File( mavenHome, "/bin/mvn.bat" );
+                executable = mavenExecutable.getPath();
+            }
+            else if ( Os.isFamily( "windows" ) )
+            {
+                executable = "mvn.bat";
             }
             else
             {
-                mvnCommand = new File( mavenHome, "/bin/mvn" );
+                executable = "mvn";
             }
-
+            
+            mavenExecutable = new File( mavenHome, "/bin/" + executable );
+            
             try
             {
-                File canonicalMvn = mvnCommand.getCanonicalFile();
-                mvnCommand = canonicalMvn;
+                File canonicalMvn = mavenExecutable.getCanonicalFile();
+                mavenExecutable = canonicalMvn;
             }
             catch ( IOException e )
             {
-                logger.debug( "Failed to canonicalize maven executable: " + mvnCommand + ". Using as-is.", e );
+                logger.debug( "Failed to canonicalize maven executable: " + mavenExecutable + ". Using as-is.", e );
             }
 
-            if ( !mvnCommand.exists() )
+            if ( !mavenExecutable.isFile() )
             {
-                throw new CommandLineConfigurationException( "Maven executable not found at: " + mvnCommand );
+                throw new CommandLineConfigurationException( "Maven executable not found at: " + mavenExecutable );
             }
         }
 
-        return mvnCommand;
+        return mavenExecutable;
     }
 
     /**
@@ -664,4 +671,19 @@
         this.workingDirectory = workingDirectory;
     }
 
+    /**
+     * {@code mavenExecutable} can either be relative to ${maven.home}/bin/ or absolute 
+     * 
+     * @param mavenExecutable the executable
+     */
+    public void setMavenExecutable( File mavenExecutable )
+    {
+        this.mavenExecutable = mavenExecutable;
+    }
+
+    public File getMavenExecutable()
+    {
+        return mavenExecutable;
+    }
+
 }
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 37b784f..e972e02 100644
--- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
@@ -1105,7 +1105,17 @@
 
         assertArgumentsPresentInOrder( commandline, "-P", profile1 + "," + profile2 );
     }
-
+    
+    public void testMvnCommand() throws Exception
+    {
+        MavenCommandLineBuilder commandLineBuilder = new MavenCommandLineBuilder();
+        File mavenExecutable = new File ( "mvnDebug" );
+        commandLineBuilder.setMavenExecutable( mavenExecutable );
+        File executable = commandLineBuilder.findMavenExecutable();
+        assertTrue( "Expected executable to exist",  executable.exists() );
+        assertTrue( "Expected executable to be absolute", executable.isAbsolute() );
+    }
+    
     public void setUp()
     {
         sysProps = System.getProperties();