You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@depot.apache.org by aj...@apache.org on 2004/08/04 03:28:32 UTC

svn commit: rev 35663 - in incubator/depot/trunk/version/src: java/org/apache/depot/version/impl java/org/apache/depot/version/specification test/java/org/apache/depot/version/impl

Author: ajack
Date: Tue Aug  3 20:28:32 2004
New Revision: 35663

Added:
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionSpecTest.java
Modified:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/VersionImporter.java
   incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/VersionSpecificationFactory.java
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
Log:
The order in which specificatons/formats are applied to the string is important,
we need the 'tightest' first. For some reason EclipseFormat was being
tried before ApacheFormat. I resolved this be adding order to the SpecFactory,
so they are attempted in order of registration.

Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/VersionImporter.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/VersionImporter.java	(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/impl/VersionImporter.java	Tue Aug  3 20:28:32 2004
@@ -180,28 +180,34 @@
 				) {
 				String specId = (String) i.next();
 
+				// Create a spec
 				VersionSpecification spec =
 					VersionSpecificationFactory
 						.createVersionSpecificationFromId(
 						specId);
 
+				Logger.getLogger().debug("Spec: " + spec);
+				
+				VersionFormat format = null;
 				try {
-					VersionFormat format = spec.getVersionFormat();
+					format = spec.getVersionFormat();
 
 					VersionData versionData = format.parseVersion(cleanData);
 
 					version = new ApacheVersion(spec, versionData);
 				}
 				catch (VersionFormatException vfe) {
-					Logger.getLogger().debug("Spec: " + spec, vfe);
+					Logger.getLogger().debug("Spec: " + spec + " Format:" + format, vfe);
 					lastVersionException = vfe;
 				}
-
 			}
 
 		if ((null == version) && (null != lastVersionException))
 			throw lastVersionException;
 
+
+		Logger.getLogger().debug("Version: " + version + " Spec: " + version.getSpecification());
+		
 		return version;
 	}
 

Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/VersionSpecificationFactory.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/VersionSpecificationFactory.java	(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/specification/VersionSpecificationFactory.java	Tue Aug  3 20:28:32 2004
@@ -16,8 +16,10 @@
 
 package org.apache.depot.version.specification;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.depot.version.VersionException;
@@ -32,10 +34,12 @@
 
 	private final static VersionSpecificationFactory INSTANCE = new VersionSpecificationFactory();
 
+	private static List l_order = null;
 	private static Map l_registry = null;
 
 	static {
 
+		l_order = new ArrayList(); 
 		l_registry = new HashMap();
 
 		registerVersionSpecification(
@@ -56,10 +60,8 @@
 		registerVersionSpecification(
 				VersionImplementationConstants.MAVEN_VERSION_ID,
 				MavenVersionSpecification.class);
-
 	}
 
-
 	/** Default */
 	public static VersionSpecification createDefaultVersionSpecification() {
 		return new ApacheVersionSpecification();
@@ -100,24 +102,17 @@
 
 	public static void registerVersionSpecification(String id, Class formatClass) {
 		synchronized (l_registry) {
+			if ( !l_registry.containsKey(id))
+				l_order.add(id);
 			l_registry.put(id, formatClass);
 		}
 	}
 
 	public static Iterator getRegisteredSpecificationIds() {
-		return l_registry.keySet().iterator();
+		return l_order.iterator();
 	}
 
 	public static Iterator getRegisteredSpecifications() {
 		return l_registry.entrySet().iterator();
-	}
-
-	/**
-	 * @param specId
-	 */
-	public VersionSpecification getSpecification(String specId) {
-		// TODO Actually check id.
-		return new ApacheVersionSpecification();
-
 	}
 }

Added: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionSpecTest.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionSpecTest.java	Tue Aug  3 20:28:32 2004
@@ -0,0 +1,73 @@
+/*
+ * $Id: $
+ */
+package org.apache.depot.version.impl;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.version.VersionException;
+import org.apache.depot.version.specification.ApacheVersionSpecification;
+import org.apache.depot.version.specification.DatetimestampedVersionSpecification;
+import org.apache.depot.version.specification.EclipseVersionSpecification;
+import org.apache.depot.version.specification.JavasoftVersionSpecification;
+import org.apache.depot.version.specification.VersionSpecification;
+import org.apache.depot.version.specification.VersionSpecificationFactory;
+import org.apache.depot.version.specification.experimental.JakartaCommonsVersionSpecification;
+import org.apache.depot.version.specification.experimental.MavenVersionSpecification;
+
+/**
+ * @author ajack
+ * @author $Author: $
+ * @version $Revision: $
+ */
+public class ApacheVersionSpecTest extends TestCase {
+
+    /*
+     * Class under test for void ApacheVersion(String)
+     */
+    public void testSpecs1() throws VersionException {
+        //Logger.testInit();
+        
+		checkVersionSpecification(
+				VersionImplementationConstants.DATETIMESTAMPED_VERSION_ID,
+				DatetimestampedVersionSpecification.class);
+		checkVersionSpecification(
+				VersionImplementationConstants.APACHE_VERSION_ID,
+				ApacheVersionSpecification.class);
+		checkVersionSpecification(
+				VersionImplementationConstants.ECLIPSE_VERSION_ID,
+				EclipseVersionSpecification.class);
+		checkVersionSpecification(
+				VersionImplementationConstants.JAVASOFT_VERSION_ID,
+				JavasoftVersionSpecification.class);
+		checkVersionSpecification(
+				VersionImplementationConstants.JAKARTA_COMMONS_VERSION_ID,
+				JakartaCommonsVersionSpecification.class);
+		checkVersionSpecification(
+				VersionImplementationConstants.MAVEN_VERSION_ID,
+				MavenVersionSpecification.class);
+    }
+    
+    public void testSpecs2()  throws VersionException{
+    	int count = 0;
+    
+    	for (Iterator i =
+			VersionSpecificationFactory.getRegisteredSpecificationIds();
+			i.hasNext();
+			) {    	
+    		VersionSpecification spec = VersionSpecificationFactory.createVersionSpecificationFromId((String)i.next());
+    		count ++;
+    		Logger.getLogger().debug("Spec: " + spec);
+    	}
+    	
+    	assertEquals("Registered Versions", count,6);
+    }
+    private void checkVersionSpecification(String id, Class clazz) throws VersionException
+    {
+    	assertEquals(clazz.getName(), 
+    			VersionSpecificationFactory.createVersionSpecificationFromId(id).getClass(), clazz);
+    }
+}
\ No newline at end of file

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java	(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/impl/ApacheVersionTest.java	Tue Aug  3 20:28:32 2004
@@ -3,12 +3,12 @@
  */
 package org.apache.depot.version.impl;
 
+import junit.framework.TestCase;
+
+import org.apache.depot.common.log.Logger;
 import org.apache.depot.version.CompoundVersion;
 import org.apache.depot.version.VersionException;
 import org.apache.depot.version.impl.data.ReleaseLevel;
-import org.apache.depot.version.impl.data.VersionData;
-
-import junit.framework.TestCase;
 
 /**
  * @author <a href="http://nick.chalko.com">Nick Chalko </a>
@@ -21,9 +21,10 @@
      * Class under test for void ApacheVersion(String)
      */
     public void testApacheVersionString() throws VersionException {
+        //Logger.testInit();
+        
         assertApacheVersion("1.2.1", 1, 2, 1, ReleaseLevel.DEFAULT);
-        assertApacheVersion("1.2.1-dev", 1, 2, 1, ReleaseLevel.DEVELOPMENT);
-
+        assertApacheVersion("1.2.1-dev", 1, 2, 1, ReleaseLevel.DEVELOPMENT);        
     }
 
     /**