From nmaven-commits-return-20-apmail-incubator-nmaven-commits-archive=incubator.apache.org@incubator.apache.org Mon Dec 11 00:43:15 2006 Return-Path: Delivered-To: apmail-incubator-nmaven-commits-archive@locus.apache.org Received: (qmail 87826 invoked from network); 11 Dec 2006 00:42:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Dec 2006 00:42:50 -0000 Received: (qmail 47574 invoked by uid 500); 11 Dec 2006 00:42:56 -0000 Delivered-To: apmail-incubator-nmaven-commits-archive@incubator.apache.org Received: (qmail 47526 invoked by uid 500); 11 Dec 2006 00:42:56 -0000 Mailing-List: contact nmaven-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: nmaven-dev@incubator.apache.org Delivered-To: mailing list nmaven-commits@incubator.apache.org Delivered-To: moderator for nmaven-commits@incubator.apache.org Received: (qmail 97558 invoked by uid 99); 10 Dec 2006 23:46:00 -0000 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r485313 [9/15] - in /incubator/nmaven/trunk: components/ components/dotnet-artifact/ components/dotnet-artifact/src/ components/dotnet-artifact/src/main/ components/dotnet-artifact/src/main/java/ components/dotnet-artifact/src/main/java/org... Date: Sun, 10 Dec 2006 23:44:12 -0000 To: nmaven-commits@incubator.apache.org From: sisbell@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061210234424.0879D1A9866@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/MatchPolicyFactory.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/MatchPolicyFactory.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/MatchPolicyFactory.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/MatchPolicyFactory.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,177 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import org.apache.maven.dotnet.vendor.VendorInfoMatchPolicy; +import org.apache.maven.dotnet.vendor.VendorInfo; +import org.apache.maven.dotnet.vendor.InvalidVersionFormatException; +import org.codehaus.plexus.logging.Logger; + +/** + * Provides factory methods for creating vendor info match policies. + * + * @author Shane Isbell + * @see VendorInfoMatchPolicy + */ +final class MatchPolicyFactory +{ + /** + * A logger for writing log messages + */ + private Logger logger; + + /** + * Default constructor + */ + MatchPolicyFactory() + { + } + + /** + * Initialize this factory + * + * @param logger the plexus logger + */ + void init( Logger logger ) + { + this.logger = logger; + } + + + /** + * Returns a match policy for a vendor name. The accepted vendor names are: Microsoft, Mono and DotGNU. + * + * @param vendorName the name of the vendor to match + * @return a match policy for a vendor name + */ + VendorInfoMatchPolicy createVendorNamePolicy( final String vendorName ) + { + return new VendorInfoMatchPolicy() + { + public boolean match( VendorInfo vendorInfo ) + { + if ( vendorInfo == null ) + { + return false; + } + return isEqual( vendorInfo.getVendor().getVendorName(), vendorName ); + } + }; + } + + /** + * Returns a match policy for a vendor version. In the case of Microsoft, this will be the same as the framework + * version. In the case of Mono and DotGNU, the framework version and vendor version are different. + * + * @param vendorVersion the vendor version to match + * @return a match policy for a vendor version + */ + VendorInfoMatchPolicy createVendorVersionPolicy( final String vendorVersion ) + { + return new VendorInfoMatchPolicy() + { + public boolean match( VendorInfo vendorInfo ) + { + if ( vendorInfo == null ) + { + return false; + } + return isEqual( vendorInfo.getVendorVersion(), vendorVersion ); + } + }; + } + + /** + * Returns a match policy for the .NET framework version. + * + * @param frameworkVersion the .NET framework version to use for matching vendor info objects + * @return a match policy for the .NET framework version + */ + VendorInfoMatchPolicy createFrameworkVersionPolicy( final String frameworkVersion ) + { + return new VendorInfoMatchPolicy() + { + public boolean match( VendorInfo vendorInfo ) + { + if ( vendorInfo == null ) + { + return false; + } + VersionMatcher versionMatcher = new VersionMatcher(); + try + { + return versionMatcher.matchVersion( frameworkVersion, vendorInfo.getFrameworkVersion() ); + } + catch ( InvalidVersionFormatException e ) + { + logger.info( "NMAVEN-101-000: Invalid framework version: Version = " + frameworkVersion, e ); + return false; + } + } + }; + } + + /** + * Returns a vendor info match policy for matching whether a vendor info is a default entry. The vendor info + * match policy's match method will return true if the vendor info is not null and is a + * default entry, otherwise it will return false. + * + * @return a vendor info match policy for matching whether a vendor info is a default entry + */ + VendorInfoMatchPolicy createVendorIsDefaultPolicy() + { + return new VendorInfoMatchPolicy() + { + public boolean match( VendorInfo vendorInfo ) + { + if ( vendorInfo == null ) + { + return false; + } + return vendorInfo.isDefault(); + } + }; + } + + /** + * Returns true if the first value equals the second value, otherwise returns false. This comparison is not + * case or white-space sensitive. Null values will be treated as an empty string, so if the first value is null and + * the second value is empty (or only contains white-space), this method will return true. + * + * @param value the first value in the comparison + * @param value1 the second value in the comparison + * @return true if the first value equals the second value, otherwise returns false. + */ + private boolean isEqual( String value, String value1 ) + { + return normalize( value ).equals( normalize( value1 ) ); + } + + /** + * Normalizes the specified value by 1) making it all lower case and 2) removing all white-space. A null value will + * be treated as an empty string. + * + * @param value the value to normalize + * @return a normalized value that is lower case with no white-space + */ + private String normalize( String value ) + { + return ( value != null ) ? value.toLowerCase().trim() : ""; + } +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/MatchPolicyFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/SettingsRepository.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/SettingsRepository.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/SettingsRepository.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/SettingsRepository.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,183 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import org.apache.maven.dotnet.registry.Repository; +import org.apache.maven.dotnet.registry.RepositoryRegistry; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.*; +import java.util.Hashtable; +import java.util.List; +import java.util.ArrayList; + +import org.apache.maven.dotnet.model.settings.NMavenSettings; +import org.apache.maven.dotnet.model.settings.Vendor; +import org.apache.maven.dotnet.model.settings.DefaultSetup; +import org.apache.maven.dotnet.model.settings.Framework; +import org.apache.maven.dotnet.model.settings.io.xpp3.NMavenSettingsXpp3Reader; +import org.apache.maven.dotnet.PlatformUnsupportedException; +import org.apache.maven.dotnet.vendor.VendorFactory; +import org.apache.maven.dotnet.vendor.VendorInfo; +import org.apache.maven.dotnet.vendor.VendorUnsupportedException; + +/** + * Provides methods for loading and reading the nmaven-settings config file. + * + * @author Shane Isbell + */ +public class SettingsRepository + implements Repository +{ + + /** + * List of all vendors from the nmaven-settings file. The Vendor is the raw model type. + */ + private List vendors; + + /** + * The default setup: framework version, vendor, vendor version. If no information is provided by the user, then + * this information will be used to choose the environment. It may also be used for partial matches, if appropriate. + */ + private DefaultSetup defaultSetup; + + /** + * List of all vendors from the nmaven-settings file. + */ + private List vendorInfos; + + /** + * Constructor. This method is intended to be invoked by the RepositoryRegistry, not by the + * application developer. + */ + public SettingsRepository() + { + } + + /** + * @see Repository#load(java.io.InputStream, java.util.Hashtable) + */ + public void load( InputStream inputStream, Hashtable properties ) + throws IOException + { + NMavenSettingsXpp3Reader xpp3Reader = new NMavenSettingsXpp3Reader(); + Reader reader = new InputStreamReader( inputStream ); + NMavenSettings settings; + try + { + settings = xpp3Reader.read( reader ); + } + catch ( XmlPullParserException e ) + { + e.printStackTrace(); + throw new IOException( "NMAVEN-104-000: Could not read executable-plugins.xml" ); + } + vendors = settings.getVendors(); + defaultSetup = settings.getDefaultSetup(); + vendorInfos = new ArrayList(); + + for ( Vendor v : vendors ) + { + List frameworks = v.getFrameworks(); + for ( Framework framework : frameworks ) + { + VendorInfo vendorInfo = VendorInfo.Factory.createDefaultVendorInfo(); + vendorInfo.setVendorVersion( v.getVendorVersion() ); + vendorInfo.setExecutablePath( new File( framework.getInstallRoot() ) ); + vendorInfo.setFrameworkVersion( framework.getFrameworkVersion() ); + try + { + vendorInfo.setVendor( VendorFactory.createVendorFromName( v.getVendorName() ) ); + } + catch ( VendorUnsupportedException e ) + { + continue; + } + vendorInfo.setDefault( + v.getIsDefault() != null && v.getIsDefault().toLowerCase().trim().equals( "true" ) ); + vendorInfos.add( vendorInfo ); + } + } + } + + /** + * @see Repository#setRepositoryRegistry(org.apache.maven.dotnet.registry.RepositoryRegistry) + */ + public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry ) + { + } + + /** + * Returns all vendor infos from the nmaven-settings file. + * + * @return all vendor infos from the nmaven-settings file + */ + List getVendorInfos() + { + return vendorInfos; + } + + /** + * Returns the install root for the .NET framework for the specified parameters. None of the parameter values + * should be null. + * + * @param vendor the vendor name + * @param vendorVersion the vendor version + * @param frameworkVersion the .NET framework version + * @return the install root for the .NET framework + * @throws org.apache.maven.dotnet.PlatformUnsupportedException if there is no install root found for the specified parameters + */ + File getInstallRootFor( String vendor, String vendorVersion, String frameworkVersion ) + throws PlatformUnsupportedException + { + if ( vendor == null || vendorVersion == null || frameworkVersion == null ) + { + throw new PlatformUnsupportedException( "NMAVEN-104-001: One of more of the parameters is null: Vendor = " + + vendor + ", Vendor Version = " + vendorVersion + ", Framework Version = " + frameworkVersion ); + } + for ( Vendor v : vendors ) + { + if ( vendor.equals( v.getVendorName().trim() ) && vendorVersion.equals( v.getVendorVersion().trim() ) ) + { + List frameworks = v.getFrameworks(); + for ( Framework framework : frameworks ) + { + if ( frameworkVersion.equals( framework.getFrameworkVersion().trim() ) ) + { + return new File( framework.getInstallRoot() ); + } + } + } + } + throw new PlatformUnsupportedException( "NMAVEN-104-002: Unable to find install root: Vendor = " + vendor + + ", Vendor Version = " + vendorVersion + ", Framework Version = " + frameworkVersion ); + } + + /** + * Returns the default setup: framework version, vendor, vendor version. If no information is provided by the user, then + * this information will be used to choose the environment. It may also be used for partial matches, if appropriate. + * + * @return the default setup: framework version, vendor, vendor version + */ + DefaultSetup getDefaultSetup() + { + return defaultSetup; + } + +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/SettingsRepository.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/StateMachineProcessorImpl.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/StateMachineProcessorImpl.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/StateMachineProcessorImpl.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/StateMachineProcessorImpl.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,138 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import org.apache.maven.dotnet.vendor.*; +import org.apache.maven.dotnet.vendor.IllegalStateException; +import org.apache.maven.dotnet.registry.RepositoryRegistry; + +import java.util.HashMap; +import java.util.Map; + +import org.codehaus.plexus.logging.LogEnabled; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; + +/** + * Provides an implementation of the StateMachineProcessor. + * + * @author Shane Isbell + */ +public class StateMachineProcessorImpl + implements StateMachineProcessor, LogEnabled, Initializable +{ + + /** + * A registry component of repository (config) files + */ + private RepositoryRegistry repositoryRegistry; + + private VendorInfoRepository vendorInfoRepository; + + private Map transitionRules; + + /** + * A logger for writing log messages + */ + private Logger logger; + + /** + * Constructor. This method is intended to be invoked by the plexus-container, not by the application developer. + */ + public StateMachineProcessorImpl() + { + } + + /** + * @see LogEnabled#enableLogging(org.codehaus.plexus.logging.Logger) + */ + public void enableLogging( Logger logger ) + { + this.logger = logger; + } + + /** + * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable#initialize() + */ + public void initialize() + throws InitializationException + { + VendorInfoTransitionRuleFactory factory = new VendorInfoTransitionRuleFactory(); + transitionRules = new HashMap(); + transitionRules.put( VendorInfoState.MTT, factory.createVendorInfoSetterForMTT() ); + transitionRules.put( VendorInfoState.MTF, factory.createVendorInfoSetterForMTF() ); + transitionRules.put( VendorInfoState.MFT, factory.createVendorInfoSetterForMFT() ); + transitionRules.put( VendorInfoState.NTT, factory.createVendorInfoSetterForNTT() ); + + try + { + factory.init( repositoryRegistry, vendorInfoRepository, logger ); + logger.debug( "NMAVEN-102-000: Initialized rule factory." ); + transitionRules.put( VendorInfoState.MFF, factory.createVendorInfoSetterForMFF() ); + transitionRules.put( VendorInfoState.FTF, factory.createVendorInfoSetterForFTF() ); + transitionRules.put( VendorInfoState.FFT, factory.createVendorInfoSetterForFFT() ); + transitionRules.put( VendorInfoState.FTT, factory.createVendorInfoSetterForFTT() ); + transitionRules.put( VendorInfoState.FFF, factory.createVendorInfoSetterForFFF() ); + transitionRules.put( VendorInfoState.NFT, factory.createVendorInfoSetterForNFT() ); + transitionRules.put( VendorInfoState.NTF, factory.createVendorInfoSetterForNTF() ); + transitionRules.put( VendorInfoState.NFF, factory.createVendorInfoSetterForNTT() ); + transitionRules.put( VendorInfoState.NFF, factory.createVendorInfoSetterForNFF() ); + transitionRules.put( VendorInfoState.GFF, factory.createVendorInfoSetterForGFF() ); + } + catch ( org.apache.maven.dotnet.InitializationException e ) + { + logger.debug( "NMAVEN-102-001: Unable to initialize rule factory.", e ); + transitionRules.put( VendorInfoState.MFF, factory.createVendorInfoSetterForMFF_NoSettings() ); + transitionRules.put( VendorInfoState.NFT, factory.createVendorInfoSetterForNFT_NoSettings() ); + transitionRules.put( VendorInfoState.NTF, factory.createVendorInfoSetterForNTF_NoSettings() ); + transitionRules.put( VendorInfoState.FTF, factory.createVendorInfoSetterForFTF_NoSettings() ); + transitionRules.put( VendorInfoState.FFT, factory.createVendorInfoSetterForFFT_NoSettings() ); + transitionRules.put( VendorInfoState.FTT, factory.createVendorInfoSetterForFTT_NoSettings() ); + transitionRules.put( VendorInfoState.FFF, factory.createVendorInfoSetterForFFF_NoSettings() ); + transitionRules.put( VendorInfoState.NFF, factory.createVendorInfoSetterForNFF_NoSettings() ); + transitionRules.put( VendorInfoState.GFF, factory.createVendorInfoSetterForGFF_NoSettings() ); + } + } + + /** + * @see StateMachineProcessor#process(org.apache.maven.dotnet.vendor.VendorInfo) + */ + public void process( VendorInfo vendorInfo ) + throws IllegalStateException + { + VendorInfoState startState = VendorInfoState.START.getState( vendorInfo ); + VendorInfoTransitionRule rule = transitionRules.get( startState ); + if ( rule == null ) + { + throw new IllegalStateException( + "NMAVEN-102-002: Could not find rule for state: State = " + startState.name() ); + } + for ( VendorInfoState state = VendorInfoState.START; !state.equals( VendorInfoState.EXIT ); ) + { + state = rule.process( vendorInfo ); + rule = transitionRules.get( state ); + if ( rule == null && !state.equals( VendorInfoState.EXIT ) ) + { + throw new IllegalStateException( + "NMAVEN-102-003: Could not find rule for state: State = " + state.name() ); + } + } + } +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/StateMachineProcessorImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoRepositoryImpl.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoRepositoryImpl.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoRepositoryImpl.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoRepositoryImpl.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,178 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import org.apache.maven.dotnet.vendor.VendorInfoRepository; +import org.apache.maven.dotnet.vendor.VendorInfo; +import org.apache.maven.dotnet.vendor.VendorInfoMatchPolicy; +import org.apache.maven.dotnet.vendor.InvalidVersionFormatException; +import org.apache.maven.dotnet.registry.RepositoryRegistry; +import org.apache.maven.dotnet.PlatformUnsupportedException; + +import java.util.List; +import java.util.Collections; +import java.util.ArrayList; +import java.util.Set; +import java.io.File; + +import org.codehaus.plexus.logging.LogEnabled; +import org.codehaus.plexus.logging.Logger; + +/** + * Provides an implementation of VendorInfoRepository. + * + * @author Shane Isbell + */ +public class VendorInfoRepositoryImpl + implements VendorInfoRepository, LogEnabled +{ + + /** + * A registry component of repository (config) files + */ + private RepositoryRegistry repositoryRegistry; + + /** + * A logger for writing log messages + */ + private Logger logger; + + /** + * Constructor. This method is intended to be invoked by the plexus-container, not by the application developer. + */ + public VendorInfoRepositoryImpl() + { + } + + /** + * @see LogEnabled#enableLogging(org.codehaus.plexus.logging.Logger) + */ + public void enableLogging( Logger logger ) + { + this.logger = logger; + } + + /** + * @see org.apache.maven.dotnet.vendor.VendorInfoRepository#exists() + */ + public boolean exists() + { + return ( repositoryRegistry.find( "nmaven-settings" ) != null ); + } + + /** + * @see VendorInfoRepository#getInstallRootFor(org.apache.maven.dotnet.vendor.VendorInfo) + */ + public File getInstallRootFor( VendorInfo vendorInfo ) + throws PlatformUnsupportedException + { + SettingsRepository settingsRepository = (SettingsRepository) repositoryRegistry.find( "nmaven-settings" ); + return settingsRepository.getInstallRootFor( vendorInfo.getVendor().getVendorName(), + vendorInfo.getVendorVersion(), vendorInfo.getFrameworkVersion() ); + } + + /** + * @see org.apache.maven.dotnet.vendor.VendorInfoRepository#getVendorInfos() + */ + public List getVendorInfos() + { + SettingsRepository settingsRepository = (SettingsRepository) repositoryRegistry.find( "nmaven-settings" ); + return Collections.unmodifiableList( settingsRepository.getVendorInfos() ); + } + + /** + * @see VendorInfoRepository#getMaxVersion(java.util.Set) + */ + public String getMaxVersion( Set versions ) + throws InvalidVersionFormatException + { + return new VersionMatcher().getMaxVersion( versions ); + } + + /** + * @see VendorInfoRepository#getVendorInfosFor(String, String, String, boolean) + */ + public List getVendorInfosFor( String vendorName, String vendorVersion, String frameworkVersion, + boolean isDefault ) + { + List vendorInfos = new ArrayList(); + MatchPolicyFactory matchPolicyFactory = new MatchPolicyFactory(); + matchPolicyFactory.init( logger ); + + List matchPolicies = new ArrayList(); + if ( vendorName != null ) + { + matchPolicies.add( matchPolicyFactory.createVendorNamePolicy( vendorName ) ); + } + if ( vendorVersion != null ) + { + matchPolicies.add( matchPolicyFactory.createVendorVersionPolicy( vendorVersion ) ); + } + if ( frameworkVersion != null ) + { + matchPolicies.add( matchPolicyFactory.createFrameworkVersionPolicy( frameworkVersion ) ); + } + if ( isDefault ) + { + matchPolicies.add( matchPolicyFactory.createVendorIsDefaultPolicy() ); + } + for ( VendorInfo vendorInfo : getVendorInfos() ) + { + if ( matchVendorInfo( vendorInfo, matchPolicies ) ) + { + vendorInfos.add( vendorInfo ); + } + } + return vendorInfos; + } + + /** + * @see VendorInfoRepository#getVendorInfosFor(org.apache.maven.dotnet.vendor.VendorInfo, boolean) + */ + public List getVendorInfosFor( VendorInfo vendorInfo, boolean isDefault ) + { + if ( vendorInfo == null ) + { + return getVendorInfos(); + } + return getVendorInfosFor( ( vendorInfo.getVendor() != null ? vendorInfo.getVendor().getVendorName() : null ), + vendorInfo.getVendorVersion(), vendorInfo.getFrameworkVersion(), isDefault ); + } + + /** + * Returns true if the specified vendor info matches all of the specified match policies, otherwise returns + * false. + * + * @param vendorInfo the vendor info to match against the match policies + * @param matchPolicies the match policies + * @return true if the specified vendor info matches all of the specified match policies, otherwise returns + * false + */ + private boolean matchVendorInfo( VendorInfo vendorInfo, List matchPolicies ) + { + for ( VendorInfoMatchPolicy matchPolicy : matchPolicies ) + { + if ( !matchPolicy.match( vendorInfo ) ) + { + return false; + } + } + return true; + } +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoRepositoryImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoTransitionRuleFactory.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoTransitionRuleFactory.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoTransitionRuleFactory.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoTransitionRuleFactory.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,787 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import org.apache.maven.dotnet.vendor.*; +import org.apache.maven.dotnet.InitializationException; +import org.apache.maven.dotnet.PlatformUnsupportedException; +import org.apache.maven.dotnet.registry.RepositoryRegistry; + +import java.util.List; +import java.util.Set; +import java.util.HashSet; +import java.io.File; + +import org.codehaus.plexus.logging.Logger; + +/** + * Provides factory methods for creating vendor info transition rules. These rules usually can determine the + * exact vendor info; but at times, it is a best guess. + * + * @author Shane Isbell + * @see VendorInfoState + */ +final class VendorInfoTransitionRuleFactory +{ + + /** + * A registry component of repository (config) files + */ + private RepositoryRegistry repositoryRegistry; + + private SettingsRepository settingsRepository; + + private VendorInfoRepository vendorInfoRepository; + + /** + * The default vendor as specified within the nmaven-settings file + */ + private Vendor defaultVendor; + + /** + * The default vendor version as specified within the nmaven-settings file + */ + private String defaultVendorVersion; + + /** + * The default framework version as specified within the nmaven-settings file + */ + private String defaultFrameworkVersion; + + private List vendorInfos; + + /** + * A logger for writing log messages + */ + private Logger logger; + + /** + * Default constructor + */ + VendorInfoTransitionRuleFactory() + { + } + + /** + * Initializes this factory. + * + * @param repositoryRegistry the repository registry containing various NMaven config information. + * @param vendorInfoRepository the vendor info repository used for accessing the nmaven-settings config file + * @param logger the plexus logger + * @throws InitializationException if there is a problem initializing this factory + */ + void init( RepositoryRegistry repositoryRegistry, VendorInfoRepository vendorInfoRepository, Logger logger ) + throws InitializationException + { + this.repositoryRegistry = repositoryRegistry; + this.vendorInfoRepository = vendorInfoRepository; + this.logger = logger; + if ( repositoryRegistry == null ) + { + throw new InitializationException( "NMAVEN-103-000: Unable to find the repository registry" ); + } + + settingsRepository = (SettingsRepository) repositoryRegistry.find( "nmaven-settings" ); + if ( settingsRepository == null ) + { + throw new InitializationException( + "NMAVEN-103-001: Settings Repository is null. Aborting initialization of VendorInfoTranstionRuleFactory" ); + + } + + try + { + defaultVendor = VendorFactory.createVendorFromName( settingsRepository.getDefaultSetup().getVendorName() ); + } + catch ( VendorUnsupportedException e ) + { + throw new InitializationException( "NMAVEN-103-002: Unknown Default Vendor: Name = " + defaultVendor ); + } + defaultVendorVersion = settingsRepository.getDefaultSetup().getVendorVersion().trim(); + defaultFrameworkVersion = settingsRepository.getDefaultSetup().getFrameworkVersion().trim(); + vendorInfos = settingsRepository.getVendorInfos(); + } + + /** + * Returns the vendor info transition rule for state: Vendor is Novell, vendor version exists, framework version exists. + * + * @return the vendor info transition rule for state: Vendor is Novell, vendor version exists, framework version exists. + */ + VendorInfoTransitionRule createVendorInfoSetterForNTT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-003: Entering State = NTT" ); + return VendorInfoState.EXIT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNFF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-004: Entering State = NFF" ); + if ( vendorInfo.getVendor().equals( defaultVendor ) ) + { + vendorInfo.setVendorVersion( defaultVendorVersion ); + vendorInfo.setFrameworkVersion( defaultFrameworkVersion ); + return VendorInfoState.EXIT; + } + else + { + List v = vendorInfoRepository.getVendorInfosFor( vendorInfo, true ); + if ( !v.isEmpty() ) + { + for ( VendorInfo vi : v ) + { + if ( vi.getVendor().equals( vendorInfo.getVendor() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + return VendorInfoState.EXIT; + } + } + } + else + { + v = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + for ( VendorInfo vi : v ) + { + if ( vi.getVendor().equals( vendorInfo.getVendor() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setFrameworkVersion( + "2.0.50727" ); //TODO: this should be according to max version + return VendorInfoState.EXIT; + } + } + } + } + return createVendorInfoSetterForNFF_NoSettings().process( vendorInfo ); + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNFF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-005: Entering State = NFF" ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + return VendorInfoState.NFT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNFT_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-006: Entering State = NFT" ); + return VendorInfoState.EXIT; //NO WAY TO KNOW + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNFT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-007: Entering State = NFT" ); + if ( vendorInfo.getFrameworkVersion().equals( defaultFrameworkVersion ) ) + { + vendorInfo.setVendorVersion( defaultVendorVersion ); + vendorInfo.setVendor( defaultVendor ); + return VendorInfoState.NTT; + } + else + { + List v = vendorInfoRepository.getVendorInfosFor( vendorInfo, true ); + if ( !v.isEmpty() ) + { + for ( VendorInfo vi : v ) + { + if ( vi.getFrameworkVersion().equals( vendorInfo.getFrameworkVersion() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + return VendorInfoState.NTT; + } + } + return createVendorInfoSetterForNFT_NoSettings().process( vendorInfo ); + } + else + { + v = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + for ( VendorInfo vi : v ) + { + if ( vi.getFrameworkVersion().equals( vendorInfo.getFrameworkVersion() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + return VendorInfoState.NTT; + } + } + return createVendorInfoSetterForNFT_NoSettings().process( vendorInfo ); + } + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNTF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-008: Entering State = NTF" ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + return VendorInfoState.NTT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForNTF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-009: Entering State = NTF" ); + if ( vendorInfo.getVendorVersion().equals( defaultVendorVersion ) ) + { + vendorInfo.setFrameworkVersion( defaultFrameworkVersion ); + vendorInfo.setVendor( defaultVendor ); + return VendorInfoState.NTT; + } + else + { + List v = vendorInfoRepository.getVendorInfosFor( vendorInfo, true ); + if ( !v.isEmpty() ) + { + for ( VendorInfo vi : v ) + { + if ( vi.getVendorVersion().equals( vendorInfo.getVendorVersion() ) ) + { + vendorInfo.setFrameworkVersion( vi.getFrameworkVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + return VendorInfoState.NTT; + } + } + return createVendorInfoSetterForNTF_NoSettings().process( vendorInfo ); + } + else + { + v = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + for ( VendorInfo vi : v ) + { + if ( vi.getVendorVersion().equals( vendorInfo.getVendorVersion() ) ) + { + vendorInfo.setFrameworkVersion( vi.getFrameworkVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + return VendorInfoState.NTT; + } + } + return createVendorInfoSetterForNTF_NoSettings().process( vendorInfo ); + } + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFTF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-010: Entering State = FTF" ); + String vendorVersion = vendorInfo.getVendorVersion(); + if ( vendorVersion.equals( "2.0.50727" ) || vendorVersion.equals( "1.1.4322" ) ) + { + vendorInfo.setVendor( Vendor.MICROSOFT ); + return VendorInfoState.MTF; + } + else + { + vendorInfo.setVendor( Vendor.MONO );//This could be dotGNU: this is best guess + return VendorInfoState.NTF; + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFTF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-011: Entering State = FTF" ); + if ( vendorInfo.getVendorVersion().equals( defaultVendorVersion ) ) + { + vendorInfo.setFrameworkVersion( defaultFrameworkVersion ); + vendorInfo.setVendor( defaultVendor ); + if ( defaultVendor.equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( defaultVendor.equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + else + { + List v = vendorInfoRepository.getVendorInfosFor( vendorInfo, true ); + if ( !v.isEmpty() ) + { + for ( VendorInfo vi : v ) + { + if ( vi.getVendorVersion().equals( vendorInfo.getVendorVersion() ) ) + { + vendorInfo.setFrameworkVersion( vi.getFrameworkVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + if ( vi.getVendor().equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( vi.getVendor().equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + } + return createVendorInfoSetterForFTF_NoSettings().process( vendorInfo ); + } + else + { + v = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + for ( VendorInfo vi : v ) + { + if ( vi.getVendorVersion().equals( vendorInfo.getVendorVersion() ) ) + { + vendorInfo.setFrameworkVersion( vi.getFrameworkVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + if ( vi.getVendor().equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( vi.getVendor().equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + } + return createVendorInfoSetterForFTF_NoSettings().process( vendorInfo ); + } + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFFT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-012: Entering State = FFT" ); + if ( vendorInfo.getFrameworkVersion().equals( defaultFrameworkVersion ) ) + { + vendorInfo.setVendorVersion( defaultVendorVersion ); + vendorInfo.setVendor( defaultVendor ); + if ( defaultVendor.equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( defaultVendor.equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + else + { + List v = vendorInfoRepository.getVendorInfosFor( vendorInfo, true ); + if ( !v.isEmpty() ) + { + for ( VendorInfo vi : v ) + { + if ( vi.getFrameworkVersion().equals( vendorInfo.getFrameworkVersion() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + if ( vi.getVendor().equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( vi.getVendor().equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + } + } + v = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + for ( VendorInfo vi : v ) + { + if ( vi.getFrameworkVersion().equals( vendorInfo.getFrameworkVersion() ) ) + { + vendorInfo.setVendorVersion( vi.getVendorVersion() ); + vendorInfo.setVendor( vi.getVendor() ); + if ( vi.getVendor().equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( vi.getVendor().equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + } + return createVendorInfoSetterForFFT_NoSettings().process( vendorInfo ); + + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFFT_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-013: Entering State = FFT" ); + try + { + vendorInfo.setVendor( VendorFactory.getDefaultVendorForOS() ); + } + catch ( PlatformUnsupportedException e ) + { + return VendorInfoState.EXIT; + } + return ( vendorInfo.getVendor().equals( Vendor.MICROSOFT ) ) ? VendorInfoState.MFT + : VendorInfoState.NFT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFTT_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-014: Entering State = FTT" ); + String vendorVersion = vendorInfo.getVendorVersion(); + Vendor defaultVendor; + try + { + defaultVendor = VendorFactory.getDefaultVendorForOS(); + } + catch ( PlatformUnsupportedException e ) + { + return VendorInfoState.EXIT; + } + if ( ( vendorVersion.equals( "2.0.50727" ) || vendorVersion.equals( "1.1.4322" ) ) && + defaultVendor.equals( Vendor.MICROSOFT ) ) + { + vendorInfo.setVendor( Vendor.MICROSOFT ); + return VendorInfoState.MTT; + } + else + { + vendorInfo.setVendor( Vendor.MONO );//This could be dotGNU: this is best guess + return VendorInfoState.NTT; + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFTT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-015: Entering State = FTT" ); + List vendorInfos = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + if ( vendorInfos.isEmpty() ) + { + return createVendorInfoSetterForFTT_NoSettings().process( vendorInfo ); + } + Vendor vendor = vendorInfos.get( 0 ).getVendor();//TODO: Do default branch + vendorInfo.setVendor( vendor ); + if ( vendor.equals( Vendor.MICROSOFT ) ) + { + return VendorInfoState.MTT; + } + else if ( vendor.equals( Vendor.MONO ) ) + { + return VendorInfoState.NTT; + } + else + { + return VendorInfoState.GTT; + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFFF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-016: Entering State = FFF" ); + try + { + vendorInfo.setVendor( VendorFactory.getDefaultVendorForOS() ); + } + catch ( PlatformUnsupportedException e ) + { + return VendorInfoState.EXIT; + } + return ( vendorInfo.getVendor().equals( Vendor.MICROSOFT ) ) ? VendorInfoState.MFF + : VendorInfoState.NFF; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForFFF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-017: Entering State = FFF" ); + vendorInfo.setVendor( defaultVendor ); + vendorInfo.setVendorVersion( defaultVendorVersion ); + vendorInfo.setFrameworkVersion( defaultFrameworkVersion ); + return VendorInfoState.EXIT; + } + }; + } + + + VendorInfoTransitionRule createVendorInfoSetterForMTT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-018: Entering State = MTT" ); + return VendorInfoState.EXIT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForMTF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-019: Entering State = MTF" ); + vendorInfo.setFrameworkVersion( vendorInfo.getVendorVersion() ); + return VendorInfoState.MTT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForMFT() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-020: Entering State = MTF" ); + vendorInfo.setVendorVersion( vendorInfo.getFrameworkVersion() ); + return VendorInfoState.MTT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForMFF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-021: Entering State = MFF" ); + File v1 = new File( "C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322" ); + File v2 = new File( "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727" ); + if ( v2.exists() ) + { + vendorInfo.setFrameworkVersion( "2.0.50727" ); + vendorInfo.setExecutablePath( v2 ); + } + else if ( v1.exists() ) + { + vendorInfo.setFrameworkVersion( "1.1.4322" ); + vendorInfo.setExecutablePath( v1 ); + } + else + { + vendorInfo.setFrameworkVersion( "2.0.50727" ); + } + return VendorInfoState.MFT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForMFF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-022: Entering State = MFF" ); + if ( vendorInfo.getVendor().equals( defaultVendor ) ) + { + vendorInfo.setVendorVersion( defaultVendorVersion ); + return VendorInfoState.MTF; + } + else + { + List vendorInfos = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + Set versions = new HashSet(); + for ( VendorInfo vi : vendorInfos ) + { + String frameworkVersion = vi.getFrameworkVersion(); + String vendorVersion = vi.getVendorVersion(); + if ( frameworkVersion != null ) + { + versions.add( frameworkVersion ); + } + if ( vendorVersion != null ) + { + versions.add( vi.getVendorVersion() ); + } + } + try + { + String maxVersion = vendorInfoRepository.getMaxVersion( versions ); + vendorInfo.setVendorVersion( maxVersion ); + return VendorInfoState.MTF; + } + catch ( InvalidVersionFormatException e ) + { + logger.info( "NMAVEN-103-030: Invalid version. Unable to determine best vendor version", e ); + return createVendorInfoSetterForMFF_NoSettings().process( vendorInfo ); + } + } + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForGFF_NoSettings() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-023: Entering State = GFF" ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + vendorInfo.setVendorVersion( "2.0.50727" ); + return VendorInfoState.EXIT; + } + }; + } + + VendorInfoTransitionRule createVendorInfoSetterForGFF() + { + return new VendorInfoTransitionRule() + { + public VendorInfoState process( VendorInfo vendorInfo ) + { + logger.debug( "NMAVEN-103-023: Entering State = GFF" ); + if ( vendorInfo.getVendor().equals( defaultVendor ) ) + { + vendorInfo.setVendorVersion( defaultVendorVersion ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + return VendorInfoState.EXIT; + } + else + { + List vendorInfos = vendorInfoRepository.getVendorInfosFor( vendorInfo, false ); + Set versions = new HashSet(); + for ( VendorInfo vi : vendorInfos ) + { + String vendorVersion = vi.getVendorVersion(); + if ( vendorVersion != null ) + { + versions.add( vi.getVendorVersion() ); + } + } + try + { + String maxVersion = vendorInfoRepository.getMaxVersion( versions ); + vendorInfo.setVendorVersion( maxVersion ); + vendorInfo.setFrameworkVersion( "2.0.50727" ); + return VendorInfoState.EXIT; + } + catch ( InvalidVersionFormatException e ) + { + logger.info( "NMAVEN-103-030: Invalid version. Unable to determine best vendor version", e ); + return createVendorInfoSetterForGFF_NoSettings().process( vendorInfo ); + } + } + } + }; + } +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VendorInfoTransitionRuleFactory.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VersionMatcher.java URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VersionMatcher.java?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VersionMatcher.java (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VersionMatcher.java Sun Dec 10 15:43:51 2006 @@ -0,0 +1,342 @@ +/* + * 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. + */ +package org.apache.maven.dotnet.vendor.impl; + +import java.util.regex.Pattern; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.dotnet.vendor.InvalidVersionFormatException; + +/** + * Provides a way to match versions. + * + * @author Shane Isbell + */ +final class VersionMatcher +{ + /** + * A pattern for a valid version format: \p{Alnum}[._-]]*[+*]?. This will be used for determining whether a + * version is valid. + */ + private static Pattern versionIdMatch = Pattern.compile( "[\\p{Alnum}[._-]]*[+*]?" ); + + /** + * Constant denoting no modifier + */ + private final static int nullModifier = 0; + + /** + * Constant for '+' modifier + */ + private final static int plusModifier = 1; + + /** + * Constant for '*' modifier + */ + private final static int starModifier = 2; + + /** + * Default constructor + */ + VersionMatcher() + { + } + + /** + * Returns true if the specified parameter versions match, otherwise returns false. [Give full rules here]. + * + * @param req the required version + * @param cap the capability version + * @return true if the specified versions (req and cap) match + * @throws InvalidVersionFormatException if the specified parameters contain an invalid version format + */ + boolean matchVersion( String req, String cap ) + throws InvalidVersionFormatException + { + String[] requirement = tokenizeVersion( req ); + String[] capability = tokenizeVersion( cap ); + + int capSize = capability.length; + int reqSize = requirement.length; + + int reqModifier = getModifier( requirement ); + if ( reqModifier == plusModifier ) + { + requirement[reqSize - 1] = requirement[reqSize - 1].replace( '+', ' ' ).trim(); + } + else if ( reqModifier == starModifier ) + { + requirement[reqSize - 1] = requirement[reqSize - 1].replace( '*', ' ' ).trim(); + } + + if ( reqSize < capSize && reqModifier != starModifier ) + { + requirement = padArray( requirement, capSize ); + } + else if ( capSize < reqSize ) + { + capability = padArray( capability, reqSize ); + } + + switch ( reqModifier ) + { + case nullModifier: + return testExactMatch( requirement, capability ); + case plusModifier: + return testGreaterThanMatch( requirement, capability ); + case starModifier: + return testPrefixMatch( requirement, capability ); + default: + return false; + } + } + + /** + * Returns the maximum version of the given set of versions. + * + * @param versions a set of versions from which to choose the maximum version + * @return the maximum version from the specified set of versions. + * @throws InvalidVersionFormatException if the format of one or more of the versions is invalid + */ + String getMaxVersion( Set versions ) + throws InvalidVersionFormatException + { + if ( versions.isEmpty() ) + { + return null; + } + Iterator i = versions.iterator(); + String maxVersion = (String) i.next(); + while ( i.hasNext() ) + { + String testValue = (String) i.next(); + if ( isGreaterThan( testValue, maxVersion ) ) + { + maxVersion = testValue; + } + } + return maxVersion; + } + + /** + * Returns true if v > v1, otherwise returns false. + * + * @param v the first value to compare + * @param v1 the second value to compare + * @return true if v > v1, otherwise returns false + */ + private boolean isGreaterThan( String v, String v1 ) + throws InvalidVersionFormatException + { + String[] requirement = tokenizeVersion( v ); + String[] capability = tokenizeVersion( v1 ); + + int capSize = capability.length; + int reqSize = requirement.length; + if ( reqSize < capSize ) + { + requirement = padArray( requirement, capSize ); + } + else if ( capSize < reqSize ) + { + capability = padArray( capability, reqSize ); + } + + return testGreaterThanMatch( requirement, capability ); + } + + /** + * Returns an array padded with zeros. This is needed because one version may contain, say 1.2, while another version may + * be 1.2.8. We need to add the implied 0 to read 1.2.0 so that the versions can be compared. + * + * @param value a string array without padded values + * @param size the size that the value array needs to be expanded + * @return a string array with padded values + */ + private String[] padArray( String[] value, int size ) + { + int valueSize = value.length; + int padSize = Math.abs( valueSize - size ); + + String[] newValue = new String[size]; + + System.arraycopy( value, 0, newValue, 0, valueSize ); + for ( int i = 0; i < padSize; i++ ) + { + newValue[i + valueSize] = "0"; + } + return newValue; + } + + /** + * Returns an int denoting a modifier (+, *) within the version. A value of 0 means that there is no modifier, a + * value of 1 means that there is a + modifier and a value of 2 means that there is a * modifier. + * + * @param value a tokenized string array of the version + * @return an int denoting a modifier within the version + */ + private int getModifier( String[] value ) + { + String lastValue = value[value.length - 1].trim(); + char lastChar = lastValue.charAt( lastValue.length() - 1 ); + if ( lastChar == '+' ) + { + return plusModifier; + } + else if ( lastChar == '*' ) + { + return starModifier; + } + else + { + return nullModifier; + } + } + + /** + * Returns true if the requirement parameter exactly matches (each array value is the same) the capability. + * + * @param requirement the requirement to match + * @param capability the capability to match + * @return true if the requirement parameter exactly matches (each array value is the same) the capability + */ + private boolean testExactMatch( String[] requirement, String[] capability ) + { + int reqSize = requirement.length; + if ( reqSize != capability.length ) + { + return false; + } + + for ( int i = 0; i < reqSize; i++ ) + { + if ( !requirement[i].equals( capability[i] ) ) + { + return false; + } + } + return true; + } + + private boolean testGreaterThanMatch( String[] requirement, String[] capability ) + { + int reqSize = requirement.length; + for ( int i = 0; i < reqSize; i++ ) + { + if ( isNumber( requirement[i] ) && isNumber( capability[i] ) ) + { + try + { + int compare = new Integer( capability[i] ).compareTo( new Integer( requirement[i] ) ); + if ( compare < 0 ) + { + return false; + } + if ( compare > 0 ) + { + return true; + } + } + catch ( NumberFormatException e ) + { + //this should never happen: already done check + } + } + else + { + for ( int j = 0; j < reqSize - 1; j++ ) + { + char req = requirement[i].charAt( j ); + char cap = capability[i].charAt( j ); + if ( req < cap ) + { + return true; + } + if ( req > cap ) + { + return false; + } + } + } + } + return true; + } + + /** + * Returns true if the specified number parameter is an integer, otherwise returns false. + * + * @param number the number to test for an integer format + * @return true if the specified number parameter is an integer, otherwise returns false + */ + private boolean isNumber( String number ) + { + try + { + new Integer( number ); + return true; + } + catch ( NumberFormatException e ) + { + return false; + } + } + + private boolean testPrefixMatch( String[] requirement, String[] capability ) + { + int reqSize = requirement.length; + for ( int i = 0; i < reqSize; i++ ) + { + if ( !requirement[i].equals( capability[i] ) ) + { + return false; + } + } + return true; + } + + /** + * Returns a tokenized string array of the version based on the following standard version delimiters: '.', '_', '-'. + * + * @param version the version to tokenize + * @return a tokenized string array of the version based on the following standard version delimiters: '.', '_', '-' + * @throws InvalidVersionFormatException if the version format is invalid + */ + private String[] tokenizeVersion( String version ) + throws InvalidVersionFormatException + { + if ( !isVersionId( version ) ) + { + throw new InvalidVersionFormatException( "Invalid Version Id: ID = " + version ); + } + return version.split( "[._-]" ); + } + + /** + * Returns true if the specified version is valid (\p{Alnum}[._-]]*[+*]?), otherwise returns false. + * + * @param version the version to test for validity + * @return true if the specified version is valid (\p{Alnum}[._-]]*[+*]?), otherwise returns false + */ + private boolean isVersionId( String version ) + { + return ( version != null ) && versionIdMatch.matcher( version ).matches(); + } + +} Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/VersionMatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/package.html URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/package.html?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/package.html (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/package.html Sun Dec 10 15:43:51 2006 @@ -0,0 +1,27 @@ + + + + + + + Provides the implementation classes of the org.apache.maven.vendor package. + + \ No newline at end of file Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/impl/package.html ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/package.html URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/package.html?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/package.html (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/package.html Sun Dec 10 15:43:51 2006 @@ -0,0 +1,29 @@ + + + + + + + Provides interfaces and classes to assist in determining missing vendor information such as framework version, + vendor name and vendor version. The core interface of this package is the StateMachineProcessor. This +package is only intended to be used by the framework, not the application or Mojo plugin developer. + + \ No newline at end of file Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/java/org/apache/maven/dotnet/vendor/package.html ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/dotnet-vendor/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/dotnet-vendor/src/main/resources/META-INF/plexus/components.xml?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/dotnet-vendor/src/main/resources/META-INF/plexus/components.xml (added) +++ incubator/nmaven/trunk/components/dotnet-vendor/src/main/resources/META-INF/plexus/components.xml Sun Dec 10 15:43:51 2006 @@ -0,0 +1,27 @@ + + + + org.apache.maven.dotnet.vendor.VendorInfoRepository + org.apache.maven.dotnet.vendor.impl.VendorInfoRepositoryImpl + + + org.apache.maven.dotnet.registry.RepositoryRegistry + + + + + + org.apache.maven.dotnet.vendor.StateMachineProcessor + org.apache.maven.dotnet.vendor.impl.StateMachineProcessorImpl + + + org.apache.maven.dotnet.vendor.VendorInfoRepository + + + org.apache.maven.dotnet.registry.RepositoryRegistry + + + + + + Propchange: incubator/nmaven/trunk/components/dotnet-vendor/src/main/resources/META-INF/plexus/components.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/pom.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/pom.xml?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/pom.xml (added) +++ incubator/nmaven/trunk/components/pom.xml Sun Dec 10 15:43:51 2006 @@ -0,0 +1,51 @@ + + 4.0.0 + org.apache.maven.dotnet + dotnet-components + pom + 0.14-SNAPSHOT + dotnet-components + + dotnet-core + dotnet-model + dotnet-artifact + dotnet-assembler + dotnet-executable + dotnet-registry + dotnet-vendor + + + + org.easymock + easymock + 2.0 + test + + + junit + junit + 3.8.1 + test + + + + + + + maven-assembly-plugin + + src/assembly/src.xml + src/target + + + + + + + + maven-release-plugin + + + + + \ No newline at end of file Propchange: incubator/nmaven/trunk/components/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/components/src/assembly/src.xml URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/components/src/assembly/src.xml?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/components/src/assembly/src.xml (added) +++ incubator/nmaven/trunk/components/src/assembly/src.xml Sun Dec 10 15:43:51 2006 @@ -0,0 +1,22 @@ + + build + + tar.gz + zip + + true + + + . + + + *.ipr + *.iws + *.iml + src/** + **/src/site/** + **/target/** + + + + \ No newline at end of file Propchange: incubator/nmaven/trunk/components/src/assembly/src.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/integration-tests/imports/maven-core-it-verifier-2.1.jar URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/integration-tests/imports/maven-core-it-verifier-2.1.jar?view=auto&rev=485313 ============================================================================== Binary file - no diff available. Propchange: incubator/nmaven/trunk/integration-tests/imports/maven-core-it-verifier-2.1.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/nmaven/trunk/integration-tests/tests/NOTICE.txt URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/integration-tests/tests/NOTICE.txt?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/integration-tests/tests/NOTICE.txt (added) +++ incubator/nmaven/trunk/integration-tests/tests/NOTICE.txt Sun Dec 10 15:43:51 2006 @@ -0,0 +1 @@ +This product includes software developed by The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file Propchange: incubator/nmaven/trunk/integration-tests/tests/NOTICE.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/integration-tests/tests/README.txt URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/integration-tests/tests/README.txt?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/integration-tests/tests/README.txt (added) +++ incubator/nmaven/trunk/integration-tests/tests/README.txt Sun Dec 10 15:43:51 2006 @@ -0,0 +1,20 @@ +it0001: CS-MS: Build a .netmodule +it0002: CS-MS: Build a library that is dependent on a .netmodule +it0003: CS-MS: Verify that .netmodules are not a compile-time transitive dependency. +it0004: CS-MS: Run an NUnit test that uses libraries and run-time transitive .netmodule dependencies. +it0005: CS-MS: Build a webapp and deploy it +it0006: PATH: Generate a class binding from a schema +it0007: PATH: Generate a schema from an XML instance and then create a class binding from the generated schema +it0008: PATH: Generate a WSDL (not included) +it0009: Test ccnet plugin (run manually: change m2Home in ccnet.config and then type ccnet from the commandline). +it0010: VB-MS: Build a library that is dependent on a .netmodule +it0011: CS-MONO: Build a library that is dependent on a .netmodule +it0012: CS-GNU: Build a .netmodule +it0013: CS-GNU: Build a library that is dependent on a .netmodule (Disabled: option yet not supported). +it0014: CS-GNU: Verify that .netmodules are not a compile-time transitive dependency. (Disabled: option not yet supported). +it0015: CS-GNU: Build a library. +it0016: CS-GNU: Build a library that is dependent on another library +it0017: CS-GNU: Run an NUnit test that uses library dependencies. +it0018: CS-MS-v1.1: Build a library with version 1.1 of the framework (verify manually by looking at the dll manifest) +it0019: CS-MS-Compact: Build a library with the COMPACT framework (windows only) +it0020: CS-MS-Resources: Generate resource file and embed into assembly \ No newline at end of file Propchange: incubator/nmaven/trunk/integration-tests/tests/README.txt ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/nmaven/trunk/integration-tests/tests/integration-tests.txt URL: http://svn.apache.org/viewvc/incubator/nmaven/trunk/integration-tests/tests/integration-tests.txt?view=auto&rev=485313 ============================================================================== --- incubator/nmaven/trunk/integration-tests/tests/integration-tests.txt (added) +++ incubator/nmaven/trunk/integration-tests/tests/integration-tests.txt Sun Dec 10 15:43:51 2006 @@ -0,0 +1,17 @@ +it0001 +it0002 +it0003 +it0004 +it0005 +it0006 +it0007 +it0010 +it0011 +it0012 +it0015 +it0016 +it0017 +it0018 +it0019 +it0020 +it0021 \ No newline at end of file Propchange: incubator/nmaven/trunk/integration-tests/tests/integration-tests.txt ------------------------------------------------------------------------------ svn:eol-style = native