[NPANDAY-523] have WIX plugin use the new execution framework

Submitted by:  Adrián Boimvaser

git-svn-id: https://svn.apache.org/repos/asf/incubator/npanday/trunk@1619663 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/components/dotnet-executable/src/main/java/npanday/executable/impl/NetExecutableFactoryImpl.java b/components/dotnet-executable/src/main/java/npanday/executable/impl/NetExecutableFactoryImpl.java
index b6da25f..cc475fe 100644
--- a/components/dotnet-executable/src/main/java/npanday/executable/impl/NetExecutableFactoryImpl.java
+++ b/components/dotnet-executable/src/main/java/npanday/executable/impl/NetExecutableFactoryImpl.java
@@ -90,7 +90,7 @@
         if ( netHome != null )
         {
             getLogger().info( "NPANDAY-066-014: Found executable path in pom: Path = " + netHome.getAbsolutePath() );
-            executableConfig.getExecutionPaths().add( netHome.getAbsolutePath() );
+            executablePaths.add( netHome.getAbsolutePath() );
         }
 
 
diff --git a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/AbstractWixMojo.java b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/AbstractWixMojo.java
index 14a840e..cb5a491 100644
--- a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/AbstractWixMojo.java
+++ b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/AbstractWixMojo.java
@@ -19,20 +19,51 @@
  * under the License.
  */
 
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecutor;
-import org.apache.commons.exec.ExecuteException;
+import npanday.PlatformUnsupportedException;
+import npanday.executable.ExecutableRequirement;
+import npanday.executable.ExecutionException;
+import npanday.executable.NetExecutable;
+
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 
+import com.google.common.collect.Lists;
+
 import java.io.File;
-import java.io.IOException;
 import java.util.List;
 
 public abstract class AbstractWixMojo
     extends AbstractMojo
 {
     /**
+     * The vendor of the framework, the executable is provided by or compatible with.
+     *
+     * @parameter expression="${vendor}"
+     */
+    private String vendor;
+
+    /**
+     * The version of the framework vendor, the executable is provided by or compatible with.
+     *
+     * @parameter expression="${vendorVersion}"
+     */
+    private String vendorVersion;
+
+    /**
+     * The framework version, the executable is compatible with.
+     *
+     * @parameter expression = "${frameworkVersion}"
+     */
+    private String frameworkVersion;
+
+    /**
+     * The configured executable version, from executable-plugins.xml, to be used.
+     *
+     * @parameter expression="${wix.version}" default-value="3.0"
+     */
+    private String executableVersion;
+
+    /**
      * WiX extensions to use
      *
      * @parameter
@@ -59,64 +90,62 @@
      */
     private boolean suppressSchemaValidation;
 
+    /**
+     * @component
+     */
+    private npanday.executable.NetExecutableFactory netExecutableFactory;
+
     public void execute()
         throws MojoExecutionException
     {
         try
         {
-            CommandLine commandLine = new CommandLine( getWixPath( getCommand() ) );
-
+            List<String> commands = Lists.newArrayList();
+                    
             if ( extensions != null )
             {
                 for ( String ext : extensions )
                 {
-                    commandLine.addArgument( "-ext" );
-                    commandLine.addArgument( ext );
+                    commands.add( "-ext" );
+                    commands.add( ext );
                 }
             }
 
             if ( suppressSchemaValidation )
             {
-                commandLine.addArgument( "-ss" );
+                commands.add( "-ss" );
             }
 
             if ( arguments != null )
             {
-                commandLine.addArgument( arguments );
+                commands.add( arguments );
             }
 
-            commandLine.addArguments( getArguments().toArray( new String[0] ) );
-
-            getLog().info( "Executing " + commandLine );
-
-            DefaultExecutor executor = new DefaultExecutor();
-            int exitValue = executor.execute( commandLine );
-            if ( exitValue != 0 )
-            {
-                throw new MojoExecutionException( "Problem executing " + getCommand() + ", return code " + exitValue );
-            }
+            commands.addAll( getArguments() );
+            
+            NetExecutable executor = netExecutableFactory.getExecutable(
+                new ExecutableRequirement(
+                        vendor, vendorVersion, frameworkVersion, getExecutableIdentifier(), executableVersion
+                        ), commands, (wixHome != null) ? new File( wixHome, "bin" ) : null
+                    );
+            executor.execute();
         }
-        catch ( ExecuteException e )
-        {
-            throw new MojoExecutionException( "Problem executing " + getCommand(), e );
+        catch (ExecutionException e) {
+            throw new MojoExecutionException(
+                "Unable to execute '" + getExecutableIdentifier() + "' for vendor " + vendor + " v"
+                    + vendorVersion + " and frameworkVersion = " + frameworkVersion, e
+                );
         }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Problem executing " + getCommand(), e );
+        catch (PlatformUnsupportedException e) {
+            throw new MojoExecutionException(
+                "Unable to execute '" + getExecutableIdentifier() + "' for vendor " + vendor + " v"
+                    + vendorVersion + " and frameworkVersion = " + frameworkVersion, e
+                );
         }
     }
 
-    private String getWixPath( String name )
-    {
-        if ( wixHome != null )
-        {
-            return new File( new File( wixHome, "bin" ), name ).getAbsolutePath();
-        }
-        return name;
-    }
-
-    public abstract String getCommand();
-
+    public abstract String getExecutableIdentifier();
+    
     public abstract List<String> getArguments()
         throws MojoExecutionException;
 }
diff --git a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/CandleMojo.java b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/CandleMojo.java
index c2b61e1..c2f6fde 100644
--- a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/CandleMojo.java
+++ b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/CandleMojo.java
@@ -63,10 +63,15 @@
      */
     private File outputDirectory;
 
+    /**
+     * The executable identifier used to locate the right configurations from executable-plugins.xml. Can't be changed.
+     */
+    private String executableIdentifier = "CANDLE";
+
     @Override
-    public String getCommand()
+    public String getExecutableIdentifier()
     {
-        return "candle";
+        return executableIdentifier;
     }
 
     @Override
diff --git a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/LightMojo.java b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/LightMojo.java
index 775e174..c29ed70 100644
--- a/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/LightMojo.java
+++ b/plugins/wix-maven-plugin/src/main/java/npanday/plugin/wix/LightMojo.java
@@ -72,10 +72,15 @@
      */
     private String[] cultures;
 
+    /**
+     * The executable identifier used to locate the right configurations from executable-plugins.xml. Can't be changed.
+     */
+    private String executableIdentifier = "LIGHT";
+
     @Override
-    public String getCommand()
+    public String getExecutableIdentifier()
     {
-        return "light";
+        return executableIdentifier;
     }
 
     @Override
diff --git a/plugins/wix-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml b/plugins/wix-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
new file mode 100644
index 0000000..f16554e
--- /dev/null
+++ b/plugins/wix-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
@@ -0,0 +1,70 @@
+<!--
+  ~ 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.
+  -->
+<executablePlugins xmlns="http://npanday.apache.org/executables/1.5.0">
+
+  <executablePlugin>
+    <profile>CANDLE</profile>
+    <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
+
+    <executable>candle</executable>
+    <executableVersion>3.0</executableVersion>
+
+    <vendor>MICROSOFT</vendor>
+
+    <frameworkVersions>
+      <frameworkVersion>2.0.50727</frameworkVersion>
+    </frameworkVersions>
+
+    <probingPaths>
+       <probingPath>%WIX%</probingPath>
+    </probingPaths>
+
+    <platforms>
+      <platform>
+        <operatingSystem>Windows</operatingSystem>
+      </platform>
+    </platforms>
+
+  </executablePlugin>
+
+  <executablePlugin>
+    <profile>LIGHT</profile>
+    <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
+
+    <executable>light</executable>
+    <executableVersion>3.0</executableVersion>
+
+    <vendor>MICROSOFT</vendor>
+
+    <frameworkVersions>
+      <frameworkVersion>2.0.50727</frameworkVersion>
+    </frameworkVersions>
+
+    <probingPaths>
+       <probingPath>%WIX%</probingPath>
+    </probingPaths>
+
+    <platforms>
+      <platform>
+        <operatingSystem>Windows</operatingSystem>
+      </platform>
+    </platforms>
+
+  </executablePlugin>
+</executablePlugins>