SF.net SVN: ant-contrib: [87] trunk/ant-contrib/src/java/net/sf/antcontrib/ net/URLImportTask.java

[email protected]
Newsgroups gmane.comp.java.ant-contrib.devel
Message-ID <[email protected]>
Revision: 87
          http://svn.sourceforge.net/ant-contrib/?rev=87&view=rev
Author:   mattinger
Date:     2007-03-01 15:19:57 -0800 (Thu, 01 Mar 2007)

Log Message:
-----------
Finishing correction of how import task calls Ivy API

Modified Paths:
--------------
    trunk/ant-contrib/src/java/net/sf/antcontrib/net/URLImportTask.java

Modified: trunk/ant-contrib/src/java/net/sf/antcontrib/net/URLImportTask.java
===================================================================
--- trunk/ant-contrib/src/java/net/sf/antcontrib/net/URLImportTask.java	2007-03-01 21:54:39 UTC (rev 86)
+++ trunk/ant-contrib/src/java/net/sf/antcontrib/net/URLImportTask.java	2007-03-01 23:19:57 UTC (rev 87)
@@ -17,9 +17,11 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.ParseException;
 import java.util.Date;
+import java.util.List;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -28,7 +30,9 @@
 import org.apache.tools.ant.taskdefs.ImportTask;
 
 import fr.jayasoft.ivy.Artifact;
+import fr.jayasoft.ivy.DefaultDependencyDescriptor;
 import fr.jayasoft.ivy.DefaultModuleDescriptor;
+import fr.jayasoft.ivy.DependencyDescriptor;
 import fr.jayasoft.ivy.DependencyResolver;
 import fr.jayasoft.ivy.Ivy;
 import fr.jayasoft.ivy.IvyContext;
@@ -36,13 +40,21 @@
 import fr.jayasoft.ivy.ModuleDescriptor;
 import fr.jayasoft.ivy.ModuleId;
 import fr.jayasoft.ivy.ModuleRevisionId;
+import fr.jayasoft.ivy.ResolveData;
+import fr.jayasoft.ivy.ResolvedModuleRevision;
+import fr.jayasoft.ivy.ant.IvyConfigure;
+import fr.jayasoft.ivy.filter.FilterHelper;
+import fr.jayasoft.ivy.latest.LatestRevisionStrategy;
 import fr.jayasoft.ivy.report.ArtifactDownloadReport;
+import fr.jayasoft.ivy.report.ConfigurationResolveReport;
 import fr.jayasoft.ivy.report.DownloadStatus;
+import fr.jayasoft.ivy.report.ResolveReport;
 import fr.jayasoft.ivy.repository.Repository;
 import fr.jayasoft.ivy.resolver.FileSystemResolver;
 import fr.jayasoft.ivy.resolver.IvyRepResolver;
 import fr.jayasoft.ivy.resolver.URLResolver;
 import fr.jayasoft.ivy.util.MessageImpl;
+import fr.jayasoft.ivy.version.LatestVersionMatcher;
 
 /***
  * Task to import a build file from a url.  The build file can be a build.xml,
@@ -108,7 +120,7 @@
 
 	public void execute()
 		throws BuildException {
-
+		
 		if (! verbose) {
 			IvyContext.getContext().setMessageImpl(
 					new MessageImpl() {
@@ -137,6 +149,7 @@
 		DependencyResolver resolver = null;
 		Repository rep = null;
 		
+		
 		if (repositoryUrl != null) {
 			resolver = new URLResolver();
 			((URLResolver)resolver).addArtifactPattern(
@@ -186,27 +199,38 @@
 		ivy.addResolver(resolver);
 		ivy.setDefaultResolver(resolver.getName());
 		
+		
+		try {
 		ModuleId moduleId =
 			new ModuleId(org, module);		
 		ModuleRevisionId revId =
 			new ModuleRevisionId(moduleId, rev);
-		ModuleDescriptor md =
-			new DefaultModuleDescriptor(revId, "integration", new Date());		
-		Artifact artifact =
-			new MDArtifact(md, module, type, type);
 		
-		ArtifactDownloadReport report =
-			ivy.download(artifact, null);
+		ResolveReport resolveReport = ivy.resolve(
+                ModuleRevisionId.newInstance(org, module, rev),
+            new String[] { "*" },
+            false,
+            true,
+            ivy.getDefaultCache(),
+            new Date(),
+            ivy.doValidate(),
+            false,
+            false,
+            FilterHelper.getArtifactTypeFilter(type));
 		
-		DownloadStatus status = report.getDownloadStatus();
-		if (status == DownloadStatus.FAILED) {
-			throw new BuildException("Could not resolve resource.");
+		if (resolveReport.hasError()) {
+			throw new BuildException("Could not resolve resource for: " +
+					"org=" + org +
+					";module=" + module +
+					";rev=" + rev);
 		}
-		
-		String path = ivy.getArchivePathInCache(artifact);
-		
-		File file = new File(ivy.getDefaultCache(), path);
-		
+
+		ModuleDescriptor desc = resolveReport.getModuleDescriptor();
+		List artifacts = resolveReport.getArtifacts();
+		Artifact artifact = (Artifact) artifacts.get(0);
+		log("Fetched revision " + artifact.getModuleRevisionId().getRevision());
+		File file = ivy.getArchiveFileInCache(ivy.getDefaultCache(), artifact);
+				
 		File importFile = null;
 		
 	    if ("xml".equalsIgnoreCase(type)) {
@@ -237,5 +261,12 @@
 	    importTask.setFile(importFile.getAbsolutePath());
 	    importTask.perform();
 	    log("Import complete.", Project.MSG_INFO);
+		}
+		catch (ParseException e) {
+			throw new BuildException(e);
+		}
+		catch (IOException e) {
+			throw new BuildException(e);
+		}
 	}
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.