01: package dalma.maven;
02:
03: import org.apache.commons.jelly.Tag;
04: import org.apache.commons.jelly.TagSupport;
05: import org.apache.commons.jelly.XMLOutput;
06: import org.apache.commons.jelly.MissingAttributeException;
07: import org.apache.commons.jelly.JellyTagException;
08: import org.apache.commons.jelly.JellyContext;
09:
10: import java.util.Map;
11: import java.util.Set;
12: import java.util.HashMap;
13: import java.util.Iterator;
14:
15: /**
16: * Used as a JellyBean to list up test properties from the context.
17: *
18: * @author Kohsuke Kawaguchi
19: */
20: public class PropertySetFinder extends TagSupport {
21:
22: /**
23: * Enumerate all properties with this prefix.
24: */
25: private String prefix;
26:
27: /**
28: * Put the resulting {@link Map} into {@link JellyContext}
29: * with this name.
30: */
31: private String var;
32:
33: public void setPrefix(String prefix) {
34: this .prefix = prefix;
35: }
36:
37: public void setVar(String var) {
38: this .var = var;
39: }
40:
41: public void doTag(XMLOutput xmlOutput)
42: throws MissingAttributeException, JellyTagException {
43: Map r = new HashMap();
44: for (JellyContext context = getContext(); context != null; context = context
45: .getParent()) {
46: for (Iterator itr = context.getVariables().entrySet()
47: .iterator(); itr.hasNext();) {
48: Map.Entry e = (Map.Entry) itr.next();
49: String key = (String) e.getKey();
50: if (key.startsWith(prefix)) {
51: if (!r.containsKey(key)) {
52: r.put(e.getKey(), e.getValue());
53: }
54: }
55: }
56: }
57:
58: getContext().setVariable(var, r);
59: }
60:
61: }
|