You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@depot.apache.org by ni...@apache.org on 2004/07/27 07:12:46 UTC

svn commit: rev 30761 - in incubator/depot/trunk/update/src/java/org/apache/depot/update: . ant/cache download impl query util/net/select

Author: nickchalko
Date: Tue Jul 27 00:12:45 2004
New Revision: 30761

Modified:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ArtifactUpdater.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedArtifactSet.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/download/DownloadManager.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/impl/RepositoryWrapper.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ArtifactResult.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/query/QueryEngine.java
   incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/select/ChildVrlSelector.java
Log:
The cachedset test is finally working.

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/ArtifactUpdater.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/ArtifactUpdater.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ArtifactUpdater.java	Tue Jul 27 00:12:45 2004
@@ -176,8 +176,9 @@
 				ArtifactQueryHelper.getArtifactQuery(artifact, m_repositorySet);
 		
 		List localInstances = get(artifactQuery);
-		
-		return (ArtifactInstance)localInstances.get(0);
+		//This always a list of lists  (ie grouped)
+		final List list = (List)localInstances.get(0);
+		return (ArtifactInstance)list.get(0);
 	}
 
 	/* (non-Javadoc)
@@ -231,7 +232,7 @@
 		RepositorySet repositorySet = query.getRepositorySet();
 
 		RepositorySetWrapper wrappers =
-			new RepositorySetWrapper(repositorySet, m_context);
+			new RepositorySetWrapper(repositorySet, m_context); 
 
 		return m_queryEngine.queryRepositories(wrappers, query);
 	}

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedArtifactSet.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedArtifactSet.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/ant/cache/CachedArtifactSet.java	Tue Jul 27 00:12:45 2004
@@ -16,6 +16,7 @@
  * ========================================================================
  */
 package org.apache.depot.update.ant.cache;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -32,6 +33,7 @@
 import org.apache.depot.update.ant.AntUtils;
 import org.apache.depot.update.query.ArtifactResult;
 import org.apache.depot.update.repository.DefaultRepository;
+import org.apache.depot.update.repository.RepositorySet;
 import org.apache.depot.update.util.io.ResolvedFile;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -46,16 +48,26 @@
  */
 public class CachedArtifactSet 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 CachedArtifactFileSet fileSet = new CachedArtifactFileSet(
 			this);
+
 	private final List resourceList = new ArrayList();
+
 	private ArtifactUpdater m_updater = null;
+
 	private boolean isAlwaysCheckRemote = false;
+
 	private boolean checkClassPath = true;
+
 	/**
 	 *  
 	 */
@@ -63,6 +75,7 @@
 		super();
 		this.project = project;
 	}
+
 	/**
 	 * @param resource
 	 * @return Artifact
@@ -72,12 +85,14 @@
 		resourceList.add(resource);
 		return resource;
 	}
+
 	/**
 	 * @return Returns the id.
 	 */
 	public String getId() {
 		return id;
 	}
+
 	/**
 	 * @param id
 	 *            The id to set.
@@ -86,25 +101,26 @@
 		this.id = id;
 		project.addReference(id + ".fileset", fileSet);
 	}
+
 	/**
 	 * @return
 	 */
-	FileScanner getFileScanner() throws UpdateException {		
+	FileScanner getFileScanner() throws UpdateException {
 		final DirectoryScanner scanner = new DirectoryScanner();
-		
+
 		// Set logging context..
 		Logger logger = Logger.pushContext(new AntLogListener(this));
 
-		try {			
+		try {
 			scanner.setBasedir(getRepoDir());
 			addArtifacts(scanner);
-		}
-		finally {
+		} finally {
 			Logger.popContext(logger);
 		}
-		
+
 		return scanner;
 	}
+
 	/**
 	 * @param scanner
 	 */
@@ -114,6 +130,7 @@
 			add(scanner, r);
 		}
 	}
+
 	/**
 	 * @param scanner
 	 * @param r
@@ -128,12 +145,13 @@
 			if (path.startsWith(basepath)) {
 				path = path.substring(basepath.length() + 1);
 			}
-			scanner.setIncludes(new String[]{path});
+			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
@@ -158,21 +176,24 @@
 		file = getCachedFile(r);
 		return file;
 	}
+
 	/**
-	 * @param r
+	 * @param element
 	 */
-	private void cacheFile(ArtifactElement r) {
+	private void cacheFile(ArtifactElement element) {
 		try {
-			ArtifactInstance artifactInstance = findBestRemoteArtifact(r);
+			ArtifactInstance artifactInstance = findBestRemoteArtifact(element);
 			if (artifactInstance != null) {
-				
-				downLoadRemoteResult(artifactInstance);
+
+				downLoadRemoteResult(artifactInstance, element.getIRepository());
 			}
 			return;
 		} catch (Exception e) {
-			throw new BuildException("Unable to get local copy of " + r, e);
+			throw new BuildException("Unable to get local copy of " + element,
+					e);
 		}
 	}
+
 	/**
 	 * @param r
 	 * @return
@@ -180,6 +201,7 @@
 	ArtifactInstance findBestRemoteArtifact(ArtifactElement r) {
 		return r.findBestRemoteArtifact();
 	}
+
 	/**
 	 * @param r
 	 */
@@ -200,6 +222,7 @@
 					e);
 		}
 	}
+
 	/**
 	 * @return
 	 */
@@ -215,6 +238,7 @@
 				"Local Repository Cache", true);
 		return repo;
 	}
+
 	/**
 	 * Should the cached set always look the remore repository for updates
 	 * 
@@ -223,6 +247,7 @@
 	public boolean isAlwaysCheckRemote() {
 		return isAlwaysCheckRemote;
 	}
+
 	/**
 	 * Should the cached set always look the remore repository for updates
 	 * 
@@ -232,6 +257,7 @@
 	public void setAlwaysCheckRemote(boolean isAlwaysCheckRemote) {
 		this.isAlwaysCheckRemote = isAlwaysCheckRemote;
 	}
+
 	/**
 	 * @param r
 	 * @param res
@@ -241,9 +267,11 @@
 		ArtifactInstance instance = ArtifactResult.getFirstArtifact(res);
 		return instance.getLocator().getLocation().getFile();
 	}
+
 	private ArtifactResult query(ArtifactElement r, Repository repo) {
 		return r.query(repo);
 	}
+
 	/**
 	 * @return
 	 */
@@ -252,14 +280,22 @@
 				LOCAL_REPOSITORY_ID, ResolvedFile.resolve(getRepoDir()));
 		return repository;
 	}
+
 	/**
+	 * @param repository
 	 * @param resource
 	 * @throws UpdateException
 	 */
-	private void downLoadRemoteResult(ArtifactInstance artifactInstance) throws UpdateException {
+	private void downLoadRemoteResult(ArtifactInstance artifactInstance,
+			Repository repository) throws UpdateException {
 		ArtifactUpdater ru = ArtifactUpdaterFactory.getDefaultUpdater();
-		ru.getInstance(artifactInstance.getArtifact());  // TODO are we doing this twice?.
+		ru.setTargetRepository(getLocalRepository());
+		ru.setRepositorySet(new RepositorySet(repository.getIdentifier()
+				+ " set", repository));
+		ru.getInstance(artifactInstance.getArtifact()); // TODO are we doing
+		// this twice?.
 	}
+
 	/**
 	 * @return Returns the unmodifiableList of resources.
 	 */

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/download/DownloadManager.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/download/DownloadManager.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/download/DownloadManager.java	Tue Jul 27 00:12:45 2004
@@ -69,17 +69,17 @@
 			new RepositoryWrapper(targetRepository, m_context);
 
 		for (Iterator i = instances.iterator(); i.hasNext();) {
-			ArtifactInstance resource = (ArtifactInstance) i.next();
+			ArtifactInstance artifact = (ArtifactInstance) i.next();
 			
 			try {
-				target.publishArtifact(resource);
+				target.publishArtifact(artifact);
 			} catch (Exception e) {
 				//
 				// (1) log (2) stash in result set error table
 				//
 				throw new RepositoryException(
 					targetRepository,
-					"Failed to publish resource: " + resource,
+					"Failed to publish resource: " + artifact,
 					e);
 			}
 		}

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/impl/RepositoryWrapper.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/impl/RepositoryWrapper.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/impl/RepositoryWrapper.java	Tue Jul 27 00:12:45 2004
@@ -285,7 +285,7 @@
 	}
 
 	public String toString() {
-		return m_repository.toString();
+		return m_repository==null?"null":m_repository.toString();
 	}
 
 	public void dump(PrintWriter out, int depth, boolean verbose) {

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ArtifactResult.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ArtifactResult.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/query/ArtifactResult.java	Tue Jul 27 00:12:45 2004
@@ -27,18 +27,21 @@
 import org.apache.depot.update.ArtifactInstance;
 
 /**
+ * A ArtifactResult is a list of lists of resources.
+ * 
  * @author arb_jack
- *
- * A ResourceResult is a list of lists of resources.
+ * 
+ * 
  *  
  */
 public class ArtifactResult extends ArrayList implements Dumpable {
 
 	public boolean m_successful = true;
+
 	public AnnotationScratchpad m_notes = null;
 
 	/**
-	 * 
+	 *  
 	 */
 	public ArtifactResult() {
 		super();
@@ -92,19 +95,19 @@
 	public void setSuccessful(boolean b) {
 		m_successful = b;
 	}
+
 	public void dump(PrintWriter out, int depth, boolean verbose) {
 		//String indent = DebugUtils.getIndent(depth);
 
 		out.println("Successful:" + m_successful);
-		
-		DebugUtils.printSeparator(out,depth+1);
+
+		DebugUtils.printSeparator(out, depth + 1);
 		DebugUtils.dumpList(out, depth + 1, "Resources: ", verbose, this);
-		
-		if ( (null != m_notes) && m_notes.hasAnnotations())
-		{
-			DebugUtils.printSeparator(out,depth+1);
-			m_notes.dump(out,depth+1,verbose);
-			
+
+		if ((null != m_notes) && m_notes.hasAnnotations()) {
+			DebugUtils.printSeparator(out, depth + 1);
+			m_notes.dump(out, depth + 1, verbose);
+
 		}
 
 	}
@@ -119,4 +122,4 @@
 		return resource;
 	}
 
-}
+}
\ No newline at end of file

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/query/QueryEngine.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/query/QueryEngine.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/query/QueryEngine.java	Tue Jul 27 00:12:45 2004
@@ -17,6 +17,7 @@
 package org.apache.depot.update.query;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -73,15 +74,13 @@
 			DebugUtils.printSeparator();
 			DebugUtils.dump(query);
 		}
-
-		// A result object, and the results (unpackaged) list
-		ArtifactResult result = new ArtifactResult();
-
+		ArtifactResult result;
 		// Package the results..
-		if (resources.isEmpty())
+		if (resources.isEmpty()) {
 			Logger.getLogger().warn(
 					Messages.getString(MessageConstants.NO_RESOURCES_FOUND));
-		else {
+			result = new ArtifactResult(Collections.EMPTY_LIST);
+		} else {
 			Logger.getLogger().info(
 					Messages.getString(MessageConstants.RESOURCES_FOUND));
 
@@ -90,11 +89,12 @@
 
 			if (Logger.getLogger().isDebug()) {
 				DebugUtils.printSeparator();
-				DebugUtils.dump("All Results", result);
+				DebugUtils.dump("resources ", resources);
 			}
-			
-			// Perform the group by...			
-			groupBy(result, resources, groupBy);
+
+			// Perform the group by...
+
+			result = groupBy(resources, groupBy);
 
 			if (Logger.getLogger().isDebug()) {
 				DebugUtils.printSeparator();
@@ -103,14 +103,16 @@
 
 			// Order the various groups
 			if (null == orderBy)
-				orderBy = StandardArtifactComparisons.getNameTypeVersionComparatorSequence();
+				orderBy = StandardArtifactComparisons
+						.getNameTypeVersionComparatorSequence();
 			orderBy(result, orderBy);
 
 			if (Logger.getLogger().isDebug()) {
 				DebugUtils.printSeparator();
 				DebugUtils.dump("Final (Grouped/Ordered) Results", result);
 
-				for (Iterator i = ArtifactResultHelper.getArtifactList(result).iterator(); i.hasNext();) {
+				for (Iterator i = ArtifactResultHelper.getArtifactList(result)
+						.iterator(); i.hasNext();) {
 					Monitor.getMonitor().notify(
 							new ArtifactEvent(ArtifactEvent.RESULT,
 									(ArtifactInstance) i.next()));
@@ -123,8 +125,8 @@
 	}
 
 	/**
-	 * Gather all the artifacts for these groups from these
-	 * repositories, and return (for filtering/grouping/ordering).
+	 * Gather all the artifacts for these groups from these repositories, and
+	 * return (for filtering/grouping/ordering).
 	 * 
 	 * @param wrappers
 	 * @param resourceGroups
@@ -143,14 +145,15 @@
 		//:TODO: Total Hack, just to allow something...
 		// Rework w/ correct configurable components
 		int searched = 0;
-		for (Iterator i = wrappers.getRepositoryWrappers().iterator(); i.hasNext();) {
+		for (Iterator i = wrappers.getRepositoryWrappers().iterator(); i
+				.hasNext();) {
 			RepositoryWrapper repo = (RepositoryWrapper) i.next();
 			try {
 				Logger.getLogger().debug(
 						Messages.getString(MessageConstants.SEARCH_REPOSITORY,
 								repo));
 				searched += 1;
-				
+
 				// Look for all groups in lists
 				int gsearched = 0;
 				for (Iterator ii = resourceGroups.iterator(); ii.hasNext();) {
@@ -182,20 +185,21 @@
 						results.addAll(resources);
 					}
 				}
-				
-				if (0 == gsearched )
+
+				if (0 == gsearched)
 					Logger.getLogger().warn("No groups searched");
-				
+
 			} catch (Exception e) {
-				String message = Messages.getString(MessageConstants.LIST_FAILED);
+				String message = Messages
+						.getString(MessageConstants.LIST_FAILED);
 
 				Logger.getLogger().warn(message, e);
 
 				// :TODO: results.getNotes().warning(message, e);
 			}
 		}
-		
-		if (0 == searched )
+
+		if (0 == searched)
 			Logger.getLogger().warn("No repositories searched");
 
 		return results;
@@ -207,8 +211,8 @@
 	// each group lists be same comparator.
 	//
 	//
-	private void groupBy(ArtifactResult result, List allResults,
-			Comparator groupBy) {
+	private ArtifactResult groupBy(List allResults, Comparator groupBy) {
+		ArtifactResult result = new ArtifactResult();
 
 		if (null != groupBy) {
 
@@ -242,6 +246,7 @@
 			// A single list (one group)...
 			result.add(allResults);
 		}
+		return result;
 	}
 
 	//

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/select/ChildVrlSelector.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/select/ChildVrlSelector.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/util/net/select/ChildVrlSelector.java	Tue Jul 27 00:12:45 2004
@@ -37,7 +37,8 @@
 	}
 
 	public boolean selectVrl(VirtualResourceLocator vrl) {
-		return (vrl.getParent().equals(m_parent));
+		final VirtualResourceLocator parent = vrl.getParent();
+		return (parent.equals(m_parent));
 	}
 
 	public String toString() {