1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.astrogrid.community.resolver.ant ;
20
21 import java.util.Properties ;
22 import java.util.Enumeration ;
23
24 import java.io.FileInputStream ;
25
26 import org.apache.tools.ant.Task ;
27 import org.apache.tools.ant.BuildException ;
28
29 import org.astrogrid.config.Config ;
30 import org.astrogrid.config.SimpleConfig ;
31
32 import org.astrogrid.community.common.security.data.SecurityToken ;
33
34 /***
35 * Base class for our Ant tasks.
36 *
37 */
38 public class CommunityResolverTask
39 extends Task
40 {
41 /***
42 * Our debug flag.
43 *
44 */
45 private static final boolean DEBUG_FLAG = true ;
46
47 /***
48 * Public constructor.
49 *
50 */
51 public CommunityResolverTask()
52 {
53
54
55 super() ;
56 }
57
58 /***
59 * Public constructor.
60 *
61 */
62 public CommunityResolverTask(Task parent)
63 {
64
65
66 super() ;
67
68
69 setProject(parent.getProject()) ;
70 }
71
72 /***
73 * Initialise our Task.
74 *
75 */
76 public void init()
77 throws BuildException
78 {
79 if (DEBUG_FLAG) System.out.println("----\"----");
80 if (DEBUG_FLAG) System.out.println("CommunityResolverTask.init()");
81 if (DEBUG_FLAG) System.out.println(" Token : " + this.getToken());
82 }
83
84 /***
85 * The name of our token property.
86 *
87 */
88 public static final String TOKEN_PROPERTY = "org.astrogrid.community.token" ;
89
90 /***
91 * Get our security token.
92 *
93 */
94 protected SecurityToken getToken()
95 {
96
97
98 if (null != this.getProject())
99 {
100
101
102 String string = this.getProject().getProperty(TOKEN_PROPERTY) ;
103
104
105 if (null != string)
106 {
107
108
109 return new SecurityToken(string) ;
110 }
111 }
112 return null ;
113 }
114
115 /***
116 * Set our security token.
117 *
118 */
119 protected void setToken(SecurityToken token)
120 {
121
122
123 if (null != this.getProject())
124 {
125
126
127 this.getProject().setProperty(
128 TOKEN_PROPERTY,
129 token.toString()
130 ) ;
131 }
132 }
133
134 /***
135 * The AstroGrid configuration.
136 *
137 */
138 protected static Config config = SimpleConfig.getSingleton() ;
139
140 /***
141 * Our registry endpoint.
142 *
143 */
144 private String registry ;
145
146 /***
147 * Access to our registry endpoint.
148 *
149 */
150 public void setRegistry(String value)
151 {
152 this.registry = value ;
153 }
154
155 /***
156 * Access to our registry endpoint.
157 *
158 */
159 public String getRegistry()
160 {
161 return this.registry ;
162 }
163
164 /***
165 * Our properties location.
166 *
167 */
168 private String properties ;
169
170 /***
171 * Get our properties location.
172 *
173 */
174 public String getProperties()
175 {
176 return this.properties ;
177 }
178
179 /***
180 * Set our properties location.
181 *
182 */
183 public void setProperties(String value)
184 {
185 this.properties = value ;
186 }
187
188 /***
189 * Load our config properties.
190 *
191 */
192 public void configure()
193 throws BuildException
194 {
195 if (DEBUG_FLAG) System.out.println("----\"----");
196 if (DEBUG_FLAG) System.out.println("CommunityResolverTask.configure()");
197
198
199 if (null != this.properties)
200 {
201
202
203 try {
204 if (DEBUG_FLAG) System.out.println(" Properties : " + this.properties);
205
206
207 Properties map = new Properties() ;
208 map.load(
209 new FileInputStream(
210 this.properties
211 )
212 ) ;
213
214
215 Enumeration enum = map.keys() ;
216 while (enum.hasMoreElements())
217 {
218 if (DEBUG_FLAG) System.out.println("----");
219
220
221 String name = (String)enum.nextElement() ;
222 if (DEBUG_FLAG) System.out.println(" Name : " + name);
223 String value = map.getProperty(name) ;
224 if (DEBUG_FLAG) System.out.println(" Value : " + value);
225
226
227 if (null != this.getProject())
228 {
229 value = this.getProject().replaceProperties(value) ;
230 }
231 if (DEBUG_FLAG) System.out.println(" Value : " + value);
232
233
234 config.setProperty(name, value) ;
235 if (DEBUG_FLAG) System.out.println("----");
236 }
237 }
238 catch (Exception ouch)
239 {
240 throw new BuildException(ouch) ;
241 }
242 }
243 }
244
245 /***
246 * Execute our Task.
247 *
248 */
249 public void execute()
250 throws BuildException
251 {
252 if (DEBUG_FLAG) System.out.println("----\"----");
253 if (DEBUG_FLAG) System.out.println("CommunityResolverTask.execute()");
254 if (DEBUG_FLAG) System.out.println(" Registry : " + this.registry);
255 if (DEBUG_FLAG) System.out.println(" Properties : " + this.properties);
256
257
258 this.configure() ;
259 }
260 }
261