--- ivy-1.4.1/src/java/fr/jayasoft/ivy/ant/IvyCacheFileset.java.orig 2007-06-29 15:53:05.000000000 +0200 +++ ivy-1.4.1/src/java/fr/jayasoft/ivy/ant/IvyCacheFileset.java 2007-06-29 15:37:45.000000000 +0200 @@ -1,10 +1,13 @@ /* * This file is subject to the license found in LICENCE.TXT in the root directory of the project. - * + * * #SNAPSHOT# */ package fr.jayasoft.ivy.ant; + +import java.io.File; +import java.io.IOException; import java.util.Iterator; import java.util.List; @@ -19,11 +22,12 @@ import fr.jayasoft.ivy.Ivy; /** * Creates an ant fileset consisting in all artifacts found during a resolve. * Note that this task is not compatible with the useOrigin mode. - * - * @author Xavier Hanin + * + * @author Xavier Hanin */ public class IvyCacheFileset extends IvyCacheTask { private String _setid; + private File _setRoot; public String getSetid() { return _setid; @@ -31,10 +35,8 @@ public class IvyCacheFileset extends Ivy public void setSetid(String id) { _setid = id; } - public void setUseOrigin(boolean useOrigin) { - if (useOrigin) { - throw new UnsupportedOperationException("the cachefileset task does not support the useOrigin mode, since filesets require to have only one root directory. Please use the the cachepath task instead"); - } + public void setOriginRoot(String originRoot) throws IOException { + _setRoot = new File(new File(originRoot).getCanonicalPath()); } public void execute() throws BuildException { @@ -46,8 +48,12 @@ public class IvyCacheFileset extends Ivy FileSet fileset = new FileSet(); fileset.setProject(getProject()); getProject().addReference(_setid, fileset); - fileset.setDir(getCache()); - + if (_setRoot == null) { + fileset.setDir(getCache()); + } else { + fileset.setDir(_setRoot); + } + List paths = getArtifacts(); if (paths.isEmpty()) { NameEntry ne = fileset.createExclude(); @@ -57,12 +63,21 @@ public class IvyCacheFileset extends Ivy for (Iterator iter = paths.iterator(); iter.hasNext();) { Artifact a = (Artifact)iter.next(); NameEntry ne = fileset.createInclude(); - ne.setName(ivy.getArchivePathInCache(a, ivy.getSavedArtifactOrigin(getCache(), a))); + if (isUseOrigin()) { + File originalFile = ivy.getArchiveFileInCache(getCache(), a, ivy.getSavedArtifactOrigin(getCache(), a), isUseOrigin()); + if (originalFile != null && originalFile.getCanonicalPath().startsWith(_setRoot.getCanonicalPath())) { + ne.setName(originalFile.getCanonicalPath().substring(_setRoot.toString().length() + 1)); + } else { + throw new BuildException(originalFile + " not found below fileset root " + _setRoot); + } + } else { + ne.setName(ivy.getArchivePathInCache(a, ivy.getSavedArtifactOrigin(getCache(), a))); + } } } } catch (Exception ex) { throw new BuildException("impossible to build ivy cache fileset: "+ex, ex); - } + } } }