From 415f3f2840d5178a11a792eee434058876b6a873 Mon Sep 17 00:00:00 2001 From: Anders Hammar Date: Tue, 15 Nov 2016 10:55:13 +0100 Subject: [PATCH] Fixed issue #7: o WstxParsingException for plugin with extension element in configuration --- .../mojo/tidy/task/EnsureOrderAndIndent.java | 11 +++++-- .../codehaus/mojo/tidy/task/PomTidyTest.java | 4 +-- .../tidy/task/complete-pom/pom-expected.xml | 7 +++++ .../mojo/tidy/task/complete-pom/pom.xml | 8 +++++ .../pom-expected.xml | 31 +++++++++++++++++++ .../pom.xml | 31 +++++++++++++++++++ 6 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom-expected.xml create mode 100644 src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom.xml diff --git a/src/main/java/org/codehaus/mojo/tidy/task/EnsureOrderAndIndent.java b/src/main/java/org/codehaus/mojo/tidy/task/EnsureOrderAndIndent.java index 0e0639e..867889d 100644 --- a/src/main/java/org/codehaus/mojo/tidy/task/EnsureOrderAndIndent.java +++ b/src/main/java/org/codehaus/mojo/tidy/task/EnsureOrderAndIndent.java @@ -64,7 +64,7 @@ class EnsureOrderAndIndent "exclusions", "optional" ) ), new SectionSorter( "exclusion", new NodeGroup( "groupId", "artifactId" ) ), - new SectionSorter( "extension", new NodeGroup( "groupId", "artifactId", "version" ) ), + new SectionSorter( "build/extensions/extension", new NodeGroup( "groupId", "artifactId", "version" ) ), new SectionSorter( "parent", new NodeGroup( "groupId", "artifactId", "version", "relativePath" ) ), new SectionSorter( "plugin", new NodeGroup( "groupId", "artifactId", "version" ) ), new SectionSorter( "relocation", new NodeGroup( "groupId", "artifactId", "version" ) ) ); @@ -123,13 +123,12 @@ String sortSections( String pom, Format format ) int pos = getPosOfNextEvent( reader ); tidyPom.append( pom.substring( posFirstUnformatted, pos ) ); tidyPom.append( formatSection( reader, pom, format ) ); - path = substringAfterLast( path, "/" ); posFirstUnformatted = getPosOfNextEvent( reader ); } } else if ( event.isEndElement() ) { - path = substringAfterLast( path, "/" ); + path = substringBeforeLast( path, "/" ); } } tidyPom.append( pom.substring( posFirstUnformatted ) ); @@ -385,6 +384,12 @@ private int getPosOfNextEvent( XMLEventReader reader ) return reader.peek().getLocation().getCharacterOffset(); } + private String substringBeforeLast( String str, String separator ) + { + int endIndex = str.lastIndexOf( separator ); + return str.substring( 0, endIndex ); + } + private String substringAfterLast( String str, String separator ) { int beginIndex = str.lastIndexOf( separator ) + 1; diff --git a/src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java b/src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java index 1063fa8..c1b4262 100644 --- a/src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java +++ b/src/test/java/org/codehaus/mojo/tidy/task/PomTidyTest.java @@ -39,8 +39,8 @@ public class PomTidyTest public static Iterable tests() { return asList( "add-xml-declaration", "complete-pom", "do-not-mix-tab-and-spaces", "groupid-artifactid-version", - "pom-space-indent", "pom-tab-indent", "pom-with-comments", "pom-with-crlf", - "pom-with-line-without-indent", "pom-with-profiles", "pom-with-reporting", + "plugin-config-with-extension-string", "pom-space-indent", "pom-tab-indent", "pom-with-comments", + "pom-with-crlf", "pom-with-line-without-indent", "pom-with-profiles", "pom-with-reporting", "project-single-line" ); } diff --git a/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom-expected.xml b/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom-expected.xml index f7ab124..7fb85fd 100644 --- a/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom-expected.xml +++ b/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom-expected.xml @@ -82,6 +82,13 @@ + + + org.apache.maven.wagon + wagon-ssh-external + 1.0-beta-6 + + diff --git a/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom.xml b/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom.xml index 2194e28..21a1663 100644 --- a/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom.xml +++ b/src/test/resources/org/codehaus/mojo/tidy/task/complete-pom/pom.xml @@ -32,6 +32,14 @@ + + + org.apache.maven.wagon + wagon-ssh-external + 1.0-beta-6 + + + diff --git a/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom-expected.xml b/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom-expected.xml new file mode 100644 index 0000000..86003f3 --- /dev/null +++ b/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom-expected.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + org.codehaus.mojo.tidy.its + plugin-config-with-extension-string + 1.0-SNAPSHOT + + Test of tidy:pom on a pom with a plugin configuration containing the string 'extension'. + + + UTF-8 + + + + + + + org.apache.cxf + cxf-xjc-plugin + 3.0.5 + + + org.apache.cxf.xjcplugins:cxf-xjc-dv:3.0.5 + + + + + + + diff --git a/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom.xml b/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom.xml new file mode 100644 index 0000000..86003f3 --- /dev/null +++ b/src/test/resources/org/codehaus/mojo/tidy/task/plugin-config-with-extension-string/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + org.codehaus.mojo.tidy.its + plugin-config-with-extension-string + 1.0-SNAPSHOT + + Test of tidy:pom on a pom with a plugin configuration containing the string 'extension'. + + + UTF-8 + + + + + + + org.apache.cxf + cxf-xjc-plugin + 3.0.5 + + + org.apache.cxf.xjcplugins:cxf-xjc-dv:3.0.5 + + + + + + +