Author: lcorneliussen Date: Tue Dec 20 19:48:23 2011 New Revision: 1221460 URL: http://svn.apache.org/viewvc?rev=1221460&view=rev Log: [NPANDAY-499] Make configuration for compiler-plugins and executable-plugins more flexible
o Added executableVersion to exectuable plugins Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableRequirement.java incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CapabilityMatcherImpl.java incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java (original) +++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java Tue Dec 20 19:48:23 2011 @@ -96,6 +96,11 @@ public interface ExecutableCapability String getExecutableName(); /** + * Returns the version of the executable that is offered as capability. + */ + String getExecutableVersion(); + + /** * Returns the class name of the executable plugin that knows how to handle the execution request. * * @return the class name of the executable plugin that knows how to handle the execution request Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableRequirement.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableRequirement.java?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableRequirement.java (original) +++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableRequirement.java Tue Dec 20 19:48:23 2011 @@ -26,7 +26,6 @@ import npanday.vendor.VendorRequirement; * * @author Shane Isbell * @author <a href="mailto:lcornelius...@apache.org">Lars Corneliussen</a> - * * @see ExecutableCapability * @see CapabilityMatcher */ @@ -36,16 +35,32 @@ public class ExecutableRequirement private String profile; + private String executableVersion; + public ExecutableRequirement( String vendorName, String vendorVersion, String frameworkVersion, String profile ) { + this( vendorName, vendorVersion, frameworkVersion, profile, null ); + } + + public ExecutableRequirement( + String vendorName, String vendorVersion, String frameworkVersion, String profile, String executableVersion ) + { super( vendorName, vendorVersion, frameworkVersion ); this.profile = profile; + this.executableVersion = executableVersion; } public ExecutableRequirement( Vendor vendor, String vendorVersion, String frameworkVersion, String profile ) { + this( vendor, vendorVersion, frameworkVersion, profile, null ); + } + + public ExecutableRequirement( + Vendor vendor, String vendorVersion, String frameworkVersion, String profile, String executableVersion ) + { super( vendor, vendorVersion, frameworkVersion ); this.profile = profile; + this.executableVersion = executableVersion; } public String getProfile() @@ -53,8 +68,8 @@ public class ExecutableRequirement return profile; } - public void setProfile( String profile ) + public String getExecutableVersion() { - this.profile = profile; + return executableVersion; } } Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CapabilityMatcherImpl.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CapabilityMatcherImpl.java?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CapabilityMatcherImpl.java (original) +++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CapabilityMatcherImpl.java Tue Dec 20 19:48:23 2011 @@ -18,6 +18,7 @@ */ package npanday.executable.impl; +import com.google.common.collect.Lists; import npanday.PlatformUnsupportedException; import npanday.executable.CapabilityMatcher; import npanday.executable.ExecutableCapability; @@ -127,6 +128,9 @@ public class CapabilityMatcherImpl matchPolicies.add( MatchPolicyFactory.createOperatingSystemPolicy( System.getProperty( "os.name" ) ) ); matchPolicies.add( MatchPolicyFactory.createProfilePolicy( executableRequirement.getProfile() ) ); + matchPolicies.add( MatchPolicyFactory.createExecutableVersionPolicy( + executableRequirement.getExecutableVersion() + ) ); return matchFromExecutableCapabilities( getExecutableCapabilities(vendorInfo), matchPolicies ); } @@ -136,21 +140,35 @@ public class CapabilityMatcherImpl List<ExecutableMatchPolicy> matchPolicies ) throws PlatformUnsupportedException { + List<ExecutableCapability> matchingCapabilities = Lists.newArrayList(); for ( ExecutableCapability executableCapability : executableCapabilities ) { if ( matchExecutableCapability( executableCapability, matchPolicies ) ) { getLogger().debug( "NPANDAY-065-001: Found matching capability: " + executableCapability ); - return executableCapability; + matchingCapabilities.add( executableCapability ); } else { getLogger().debug( "NPANDAY-065-005: Capability doesn't match: " + executableCapability ); } } - throw new PlatformUnsupportedException( - "NPANDAY-065-002: Could not match any of the " + executableCapabilities.size() + " capabilities with " - + matchPolicies ); + + if (matchingCapabilities.size() == 0){ + throw new PlatformUnsupportedException( + "NPANDAY-065-002: Could not match any of the " + executableCapabilities.size() + " capabilities with " + + matchPolicies ); + } + + if ( matchingCapabilities.size() > 1 ) + { + getLogger().warn( + "NPANDAY-065-010: Found multiple matching capabilities; will choose the first one: " + + matchingCapabilities + ); + } + + return matchingCapabilities.get( 0 ); } private VendorInfo matchVendorInfo(ExecutableRequirement executableRequirement) Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java (original) +++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/MatchPolicyFactory.java Tue Dec 20 19:48:23 2011 @@ -22,6 +22,8 @@ import npanday.executable.ExecutableCapa import npanday.executable.ExecutableMatchPolicy; import npanday.executable.compiler.CompilerCapability; +import static com.google.common.base.Strings.isNullOrEmpty; + /** * Creates executable match policies. * @@ -109,4 +111,31 @@ final class MatchPolicyFactory } }; } + + public static ExecutableMatchPolicy createExecutableVersionPolicy( final String requiredExecutableVersion ) + { + return new ExecutableMatchPolicy() + { + public boolean match( ExecutableCapability executableCapability ) + { + // if not specified, all versions are valid + if (isNullOrEmpty(requiredExecutableVersion)) + return true; + + final 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() ); + } + + public String toString() + { + return "ExecutableMatchPolicy[executableVersion: '" + requiredExecutableVersion + "']"; + } + }; + } } Modified: incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo (original) +++ incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo Tue Dec 20 19:48:23 2011 @@ -55,7 +55,10 @@ under the License. <name>identifier</name> <version>1.0.0+</version> <type>String</type> - <description>An id for the executable. It should be (but is not required to be) unique.</description> + <description> + The platform-independent identifier for the executable as it will be + requested through the npanday.executable.ExecutableRequirement. + </description> </field> <field> <name>pluginClass</name> @@ -69,7 +72,7 @@ under the License. <name>vendor</name> <version>1.0.0+</version> <type>String</type> - <description>Vendor this executable is provided by or compatible with: MICROSOFT, MONO, DotGNU</description> + <description>Vendor this executable is provided by or compatible with. For example MICROSOFT, MONO, DotGNU</description> </field> <field> <name>vendorVersion</name> @@ -82,6 +85,7 @@ under the License. <name>profile</name> <version>1.0.0+</version> <type>String</type> + <required>true</required> <description>Profile for the plugin.</description> </field> <field> @@ -92,6 +96,16 @@ under the License. <description>Executable name without extension, as run from the command line.</description> </field> <field> + <name>executableVersion</name> + <version>1.5.0+</version> + <type>String</type> + <description> + The version of the executable, since multiple could be found on different paths (specified in 'probingPaths'). + Applicable, if executable is NOT provided by the .NET vendor (as specified in 'vendor'). + </description> + <required>false</required> + </field> + <field> <name>probingPaths</name> <version>1.5.0+</version> <description> Modified: incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy (original) +++ incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy Tue Dec 20 19:48:23 2011 @@ -37,5 +37,6 @@ class ExecutablePluginXpp3ReaderTest assert model.executablePlugins[0].probingPaths != null assert model.executablePlugins[0].probingPaths.size() == 2 assert model.executablePlugins[0].probingPaths[0] == "one" + assert model.executablePlugins[0].executableVersion == "5.0" } } Modified: incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml?rev=1221460&r1=1221459&r2=1221460&view=diff ============================================================================== --- incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml (original) +++ incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml Tue Dec 20 19:48:23 2011 @@ -22,6 +22,7 @@ under the License. <pluginClass>npanday.executable.impl.DefaultNetExecutable</pluginClass> <vendor>MICROSOFT</vendor> <executable>NCover.Console</executable> + <executableVersion>5.0</executableVersion> <profile>NCover:NCover.Console</profile> <frameworkVersions> <frameworkVersion>4.0</frameworkVersion>