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/17 18:05:41 UTC

svn commit: rev 10704 - in incubator/depot/trunk/update/src: java java/org/apache/depot/update/ant java/org/apache/depot/update/ant/cache java/org/apache/depot/update/ant/task java/org/apache/depot/update/ant/tool java/org/apache/depot/update/query test/org/apache/depot/update/ant test/org/apache/depot/update/ant/cache test/org/apache/depot/update/ant/sync test/org/apache/depot/update/ant/task

Author: ajack
Date: Mon May 17 11:05:40 2004
New Revision: 10704

Added:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceFileSet.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSet.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSetExportTask.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/RepositoryElement.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/ResourceElement.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/EnvironmentToolTask.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/RepositoryToolTask.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/AntTasksTests.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/anttasks.xml
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/CachedResourceSetTaskTest.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/build.xml
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/test1-export.build.xml
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/SynchronizeTaskTests.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/reposync.xml
Removed:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/CachedResourceSet.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/RepositoryElement.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/task/
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/task/
Modified:
   incubator/depot/trunk/update/src/java/depot-update-antlib.xml
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/AntUtils.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ResourceResult.java
Log:
Refactoring to not name packages after a sub-class type,
but after purpose.


Modified: incubator/depot/trunk/update/src/java/depot-update-antlib.xml
==============================================================================
--- incubator/depot/trunk/update/src/java/depot-update-antlib.xml	(original)
+++ incubator/depot/trunk/update/src/java/depot-update-antlib.xml	Mon May 17 11:05:40 2004
@@ -14,14 +14,13 @@
 limitations under the License.
 -->
 <antlib>
-    <typedef name="cachedset" classname="org.apache.depot.update.ant.CachedResourceSet"/>
-    <taskdef name="cachedsetexport" classname="org.apache.depot.update.ant.CachedResourceSetExportTask"/>
+    <typedef name="cachedset" classname="org.apache.depot.update.cache.CachedResourceSet"/>
+    <taskdef name="cachedsetexport" classname="org.apache.depot.update.cache.CachedResourceSetExportTask"/>    
+    <typedef name="resource" classname="org.apache.depot.update.cache.ResourceElement"/>
+    <typedef name="repository" classname="org.apache.depot.update.cache.RepositoryElement"/>
     
-    <typedef name="resource" classname="org.apache.depot.update.ant.ResourceElement"/>
-    <typedef name="repository" classname="org.apache.depot.update.ant.RepositoryElement"/>
+    <taskdef name="repoenv" classname="org.apache.depot.update.ant.tool.EnvironmentToolTask"/>
+    <taskdef name="repotool" classname="org.apache.depot.update.ant.tool.RepositoryToolTask"/>
     
-    <taskdef name="repoenv" classname="org.apache.depot.update.ant.task.EnvironmentToolTask"/>
-    <taskdef name="repotool" classname="org.apache.depot.update.ant.task.RepositoryToolTask"/>
-    
-    <taskdef name="reposync" classname="org.apache.depot.update.ant.task.SynchronizeTask"/>
+    <taskdef name="reposync" classname="org.apache.depot.update.ant.sync.SynchronizeTask"/>
 </antlib>

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/AntUtils.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/AntUtils.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/AntUtils.java	Mon May 17 11:05:40 2004
@@ -117,13 +117,4 @@
 		}
 		return depotHome;
 	}
-	/**
-	 * @param this
-	 * @return
-	 */
-	static Resource getFirstResource(ResourceResult res) {
-		List l = (List) res.get(0);
-		Resource resource = (Resource) l.get(0);
-		return resource;
-	}
 }

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceFileSet.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceFileSet.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,66 @@
+/*
+ * ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.update.ant.cache;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.FileScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+/**
+ *  
+ */
+final class CachedResourceFileSet extends FileSet {
+	private final CachedResourceSet updateSet;
+	private boolean initialized = false;
+	private FileScanner scanner;
+	CachedResourceFileSet(CachedResourceSet updateSet) {
+		this.updateSet = updateSet;
+	}
+	private synchronized void initialize() {
+		if (!initialized) {
+			try {
+				scanner = updateSet.getFileScanner();
+				scanner.getIncludedFiles();
+				setDir(scanner.getBasedir());
+				setupDirectoryScanner(scanner, updateSet.getProject());
+			} catch (BuildException e) {
+				throw e;
+			} catch (Exception e) {
+				throw new BuildException("error initializing " + getDataTypeName(), e);
+			}
+		}
+		initialized = true;
+	}
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.tools.ant.types.AbstractFileSet#getDirectoryScanner(org.apache.tools.ant.Project)
+	 */
+	public DirectoryScanner getDirectoryScanner(Project p) {
+		initIfNeeded();
+		return super.getDirectoryScanner(p);
+	}
+	/**
+	 *  
+	 */
+	private void initIfNeeded() {
+		if (!initialized) {
+			initialize();
+		}
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSet.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSet.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,263 @@
+/*
+ * ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.update.ant.cache;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.depot.common.DepotException;
+import org.apache.depot.update.ResourceUpdater;
+import org.apache.depot.update.UpdateException;
+import org.apache.depot.update.ant.AntUtils;
+import org.apache.depot.update.impl.RepositorySetWrapper;
+import org.apache.depot.update.impl.ResourceUpdaterContext;
+import org.apache.depot.update.protocols.DefaultProtocolOperationsManager;
+import org.apache.depot.update.query.DefaultQueryEngine;
+import org.apache.depot.update.query.ResourceQuery;
+import org.apache.depot.update.query.ResourceResult;
+import org.apache.depot.update.repository.DefaultRepository;
+import org.apache.depot.update.repository.IRepository;
+import org.apache.depot.update.repository.RepositorySet;
+import org.apache.depot.update.resource.Resource;
+import org.apache.depot.update.resource.compare.VersionComparator;
+import org.apache.depot.update.util.io.ResolvedFile;
+import org.apache.depot.version.VersionException;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.FileScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.DataType;
+/**
+ * A locally cached repository backed set of resources.
+ * 
+ * @version $Revision: $
+ */
+public class CachedResourceSet extends DataType {
+	public static final String DEFAULT_LOCAL_REPOSITORY_DIR_NAME = "local-repository";
+	public static final String LOCAL_REPOSITORY_ID = "local.repository";
+	public static final String REPOSITORY_DIR_PROPERTY = "repository.dir";
+	private final Project project;
+	private String id;
+	private final CachedResourceFileSet fileSet = new CachedResourceFileSet(
+			this);
+	private final List resourceList = new ArrayList();
+	private ResourceUpdater m_updater = null;
+	private boolean isAlwaysCheckRemote = false;
+	private boolean checkClassPath = true;
+	/**
+	 *  
+	 */
+	public CachedResourceSet(Project project) {
+		super();
+		this.project = project;
+	}
+	/**
+	 * @param resource
+	 * @return Resource
+	 */
+	public ResourceElement createResource() {
+		ResourceElement resource = new ResourceElement(project);
+		resourceList.add(resource);
+		return resource;
+	}
+	/**
+	 * @return Returns the id.
+	 */
+	public String getId() {
+		return id;
+	}
+	/**
+	 * @param id
+	 *            The id to set.
+	 */
+	public void setId(String id) {
+		this.id = id;
+		project.addReference(id + ".fileset", fileSet);
+	}
+	/**
+	 * @return
+	 */
+	FileScanner getFileScanner() throws UpdateException {
+		final DirectoryScanner scanner = new DirectoryScanner();
+		scanner.setBasedir(getRepoDir());
+		addResources(scanner);
+		return scanner;
+	}
+	/**
+	 * @param scanner
+	 */
+	private void addResources(DirectoryScanner scanner) throws UpdateException {
+		for (Iterator i = resourceList.iterator(); i.hasNext();) {
+			ResourceElement r = (ResourceElement) i.next();
+			add(scanner, r);
+		}
+	}
+	/**
+	 * @param scanner
+	 * @param r
+	 */
+	private void add(DirectoryScanner scanner, ResourceElement r)
+			throws UpdateException {
+		log("Looking for " + r, Project.MSG_DEBUG);
+		File f = getLocalFile(r);
+		if (f != null) {
+			String path = f.getAbsolutePath();
+			String basepath = scanner.getBasedir().getAbsolutePath();
+			if (path.startsWith(basepath)) {
+				path = path.substring(basepath.length() + 1);
+			}
+			scanner.setIncludes(new String[]{path});
+			scanner.scan();
+		} else {
+			throw new BuildException("Unable to find " + r);
+		}
+	}
+	/**
+	 * Find and download if needed a the best local cached copy of a file. First
+	 * check if a compitable file is available locally. If not down load the
+	 * best one available from the repository. And finally return the best
+	 * compatible file.
+	 * 
+	 * @param r
+	 *            resourceElement the ant element describeing the resouce to
+	 *            find
+	 * @return File null if a compatible file can't be found.
+	 * @throws UpdateException
+	 */
+	private File getLocalFile(ResourceElement r) throws UpdateException {
+		// TODO respect the ant build.classpath property.
+		File file = null;
+		if (!isAlwaysCheckRemote) {
+			file = getCachedFile(r);
+		}
+		if (file == null) {
+			cacheFile(r);
+		}
+		file = getCachedFile(r);
+		return file;
+	}
+	/**
+	 * @param r
+	 */
+	private void cacheFile(ResourceElement r) {
+		try {
+			Resource resource = findBestRepoteResource(r);
+			if (resource != null) {
+				r.setDownloadedFrom(resource.getLocation().toExternalForm());
+				downLoadRemoteResult(resource);
+			}
+			return;
+		} catch (Exception e) {
+			throw new BuildException("Unable to get local copy of " + r, e);
+		}
+	}
+	/**
+	 * @param r
+	 * @return
+	 */
+	Resource findBestRepoteResource(ResourceElement r) {
+		return r.findBestRepoteResource();
+	}
+	/**
+	 * @param r
+	 */
+	private File getCachedFile(ResourceElement r) throws UpdateException {
+		try {
+			ResourceResult res = query(r, getLocalRepository());
+			if (res.size() == 0) {
+				return null;
+			} else if (res.size() == 1) {
+				return getFirstFile(res);
+			} else {
+				log("Found " + res.size() + " matches for " + r
+						+ " returning first", Project.MSG_VERBOSE);
+				return getFirstFile(res);
+			}
+		} catch (Exception e) {
+			throw new BuildException("Error trying to get local copy of " + r,
+					e);
+		}
+	}
+	/**
+	 * @return
+	 */
+	private File getRepoDir() {
+		// TODO cache this.
+		File repo = AntUtils.findAndCreateDirFromProperty(getProject(),
+				REPOSITORY_DIR_PROPERTY);
+		if (repo == null) {
+			repo = new File(AntUtils.getDepotHome(getProject()),
+					DEFAULT_LOCAL_REPOSITORY_DIR_NAME);
+		}
+		AntUtils.createAndValidateDir(getProject(), repo,
+				"Local Repository Cache", true);
+		return repo;
+	}
+	/**
+	 * Should the cached set always look the remore repository for updates
+	 * 
+	 * @return Returns the isAlwaysCheckRemote.
+	 */
+	public boolean isAlwaysCheckRemote() {
+		return isAlwaysCheckRemote;
+	}
+	/**
+	 * Should the cached set always look the remore repository for updates
+	 * 
+	 * @param isAlwaysCheckRemote
+	 *            The isAlwaysCheckRemote to set.
+	 */
+	public void setAlwaysCheckRemote(boolean isAlwaysCheckRemote) {
+		this.isAlwaysCheckRemote = isAlwaysCheckRemote;
+	}
+	/**
+	 * @param r
+	 * @param res
+	 * @return
+	 */
+	private File getFirstFile(ResourceResult res) throws Exception {
+		Resource resource = ResourceResult.getFirstResource(res);
+		return resource.getLocation().getFile();
+	}
+	private ResourceResult query(ResourceElement r, IRepository repo) {
+		return r.query(repo);
+	}
+	/**
+	 * @return
+	 */
+	private IRepository getLocalRepository() {
+		DefaultRepository repository = new DefaultRepository(
+				LOCAL_REPOSITORY_ID, ResolvedFile.resolve(getRepoDir()));
+		return repository;
+	}
+	/**
+	 * @param resource
+	 * @throws UpdateException
+	 */
+	private void downLoadRemoteResult(Resource resource) throws UpdateException {
+		ResourceUpdater ru = new ResourceUpdater();
+		ru.downloadResource(resource, getLocalRepository());
+	}
+	/**
+	 * @return Returns the unmodifiableList of resources.
+	 */
+	List getResourceList() {
+		return Collections.unmodifiableList(resourceList);
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSetExportTask.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedResourceSetExportTask.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,118 @@
+/*
+ * ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.update.ant.cache;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.xml.utils.XMLChar;
+/**
+ * Export a cached resource set to xml file. <code>
+ * <cachedresourceset>
+ *      <resource name="foo" 
+ *                version="1.2.3"  
+ *                href="http://mydownload.com/bar/foo-1.2.3.jar" 
+ *                local="${local.repository}/bar/jars/foo-1.2.3.jar"/>
+ * </cachedresourceset>
+ * </code>
+ */
+public class CachedResourceSetExportTask extends Task {
+	private String refid;
+	private File toFile;
+	/**
+	 * The refid of the cachedset to export.
+	 * 
+	 * @return Returns the refid.
+	 */
+	public String getRefid() {
+		return refid;
+	}
+	/**
+	 * SEt the refid of the cachedset to export
+	 * 
+	 * @param refid
+	 *            The refid to set.
+	 */
+	public void setRefid(String refid) {
+		this.refid = refid;
+	}
+	/**
+	 * The file to export the Cached set to
+	 * 
+	 * @return Returns the toFile.
+	 */
+	public File getToFile() {
+		return toFile;
+	}
+	/**
+	 * The file to export the Cached set to
+	 * 
+	 * @param toFile
+	 *            The toFile to set.
+	 */
+	public void setToFile(File toFile) {
+		this.toFile = toFile;
+	}
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.tools.ant.Task#execute()
+	 */
+	public void execute() throws BuildException {
+		try {
+			CachedResourceSet cachedResourceSet = (CachedResourceSet) getProject()
+					.getReference(getRefid());
+			// TODO use real XML stuff
+			// njc Feeling lazy tonight
+			Writer writer = new FileWriter(getToFile());
+			PrintWriter out = new PrintWriter(writer);
+			List resourceList = cachedResourceSet.getResourceList();
+			out.println("<?xml " + nameValue("version", "1.0") + "?>");
+			out
+					.println("<!DOCTYPE cachedresourceset PUBLIC \"-//APACHE//DTD CachedResource V0.1//EN\" \"http://incubator.apache.org/depot/dtd/cachedresource-v01.dtd\">");
+			out.println("<cachedresourceset " + nameValue("id", getRefid())
+					+ ">");
+			for (Iterator i = resourceList.iterator(); i.hasNext();) {
+				ResourceElement resource = (ResourceElement) i.next();
+				out.println("    <resource "
+						+ nameValue("name", resource.getName()));
+				out.println("              "
+						+ nameValue("version", resource.getVersion()));
+				out.println("              "
+						+ nameValue("href", resource.getDownloadedFrom()));
+				out.println("     />");
+				log(resource + "  from  " + resource.getDownloadedFrom());
+			}
+			out.println("</cachedresourceset>");
+			out.close();
+			writer.close();
+		} catch (Exception e) {
+			throw new BuildException("Error exporting cached resource set "
+					+ getRefid(), e);
+		}
+	}
+	private String nameValue(final String name, final String value) {
+		String togther = name + "=\"" + value + "\"";
+		return togther;
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/RepositoryElement.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/RepositoryElement.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,73 @@
+/* ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *    Licensed 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.depot.update.ant.cache;
+
+import java.net.URL;
+
+import org.apache.tools.ant.types.DataType;
+
+ 
+/**
+ * Describes a Repository for use in other Depot Ant tasks.
+ *  @version $Revision: $
+ */
+public class RepositoryElement extends DataType {
+	
+
+	private URL url;
+	private boolean remote;
+	private String id;
+
+	/**
+	 * @return Returns the remote.
+	 */
+	public boolean isRemote() {
+		return remote;
+		
+	}
+	/**
+	 * @param remote The remote to set.
+	 */
+	public void setRemote(boolean remote) {
+		this.remote = remote;
+	}
+	/**
+	 * @return Returns the url.
+	 */
+	public URL getUrl() {
+		return url;
+	}
+	/**
+	 * @param url The url to set.
+	 */
+	public void setUrl(URL url) {
+		this.url = url;
+	}
+	/**
+	 * @return Returns the id.
+	 */
+	public String getId() {
+		return id;
+	}
+	/**
+	 * @param id The id to set.
+	 */
+	public void setId(String id) {
+		this.id = id;
+		
+	}
+}

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/ResourceElement.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/ResourceElement.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,267 @@
+/*
+ * ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.update.ant.cache;
+import java.io.File;
+import java.util.List;
+import org.apache.depot.update.UpdateException;
+import org.apache.depot.update.ant.AntUtils;
+import org.apache.depot.update.impl.RepositorySetWrapper;
+import org.apache.depot.update.impl.ResourceUpdaterContext;
+import org.apache.depot.update.protocols.DefaultProtocolOperationsManager;
+import org.apache.depot.update.query.DefaultQueryEngine;
+import org.apache.depot.update.query.ResourceQuery;
+import org.apache.depot.update.query.ResourceResult;
+import org.apache.depot.update.repository.DefaultRepository;
+import org.apache.depot.update.repository.IRepository;
+import org.apache.depot.update.repository.RepositorySet;
+import org.apache.depot.update.resource.Resource;
+import org.apache.depot.update.resource.ResourceGroup;
+import org.apache.depot.update.resource.ResourceType;
+import org.apache.depot.update.resource.compare.VersionComparator;
+import org.apache.depot.update.resource.select.NameSelector;
+import org.apache.depot.update.resource.select.TypeSelector;
+import org.apache.depot.update.resource.select.VersionSelector;
+import org.apache.depot.update.util.io.ResolvedFile;
+import org.apache.depot.update.util.net.VirtualResourceLocator;
+import org.apache.depot.update.util.select.ISelector;
+import org.apache.depot.update.util.select.logic.AndSelector;
+import org.apache.depot.version.Version;
+import org.apache.depot.version.VersionException;
+import org.apache.depot.version.impl.VersionImporter;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.DataType;
+/**
+ * @version $Revision: $
+ */
+public class ResourceElement extends DataType {
+	private String group;
+	private String name;
+	private String version;
+	private String repository;
+	private String ext;
+	private String downloadedFrom;
+	private final Project project;
+	/**
+	 * @return Returns the name.
+	 */
+	public String getName() {
+		return name;
+	}
+	/**
+	 * @param name
+	 *            The name to set.
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+	/**
+	 * @return Returns the repository.
+	 */
+	public String getRepository() {
+		return repository;
+	}
+	/**
+	 * @param repository
+	 *            The repository to set.
+	 */
+	public void setRepository(String repository) {
+		this.repository = repository;
+	}
+	/**
+	 * @return Returns the version.
+	 */
+	public String getVersion() {
+		return version;
+	}
+	/**
+	 * @param version
+	 *            The version to set.
+	 */
+	public void setVersion(String version) {
+		this.version = version;
+	}
+	/**
+	 * @return Returns the ext.
+	 */
+	public String getExt() {
+		return ext;
+	}
+	/**
+	 * * The ext to set.
+	 */
+	public void setExt(String ext) {
+		this.ext = ext;
+	}
+	public String toString() {
+		return name + "-" + version + "." + ext + "@" + repository;
+	}
+	/**
+	 * @return
+	 */
+	Resource initResource() {
+		Resource r = new Resource(getResourceGroup(), name, getVersionObject(),
+				getResourceType(), ext, getFileName(), getLocation());
+		return r;
+	}
+	/**
+	 * @return
+	 */
+	private VirtualResourceLocator getLocation() {
+		ResolvedFile rf = ResolvedFile.resolve(new File(getFileName()));
+		VirtualResourceLocator vrl = new VirtualResourceLocator(rf);
+		// TODO Auto-generated method stub
+		return vrl;
+	}
+	/**
+	 * @return
+	 */
+	private String getFileName() {
+		// TODO Auto-generated method stub
+		return getName() + "-" + getVersion() + "." + getExt();
+	}
+	/**
+	 * @return
+	 */
+	ResourceType getResourceType() {
+		return ResourceType.JAVA_BINARY;// TODO fix
+	}
+	/**
+	 * @return
+	 */
+	private Version getVersionObject() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+	/**
+	 * @return
+	 */
+	ResourceGroup getResourceGroup() {
+		ResourceGroup rg = new ResourceGroup(group == null ? name : group);
+		return rg;
+	}
+	/**
+	 * @return Returns the group.
+	 */
+	public String getGroup() {
+		return group;
+	}
+	/**
+	 * @param group
+	 *            The group to set.
+	 */
+	public void setGroup(String group) {
+		this.group = group;
+	}
+	/**
+	 * @return
+	 */
+	public TypeSelector getResourceTypeSelector() {
+		// TODO Auto-generated method stub
+		return new TypeSelector(getResourceType());
+	}
+	/**
+	 * @return
+	 */
+	public IRepository getIRepository() {
+		RepositoryElement repositoryElement = (RepositoryElement) project
+				.getReference(getRepository());
+		return new DefaultRepository(repositoryElement.getId(),
+				new VirtualResourceLocator(repositoryElement.getUrl()));
+	}
+	/**
+	 *  
+	 */
+	public ResourceElement(Project project) {
+		super();
+		this.project = project;
+	}
+	public ISelector getResourceSelector() throws VersionException {
+		AndSelector set = new AndSelector();
+		set.addSelector(new NameSelector(name));
+		set.addSelector(new TypeSelector(getResourceType()));
+		if (null != version) {
+			set.addSelector(new VersionSelector(VersionImporter
+					.importVersion(version)));
+		}
+		return (ISelector) set;
+	}
+	/**
+	 * @return
+	 */
+	public String getDownloadedFrom() {
+		if (downloadedFrom == null) {
+			Resource resource = findBestRepoteResource();
+			if (resource != null) {
+			downloadedFrom=resource.getLocation().toExternalForm();
+			}
+		}
+		return downloadedFrom;
+	}
+	/**
+	 * @param downloadedFrom
+	 *            The downloadedFrom to set.
+	 */
+	void setDownloadedFrom(String downloadedFrom) {
+		this.downloadedFrom = downloadedFrom;
+	}
+	/**
+	 * @param this
+	 * @return
+	 */
+	Resource findBestRepoteResource() {
+		ResourceResult res = query(getIRepository());
+		Resource resource = null;
+		if (res.size() == 0) {
+			resource = null;
+		} else if (res.size() == 1) {
+			resource = ResourceResult.getFirstResource(res);
+		} else {
+			getProject().log(
+					"Found " + res.size() + " matches for " + this
+							+ " returning first", Project.MSG_VERBOSE);
+			resource = ResourceResult.getFirstResource(res);
+		}
+		return resource;
+	}
+	
+	ResourceResult query(IRepository repo) { //TODO
+		// experiment
+		getProject().log("Looking for " + this, Project.MSG_DEBUG);
+		try {
+			DefaultQueryEngine dqe = new DefaultQueryEngine();
+			ResourceQuery query = new ResourceQuery(getResourceGroup(),
+					getResourceSelector(), null, VersionComparator.REVERSE);
+			//TODO need to be a better way to sort by.
+			ResourceUpdaterContext context = new ResourceUpdaterContext();
+			context.setProtocolManager(new DefaultProtocolOperationsManager(
+					context));
+			RepositorySet repositorySet = RepositorySet.getRepositorySet(repo
+					.getIdentifier().getId(), true);
+			repositorySet.addRepository(repo);
+			RepositorySetWrapper rw = new RepositorySetWrapper(repositorySet,
+					context);
+			ResourceResult result = dqe.queryRepositories(rw, query);
+			return result;
+		} catch (VersionException e) {
+			throw new BuildException("Unable to process " + this, e);
+		} catch (UpdateException e) {
+			throw new BuildException("Unable to get " + this, e);
+		}
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/EnvironmentToolTask.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/EnvironmentToolTask.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,69 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed 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.depot.update.ant.tool;
+
+import org.apache.depot.common.log.LogConstants;
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.common.util.envsafe.ClassLoaderContext;
+import org.apache.depot.update.protocols.DefaultProtocolOperationsManager;
+import org.apache.depot.version.ant.util.AntLogListener;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+/**
+ * @author ajack
+ */
+public class EnvironmentToolTask extends Task {
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.tools.ant.Task#execute()
+	 */
+	public void execute() throws BuildException {
+
+		log("Execute RepositoryTool...", Project.MSG_DEBUG);
+
+		// Set logging context, to only errors...
+		Logger logger = Logger.pushContext(new AntLogListener(this));
+	
+		try {			
+			ClassLoaderContext context = new ClassLoaderContext(this);
+
+			// See which (if any) of these are loadable.
+			// Would have to imagine  one (plain JDK) is.	
+			testLoad(context, DefaultProtocolOperationsManager.URL_PROVIDER);
+			testLoad(context, DefaultProtocolOperationsManager.HTTP_CLIENT_PROVIDER);	
+			testLoad(context, DefaultProtocolOperationsManager.VFS_PROVIDER);	
+		}
+		finally {
+			Logger.popContext(logger);
+		}
+	}
+	
+	private void testLoad(ClassLoaderContext context, String clazzName) {
+		try{
+			Object o = context.attemptLoad(clazzName, "test");			
+			Logger.getLogger().info("Loaded [" + clazzName + "] as [" + o + "]");
+		}
+		catch (Throwable t)
+		{
+			Logger.getLogger().info("Failed to load [" + clazzName + "] : ", t);
+		}
+	}
+}

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/RepositoryToolTask.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/tool/RepositoryToolTask.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,196 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed 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.depot.update.ant.tool;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.depot.common.log.LogConstants;
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.update.UpdateException;
+import org.apache.depot.update.config.UpdateConfig;
+import org.apache.depot.update.impl.RepositoryWrapper;
+import org.apache.depot.update.impl.ResourceUpdaterContext;
+import org.apache.depot.update.monitor.Monitor;
+import org.apache.depot.update.monitor.StatisticsMonitor;
+import org.apache.depot.update.repository.IRepository;
+import org.apache.depot.update.repository.RepositorySet;
+import org.apache.depot.update.resource.ResourceGroup;
+import org.apache.depot.update.resource.ResourceSpecifier;
+import org.apache.depot.update.util.UpdateConstants;
+import org.apache.depot.update.util.select.AllSelector;
+import org.apache.depot.version.ant.util.AntLogListener;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+/**
+ * @author ajack
+ */
+public class RepositoryToolTask extends Task {
+
+	private String m_updater = UpdateConstants.DEFAULT;
+	private String m_repositories = UpdateConstants.DEFAULT;
+	private String m_group = null;
+
+	/**
+	 * @param string
+	 */
+	public void setRepositories(String string) {
+		m_repositories = string;
+	}
+
+	/**
+	 * @param string
+	 */
+	public void setUpdater(String updater) {
+		m_updater = updater;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.tools.ant.Task#execute()
+	 */
+	public void execute() throws BuildException {
+
+		log("Execute RepositoryTool...", Project.MSG_DEBUG);
+
+		// Set logging context, to only errors...
+		Logger logger = Logger.pushContext(LogConstants.ERROR,
+				new AntLogListener(this));
+
+		UpdateConfig.configure();
+
+		StatisticsMonitor statistics = new StatisticsMonitor();
+		Monitor monitor = Monitor.pushContext(statistics);
+
+		try {
+			log("RepositorySet: " + m_repositories);
+
+			ResourceUpdaterContext context = ResourceUpdaterContext.getDefaultContext();
+
+			//
+			// This uses default or configured stuff..
+			//
+			RepositorySet set = RepositorySet.getRepositorySet(m_repositories,
+					true);
+
+			int repoCnt = 0;
+			for (Iterator i = set.getRepositories().iterator(); i.hasNext(); repoCnt++) {
+				IRepository r = (IRepository) i.next();
+				RepositoryWrapper repo = new RepositoryWrapper(r, context);
+
+				log("Repository: " + repo + "[" + r.getClass().getName() + "]");
+
+				if (null == m_group) {
+					try {
+						// List groups ...
+						List groups = repo.listGroups(AllSelector.getInstance());
+
+						for (Iterator gi = groups.iterator(); gi.hasNext();) {
+							ResourceGroup group = (ResourceGroup) gi.next();
+
+							try {
+
+								List specifiers = repo.listSpecifiers(group,
+										AllSelector.getInstance());
+
+								log(" - Group: " + group + " (Specifiers : "
+										+ specifiers.size() + ")");
+
+								for (Iterator si = specifiers.iterator(); si.hasNext();) {
+									ResourceSpecifier specifier = (ResourceSpecifier) si.next();
+
+									log("  - " + specifier, Project.MSG_VERBOSE);
+								}
+							} catch (UpdateException re) {
+								Logger.getLogger().error(
+										" - Failed to list specifiers in group: "
+												+ group, re);
+							}
+						}
+					} catch (UpdateException re) {
+						Logger.getLogger().error(" - Failed to list groups: ",
+								re);
+					}
+				} else {
+					ResourceGroup group = new ResourceGroup(m_group);
+
+					try {
+						// List groups ...
+						List specifiers = repo.listSpecifiers(group,
+								AllSelector.getInstance());
+
+						for (Iterator gi = specifiers.iterator(); gi.hasNext();) {
+							ResourceSpecifier specifier = (ResourceSpecifier) gi.next();
+
+							log(" -  " + specifier, Project.MSG_VERBOSE);
+						}
+					} catch (UpdateException re) {
+						Logger.getLogger().error(" - Failed to list groups: ",
+								re);
+					}
+				}
+			}
+
+			log(" Artefact Statistics : Parsed=" + statistics.getParsed()
+					+ " Failed=" + statistics.getFailed() + " Ignored="
+					+ statistics.getIgnored());
+
+			List ignored = statistics.getIgnoredObjects();
+			for (Iterator i = ignored.iterator(); i.hasNext();) {
+				log(" Ignored : " + i.next());
+			}
+
+			List failed = statistics.getFailedObjects();
+			for (Iterator i = failed.iterator(); i.hasNext();) {
+				log(" Failed : " + i.next());
+			}
+
+			if (0 == repoCnt)
+				log("No repositories in set: " + m_repositories,
+						Project.MSG_WARN);
+		}
+		//		catch (RuperException re2) {
+		//			log(
+		//				"RepositoryTool failed: " + re2.getLocalizedMessage(),
+		//				Project.MSG_WARN);
+		//
+		//			throw new BuildException("RepositoryTool failed: ", re2);
+		//		}
+		finally {
+			Monitor.popContext(monitor);
+			Logger.popContext(logger);
+		}
+	}
+
+	/**
+	 * @return
+	 */
+	public String getGroup() {
+		return m_group;
+	}
+
+	/**
+	 * @param string
+	 */
+	public void setGroup(String string) {
+		m_group = string;
+	}
+
+}

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ResourceResult.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ResourceResult.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ResourceResult.java	Mon May 17 11:05:40 2004
@@ -109,4 +109,14 @@
 
 	}
 
+	/**
+	 * @param this
+	 * @return
+	 */
+	public static Resource getFirstResource(ResourceResult res) {
+		List l = (List) res.get(0);
+		Resource resource = (Resource) l.get(0);
+		return resource;
+	}
+
 }

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/AntTasksTests.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/AntTasksTests.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,48 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed 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.depot.update.ant;
+
+import org.apache.tools.ant.BuildFileTest;
+
+/**
+ * 
+ * @author $Author: arb_jack $
+ * @version $Revision: 1.1 $
+ */
+public class AntTasksTests extends BuildFileTest {
+
+	/**
+	 * Constructor for UpdateDependTaskTest.
+	 * @param arg0
+	 */
+	public AntTasksTests(String arg0) {
+		super(arg0);
+	}
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(AntTasksTests.class);
+	}
+
+	public void setUp() throws Exception {
+    	super.setUp();
+		configureProject("src/test/org/apache/depot/update/ant/anttasks.xml");
+	}
+
+	public void test1() {
+		executeTarget("typical");
+	}
+}

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/anttasks.xml
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/anttasks.xml	Mon May 17 11:05:40 2004
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<project name="update-repotool-test" basedir="." default="all">
+	<taskdef resource="depot-update-antlib.xml"/>	
+		
+	<target name="typical">
+		
+		<reposync group="junit" />
+		<reposync group="log4j" />
+		<reposync group="jxpath" />
+		
+		<repotool repositories="lib"/>
+	</target>
+	
+	<target name="all" depends="typical" />
+</project>

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/CachedResourceSetTaskTest.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/CachedResourceSetTaskTest.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,119 @@
+/*
+ * ========================================================================
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.update.ant.cache;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.depot.common.log.Logger;
+import org.apache.tools.ant.BuildFileTest;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.xml.sax.SAXException;
+/**
+ * @author <a href="http://incubator.apache.org/depot" >The Apache Incubator
+ *         Depot Project </a>
+ * @version $LastChangedRevision: 9844 $
+ */
+public class CachedResourceSetTaskTest extends BuildFileTest {
+	private final String SANDBOX = "build/test/sandbox";
+	/**
+	 * Constructor for RuperDependTaskTest.
+	 * 
+	 * @param arg0
+	 */
+	public CachedResourceSetTaskTest(String arg0) {
+		super(arg0);
+	}
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(CachedResourceSetTaskTest.class);
+	}
+	public void setUp() {
+		Logger.testInit();
+		configureProject("src/test/org/apache/depot/update/ant/cache/build.xml");
+	}
+	public void test1() {
+		try {
+			executeTarget("test1");
+			File file = new File(SANDBOX
+					+ "/helloworld/jars/helloworld-1.1.jar");
+			assertTrue("Expected " + file + " to  exists", file.exists());
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+	public void test2() {
+		try {
+			executeTarget("test2");
+			File file = new File(SANDBOX
+					+ "/helloworld/jars/helloworld-1.2.jar");
+			assertTrue("Expected " + file + " to  exists", file.exists());
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+	public void test3() {
+		try {
+			expectSpecificBuildException("test3",
+					"Only helloworld 1.1 and 1.2 exist's",
+					"Unable to find helloworld-1.3.jar@localtest");
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+	public void test4() {
+		try {
+			executeTarget("test4");
+			File file = new File(SANDBOX
+					+ "/helloworld/jars/helloworld-1.2.jar");
+			assertTrue("Expected " + file + " to  exists", file.exists());
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+	public void testNotFound() {
+		try {
+			expectSpecificBuildException("testNotFound",
+					"notfound does not exist",
+					"Unable to find notfound-1.2.jar@localtest");
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+	/**
+	 * Test the exporting of cached set test1.
+	 *  
+	 */
+	public void testExport1() throws FileNotFoundException, SAXException,
+			IOException, ParserConfigurationException {
+		try {
+			executeTarget("testExport1");
+			File generatedFile = new File("build/test1-export.build.xml");
+			File expectedFile = new File(
+					"build/expected-test1-export.build.xml");
+			assertTrue("Expected " + generatedFile + " to  exists",
+					generatedFile.exists());
+			XMLAssert
+					.assertXMLEqual("Exported cached set test1",
+							new FileReader(expectedFile), new FileReader(
+									generatedFile));
+		} finally {
+			System.out.println(getOutput());
+		}
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/build.xml
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/build.xml	Mon May 17 11:05:40 2004
@@ -0,0 +1,121 @@
+<!--
+$HeadURL: https://svn.apache.org/repos/asf/incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/build.xml $
+$LastChangedRevision: 10556 $
+
+Copyright 2004 The Apache Software Foundation
+Licensed 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.
+-->
+<project name="updateModule-test" basedir="../../../../../../../" default="test1">
+	<property name="localtest.dir" value="${basedir}/src/resources/test/repo" />
+
+
+
+	<property name="depot.home" value="${basedir}/build/depot-home" />
+	<property name="local.repository" value="${depot.home}/local-repository" />
+	<property name="sandbox.dir" value="build/test/sandbox" />
+
+	<path id="update.classpath">
+		<fileset dir="lib">
+			<include name="*.jar" />
+		</fileset>
+		<pathelement location="build/depot-update/classes" />
+	</path>
+
+	<typedef resource="depot-update-antlib.xml" classpathref="update.classpath" />
+	<repository id="maven" url="http://www.ibiblio.org/maven/" remote="true" />
+	<repository id="localtest" url="file:///${localtest.dir}" remote="true" />
+	<target name="test1" depends="clean-jars">
+
+		<!-- this test should find the 1.1 jar already in place. -->
+		<copy toDir="${depot.home}/local-repository">
+			<fileset dir="${localtest.dir}">
+				<include name="**/*1.1*" />
+			</fileset>
+		</copy>
+		<cachedset id="test1">
+			<resource name="helloworld" ext="jar" version="1.1" repository="localtest" />
+		</cachedset>
+		<copy toDir="${sandbox.dir}">
+			<fileset refid="test1.fileset" />
+		</copy>
+	</target>
+	<target name="test2" depends="clean-jars">
+		<!-- Since the local repo is cleaned this test should return the 1.2 jar downloaded for localtest -->
+		<cachedset id="test2">
+			<resource name="helloworld" ext="jar" version="1.2" repository="localtest" />
+		</cachedset>
+		<copy toDir="${sandbox.dir}">
+			<fileset refid="test2.fileset" />
+		</copy>
+	</target>
+	<target name="test3" depends="clean-jars">
+
+		<!-- helloworld 1.3 does not exist this should fail. -->
+		<cachedset id="test3">
+			<resource name="helloworld" ext="jar" version="1.3" repository="localtest" />
+		</cachedset>
+		<copy toDir="${sandbox.dir}">
+			<fileset refid="test3.fileset" />
+		</copy>
+	</target>
+	<target name="test4" depends="clean-jars">
+
+		<!-- this test should find the 1.2 jar from localtest -->
+		<copy toDir="${depot.home}/local-repository">
+			<fileset dir="${localtest.dir}">
+				<include name="**/*1.1*" />
+			</fileset>
+		</copy>
+		<cachedset id="test4">
+			<resource name="helloworld" ext="jar" version="1.2" repository="localtest" />
+		</cachedset>
+		<copy toDir="${sandbox.dir}">
+			<fileset refid="test4.fileset" />
+		</copy>
+	</target>
+
+
+	<target name="test99">
+		<!--cachedset id="foo">
+			<project name="xalan" version="4" module="http://gump.apache.org/modules/xalan.xml" />
+		</cachedset-->
+	</target>
+	<target name="testNotFound">
+		<cachedset id="testNotFound">
+			<resource name="notfound" ext="jar" version="1.2" repository="localtest" />
+		</cachedset>
+		<!-- have to use the chaced set before it is used. -->
+		<copy toDir="${sandbox.dir}">
+			<fileset refid="testNotFound.fileset" />
+		</copy>
+	</target>
+
+
+	<target name="testExport1" depends="test1">
+		<delete file="build/test1-export.build.xml" />
+		<path id="convert" location="${basedir}" />
+		<pathconvert property="converted" refid="convert" targetos="unix" />
+		<copy file="src/test/org/apache/depot/update/ant/test1-export.build.xml"
+		      tofile="build/expected-test1-export.build.xml" overwrite="true">
+			<filterset>
+				<filter token="basedir" value="${converted}" />
+			</filterset>
+		</copy>
+		<cachedsetexport refid="test1" toFile="build/test1-export.build.xml" />
+	</target>
+
+	<target name="clean-jars">
+		<delete dir="${local.repository}" />
+		<delete dir="${sandbox.dir}" />
+	</target>
+</project>

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/test1-export.build.xml
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/cache/test1-export.build.xml	Mon May 17 11:05:40 2004
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE cachedresourceset PUBLIC "-//APACHE//DTD CachedResource V0.1//EN" "http://incubator.apache.org/depot/dtd/cachedresource-v01.dtd">
+<cachedresourceset id="test1">
+    <resource name="helloworld" 
+              version="1.1" 
+              href="file://@basedir@/src/resources/test/repo/helloworld/jars/helloworld-1.1.jar"/>
+</cachedresourceset>

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/SynchronizeTaskTests.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/SynchronizeTaskTests.java	Mon May 17 11:05:40 2004
@@ -0,0 +1,63 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed 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.depot.update.ant.sync;
+
+import junit.framework.Assert;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileTest;
+
+/**
+ * 
+ * @author $Author: arb_jack $
+ * @version $Revision: 1.2 $
+ */
+public class SynchronizeTaskTests extends BuildFileTest {
+
+	/**
+	 * Constructor for RuperDependTaskTest.
+	 * @param arg0
+	 */
+	public SynchronizeTaskTests(String arg0) {
+		super(arg0);
+	}
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(SynchronizeTaskTests.class);
+	}
+
+	public void setUp() {
+		configureProject("src/test/org/apache/depot/update/ant/sync/reposync.xml");
+	}
+
+	public void test1() {
+		executeTarget("test1");
+	}
+
+	public void test3() {
+		boolean passed = false;
+		try {
+			executeTarget("test2");
+		}
+		catch (BuildException be) {
+			passed = true;
+		}
+
+		if (!passed)
+			Assert.fail("Should've complained about no arguments...");
+	}
+}

Added: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/reposync.xml
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/sync/reposync.xml	Mon May 17 11:05:40 2004
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<project name="ruper-synchronize-test" basedir="." default="all">
+	<taskdef resource="depot-update-antlib.xml"/>	
+		
+	<target name="test1">
+		<reposync group="test" />
+	</target>
+		
+	<target name="test2">
+		<!-- Intended to fail w/ "no args" message -->
+		<reposync />
+	</target>
+	
+	<target name="all" depends="test1,test2" />
+</project>