01: package dalma.ant;
02:
03: import org.apache.tools.ant.types.Environment;
04:
05: import java.util.Properties;
06: import java.util.Vector;
07: import java.util.Map;
08: import java.io.File;
09: import java.io.BufferedInputStream;
10: import java.io.InputStream;
11: import java.io.FileInputStream;
12: import java.io.IOException;
13:
14: /**
15: * @author Kohsuke Kawaguchi
16: */
17: final class PropList extends Environment {
18: public Properties toProperties() {
19: Properties r = new Properties();
20: for (Variable v : (Vector<Variable>) variables) {
21: r.put(v.getKey(), v.getValue());
22: }
23: return r;
24: }
25:
26: public void addPropertyFile(File propFile) throws IOException {
27: Properties props = new Properties();
28: InputStream in = new BufferedInputStream(new FileInputStream(
29: propFile));
30: try {
31: props.load(in);
32: for (Map.Entry<Object, Object> e : props.entrySet()) {
33: Variable v = new Variable();
34: v.setKey(e.getKey().toString());
35: v.setValue(e.getValue().toString());
36: variables.add(v);
37: }
38: } finally {
39: in.close();
40: }
41: }
42: }
|