KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ant > IvyCacheFileset


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.ant;
7
8 import java.util.Iterator JavaDoc;
9 import java.util.List JavaDoc;
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 /**
20  * Creates an ant fileset consisting in all artifacts found during a resolve.
21  * Note that this task is not compatible with the useOrigin mode.
22  *
23  * @author Xavier Hanin
24  */

25 public class IvyCacheFileset extends IvyCacheTask {
26     private String JavaDoc _setid;
27
28     public String JavaDoc getSetid() {
29         return _setid;
30     }
31     public void setSetid(String JavaDoc id) {
32         _setid = id;
33     }
34     public void setUseOrigin(boolean useOrigin) {
35         if (useOrigin) {
36             throw new UnsupportedOperationException JavaDoc("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 JavaDoc paths = getArtifacts();
52             if (paths.isEmpty()) {
53                 NameEntry ne = fileset.createExclude();
54                 ne.setName("**/*");
55             } else {
56                 Ivy ivy = getIvyInstance();
57                 for (Iterator JavaDoc 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 JavaDoc ex) {
64             throw new BuildException("impossible to build ivy cache fileset: "+ex, ex);
65         }
66     }
67
68 }
69
Popular Tags