KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.jayasoft.ivy.ant;
2
3 import org.apache.tools.ant.BuildException;
4
5 import fr.jayasoft.ivy.Ivy;
6 import fr.jayasoft.ivy.ModuleRevisionId;
7 import fr.jayasoft.ivy.matcher.PatternMatcher;
8 import fr.jayasoft.ivy.util.IvyPatternHelper;
9
10 /**
11  * Look for modules in the repository matching the given criteria, and sets a set of properties
12  * according to what was found.
13  *
14  * @author Xavier Hanin
15  */

16 public class IvyListModules extends IvyTask {
17     private String JavaDoc _organisation;
18     private String JavaDoc _module;
19     private String JavaDoc _branch = PatternMatcher.ANY_EXPRESSION;
20     private String JavaDoc _revision;
21     private String JavaDoc _matcher = PatternMatcher.EXACT_OR_REGEXP;
22     
23     private String JavaDoc _property;
24     private String JavaDoc _value;
25     
26     public String JavaDoc getMatcher() {
27         return _matcher;
28     }
29
30     public void setMatcher(String JavaDoc matcher) {
31         _matcher = matcher;
32     }
33
34     public String JavaDoc getModule() {
35         return _module;
36     }
37
38     public void setModule(String JavaDoc module) {
39         _module = module;
40     }
41
42     public String JavaDoc getProperty() {
43         return _property;
44     }
45
46     public void setProperty(String JavaDoc name) {
47         _property = name;
48     }
49
50     public String JavaDoc getOrganisation() {
51         return _organisation;
52     }
53
54     public void setOrganisation(String JavaDoc organisation) {
55         _organisation = organisation;
56     }
57
58     public String JavaDoc getRevision() {
59         return _revision;
60     }
61
62     public void setRevision(String JavaDoc revision) {
63         _revision = revision;
64     }
65
66     public String JavaDoc getValue() {
67         return _value;
68     }
69
70     public void setValue(String JavaDoc value) {
71         _value = value;
72     }
73
74     public String JavaDoc getBranch() {
75         return _branch;
76     }
77
78     public void setBranch(String JavaDoc branch) {
79         _branch = branch;
80     }
81
82     public void execute() throws BuildException {
83         if (_organisation == null) {
84             throw new BuildException("no organisation provided for ivy findmodules");
85         }
86         if (_module == null) {
87             throw new BuildException("no module name provided for ivy findmodules");
88         }
89         if (_revision == null) {
90             throw new BuildException("no revision provided for ivy findmodules");
91         }
92         if (_property == null) {
93             throw new BuildException("no property provided for ivy findmodules");
94         }
95         if (_value == null) {
96             throw new BuildException("no value provided for ivy findmodules");
97         }
98         Ivy ivy = getIvyInstance();
99         ModuleRevisionId[] mrids = ivy.listModules(ModuleRevisionId.newInstance(_organisation, _module, _branch, _revision), ivy.getMatcher(_matcher));
100         for (int i = 0; i < mrids.length; i++) {
101             String JavaDoc name = IvyPatternHelper.substitute(ivy.substitute(_property), mrids[i]);
102             String JavaDoc value = IvyPatternHelper.substitute(ivy.substitute(_value), mrids[i]);
103             getProject().setProperty(name, value);
104         }
105     }
106 }
107
Popular Tags