Permalink
Browse files

Everything is parsing and marshalling correctly into models now

  • Loading branch information...
1 parent dbed90a commit 9ae9d6bb506b4c3ae1a6868437fb00e76ca961fe @dhanji dhanji committed Apr 20, 2012
@@ -357,19 +357,29 @@ private Plugin plugin() {
return plugin;
// Transform the parsed config map into maven's XPP3 Dom thing.
- Xpp3Dom xConfig = new Xpp3Dom("configuration");
+ plugin.setConfiguration(toXpp3DomTree("configuration", config));
+
+ return plugin;
+ }
+
+ private Xpp3Dom toXpp3DomTree(String name, Map<String, Object> config) {
+ Xpp3Dom xConfig = new Xpp3Dom(name);
for (Entry<String, Object> entry : config.entrySet()) {
if (entry.getValue() instanceof String) {
Xpp3Dom node = new Xpp3Dom(entry.getKey());
node.setValue(entry.getValue().toString());
xConfig.addChild(node);
+ } else {
+ @SuppressWarnings("unchecked") // Guaranteed by #configurationMap()
+ Map<String, Object> childMap = (Map<String, Object>) entry.getValue();
+
+ // Recurse.
+ Xpp3Dom child = toXpp3DomTree(entry.getKey(), childMap);
+ xConfig.addChild(child);
}
}
-
- plugin.setConfiguration(xConfig);
-
- return plugin;
+ return xConfig;
}
private Map<String, Object> configurationMap() {
@@ -381,7 +391,7 @@ private Plugin plugin() {
// Match the rest of the line as either an atom or as another set of properties.
String atom = idFragment();
- if (atom == null || StringUtils.isEmpty(atom)) {
+ if (atom == null) {
List<Token> tokens = match(Kind.STRING);
if (tokens != null)
atom = tokens.get(0).value;
@@ -394,8 +404,9 @@ private Plugin plugin() {
atom = atom.substring(1, atom.length() - 1);
config.put(propKey.get(0).value, atom);
- if (match(Kind.EOL) == null)
- log.severe("Expected end of line in plugin config");
+
+ // eol here is optional.
+ match(Kind.EOL);
} else {
// This is a multilevel thing, recurse!
if (match(Kind.LBRACKET) != null) {
@@ -636,6 +647,10 @@ private String idFragment() {
}
}
+ // Nothing matched.
+ if (fragment.length() == 0)
+ return null;
+
return fragment.toString();
}
@@ -42,8 +42,6 @@ public Token(String value, Kind kind) {
LPAREN,
RPAREN,
- LBRACE,
- RBRACE,
LBRACKET,
RBRACKET,
@@ -95,6 +93,8 @@ public Token(String value, Kind kind) {
TOKEN_MAP.put(")", RPAREN);
TOKEN_MAP.put("[", LBRACKET);
TOKEN_MAP.put("]", RBRACKET);
+ TOKEN_MAP.put("{", LBRACKET); // Alias braces as brackets.
+ TOKEN_MAP.put("}", RBRACKET);
TOKEN_MAP.put("\n", EOL);
TOKEN_MAP.put("id", ID);
@@ -88,6 +88,20 @@ public final void testProjectParsing() {
Xpp3Dom config = (Xpp3Dom) compiler.getConfiguration();
assertTrue(containsChild(config, "source", "1.5"));
assertTrue(containsChild(config, "target", "1.5"));
+
+ config = (Xpp3Dom) surefire.getConfiguration();
+ assertTrue(containsChild(config, "childDelegation", "true"));
+
+ Xpp3Dom extra = config.getChild("extra");
+ assertNotNull(extra);
+ assertEquals(2, extra.getChildCount());
+
+ assertTrue(containsChild(extra, "useThings", "true"));
+
+ Xpp3Dom useOtherThings = extra.getChild("useOtherThings");
+ assertNotNull(useOtherThings);
+ assertEquals(1, useOtherThings.getChildCount());
+ assertTrue(containsChild(useOtherThings, "maybe", "false"));
}
private static boolean containsChild(Xpp3Dom node, String key, String value) {
@@ -25,4 +25,6 @@ plugin
plugin
id: org.apache.maven.plugins:maven-surefire-plugin:2.0.1
childDelegation: "true"
+ extra: [ useThings: "true"
+ useOtherThings: { maybe: "false" } ]

0 comments on commit 9ae9d6b

Please sign in to comment.