KickJava   Java API By Example, From Geeks To Geeks.

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


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.ModuleId;
7 import fr.jayasoft.ivy.ModuleRevisionId;
8 import fr.jayasoft.ivy.ResolvedModuleRevision;
9
10 /**
11  * Look for the latest module in the repository matching the given criteria,
12  * and sets a set of properties according to what was found.
13  *
14  * @author Xavier Hanin
15  */

16 public class IvyFindRevision extends IvyTask {
17     private String JavaDoc _organisation;
18     private String JavaDoc _module;
19     private String JavaDoc _branch;
20     private String JavaDoc _revision;
21     
22     private String JavaDoc _property = "ivy.revision";
23     
24     public String JavaDoc getModule() {
25         return _module;
26     }
27
28     public void setModule(String JavaDoc module) {
29         _module = module;
30     }
31
32     public String JavaDoc getOrganisation() {
33         return _organisation;
34     }
35
36     public void setOrganisation(String JavaDoc organisation) {
37         _organisation = organisation;
38     }
39
40     public String JavaDoc getRevision() {
41         return _revision;
42     }
43
44     public void setRevision(String JavaDoc revision) {
45         _revision = revision;
46     }
47
48
49     public String JavaDoc getBranch() {
50         return _branch;
51     }
52
53     public void setBranch(String JavaDoc branch) {
54         _branch = branch;
55     }
56
57     public String JavaDoc getProperty() {
58         return _property;
59     }
60
61     public void setProperty(String JavaDoc prefix) {
62         _property = prefix;
63     }
64
65
66     public void execute() throws BuildException {
67         if (_organisation == null) {
68             throw new BuildException("no organisation provided for ivy findmodules");
69         }
70         if (_module == null) {
71             throw new BuildException("no module name provided for ivy findmodules");
72         }
73         if (_revision == null) {
74             throw new BuildException("no revision provided for ivy findmodules");
75         }
76         
77         Ivy ivy = getIvyInstance();
78         if (_branch == null) {
79             ivy.getDefaultBranch(new ModuleId(_organisation, _module));
80         }
81         ResolvedModuleRevision rmr = ivy.findModule(ModuleRevisionId.newInstance(_organisation, _module, _branch, _revision));
82         if (rmr != null) {
83             getProject().setProperty(_property, rmr.getId().getRevision());
84         }
85     }
86 }
87
Popular Tags