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/03 20:17:00 UTC
svn commit: rev 10514 - in incubator/depot/trunk/update/src: java java/org/apache/depot/update/ant/task java/org/apache/depot/update/files java/org/apache/depot/update/protocols java/org/apache/depot/update/protocols/impl java/org/apache/depot/update/util/net/http test/org/apache/depot/update/files test/org/apache/depot/update/protocols test/org/apache/depot/update/usecases
Author: ajack
Date: Mon May 3 13:16:59 2004
New Revision: 10514
Modified:
incubator/depot/trunk/update/src/java/depot-update.xml
incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/task/RepositoryToolTask.java
incubator/depot/trunk/update/src/java/org/apache/depot/update/files/DefaultResourceFilenameAnalyzer.java
incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/DefaultProtocolOperationsManager.java
incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java
incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/FileProtocolOperationsProvider.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/util/net/http/HttpClientUserAgent.java
incubator/depot/trunk/update/src/test/org/apache/depot/update/files/DefaultResourceAnalyzerTests.java
incubator/depot/trunk/update/src/test/org/apache/depot/update/protocols/ProtocolOperationsManagerTests.java
incubator/depot/trunk/update/src/test/org/apache/depot/update/usecases/SynchronizeTests.java
Log:
Get working on HttpClient (not via VFS),
make less verbose.
Modified: incubator/depot/trunk/update/src/java/depot-update.xml
==============================================================================
--- incubator/depot/trunk/update/src/java/depot-update.xml (original)
+++ incubator/depot/trunk/update/src/java/depot-update.xml Mon May 3 13:16:59 2004
@@ -24,12 +24,7 @@
<repository id="apache"
url="http://www.apache.org/library/projects/"
- remote="true"/>
-
- <repository id="apache_sf"
- url="http://prdownloads.sourceforge.net/apache/"
- remote="true"
- hierarchical="false" />
+ remote="true"/>
</repositoryset>
<repositoryset id="test">
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/task/RepositoryToolTask.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/task/RepositoryToolTask.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/task/RepositoryToolTask.java Mon May 3 13:16:59 2004
@@ -93,7 +93,7 @@
IRepository r = (IRepository) i.next();
RepositoryWrapper repo = new RepositoryWrapper(r, context);
- log("Repository: " + repo);
+ log("Repository: " + repo + "[" + r.getClass().getName() + "]");
if (null == m_group) {
try {
@@ -111,12 +111,12 @@
for (Iterator si = specifiers.iterator(); si.hasNext();) {
ResourceSpecifier specifier = (ResourceSpecifier) si.next();
- log(" - " + specifier);
+ log(" - " + specifier, Project.MSG_VERBOSE);
}
}
} catch (UpdateException re) {
- log(" - Failed to list groups: "
- + re.getLocalizedMessage(), Project.MSG_WARN);
+ Logger.getLogger().error(" - Failed to list groups: ",
+ re);
}
} else {
ResourceGroup group = new ResourceGroup(m_group);
@@ -129,28 +129,26 @@
for (Iterator gi = specifiers.iterator(); gi.hasNext();) {
ResourceSpecifier specifier = (ResourceSpecifier) gi.next();
- log(" - Specifier: " + specifier);
+ log(" - " + specifier, Project.MSG_VERBOSE);
}
} catch (UpdateException re) {
- log(" - Failed to list groups: "
- + re.getLocalizedMessage(), Project.MSG_WARN);
+ Logger.getLogger().error(" - Failed to list groups: ",
+ re);
}
}
}
- log(" Statistics : Parsed=" + statistics.getParsed() + " Failed="
+ log(" Artefact Statistics : Parsed=" + statistics.getParsed() + " Failed="
+ statistics.getFailed() + " Ignored="
+ statistics.getIgnored());
-
+
List ignored = statistics.getIgnoredObjects();
- for ( Iterator i = ignored.iterator(); i.hasNext(); )
- {
+ for (Iterator i = ignored.iterator(); i.hasNext();) {
log(" Ignored : " + i.next());
}
List failed = statistics.getFailedObjects();
- for ( Iterator i = failed.iterator(); i.hasNext(); )
- {
+ for (Iterator i = failed.iterator(); i.hasNext();) {
log(" Failed : " + i.next());
}
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/files/DefaultResourceFilenameAnalyzer.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/files/DefaultResourceFilenameAnalyzer.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/files/DefaultResourceFilenameAnalyzer.java Mon May 3 13:16:59 2004
@@ -222,8 +222,11 @@
store);
else if (entity instanceof VirtualResourceLocator)
processVRL((VirtualResourceLocator) entity, store);
- else if (entity instanceof File)
+ else if (entity instanceof ResolvedFile)
processFile((ResolvedFile) entity, store);
+ else if (entity instanceof File)
+ // :TODO: Do we have resolver context?
+ processFile(ResolvedFile.resolve(entity), store);
//
// Hmm VFS? How utilize yet be separate? Maybe String...
//
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 Mon May 3 13:16:59 2004
@@ -16,6 +16,7 @@
package org.apache.depot.update.protocols;
+import org.apache.depot.common.log.Logger;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.common.util.envsafe.ClassLoaderContext;
import org.apache.depot.update.UpdateRuntimeException;
@@ -43,13 +44,15 @@
ClassLoaderContext loader = new ClassLoaderContext(context);
IProtocolOperationsProvider provider = (IProtocolOperationsProvider) loader.loadClassWithFallbacks(
- VFS_PROVIDER, HTTP_CLIENT_PROVIDER, URL_PROVIDER);
+ HTTP_CLIENT_PROVIDER, VFS_PROVIDER, URL_PROVIDER);
registerProvider(provider);
+
+ Logger.getLogger().info("Selected " + provider.getClass().getName());
} catch (Exception ve) {
throw new UpdateRuntimeException(
"No *Working* Protocol Operation Providers Detected", ve);
- }
+ }
}
public static void main(String args[]) {
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/ProtocolOperationsManager.java Mon May 3 13:16:59 2004
@@ -137,8 +137,7 @@
public boolean checkExists(VirtualResourceLocator container)
throws Exception {
Logger.getLogger().debug("Check EXISTS: " + container);
- boolean exists= determineProviderFor(container).exists(container);
- Logger.getLogger().debug("Check EXISTS: " + container + " returns " + exists);
+ boolean exists = determineProviderFor(container).exists(container);
return exists;
}
@@ -154,9 +153,7 @@
VirtualResourceLocator to,
ISelector selector)
throws Exception {
-
Logger.getLogger().info("Perform COPY " + from + " -> " + to);
-
determineProviderFor(from, to).copy(from, to, selector);
}
@@ -171,9 +168,7 @@
VirtualResourceLocator locator,
ISelector selector)
throws Exception {
-
Logger.getLogger().info("Perform DELETE " + locator);
-
determineProviderFor(locator).delete(locator, selector);
}
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/FileProtocolOperationsProvider.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/FileProtocolOperationsProvider.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/protocols/impl/FileProtocolOperationsProvider.java Mon May 3 13:16:59 2004
@@ -20,6 +20,7 @@
import java.util.List;
import org.apache.depot.common.log.Logger;
+import org.apache.depot.update.UpdateException;
import org.apache.depot.update.impl.ResourceUpdaterContext;
import org.apache.depot.update.protocols.Protocol;
import org.apache.depot.update.util.io.FileUtils;
@@ -31,7 +32,8 @@
* @author ajack
*/
public class FileProtocolOperationsProvider
- extends AbstractProtocolOperationsProvider {
+ extends
+ AbstractProtocolOperationsProvider {
public void init(ResourceUpdaterContext context) throws Exception {
super.init(context);
@@ -46,43 +48,45 @@
}
public List list(VirtualResourceLocator container, ISelector selector)
- throws Exception {
+ throws Exception {
List children = new ArrayList();
File folder = container.getFile();
+
+ if (!folder.isDirectory())
+ throw new UpdateException("Not a directory : " + folder);
+
File files[] = folder.listFiles();
- for (int i = 0; i < files.length; ++i) {
- File file = files[i];
- children.add(
- new VirtualResourceLocator(
- ResolvedFile.resolve(folder, file.getName())));
- }
+
+ if (null != files)
+ for (int i = 0; i < files.length; ++i) {
+ File file = files[i];
+ children.add(new VirtualResourceLocator(ResolvedFile.resolve(
+ folder, file.getName())));
+ }
return children;
}
- public void copy(
- VirtualResourceLocator from,
- VirtualResourceLocator to,
- ISelector selector)
- throws Exception {
+ public void copy(VirtualResourceLocator from, VirtualResourceLocator to,
+ ISelector selector) throws Exception {
File toFile = to.getFile();
// Build Folders to this Folder
toFile.getParentFile().mkdirs();
try {
FileUtils.transfer(from.getFile(), toFile);
- }
- catch (Exception e) { // Attempt at cleanup
+ } finally { // Attempt at cleanup
try {
toFile.delete();
+ } catch (Exception ee) {
}
- catch (Exception ee) {
- }
+ Logger.getLogger().error(
+ "Failed to copy from: " + from + " to " + to);
}
}
public void delete(VirtualResourceLocator locator, ISelector selector)
- throws Exception {
+ throws Exception {
File file = locator.getFile();
boolean deleted = file.delete();
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 Mon May 3 13:16:59 2004
@@ -29,6 +29,9 @@
import org.apache.depot.update.util.select.ISelector;
/**
+ *
+ * Implments an HTTP provider (ontop of File) so can do http:// file://
+ *
* @author ajack
*/
public class HttpClientProtocolOperationsProvider
@@ -45,6 +48,9 @@
m_agent = new HttpClientUserAgent();
}
+ /**
+ * Check if the VRL exists
+ */
public boolean exists(VirtualResourceLocator container) throws Exception {
boolean exists = false;
@@ -56,6 +62,9 @@
return exists;
}
+ /**
+ * List the contents of the VRL
+ */
public List list(VirtualResourceLocator container, ISelector selector)
throws Exception {
List children = null;
@@ -73,14 +82,19 @@
return children;
}
+ /**
+ * Copy from one (remote) location to another (local) location.
+ */
public void copy(
VirtualResourceLocator from,
VirtualResourceLocator to,
ISelector selector)
throws Exception {
File toFile = to.getFile();
+
// Build Folders to this Folder
toFile.getParentFile().mkdirs();
+
try {
if (Protocol.isHTTP(from.getProtocol())) { // Copy data...
FileOutputStream stream = null;
@@ -94,9 +108,8 @@
}
else
super.copy(from, to, selector);
-
}
- catch (Exception e) { // Attempt at cleanup
+ finally { // Attempt at cleanup
try {
toFile.delete();
}
Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/http/HttpClientUserAgent.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/http/HttpClientUserAgent.java (original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/http/HttpClientUserAgent.java Mon May 3 13:16:59 2004
@@ -22,6 +22,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.HeadMethod;
import org.apache.commons.httpclient.util.HttpURLConnection;
@@ -40,13 +41,12 @@
private HttpClient m_client = null;
public HttpClientUserAgent() {
- m_client = new HttpClient();//new MultiThreadedHttpConnectionManager());
+ m_client = new HttpClient(new MultiThreadedHttpConnectionManager());
//
// Enable a timeout
//
- // :TODO: Temporarily removed so will Gump on chalko...
- // m_client.getParams().setConnectionTimeout(30000);
+ m_client.getParams().setConnectionManagerTimeout(30000);
}
/**
@@ -56,24 +56,23 @@
* @param url
* @return
*/
- public boolean exists(String url) {
+ public boolean exists(String url) throws Exception {
boolean exists = false;
HeadMethod head = null;
try {
-
head = getHead(url);
-
int resultCode = m_client.executeMethod(head);
-
exists = (HttpURLConnection.HTTP_OK == resultCode);
}
catch (Exception ex) {
Logger.getLogger().error("Failed to HTTP HEAD [" + url + "]", ex);
+ throw ex;
}
finally {
- head.releaseConnection();
+ if ( null != head )
+ head.releaseConnection();
}
return exists;
@@ -84,24 +83,24 @@
* @param url
* @return
*/
- public String getContents(String url) {
+ public String getContents(String url) throws Exception {
String content = null;
GetMethod get = null;
try {
get = getGet(url);
-
int resultCode = m_client.executeMethod(get);
-
if (HttpURLConnection.HTTP_OK == resultCode)
content = get.getResponseBodyAsString();
}
catch (Exception ex) {
Logger.getLogger().error("Failed to HTTP GET [" + url + "]", ex);
+ throw ex;
}
finally {
- get.releaseConnection();
+ if ( null != get )
+ get.releaseConnection();
}
return content;
@@ -112,7 +111,7 @@
* @param url
* @param output
*/
- public void transferContents(String url, OutputStream output) {
+ public void transferContents(String url, OutputStream output) throws Exception {
GetMethod get = null;
try {
@@ -129,9 +128,12 @@
}
catch (Exception ex) {
Logger.getLogger().error("Failed to HTTP GET [" + url + "]", ex);
+
+ throw ex;
}
finally {
- get.releaseConnection();
+ if ( null != get )
+ get.releaseConnection();
}
}
@@ -164,13 +166,19 @@
*
*/
private void configureMethod(HttpMethod method) {
+
+ //
method.setFollowRedirects(true);
+
+ //
+ // Identify use (in case we upset any folks).
+ //
method.setRequestHeader(
"User-Agent",
"Apache-Depot-Update/" + VersionHelper.getMarker().getLongVersion());
}
- public static void main(String args[]) {
+ public static void main(String args[]) throws Exception {
HttpClientUserAgent agent = new HttpClientUserAgent();
String url = "http://www.ibiblio.org/maven/junit/jars";
Modified: incubator/depot/trunk/update/src/test/org/apache/depot/update/files/DefaultResourceAnalyzerTests.java
==============================================================================
--- incubator/depot/trunk/update/src/test/org/apache/depot/update/files/DefaultResourceAnalyzerTests.java (original)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/files/DefaultResourceAnalyzerTests.java Mon May 3 13:16:59 2004
@@ -20,6 +20,7 @@
import junit.framework.TestCase;
+import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.update.UpdateException;
import org.apache.depot.update.resource.Resource;
import org.apache.depot.update.resource.ResourceType;
@@ -33,6 +34,7 @@
public class DefaultResourceAnalyzerTests extends TestCase {
private DefaultResourceFilenameAnalyzer m_analyzer = null;
+
//private VirtualResourceLocator m_http = null;
//private VirtualResourceLocator m_file = null;
@@ -41,8 +43,7 @@
}
public void setUp() throws Exception {
- m_analyzer =
- new DefaultResourceFilenameAnalyzer(
+ m_analyzer = new DefaultResourceFilenameAnalyzer(
VirtualResourceLocator.getTestVRL());
}
@@ -53,22 +54,14 @@
}
public void testVersionSeparator() throws Exception {
- assertEquals(
- "Found Dash Version",
- 3,
- m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
- assertEquals(
- "Found Underscore Version",
- 3,
- m_analyzer.findSeparatorBeforeVersionNumbers("A-B_1"));
- assertEquals(
- "Found Underscore then Dash Version",
- 3,
- m_analyzer.findSeparatorBeforeVersionNumbers("A_B-1"));
- assertEquals(
- "Found Dash then Dash Version",
- 3,
- m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
+ assertEquals("Found Dash Version", 3,
+ m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
+ assertEquals("Found Underscore Version", 3,
+ m_analyzer.findSeparatorBeforeVersionNumbers("A-B_1"));
+ assertEquals("Found Underscore then Dash Version", 3,
+ m_analyzer.findSeparatorBeforeVersionNumbers("A_B-1"));
+ assertEquals("Found Dash then Dash Version", 3,
+ m_analyzer.findSeparatorBeforeVersionNumbers("A-B-1"));
}
public void testExtensions1() throws UpdateException {
@@ -77,73 +70,65 @@
testList.add("fred");
checkExtensionList(testPattern, testList);
- checkResource(
- testPattern,
- createResource(testPattern, "mystuff", "1.2", null,""));
+ //:TODO: Do we want UNKNOWN type?
+ checkResource(testPattern, createResource(testPattern, "mystuff",
+ "1.2", null, "fred"));
}
- public void testExtensions2() throws UpdateException{
+ public void testExtensions2() throws UpdateException {
String testPattern = "mystuff-1.2-src.fred";
List testList = new ArrayList();
testList.add("fred");
checkExtensionList(testPattern, testList);
- checkResource(
- testPattern,
- createResource(testPattern, "mystuff", "1.2", "src",""));
+ checkResource(testPattern, createResource(testPattern, "mystuff",
+ "1.2", "src", "fred"));
}
- public void testExtensions3() throws UpdateException{
+ public void testExtensions3() throws UpdateException {
String testPattern = "mystuff-1.2-src.fred.Z";
List testList = new ArrayList();
testList.add("fred.Z");
testList.add("Z");
checkExtensionList(testPattern, testList);
- checkResource(
- testPattern,
- createResource(testPattern, "mystuff", "1.2", "src",""));
+ // :TODO: Is lower case ok?
+ checkResource(testPattern, createResource(testPattern, "mystuff",
+ "1.2", "src", "fred.z"));
}
- private Resource createResource(
- String filename,
- String name,
- String v,
- String t,
- String e)
- throws UpdateException {
+ private Resource createResource(String filename, String name, String v,
+ String t, String e) throws UpdateException {
Version version = null;
if (null != v) {
try {
version = VersionImporter.importVersion(v);
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
}
}
ResourceType resourceType = null;
- resourceType = ResourceType.getFromString(t);
+ if (null != t )
+ resourceType = ResourceType.getFromString(t);
+ else
+ resourceType = ResourceType.UNKNOWN;
+
- return new Resource(
- name,
- version,
- resourceType,
- e,
- filename,
- new VirtualResourceLocator(filename));
+ return new Resource(name, version, resourceType, e, filename,
+ new VirtualResourceLocator(new VirtualResourceLocator(
+ "http://www.apache.org/depot"), filename));
}
private void checkResource(String pattern, Resource expected)
- throws UpdateException {
-
- //DebugUtils.printSeparator();
- //DebugUtils.dump(expected);
-
+ throws UpdateException {
+
+ DebugUtils.printSeparator();
+ DebugUtils.dump(expected);
+
Resource resource = m_analyzer.determineResource(pattern);
-
assertNotNull("Determined something", resource);
- //DebugUtils.printSeparator();
- //DebugUtils.dump(resource);
+ DebugUtils.printSeparator();
+ DebugUtils.dump(resource);
assertEquals("Same Resource", expected, resource);
}
Modified: incubator/depot/trunk/update/src/test/org/apache/depot/update/protocols/ProtocolOperationsManagerTests.java
==============================================================================
--- incubator/depot/trunk/update/src/test/org/apache/depot/update/protocols/ProtocolOperationsManagerTests.java (original)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/protocols/ProtocolOperationsManagerTests.java Mon May 3 13:16:59 2004
@@ -16,6 +16,8 @@
package org.apache.depot.update.protocols;
+import java.util.List;
+
import junit.framework.TestCase;
import org.apache.depot.update.impl.ResourceUpdaterContext;
@@ -54,12 +56,16 @@
//DebugUtils.dump(m_pom);
}
- public void testList1() throws Exception {
- m_pom.performList(m_http, AllSelector.getInstance());
+ public void testListHttp() throws Exception {
+ List files = m_pom.performList(m_http, AllSelector.getInstance());
+ assertNotNull("Files List", files);
+ assertFalse("Listed Some Files", files.isEmpty());
}
- public void testList2() throws Exception {
- assertNotNull("Perform List", m_pom.performList(m_file, AllSelector.getInstance()));
+ public void testListFile() throws Exception {
+ List files = m_pom.performList(m_file, AllSelector.getInstance());
+ assertNotNull("Files List", files);
+ assertFalse("Listed Some Files", files.isEmpty());
//DebugUtils.dump();
}
Modified: incubator/depot/trunk/update/src/test/org/apache/depot/update/usecases/SynchronizeTests.java
==============================================================================
--- incubator/depot/trunk/update/src/test/org/apache/depot/update/usecases/SynchronizeTests.java (original)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/usecases/SynchronizeTests.java Mon May 3 13:16:59 2004
@@ -87,7 +87,6 @@
// assertFalse("Old file has been removed", targetFile.exists() );
// 8. Depot reports results to User
-
}
public static Test suite() {