01: package org.andromda.maven;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05:
06: import org.apache.commons.collections.CollectionUtils;
07: import org.apache.commons.jelly.JellyContext;
08: import org.apache.maven.jelly.MavenJellyContext;
09:
10: /**
11: * Contains some utilities for use within
12: * the Maven plugins that run AndroMDA.
13: *
14: * @author Chad Brandon
15: */
16: public class AndroMDAMavenUtils {
17: /**
18: * The maven jelly context.
19: */
20: private MavenJellyContext context;
21:
22: /**
23: * Sets the maven jelly context for this instance.
24: */
25: public void setContext(MavenJellyContext context) {
26: this .context = context;
27: }
28:
29: /**
30: * Gets all property names.
31: *
32: * @return the property names.
33: */
34: public String[] getPropertyNames() {
35: final Collection properties = new ArrayList();
36: for (JellyContext context = this .context; context != null; context = context
37: .getParent()) {
38: CollectionUtils.addAll(properties, context
39: .getVariableNames());
40: }
41: return (String[]) properties.toArray(new String[0]);
42: }
43:
44: /**
45: * The property reference pattern.
46: */
47: private static final String PROPERTY_REFERENCE = "\\$\\{.*\\}";
48:
49: /**
50: * Removes any ${some.property} type references from the string
51: * and returns the modifed string.
52: * @param string the string from which to remove the property
53: * references
54: *
55: * @return the modified string.
56: */
57: public static String removePropertyReferences(String string) {
58: if (string != null) {
59: string = string.replaceAll(PROPERTY_REFERENCE, "");
60: }
61: return string;
62: }
63: }
|