Skip to content

Commit

Permalink
Fixed mojohaus#14
Browse files Browse the repository at this point in the history
Added support for xinclude in transformation and validation

Added integration- and unit tests to prove functionality.
Extend site to document new attributes in plug-in configuration.
  • Loading branch information
G-Ork committed May 6, 2017
1 parent 3224de2 commit 7dc519d
Show file tree
Hide file tree
Showing 33 changed files with 884 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<name>Nick Stolwijk</name>
<email>nstolwijk@iprofs.nl</email>
</contributor>
<contributor>
<name>Georg Tsakumagos</name>
<email>tsakumagos@gmail.com</email>
</contributor>
<contributor>
<name>Andrew Thornton</name>
<email>art27@cantab.net</email>
Expand Down
1 change: 1 addition & 0 deletions src/it/xinclude-xsd/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean xml:validate
57 changes: 57 additions & 0 deletions src/it/xinclude-xsd/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>
<groupId>org.codehaus.mojo.xml</groupId>
<artifactId>xinclude</artifactId>
<version>0.1</version>
<name>Maven XML Plugin IT xinclude - validate</name>
<description>Integration Test to check xinclude awarenes for the Maven XML Plugin</description>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>@pom.version@</version>
<executions>
<execution>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
<configuration>
<validationSets>
<validationSet>
<xincludeAware>true</xincludeAware>
<dir>src/main/xml</dir>
<includes>
<include>book.xml</include>
</includes>
<systemId>src/main/xsd/schema.xsd</systemId>
</validationSet>
</validationSets>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
23 changes: 23 additions & 0 deletions src/it/xinclude-xsd/src/main/xml/book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<book xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../xsd/schema.xsd" >

<xi:include href="chapter.xml"/>
</book>
24 changes: 24 additions & 0 deletions src/it/xinclude-xsd/src/main/xml/chapter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<chapter xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../xsd/schema.xsd" >

<xi:include href="section.xml"/>

</chapter>
22 changes: 22 additions & 0 deletions src/it/xinclude-xsd/src/main/xml/section.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<section xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../xsd/schema.xsd" >
Hello World
</section>
54 changes: 54 additions & 0 deletions src/it/xinclude-xsd/src/main/xsd/schema.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/03/xml.xsd" />

<xs:element name="book" type="book"/>
<xs:element name="chapter" type="chapter"/>
<xs:element name="section" type="section"/>

<xs:complexType name="book" >
<xs:sequence>
<xs:element name="chapter" minOccurs="1" maxOccurs="unbounded"
type="chapter" />
</xs:sequence>
<xs:attribute ref="xml:base" use="optional"/>
</xs:complexType>

<xs:complexType name="chapter">
<xs:sequence>
<xs:element name="section" minOccurs="1" maxOccurs="unbounded"
type="section" />
</xs:sequence>
<xs:attribute ref="xml:base" use="optional"/>
</xs:complexType>

<xs:complexType name="section" mixed="true">
<xs:sequence>
<xs:any minOccurs="0" />
</xs:sequence>
<xs:attribute ref="xml:base" use="optional"/>
</xs:complexType>


</xs:schema>
1 change: 1 addition & 0 deletions src/it/xinclude-xsl/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean xml:transform
60 changes: 60 additions & 0 deletions src/it/xinclude-xsl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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>
<groupId>org.codehaus.mojo.xml</groupId>
<artifactId>xinclude</artifactId>
<version>0.1</version>
<name>Maven XML Plugin IT xinclude - transform</name>
<description>Integration Test to check xinclude awarenes for the Maven XML Plugin</description>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>@pom.version@</version>
<configuration>
<transformationSets>
<transformationSet>
<xincludeAware>true</xincludeAware>
<dir>src/main/xml</dir>
<stylesheet>src/main/xsl/copy.xsl</stylesheet>
<includes>
<include>book.xml</include>
</includes>
</transformationSet>

<transformationSet>
<xincludeAware>false</xincludeAware>
<dir>src/main/xml</dir>
<stylesheet>src/main/xsl/copy.xsl</stylesheet>
<includes>
<include>chapter.xml</include>
</includes>
</transformationSet>
</transformationSets>
<forceCreation>true</forceCreation>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
20 changes: 20 additions & 0 deletions src/it/xinclude-xsl/src/main/xml/book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<book xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="chapter.xml" xpointer="element(/1)"/>
</book>
24 changes: 24 additions & 0 deletions src/it/xinclude-xsl/src/main/xml/chapter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="section.xml" xpointer="element(/1)">
<xi:fallback>
<fallbackSection/>
</xi:fallback>
</xi:include>
</chapter>
18 changes: 18 additions & 0 deletions src/it/xinclude-xsl/src/main/xml/section.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<section xmlns:xi="http://www.w3.org/2001/XInclude">Hello World</section>
29 changes: 29 additions & 0 deletions src/it/xinclude-xsl/src/main/xsl/copy.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="comment()|processing-instruction()|text()">
<xsl:copy/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="comment()|processing-instruction()|text()|*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
11 changes: 11 additions & 0 deletions src/it/xinclude-xsl/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import org.codehaus.plexus.util.FileUtils

File xmlFile = new File(basedir, "/target/generated-resources/xml/xslt/book.xml")
assert xmlFile.isFile()

def book = new XmlSlurper().parse(xmlFile)

assert book instanceof groovy.util.slurpersupport.GPathResult

assert book.chapter.section == 'Hello World'

Loading

0 comments on commit 7dc519d

Please sign in to comment.