From dc57e9387cd41ae4973d7a619fae69ce7c74abe1 Mon Sep 17 00:00:00 2001 From: mattinger Date: Mon, 16 Jun 2008 17:38:26 +0000 Subject: Adding in Ivy 2.0 support, but maintaining backward compatibility with Ivy 1.4.1 git-svn-id: file:///home/sven/projects/JOGL/temp/ant-contrib/svn/ant-contrib-code/ant-contrib/trunk@171 32d7a393-a5a9-423c-abd3-5d954feb1f2f --- ivy-conf.xml | 2 +- ivy.xml | 6 +- lib/ivy/jars/ivy-2.0.0-rc1.jar | Bin 0 -> 840894 bytes .../java/net/sf/antcontrib/net/Ivy14Adapter.java | 130 +++++++++++++++++ .../java/net/sf/antcontrib/net/Ivy20Adapter.java | 133 +++++++++++++++++ .../java/net/sf/antcontrib/net/IvyAdapter.java | 6 + .../java/net/sf/antcontrib/net/URLImportTask.java | 157 ++++++++------------- 7 files changed, 334 insertions(+), 100 deletions(-) create mode 100644 lib/ivy/jars/ivy-2.0.0-rc1.jar create mode 100644 src/main/java/net/sf/antcontrib/net/Ivy14Adapter.java create mode 100644 src/main/java/net/sf/antcontrib/net/Ivy20Adapter.java create mode 100644 src/main/java/net/sf/antcontrib/net/IvyAdapter.java diff --git a/ivy-conf.xml b/ivy-conf.xml index 4a778b1..dc022c8 100644 --- a/ivy-conf.xml +++ b/ivy-conf.xml @@ -1,5 +1,5 @@ - + diff --git a/ivy.xml b/ivy.xml index c313e3e..881dc62 100644 --- a/ivy.xml +++ b/ivy.xml @@ -18,7 +18,7 @@ conf="default->default" /> + "); + fw.write(""); + fw.write(""); + if (repositoryDir != null) { + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + } + else { + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + } + fw.write(""); + + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + fw.close(); + + + fw = null; + + configure.setFile(temp); + } + catch (IOException e) { + throw new BuildException(e); + } + finally { + try { + if (fw != null) { + fw.close(); + fw = null; + } + } + catch (IOException e) { + ; + } + } + } + + configure.execute(); + } + + public void fileset(URLImportTask task, String setId) { + String org = task.getOrg(); + String module = task.getModule(); + String rev = task.getRev(); + String conf = task.getConf(); + + IvyCacheFileset cacheFileSet = new IvyCacheFileset(); + cacheFileSet.setProject(task.getProject()); + cacheFileSet.setLocation(task.getLocation()); + cacheFileSet.setOwningTarget(task.getOwningTarget()); + cacheFileSet.setTaskName(task.getTaskName()); + cacheFileSet.setInline(true); + cacheFileSet.setOrganisation(org); + cacheFileSet.setModule(module); + cacheFileSet.setRevision(rev); + cacheFileSet.setConf(conf); + cacheFileSet.init(); + cacheFileSet.setSetid(setId); + cacheFileSet.execute(); + } + +} diff --git a/src/main/java/net/sf/antcontrib/net/Ivy20Adapter.java b/src/main/java/net/sf/antcontrib/net/Ivy20Adapter.java new file mode 100644 index 0000000..116b1f7 --- /dev/null +++ b/src/main/java/net/sf/antcontrib/net/Ivy20Adapter.java @@ -0,0 +1,133 @@ +package net.sf.antcontrib.net; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.apache.ivy.ant.IvyAntSettings; +import org.apache.ivy.ant.IvyCacheFileset; +import org.apache.tools.ant.BuildException; + +public class Ivy20Adapter + implements IvyAdapter { + + public void configure(URLImportTask task) { + IvyAntSettings configure = new IvyAntSettings(); + configure.setProject(task.getProject()); + configure.setLocation(task.getLocation()); + configure.setOwningTarget(task.getOwningTarget()); + configure.setTaskName(task.getTaskName()); + configure.setOverride("true"); + configure.setId("urlimporttask"); + configure.init(); + + URL ivyConfUrl = task.getIvyConfUrl(); + File ivyConfFile = task.getIvyConfFile(); + String repositoryUrl = task.getRepositoryUrl(); + File repositoryDir = task.getRepositoryDir(); + String ivyPattern = task.getIvyPattern(); + String artifactPattern = task.getArtifactPattern(); + + if (ivyConfUrl != null) { + if (ivyConfUrl.getProtocol().equalsIgnoreCase("file")) { + String path = ivyConfUrl.getPath(); + File f = new File(path); + if (! f.isAbsolute()) { + f = new File(task.getProject().getBaseDir(), path); + } + configure.setFile(f); + } + else { + try { + configure.setUrl(ivyConfUrl.toExternalForm()); + } + catch (MalformedURLException e) { + throw new BuildException(e); + } + } + } + else if (ivyConfFile != null) { + configure.setFile(ivyConfFile); + } + else if (repositoryDir != null || + repositoryUrl != null) { + File temp = null; + FileWriter fw = null; + + try { + temp = File.createTempFile("ivyconf", ".xml"); + temp.deleteOnExit(); + fw = new FileWriter(temp); + fw.write(""); + fw.write(""); + fw.write(""); + if (repositoryDir != null) { + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + } + else { + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + } + fw.write(""); + + fw.write(""); + fw.write(""); + fw.write(""); + fw.write(""); + fw.close(); + + + fw = null; + + configure.setFile(temp); + } + catch (IOException e) { + throw new BuildException(e); + } + finally { + try { + if (fw != null) { + fw.close(); + fw = null; + } + } + catch (IOException e) { + ; + } + } + } + + configure.execute(); + } + + public void fileset(URLImportTask task, String setId) { + String org = task.getOrg(); + String module = task.getModule(); + String rev = task.getRev(); + String conf = task.getConf(); + + IvyCacheFileset cacheFileSet = new IvyCacheFileset(); + cacheFileSet.setProject(task.getProject()); + cacheFileSet.setLocation(task.getLocation()); + cacheFileSet.setOwningTarget(task.getOwningTarget()); + cacheFileSet.setTaskName(task.getTaskName()); + cacheFileSet.setInline(true); + cacheFileSet.setOrganisation(org); + cacheFileSet.setModule(module); + cacheFileSet.setRevision(rev); + cacheFileSet.setConf(conf); + cacheFileSet.init(); + cacheFileSet.setSetid(setId); + cacheFileSet.setSettingsRef( + new org.apache.tools.ant.types.Reference(task.getProject(), "urlimporttask")); + cacheFileSet.execute(); + } + +} diff --git a/src/main/java/net/sf/antcontrib/net/IvyAdapter.java b/src/main/java/net/sf/antcontrib/net/IvyAdapter.java new file mode 100644 index 0000000..db4fd4f --- /dev/null +++ b/src/main/java/net/sf/antcontrib/net/IvyAdapter.java @@ -0,0 +1,6 @@ +package net.sf.antcontrib.net; + +public interface IvyAdapter { + void configure(URLImportTask task); + void fileset(URLImportTask task, String setId); +} diff --git a/src/main/java/net/sf/antcontrib/net/URLImportTask.java b/src/main/java/net/sf/antcontrib/net/URLImportTask.java index a155767..4792ef4 100755 --- a/src/main/java/net/sf/antcontrib/net/URLImportTask.java +++ b/src/main/java/net/sf/antcontrib/net/URLImportTask.java @@ -16,9 +16,6 @@ package net.sf.antcontrib.net; import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import org.apache.tools.ant.BuildException; @@ -28,9 +25,6 @@ import org.apache.tools.ant.taskdefs.Expand; import org.apache.tools.ant.taskdefs.ImportTask; import org.apache.tools.ant.types.FileSet; -import fr.jayasoft.ivy.ant.IvyCacheFileset; -import fr.jayasoft.ivy.ant.IvyConfigure; - /*** * Task to import a build file from a url. The build file can be a build.xml, * or a .zip/.jar, in which case we download and extract the entire archive, and @@ -106,105 +100,72 @@ public class URLImportTask throw new BuildException("'file' property not accessed for ImportURL."); } + public String getOrg() { + return org; + } + + public String getModule() { + return module; + } + + public String getRev() { + return rev; + } + + public String getConf() { + return conf; + } + + public String getType() { + return type; + } + + public String getRepositoryUrl() { + return repositoryUrl; + } + + public File getRepositoryDir() { + return repositoryDir; + } + + public URL getIvyConfUrl() { + return ivyConfUrl; + } + + public File getIvyConfFile() { + return ivyConfFile; + } + + public String getResource() { + return resource; + } + + public String getArtifactPattern() { + return artifactPattern; + } + + public String getIvyPattern() { + return ivyPattern; + } + public void execute() throws BuildException { - IvyConfigure configure = new IvyConfigure(); - configure.setProject(getProject()); - configure.setLocation(getLocation()); - configure.setOwningTarget(getOwningTarget()); - configure.setTaskName(getTaskName()); - configure.init(); - if (ivyConfUrl != null) { - if (ivyConfUrl.getProtocol().equalsIgnoreCase("file")) { - String path = ivyConfUrl.getPath(); - File f = new File(path); - if (! f.isAbsolute()) { - f = new File(getProject().getBaseDir(), path); - } - configure.setFile(f); - } - else { - try { - configure.setUrl(ivyConfUrl.toExternalForm()); - } - catch (MalformedURLException e) { - throw new BuildException(e); - } - } - } - else if (ivyConfFile != null) { - configure.setFile(ivyConfFile); + IvyAdapter adapter = null; + + try { + Class.forName("org.apache.ivy.Ivy"); + adapter = new Ivy20Adapter(); } - else if (repositoryDir != null || - repositoryUrl != null) { - File temp = null; - FileWriter fw = null; - - try { - temp = File.createTempFile("ivyconf", ".xml"); - temp.deleteOnExit(); - fw = new FileWriter(temp); - fw.write(""); - fw.write(""); - fw.write(""); - if (repositoryDir != null) { - fw.write(""); - fw.write(""); - fw.write(""); - fw.write(""); - } - else { - fw.write(""); - fw.write(""); - fw.write(""); - fw.write(""); - } - fw.write(""); - - fw.write(""); - fw.write(""); - fw.write(""); - fw.write(""); - fw.close(); - fw = null; - - configure.setFile(temp); - } - catch (IOException e) { - throw new BuildException(e); - } - finally { - try { - if (fw != null) { - fw.close(); - fw = null; - } - } - catch (IOException e) { - ; - } - } + catch (ClassNotFoundException e) { + adapter = new Ivy14Adapter(); } - configure.execute(); - - IvyCacheFileset cacheFileSet = new IvyCacheFileset(); - cacheFileSet.setProject(getProject()); - cacheFileSet.setLocation(getLocation()); - cacheFileSet.setOwningTarget(getOwningTarget()); - cacheFileSet.setTaskName(getTaskName()); - cacheFileSet.setInline(true); - cacheFileSet.setOrganisation(org); - cacheFileSet.setModule(module); - cacheFileSet.setRevision(rev); - cacheFileSet.setConf(conf); - cacheFileSet.init(); - cacheFileSet.setSetid(org + module + rev + ".fileset"); - cacheFileSet.execute(); + String setId = org + "." + module + "." + rev + ".fileset"; + adapter.configure(this); + adapter.fileset(this, setId); - FileSet fileset = - (FileSet) getProject().getReference(org + module + rev + ".fileset"); + FileSet fileset =(FileSet) getProject().getReference(setId); DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); -- cgit v1.2.3