KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.jayasoft.ivy.ant;
2
3 import org.apache.tools.ant.BuildException;
4 import org.apache.tools.ant.Project;
5 import org.apache.tools.ant.Task;
6 import org.apache.tools.ant.types.DirSet;
7 import org.apache.tools.ant.types.FileList;
8 import org.apache.tools.ant.types.FileSet;
9 import org.apache.tools.ant.types.Path;
10 import org.apache.tools.ant.types.Path.PathElement;
11
12 /**
13  * This task is not directly related to ivy, but is useful in some modular build systems.
14  *
15  * The idea is to be able to contribute new sub path elements to an existing path.
16  *
17  * @author Xavier Hanin
18  */

19 public class AddPathTask extends Task {
20     private String JavaDoc _topath;
21     private boolean _first = false;
22     private Path _toadd;
23
24     public String JavaDoc getTopath() {
25         return _topath;
26     }
27
28     public void setTopath(String JavaDoc topath) {
29         _topath = topath;
30     }
31     
32     public void setProject(Project project) {
33         super.setProject(project);
34         _toadd = new Path(project);
35     }
36     
37     
38     public void execute() throws BuildException {
39         Object JavaDoc element = getProject().getReference(_topath);
40         if (element == null) {
41             throw new BuildException("destination path not found: "+_topath);
42         }
43         if (! (element instanceof Path)) {
44             throw new BuildException("destination path is not a path: "+element.getClass());
45         }
46         Path dest = (Path) element;
47         if (_first) {
48             // now way to add path elements at te beginning of the existing path: we do the opposite
49
// and replace the reference
50
_toadd.append(dest);
51             getProject().addReference(_topath, _toadd);
52         } else {
53             dest.append(_toadd);
54         }
55     }
56
57     public void add(Path path) throws BuildException {
58         _toadd.add(path);
59     }
60
61     public void addDirset(DirSet dset) throws BuildException {
62         _toadd.addDirset(dset);
63     }
64
65     public void addFilelist(FileList fl) throws BuildException {
66         _toadd.addFilelist(fl);
67     }
68
69     public void addFileset(FileSet fs) throws BuildException {
70         _toadd.addFileset(fs);
71     }
72
73     public Path createPath() throws BuildException {
74         return _toadd.createPath();
75     }
76
77     public PathElement createPathElement() throws BuildException {
78         return _toadd.createPathElement();
79     }
80
81     public boolean isFirst() {
82         return _first;
83     }
84
85     public void setFirst(boolean first) {
86         _first = first;
87     }
88 }
89
Popular Tags