incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickcha...@apache.org
Subject svn commit: rev 6948 - in incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant: . sandbox/chalko
Date Mon, 01 Mar 2004 09:13:44 GMT
Author: nickchalko
Date: Mon Mar  1 01:13:43 2004
New Revision: 6948

Removed:
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/Repository.java
Modified:
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/antlib.xml
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RepositoryElement.java
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/ResourceElement.java
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperFileSet.java
   incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperSet.java
Log:
Ruperset for files in the LocalRepo  are now working!.

Modified: incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/antlib.xml
==============================================================================
--- incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/antlib.xml	(original)
+++ incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/antlib.xml	Mon Mar  1 01:13:43
2004
@@ -16,7 +16,7 @@
 <antlib>
     <typedef name="ruperset" classname="org.apache.ruper.ant.sandbox.chalko.RuperSet"/>
     <typedef name="resource" classname="org.apache.ruper.ant.sandbox.chalko.ResourceElement"/>
-    <typedef name="repository" classname="org.apache.ruper.ant.sandbox.chalko.Repository"/>
+    <typedef name="repository" classname="org.apache.ruper.ant.sandbox.chalko.RepositoryElement"/>
     <typedef name="repotool" classname="org.apache.ruper.ant.task.RepositoryToolTask"/>
     <typedef name="reposync" classname="org.apache.ruper.ant.task.SynchronizeTask"/>
 </antlib>

Modified: incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RepositoryElement.java
==============================================================================
--- incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RepositoryElement.java
(original)
+++ incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RepositoryElement.java
Mon Mar  1 01:13:43 2004
@@ -29,6 +29,7 @@
 
 	private URL url;
 	private boolean remote;
+	private String id;
 
 	/**
 	 * @return Returns the remote.
@@ -53,5 +54,18 @@
 	 */
 	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;
+		
 	}
 }

Modified: incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/ResourceElement.java
==============================================================================
--- incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/ResourceElement.java
(original)
+++ incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/ResourceElement.java
Mon Mar  1 01:13:43 2004
@@ -15,10 +15,19 @@
  * ========================================================================
  */
 package org.apache.ruper.ant.sandbox.chalko;
+import java.io.File;
+import org.apache.ruper.impl.RepositoryObject;
+import org.apache.ruper.repository.DefaultRepository;
+import org.apache.ruper.repository.IRepository;
+import org.apache.ruper.repository.RepositoryManager;
 import org.apache.ruper.resource.Resource;
 import org.apache.ruper.resource.ResourceGroup;
 import org.apache.ruper.resource.ResourceType;
+import org.apache.ruper.resource.select.TypeSelector;
+import org.apache.ruper.tool.RepositoryTool;
+import org.apache.ruper.util.io.ResolvedFile;
 import org.apache.ruper.util.net.VirtualResourceLocator;
+import org.apache.tools.ant.Project;
 import org.apache.version.Version;
 /**
  * @version $Revision: $
@@ -29,6 +38,7 @@
 	private String version;
 	private String repository;
 	private String ext;
+	private final Project project;
 	/**
 	 * @return Returns the name.
 	 */
@@ -96,22 +106,23 @@
 	 * @return
 	 */
 	private VirtualResourceLocator getLocation() {
+		ResolvedFile rf = ResolvedFile.resolve(new File(getFileName()));
+		VirtualResourceLocator vrl = new VirtualResourceLocator(rf);
 		// TODO Auto-generated method stub
-		return null;
+		return vrl;
 	}
 	/**
 	 * @return
 	 */
 	private String getFileName() {
 		// TODO Auto-generated method stub
-		return null;
+		return getName() + "-" + getVersion() + "." + getExt();
 	}
 	/**
 	 * @return
 	 */
-	private ResourceType getResourceType() {
-		// TODO Auto-generated method stub
-		return null;
+	ResourceType getResourceType() {
+		return ResourceType.JAVA_BINARY;// TODO fic
 	}
 	/**
 	 * @return
@@ -123,9 +134,9 @@
 	/**
 	 * @return
 	 */
-	private ResourceGroup getResourceGroup() {
-		// TODO Auto-generated method stub
-		return null;
+	ResourceGroup getResourceGroup() {
+		ResourceGroup rg = new ResourceGroup(group == null ? name : group);
+		return rg;
 	}
 	/**
 	 * @return Returns the group.
@@ -139,5 +150,28 @@
 	 */
 	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;
 	}
 }

Modified: incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperFileSet.java
==============================================================================
--- incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperFileSet.java
(original)
+++ incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperFileSet.java
Mon Mar  1 01:13:43 2004
@@ -25,14 +25,17 @@
 final class RuperFileSet extends FileSet {
 	private final RuperSet ruperSet;
 	private boolean initialized = false;
+	private FileScanner scanner;
 	RuperFileSet(RuperSet ruperSet) {
 		this.ruperSet = ruperSet;
 	}
 	private synchronized void initialize() {
 		if (!initialized) {
-			FileScanner scanner = ruperSet.getFileScanner();
+			 scanner = ruperSet.getFileScanner();
+			String [] includes= scanner.getIncludedFiles();
 			setDir(scanner.getBasedir());
 			setupDirectoryScanner(scanner, ruperSet.getProject());
+
 		}
 		initialized = true;
 	}

Modified: incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperSet.java
==============================================================================
--- incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperSet.java
(original)
+++ incubator/depot/trunk/ruper/src/java/ant/org/apache/ruper/ant/sandbox/chalko/RuperSet.java
Mon Mar  1 01:13:43 2004
@@ -22,8 +22,17 @@
 import java.util.List;
 import org.apache.ruper.ResourceUpdater;
 import org.apache.ruper.RuperException;
+import org.apache.ruper.impl.RepositorySetWrapper;
+import org.apache.ruper.impl.ResourceUpdaterContext;
+import org.apache.ruper.messaging.ResourceRequest;
+import org.apache.ruper.protocols.DefaultProtocolOperationsManager;
+import org.apache.ruper.query.DefaultQueryEngine;
+import org.apache.ruper.query.ResourceQuery;
+import org.apache.ruper.query.ResourceQueryHelper;
+import org.apache.ruper.query.ResourceResult;
 import org.apache.ruper.repository.DefaultRepository;
 import org.apache.ruper.repository.IRepository;
+import org.apache.ruper.repository.RepositorySet;
 import org.apache.ruper.resource.Resource;
 import org.apache.ruper.resource.ResourceGroup;
 import org.apache.ruper.util.io.ResolvedFile;
@@ -32,6 +41,8 @@
 import org.apache.tools.ant.FileScanner;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.DataType;
+import org.apache.version.util.debug.DebugUtils;
+import sun.security.action.GetBooleanAction;
 /**
  * A locally cached repository backed set of resources.
  * 
@@ -56,7 +67,7 @@
 	 * @return Resource
 	 */
 	public ResourceElement createResource() {
-		ResourceElement resource = new ResourceElement();
+		ResourceElement resource = new ResourceElement(project);
 		resourceList.add(resource);
 		return resource;
 	}
@@ -98,20 +109,116 @@
 	 */
 	private void add(DirectoryScanner scanner, ResourceElement r) {
 		log("Looking for " + r, Project.MSG_DEBUG);
+		File f = findLocalFile(r);
+		if (f == null) {
+			f = downLoadRepoteFile(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);
+		}
+	}
+	/**
+	 * @param r
+	 * @return
+	 */
+	private File downLoadRepoteFile(ResourceElement r) {
+		try {
+			ResourceResult res = query(r, r.getIRepository());
+			if (res.size() == 0) {
+				return null;
+			} else if (res.size() == 1) {
+				downLoadRemoteResult(res);
+				return findLocalFile(r);
+			} else {
+				log("Found " + res.size() + " matches for " + r
+						+ " returning first", Project.MSG_VERBOSE);
+				downLoadRemoteResult(res);
+				return findLocalFile(r);
+			}
+		} catch (Exception e) {
+			throw new BuildException("Unable to get local copy of " + r, e);
+		}
+	}
+	/**
+	 * @param res
+	 * @throws RuperException
+	 */
+	private void downLoadRemoteResult(ResourceResult res) throws RuperException {
+		Resource resource= getFirstResource(res);
 		ResourceUpdater ru = new ResourceUpdater();
-		ru.setTargetRepository(getRepository());
-		Resource resource = r.initResource();
+		ru.downloadResource(resource,getLocalRepository());
+	}
+	/**
+	 * @param r
+	 * @return
+	 */
+	private File findLocalFile(ResourceElement r) {
+		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() + " mathees for " + r
+						+ " returning first", Project.MSG_VERBOSE);
+				return getFirstFile(res);
+			}
+		} catch (Exception e) {
+			throw new BuildException("Unable to get local copy of " + r, e);
+		}
+	}
+	/**
+	 * @param r
+	 * @param res
+	 * @return
+	 */
+	private File getFirstFile(ResourceResult res) throws Exception {
+		Resource resource = getFirstResource(res);
+		return resource.getLocation().getFile();
+	}
+	/**
+	 * @param res
+	 * @return
+	 */
+	private Resource getFirstResource(ResourceResult res) {
+		List l = (List) res.get(0);
+		Resource resource = (Resource) l.get(0);
+		return resource;
+	}
+	private ResourceResult query(ResourceElement r, IRepository repo) { //TODO
+		// experiment
+		log("Looking for " + r, Project.MSG_DEBUG);
 		try {
-			ru.downloadResource(resource);
+			DefaultQueryEngine dqe = new DefaultQueryEngine();
+			ResourceQuery query = new ResourceQuery(r.getResourceGroup(), r
+					.getResourceTypeSelector(), null, null);
+			ResourceUpdaterContext context = new ResourceUpdaterContext();
+			context.setProtocolManager(new DefaultProtocolOperationsManager(
+					context));
+			RepositorySet repositorySet = RepositorySet.getRepositorySet(
+					getId(), true);
+			repositorySet.addRepository(repo);
+			RepositorySetWrapper rw = new RepositorySetWrapper(repositorySet,
+					context);
+			ResourceResult result = dqe.queryRepositories(rw, query);
+			return result;
 		} catch (RuperException e) {
-			throw new BuildException("Unable to get "+r,e);
+			throw new BuildException("Unable to get " + r, e);
 		}
 	}
-
 	/**
 	 * @return
 	 */
-	private IRepository getRepository() {
+	private IRepository getLocalRepository() {
 		DefaultRepository repository = new DefaultRepository(
 				LOCAL_REPOSITORY_ID, ResolvedFile.resolve(getRepoDir()));
 		return repository;

Mime
View raw message