1 6 package fr.jayasoft.ivy.ant; 7 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 import org.apache.tools.ant.BuildException; 12 import org.apache.tools.ant.types.FileSet; 13 import org.apache.tools.ant.types.PatternSet.NameEntry; 14 15 import fr.jayasoft.ivy.Artifact; 16 import fr.jayasoft.ivy.Ivy; 17 18 19 25 public class IvyCacheFileset extends IvyCacheTask { 26 private String _setid; 27 28 public String getSetid() { 29 return _setid; 30 } 31 public void setSetid(String id) { 32 _setid = id; 33 } 34 public void setUseOrigin(boolean useOrigin) { 35 if (useOrigin) { 36 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"); 37 } 38 } 39 40 public void execute() throws BuildException { 41 prepareAndCheck(); 42 if (_setid == null) { 43 throw new BuildException("setid is required in ivy cachefileset"); 44 } 45 try { 46 FileSet fileset = new FileSet(); 47 fileset.setProject(getProject()); 48 getProject().addReference(_setid, fileset); 49 fileset.setDir(getCache()); 50 51 List paths = getArtifacts(); 52 if (paths.isEmpty()) { 53 NameEntry ne = fileset.createExclude(); 54 ne.setName("**/*"); 55 } else { 56 Ivy ivy = getIvyInstance(); 57 for (Iterator iter = paths.iterator(); iter.hasNext();) { 58 Artifact a = (Artifact)iter.next(); 59 NameEntry ne = fileset.createInclude(); 60 ne.setName(ivy.getArchivePathInCache(a, ivy.getSavedArtifactOrigin(getCache(), a))); 61 } 62 } 63 } catch (Exception ex) { 64 throw new BuildException("impossible to build ivy cache fileset: "+ex, ex); 65 } 66 } 67 68 } 69 | Popular Tags |