[NPANDAY-585] support any version of Azure SDK

Use a version range for executable version matching, and then construct
the probingPath directly using the registry key and executable version

git-svn-id: https://svn.apache.org/repos/asf/incubator/npanday/trunk@1619693 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java b/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java
index cc4fe6d..f9727ef 100644
--- a/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java
+++ b/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java
@@ -22,6 +22,9 @@
 import npanday.executable.ExecutableCapability;
 import npanday.executable.ExecutableMatchPolicy;
 import npanday.executable.compiler.CompilerCapability;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
 
 import static com.google.common.base.Strings.isNullOrEmpty;
 
@@ -123,14 +126,21 @@
                 if (isNullOrEmpty(requiredExecutableVersion))
                     return true;
 
-                final String offeredExecutableVersion = executableCapability.getExecutableVersion();
+                String offeredExecutableVersion = executableCapability.getExecutableVersion();
 
                 // if not specified, it is valid for all versions!
                 if (isNullOrEmpty( offeredExecutableVersion ))
                     return true;
 
-                // TODO: NPANDAY-499 this should support version range expressions
-                return requiredExecutableVersion.toLowerCase().trim().equals( offeredExecutableVersion.toLowerCase().trim() );
+                String required = requiredExecutableVersion.toLowerCase().trim();
+                offeredExecutableVersion = offeredExecutableVersion.toLowerCase().trim();
+                try {
+                    VersionRange range = VersionRange.createFromVersionSpec( offeredExecutableVersion );
+                    return range.containsVersion( new DefaultArtifactVersion( required ) );
+                } catch (InvalidVersionSpecificationException e) {
+                    // fallback to just matching version if not a valid range
+                    return required.equals(offeredExecutableVersion);
+                }
             }
 
             public String toString()
diff --git a/plugins/azure-maven-plugin/src/main/java/npanday/plugin/azure/AbstractCSPackDeployMojo.java b/plugins/azure-maven-plugin/src/main/java/npanday/plugin/azure/AbstractCSPackDeployMojo.java
index 7f3b26b..bc58990 100644
--- a/plugins/azure-maven-plugin/src/main/java/npanday/plugin/azure/AbstractCSPackDeployMojo.java
+++ b/plugins/azure-maven-plugin/src/main/java/npanday/plugin/azure/AbstractCSPackDeployMojo.java
@@ -23,9 +23,12 @@
 import npanday.executable.ExecutableRequirement;
 import npanday.executable.ExecutionException;
 import npanday.executable.NetExecutable;
+import npanday.registry.impl.WinRegistry;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 
 
@@ -67,12 +70,26 @@
 
         try
         {
-            // TODO: confusion of 'identifier' and 'profile' / align to new NPANDAY-499
+            File sdkHome = null;
+            try {
+                String azureSdkInstallPath = WinRegistry.readString(WinRegistry.HKEY_LOCAL_MACHINE,
+                        "SOFTWARE\\Microsoft\\Microsoft SDKs\\ServiceHosting\\v" + executableVersion, "InstallPath");
+                if ( azureSdkInstallPath != null )
+                {
+                    sdkHome = new File(azureSdkInstallPath, "bin");
+                }
+            } catch (IllegalAccessException e) {
+                getLog().warn("Error looking up Azure SDK location from registry: " + e.getLocalizedMessage() + " - will rely on PATH");
+            } catch (InvocationTargetException e) {
+                getLog().warn("Error looking up Azure SDK location from registry: " + e.getLocalizedMessage() + " - will rely on PATH");
+            }
+
+             // TODO: confusion of 'identifier' and 'profile' / align to new NPANDAY-499
             final NetExecutable executable = netExecutableFactory.getExecutable(
                 new ExecutableRequirement(
                     vendor, vendorVersion, frameworkVersion, executableIdentifier, executableVersion
                     /*, executableProfile*/
-                ), getCommands(), null
+                ), getCommands(), sdkHome
             );
             executable.execute();
         }
diff --git a/plugins/azure-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml b/plugins/azure-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
index 2875f0a..e0830be 100644
--- a/plugins/azure-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
+++ b/plugins/azure-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
@@ -23,7 +23,7 @@
     <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
 
     <executable>cspack</executable>
-    <executableVersion>1.6</executableVersion>
+    <executableVersion>[1.6,)</executableVersion>
 
     <vendor>MICROSOFT</vendor>
 
@@ -34,90 +34,11 @@
       <frameworkVersion>3.5</frameworkVersion>
     </frameworkVersions>
 
+    <!-- Paths are supplied in the mojo, so it can lookup the one matching the version used
     <probingPaths>
        <probingPath>${HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v1.6@InstallPath}\bin</probingPath>
     </probingPaths>
-
-    <platforms>
-      <platform>
-        <operatingSystem>Windows</operatingSystem>
-      </platform>
-    </platforms>
-
-  </executablePlugin>
-  <executablePlugin>
-    <profile>CSPACK</profile>
-    <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
-
-    <executable>cspack</executable>
-    <executableVersion>1.7</executableVersion>
-
-    <vendor>MICROSOFT</vendor>
-
-    <frameworkVersions>
-      <frameworkVersion>4.5.1</frameworkVersion>
-      <frameworkVersion>4.5</frameworkVersion>
-      <frameworkVersion>4.0</frameworkVersion>
-      <frameworkVersion>3.5</frameworkVersion>
-    </frameworkVersions>
-
-    <probingPaths>
-       <probingPath>${HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v1.7@InstallPath}\bin</probingPath>
-    </probingPaths>
-
-    <platforms>
-      <platform>
-        <operatingSystem>Windows</operatingSystem>
-      </platform>
-    </platforms>
-
-  </executablePlugin>
-  <executablePlugin>
-    <profile>CSPACK</profile>
-    <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
-
-    <executable>cspack</executable>
-    <executableVersion>1.8</executableVersion>
-
-    <vendor>MICROSOFT</vendor>
-
-    <frameworkVersions>
-      <frameworkVersion>4.5.1</frameworkVersion>
-      <frameworkVersion>4.5</frameworkVersion>
-      <frameworkVersion>4.0</frameworkVersion>
-      <frameworkVersion>3.5</frameworkVersion>
-    </frameworkVersions>
-
-    <probingPaths>
-       <probingPath>${HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v1.8@InstallPath}\bin</probingPath>
-    </probingPaths>
-
-    <platforms>
-      <platform>
-        <operatingSystem>Windows</operatingSystem>
-      </platform>
-    </platforms>
-
-  </executablePlugin>
-  <executablePlugin>
-    <profile>CSPACK</profile>
-    <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass>
-
-    <executable>cspack</executable>
-    <executableVersion>2.0</executableVersion>
-
-    <vendor>MICROSOFT</vendor>
-
-    <frameworkVersions>
-      <frameworkVersion>4.5.1</frameworkVersion>
-      <frameworkVersion>4.5</frameworkVersion>
-      <frameworkVersion>4.0</frameworkVersion>
-      <frameworkVersion>3.5</frameworkVersion>
-    </frameworkVersions>
-
-    <probingPaths>
-       <probingPath>${HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v2.0@InstallPath}\bin</probingPath>
-    </probingPaths>
+    -->
 
     <platforms>
       <platform>