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/05/10 01:51:31 UTC

svn commit: rev 10573 - in incubator/depot/trunk/update/src: java/org/apache/depot/update/protocols java/org/apache/depot/update/protocols/impl java/org/apache/depot/update/util/io java/org/apache/depot/update/util/security test/org/apache/depot/update/util/security

Author: ajack
Date: Sun May  9 18:51:30 2004
New Revision: 10573

Modified:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/DefaultProtocolOperationsManager.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/HttpClientProtocolOperationsProvider.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/VfsProtocolOperationsProvider.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/util/io/VfsUtils.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/util/security/HashCodeManager.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/util/security/HashCodeManagerTest.java
Log:
Earlier check for HttpClient.


Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/DefaultProtocolOperationsManager.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/DefaultProtocolOperationsManager.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/DefaultProtocolOperationsManager.java	Sun May  9 18:51:30 2004
@@ -44,7 +44,7 @@
 			ClassLoaderContext loader = new ClassLoaderContext(context);
 
 			IProtocolOperationsProvider provider = (IProtocolOperationsProvider) loader.loadClassWithFallbacks(
-					HTTP_CLIENT_PROVIDER, VFS_PROVIDER, URL_PROVIDER);
+					VFS_PROVIDER, HTTP_CLIENT_PROVIDER, URL_PROVIDER);
 
 			registerProvider(provider);
 			

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/HttpClientProtocolOperationsProvider.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/HttpClientProtocolOperationsProvider.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/HttpClientProtocolOperationsProvider.java	Sun May  9 18:51:30 2004
@@ -20,6 +20,8 @@
 import java.io.FileOutputStream;
 import java.util.List;
 
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.logging.LogFactory;
 import org.apache.depot.common.util.io.IOUtils;
 import org.apache.depot.update.impl.ResourceUpdaterContext;
 import org.apache.depot.update.protocols.Protocol;
@@ -38,6 +40,14 @@
 	extends FileProtocolOperationsProvider {
 
 	private HttpClientUserAgent m_agent = null;
+	
+	public HttpClientProtocolOperationsProvider() {
+		// Force an early fail, not on in init, so can trap it
+		// and try another provider
+		Class causeAFailedLoadAtConstructionIfGoingToHappen = HttpClientUserAgent.class;
+		Class causeAFailedLoadAtConstructionIfGoingToHappen2 = LogFactory.class;
+		Class causeAFailedLoadAtConstructionIfGoingToHappen3 = HttpMethod.class;
+		}
 
 	public void init(ResourceUpdaterContext context) throws Exception {
 		super.init(context);

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/VfsProtocolOperationsProvider.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/VfsProtocolOperationsProvider.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/VfsProtocolOperationsProvider.java	Sun May  9 18:51:30 2004
@@ -20,6 +20,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.FileSystemManager;
 import org.apache.depot.update.impl.ResourceUpdaterContext;
@@ -40,6 +41,7 @@
 		// Force an early fail, not on in init, so can trap it
 		// and try another provider
 		Class causeAFailedLoadAtConstructionIfGoingToHappen = FileSystemManager.class;
+		Class causeAFailedLoadAtConstructionIfGoingToHappen2 = LogFactory.class;
 	}
 
 	public void init(ResourceUpdaterContext context) throws Exception {

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/util/io/VfsUtils.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/util/io/VfsUtils.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/util/io/VfsUtils.java	Sun May  9 18:51:30 2004
@@ -39,9 +39,6 @@
 
 /**
  * @author ajack
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
  */
 /**
  *

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/util/security/HashCodeManager.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/util/security/HashCodeManager.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/util/security/HashCodeManager.java	Sun May  9 18:51:30 2004
@@ -27,10 +27,9 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
 
+import org.apache.depot.update.UpdateRuntimeException;
 import org.apache.tools.ant.BuildException;
 
-
-
 //import org.apache.depot.update.RuperException;
 
 /**
@@ -39,7 +38,7 @@
  */
 public class HashCodeManager {
     public static final String DEFAULT_ALGORITHM = "MD5";
-    public static final int DEFAULT_BUFFERSIZE = 8 * 1024;
+    public static final int DEFAULT_BUFFERSIZE = (8 * 1024);
 
     /**
      *
@@ -222,7 +221,7 @@
         int l = data.length;
 
         if ((l & 0x01) != 0) {
-//            throw new BuildException("odd number of characters.");
+            throw new UpdateRuntimeException("odd number of characters.");
         }
 
         byte[] out = new byte[l >> 1];

Modified: incubator/depot/trunk/update/src/test/org/apache/depot/update/util/security/HashCodeManagerTest.java
==============================================================================
--- incubator/depot/trunk/update/src/test/org/apache/depot/update/util/security/HashCodeManagerTest.java	(original)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/util/security/HashCodeManagerTest.java	Sun May  9 18:51:30 2004
@@ -16,8 +16,6 @@
 package org.apache.depot.update.util.security;
 
 import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
@@ -35,7 +33,7 @@
 public class HashCodeManagerTest extends TestCase {
     private MessageDigest messageDigest;
     
-    private int readBufferSize = 8 * 1024;
+    private int readBufferSize = (8 * 1024);
     
     /**
      * Creates a new HashHelperTest object.
@@ -61,15 +59,8 @@
      * @throws Exception TODO
      */
     public void testGetDigest() throws Exception {
-        ClassLoader clazzLoader = this.getClass().getClassLoader();
-        URL urlHashFile = clazzLoader.getResource("org/apache/depot/update/util/security/test.txt");
-        URL urlMetaFile = clazzLoader.getResource("org/apache/depot/update/util/security/test.txt.md5");
-
-        assertNotNull("Loaded HashFile", urlHashFile);
-        assertNotNull("Loaded MetaFile", urlMetaFile);
-
-        File hashFile = new File(urlHashFile.getPath());
-        File metaFile = new File(urlMetaFile.getPath());
+        File hashFile = new File("src/resources/test/org/apache/depot/update/util/security/test.txt");
+        File metaFile = new File("src/resources/test/org/apache/depot/update/util/security/test.txt.md5");
                 
         byte[] firstByteArray = HashCodeManager.getDigest(hashFile,  this.messageDigest, this.readBufferSize);
         byte[] sameByteArray = HashCodeManager.getDigest(hashFile, this.messageDigest, this.readBufferSize);
@@ -85,9 +76,9 @@
 		String snd =   "Hello again!";
 		String third = "Hello again World";
 		
-		assertTrue(HashCodeManager.compareHashes(first.getBytes(), first.getBytes()));
-		assertFalse(HashCodeManager.compareHashes(first.getBytes(), snd.getBytes()));
-		assertFalse(HashCodeManager.compareHashes(first.getBytes(), third.getBytes()));		
+		assertTrue("Hashes over same", HashCodeManager.compareHashes(first.getBytes(), first.getBytes()));
+		assertFalse("Hashes over different", HashCodeManager.compareHashes(first.getBytes(), snd.getBytes()));
+		assertFalse("Hashes over inserted", HashCodeManager.compareHashes(first.getBytes(), third.getBytes()));		
 	}
 	
 	public void testCreateDigester() throws Exception {
@@ -96,14 +87,12 @@
 		try {
 			md = HashCodeManager.createDigester(null, null);						
 		} catch (NoSuchProviderException nspex) {
-			assertTrue(true);
+			assertTrue("Can't create a null propvider", true);
 		}
 		
 		assertEquals(HashCodeManager.DEFAULT_ALGORITHM, md.getAlgorithm());
-		
 		md = HashCodeManager.createDigester("SHA", null);
-		
-		assertEquals("SHA", md.getAlgorithm());
+		assertEquals("Asked for SHA got SHA", "SHA", md.getAlgorithm());
 		
 		boolean success = false;
 
@@ -116,7 +105,7 @@
 			success = true;
 		}
 		
-		assertTrue(success);		
+		assertTrue("Can't create an XYZ digest", success);		
 		success = false;
 		
 		try {
@@ -128,16 +117,11 @@
 			success = false;
 		}
 		
-		assertTrue(success);		
+		assertTrue("Can't create an MD5 with some bogus provider", success);		
 	}
 			
 	public void testReadHashFromFile() throws Exception {
-        ClassLoader clazzLoader = this.getClass().getClassLoader();
-        URL urlMetaFile = clazzLoader.getResource("org/apache/depot/update/util/security/test.txt.md5");
-
-        assertNotNull("Loaded MetaFile", urlMetaFile);
-        
-        File metaFile = new File(urlMetaFile.getPath());
+        File metaFile = new File("src/resources/test/org/apache/depot/update/util/security/test.txt.md5");
 
 		byte[] digest = HashCodeManager.readHashFromFile(metaFile);
 		assertNotNull(digest);
@@ -158,8 +142,8 @@
 	 *
 	 * @throws Exception
 	 */
-	public void testGenerateHash() throws Exception {
-		/* get classloader to load needed resources - should be done in a static way (utils class) */
+	/*public void testGenerateHash() throws Exception {
+		 get classloader to load needed resources - should be done in a static way (utils class) 
 		ClassLoader loader = this.getClass().getClassLoader();
 		InputStream stream = loader.getResourceAsStream("test.xml");
 
@@ -167,7 +151,7 @@
 		
 //		GenerateHash(file, digest)
 		
-	}
+	}*/
 	
 	/**	
      *