avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: rev 46121 - in avalon/trunk/runtime/repository/util/src: java/org/apache/avalon/repository/util test/org/apache/avalon/repository/util
Date Wed, 15 Sep 2004 16:13:41 GMT
Author: niclas
Date: Wed Sep 15 09:13:40 2004
New Revision: 46121

Added:
   avalon/trunk/runtime/repository/util/src/test/org/apache/avalon/repository/util/LoaderUtilsTest.java
  (contents, props changed)
Modified:
   avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
Log:
Patch submitted by David Leangen. Testcases are good, but the LoadUtils implementation rewritten
for JDK1.3.

Modified: avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
==============================================================================
--- avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
(original)
+++ avalon/trunk/runtime/repository/util/src/java/org/apache/avalon/repository/util/LoaderUtils.java
Wed Sep 15 09:13:40 2004
@@ -406,12 +406,23 @@
         return destination.toURL();
     }
 
-    private static boolean isSnapshot( File file )
+    static boolean isSnapshot( File file )
     {
-        return file.getName().endsWith( "SNAPSHOT" );
+        if( file == null )
+            return false;
+        String name = file.getName();
+        int posSS = name.indexOf( "-SNAPSHOT" );
+        int posDot = name.indexOf( ".", posSS + 8 );
+        if( posDot > -1 )
+        {
+             String sub = name.substring( 0, posDot );
+             return sub.endsWith( "-SNAPSHOT" );
+        }
+        return name.endsWith( "-SNAPSHOT" );
     }
 
-    private static URL getURL( File file ) throws RepositoryException
+    private static URL getURL( File file ) 
+        throws RepositoryException
     {
         try
         {

Added: avalon/trunk/runtime/repository/util/src/test/org/apache/avalon/repository/util/LoaderUtilsTest.java
==============================================================================
--- (empty file)
+++ avalon/trunk/runtime/repository/util/src/test/org/apache/avalon/repository/util/LoaderUtilsTest.java
Wed Sep 15 09:13:40 2004
@@ -0,0 +1,88 @@
+package org.apache.avalon.repository.util;
+
+import junit.framework.TestCase;
+import java.io.File;
+
+public class LoaderUtilsTest extends TestCase
+{
+
+    public LoaderUtilsTest(String name)
+    {
+        super(name);
+    }
+    
+    public void testIsSnapshot()
+    {
+        // First, try without file extension
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1")));
+        assertFalse(LoaderUtils.isSnapshot(null));
+
+        // With 0-char file extensions
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT.")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT.")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT.")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT.")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot.")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT.")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT.")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1.")));
+
+        // With 1-char file extensions
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT.a")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT.a")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT.a")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT.a")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot.a")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT.a")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT.a")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1.a")));
+
+        // With 2-char file extensions
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT.ab")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT.ab")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT.ab")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT.ab")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot.ab")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT.ab")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT.ab")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1.ab")));
+
+        // With 3-char file extensions
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT.abc")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT.abc")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT.abc")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT.abc")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot.abc")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT.abc")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT.abc")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1.abc")));
+
+        // With 4-char file extensions
+        assertTrue(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT.abcd")));
+        assertTrue(LoaderUtils.isSnapshot(new File(".some-file-SNAPSHOT.abcd")));
+        assertTrue(LoaderUtils.isSnapshot(new File("/home/usr/some/path/some-file-SNAPSHOT.abcd")));
+        assertTrue(LoaderUtils.isSnapshot(new File("C:\\home\\usr\\some\\parh\\some-file-SNAPSHOT.abcd")));
+        
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-snapshot.abcd")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SAPSHOT.abcd")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-fileSNAPSHOT.abcd")));
+        assertFalse(LoaderUtils.isSnapshot(new File("some-file-SNAPSHOT1.abcd")));
+
+        // We'll assume that it will pass for n-char file extensions
+        
+    }
+
+}
+

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message