Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Now roundtripping plugins and modules correctly with nested configura…

…tion elements
  • Loading branch information...
commit 0962f890e9259ae75398e03b7f5adfd8b1aa5b98 1 parent db8a646
@dhanji dhanji authored
View
67 tesla-polyglot/tesla-polyglot-atom/src/main/java/org/sonatype/maven/polyglot/atom/AtomModelWriter.java
@@ -55,6 +55,7 @@ public void write(final Writer output, final Map<String, Object> options, final
dependencyManagement(pw, model);
dependencies(pw, model);
modules(pw, model);
+ pw.println();
pluginManagement(pw, model);
plugins(pw, model);
@@ -133,7 +134,6 @@ private void properties(PrintWriter pw, Model model) {
}
}
pw.println(" ]");
- pw.println();
}
}
@@ -144,7 +144,7 @@ private void modules(PrintWriter pw, Model model) {
for (int i = 0; i < modules.size(); i++) {
String module = modules.get(i);
if (i != 0) {
- pw.print(" ");
+ pw.print(indent + " ");
}
pw.print(module);
if (i + 1 != modules.size()) {
@@ -152,7 +152,6 @@ private void modules(PrintWriter pw, Model model) {
}
}
pw.println(" ]");
- pw.println();
}
}
@@ -191,7 +190,6 @@ private void deps(PrintWriter pw, String elementName, List<Dependency> deps) {
}
}
pw.println(" ]");
- pw.println();
}
}
@@ -210,38 +208,57 @@ private void plugins(PrintWriter pw, Model model) {
// need to write nested objects
private void plugins(PrintWriter pw, String elementName, List<Plugin> plugins) {
if (!plugins.isEmpty()) {
- pw.print(indent + elementName + ": [ ");
for (int i = 0; i < plugins.size(); i++) {
Plugin plugin = plugins.get(i);
- if (i != 0) {
- pw.print(" ");
- }
- pw.print(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion());
+ pw.println("plugin");
+
+ pw.print(indent + "id: " + plugin.getGroupId() + ":" + plugin.getArtifactId());
+ if (plugin.getVersion() != null)
+ pw.print(":" + plugin.getVersion());
if (plugin.getConfiguration() != null) {
pw.println();
Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
- if (configuration.getChildCount() != 0) {
- int count = configuration.getChildCount();
- for (int j = 0; j < count; j++) {
- Xpp3Dom c = configuration.getChild(j);
- if (c.getValue() != null) {
- if (j != 0) {
- pw.print(" ");
- }
- pw.print(c.getName() + ": " + c.getValue());
- if (j + 1 != count) {
- pw.println();
- }
- }
- }
- }
+ printChildren(pw, configuration);
}
if (i + 1 != plugins.size()) {
pw.println();
}
}
- pw.println(" ]");
pw.println();
}
}
+
+ private boolean flipBrackets = false;
+
+ private void printChildren(PrintWriter pw, Xpp3Dom configuration) {
+ if (configuration.getChildCount() > 0) {
+ int count = configuration.getChildCount();
+ for (int j = 0; j < count; j++) {
+ Xpp3Dom c = configuration.getChild(j);
+ if (c.getValue() != null) {
+ pw.print(indent + c.getName() + ": " + c.getValue());
+ if (j + 1 != count) {
+ pw.println();
+ }
+ } else {
+ pw.println(indent + c.getName() + ": " + lbraceket());
+ String oldIndent = indent;
+ indent += " ";
+ flipBrackets = !flipBrackets;
+ printChildren(pw, c);
+ flipBrackets = !flipBrackets;
+ indent = oldIndent;
+ pw.print("\n" + indent + rbraceket());
+ }
+ }
+ }
+ }
+
+ private char lbraceket() {
+ return (flipBrackets ? '{' : '[');
+ }
+
+ private char rbraceket() {
+ return (flipBrackets ? '}' : ']');
+ }
}
View
12 tesla-polyglot/tesla-polyglot-atom/src/main/java/org/sonatype/maven/polyglot/atom/parsing/AtomParser.java
@@ -338,7 +338,7 @@ private Plugin plugin() {
return null;
}
- Id pluginId = id();
+ Id pluginId = id(true);
if (pluginId == null) {
log.severe("Plugin id declaration malformed");
return null;
@@ -409,11 +409,17 @@ private Xpp3Dom toXpp3DomTree(String name, Map<String, Object> config) {
// eol here is optional.
match(Kind.EOL);
+
+ if (match(Kind.RBRACE) != null || match(Kind.RBRACKET) != null)
+ break;
} else {
// This is a multilevel thing, recurse!
if (anyOf(Kind.LBRACKET, Kind.LBRACE) != null) {
-
+ chewEols();
+ chewIndents();
Map<String, Object> childProps = configurationMap();
+ chewEols();
+ chewIndents();
if (match(Kind.RBRACKET) == null && match(Kind.RBRACE) == null)
parseException("Expected ']' after configuration properties");
@@ -471,7 +477,7 @@ private Xpp3Dom toXpp3DomTree(String name, Map<String, Object> config) {
chewIndents();
String module;
- while ((module = idFragment()).length() != 0) {
+ while ((module = idFragment()) != null) {
chewEols();
chewIndents();
modules.add(module);
View
10 tesla-polyglot/tesla-polyglot-atom/src/test/java/org/sonatype/maven/polyglot/atom/AtomModelWithSBTest.java
@@ -24,7 +24,7 @@
@Named("${basedir}/src/test/poms")
private File poms;
- public void _testAtomModelWriter() throws Exception {
+ public void testAtomModelWriter() throws Exception {
File pom = new File(poms, "sitebricks-parent-pom.xml");
MavenXpp3Reader xmlModelReader = new MavenXpp3Reader();
Model xmlModel = xmlModelReader.read(new FileInputStream(pom));
@@ -56,6 +56,9 @@ public void _testAtomModelWriter() throws Exception {
MavenXpp3Writer xmlWriter = new MavenXpp3Writer();
xmlWriter.write(w, xmlModel);
System.out.println(w.toString());
+
+ assertEquals(xmlModel.getModules(), atomModel.getModules());
+ assertEquals(xmlModel.getRepositories().size(), atomModel.getRepositories().size());
}
public void testAtomModelWriterWhereModelHasDependenciesWithNoVersions() throws Exception {
@@ -82,9 +85,7 @@ public void testAtomModelWriterWhereModelHasDependenciesWithNoVersions() throws
//
// Test for fidelity
//
- //assertNotNull(atomModel);
-
-
+ assertNotNull(atomModel);
}
void testMavenModelForCompleteness(Model model) {
@@ -138,5 +139,4 @@ String gav(Dependency d) {
String gav(Plugin p) {
return p.getGroupId() + ":" + p.getArtifactId() + ":" + p.getVersion();
}
-
}
View
35 tesla-polyglot/tesla-polyglot-atom/src/test/poms/sitebricks-pom.xml
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.sitebricks</groupId>
@@ -7,6 +9,7 @@
</parent>
<artifactId>sitebricks</artifactId>
<name>Sitebricks :: Core</name>
+ <url>http://sitebricks.org</url>
<dependencies>
<dependency>
@@ -21,8 +24,8 @@
<artifactId>sitebricks-converter</artifactId>
</dependency>
<dependency>
- <groupId>com.google.sitebricks</groupId>
- <artifactId>sitebricks-client</artifactId>
+ <groupId>com.google.sitebricks</groupId>
+ <artifactId>sitebricks-client</artifactId>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
@@ -137,4 +140,30 @@
</repository>
</distributionManagement>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>source-release-assembly</id>
+ <configuration>
+ <!-- we have a dedicated distribution module -->
+ <skipAssembly>true</skipAssembly>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <someCompoundKey>
+ <someKey>someValue</someKey>
+ <someKey2>someValue</someKey2>
+ <someCompoundKeyInner>
+ <someKey>someValue</someKey>
+ </someCompoundKeyInner>
+ </someCompoundKey>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
Please sign in to comment.
Something went wrong with that request. Please try again.