xml-maven-plugin-1.0/0000755000175000017500000000000012137716637014071 5ustar eugeneeugenexml-maven-plugin-1.0/NOTICE.txt0000644000175000017500000000024510773161441015603 0ustar eugeneeugeneMaven XML Plugin Copyright 2007 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). xml-maven-plugin-1.0/LICENSE.txt0000644000175000017500000002613610773161441015713 0ustar eugeneeugene Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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. xml-maven-plugin-1.0/pom.xml0000644000175000017500000001561111526205074015377 0ustar eugeneeugene 4.0.0 org.codehaus.mojo mojo-parent 28 xml-maven-plugin maven-plugin Maven XML Plugin 1.0 ${mavenVersion} A plugin for various XML related tasks like validation, transformation, and the like. 2006 The Apache Software Foundation http://www.apache.org/ jochen Jochen Wiedmann jochen.wiedmann@gmail.com olamy Olivier Lamy olamy@apache.org Luke W. Patterson lukewpatterson@gmail.com Anagnostopoulos Kostis ankostis@gmail.com Andrew Thornton art27@cantab.net Aleksei Valikov valikov@gmx.net Nick Stolwijk nstolwijk@iprofs.nl Mykola Nikishov mn@mn.com.ua Mark Hobson markhobson@gmail.com Ramón Torres Bátiz rbatiz@gmail.com Andreas Eternach a.eternach@directbox.com The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.txt repo scm:svn:http://svn.codehaus.org/mojo/tags/xml-maven-plugin-1.0 scm:svn:https://svn.codehaus.org/mojo/tags/xml-maven-plugin-1.0 http://fisheye.codehaus.org/browse/mojo/tags/xml-maven-plugin-1.0 jira http://jira.codehaus.org/browse/MOJO/component/12247 org.apache.maven maven-plugin-api ${mavenVersion} org.apache.maven maven-project ${mavenVersion} org.apache.maven maven-model ${mavenVersion} org.apache.maven maven-settings ${mavenVersion} org.codehaus.plexus plexus-utils 1.2 org.codehaus.plexus plexus-resources 1.0-alpha-7 xerces xercesImpl 2.9.1 xml-apis xml-apis 1.3.04 xml-resolver xml-resolver 1.2 org.codehaus.plexus plexus-io 1.0-alpha-5 org.codehaus.plexus plexus-component-api org.apache.maven.shared maven-plugin-testing-harness 1.1 test net.sf.saxon saxon 8.7 test xalan xalan 2.7.1 test org.apache.maven.plugins maven-invoker-plugin src/it ${project.build.directory}/it */pom.xml setup verify ${project.build.directory}/local-repo src/it/settings.xml integration-test install run org.apache.maven.plugins maven-changes-plugin 2.1 changes-report org.apache.rat apache-rat-plugin 0.7 src/main/checkstyle/maven-header.txt src/test/it*/target/**/* 2.0.7 xml-maven-plugin-1.0/src/0000755000175000017500000000000012137716637014660 5ustar eugeneeugenexml-maven-plugin-1.0/src/site/0000755000175000017500000000000012137716637015624 5ustar eugeneeugenexml-maven-plugin-1.0/src/site/fml/0000755000175000017500000000000012137716637016402 5ustar eugeneeugenexml-maven-plugin-1.0/src/site/fml/faq.fml0000644000175000017500000001346211526203237017643 0ustar eugeneeugene General What goals does the XML Maven Plugin offer?

The plugin offers the xml:validate goal for validating XML files and the xml:transform goal for transforming XML files.

How do I use snapshot versions of the plugin?

The use of snapshot versions is described in the Usage document.

How do I tell the plugin to use my proxy server?

Use the standard Maven proxy settings. See the Mini guide on proxy configuration for details.

I have a stylesheet (a schema, another resource), which should be loaded through the class loader.

The plugin attempts to resolve resources through the class loader automatically. Alternatively, you can enforce using the class loader, if you specify your resource with an URI like "resource:org/foo/stylesheet.xsl".

The plugin doesn't work in offline mode. It always tries to resolve external resources and fails, if the network is not available.

You've got to download the resources in question once and store them as part of the project. A catalog file will replace the external resource with your local copy. See this example for details.

Transformation How do I use an XSLT stylesheet for transforming files?

See this example.

How do I transform the names of the generated files?

Use a File Mapper. See this example.

How do I perform other kinds of name transformations?

Check the list of available file mappers at File Mapper. Perhaps, there is one which suits your needs.

If not, you need to implement your own. If you feel that it is sufficiently generic, then you might consider to submit it as a contribution to the Plexus IO component.

See this example for how to configure the transformer to map names.

How can I use XSLT 2.0 in my stylesheets?

You need to use an XSLT 2.0 complicant stylesheet processor like Saxon. See this example.

How do I use another XSLT processor, for example Saxon?

You need to specify your favorite XSLT processor as a dependency. See this example.

How do I set a transformers output properties?

Use the element outputProperties in the transformation set. See this example for details.

How do I set stylesheet parameters?

Use the element parameters in the transformation set. See this example for details.

Validation How do I check files for well formedness?

See this example.

How do I make sure, that files are matching an XML schema?

See this example.

xml-maven-plugin-1.0/src/site/site.xml0000644000175000017500000000460511526203237017303 0ustar eugeneeugene Mojo http://mojo.codehaus.org/images/mojo_logo.png http://mojo.codehaus.org Codehaus http://mojo.codehaus.org/images/codehaus-small.png http://www.codehaus.org xml-maven-plugin-1.0/src/site/apt/0000755000175000017500000000000012137716636016407 5ustar eugeneeugenexml-maven-plugin-1.0/src/site/apt/index.apt0000644000175000017500000000417711526203237020222 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ---------------- XML Maven Plugin ---------------- The XML Maven Plugin This Plugin is a collection of several XML related tasks. * Goals Overview The plugin offers the following goals: * {{{./validate-mojo.html}xml:validate}} validates XML files against a schema. If the files aren't matching a certain schema, one may simply check, whether they are well formed. * {{{./transform-mojo.html}xml:transform}} transforms XML files by applying XSLT stylesheets. * Usage Instructions on how to use the XML Maven Plugin can be found on the {{{./usage.html}usage page}}. * Examples To provide you with better understanding of some usages of the XML Maven Plugin, you can take a look into the following examples: * Checking, whether XML files are {{{./examples/validate-well-formedness.html}well formed}} * Checking, whether XML files are {{{./examples/validate-schema.html}matching an XML schema}} * {{{./examples/transform-basic.html}Transforming}} XML files by applying an XSLT stylesheet * {{{./examples/transform-change-extension.html}Changing the extension}} of a transformations result files. * Using an {{{./examples/transform-saxon.html}XSLT 2.0 compliant processor}}. * Setting {{{./examples/transform-outputProperties.html}output properties}} on a transformer. * Setting {{{./examples/transform-parameters.html}stylesheet parameters}}. * Suppressing access to external resources by using a {{{./examples/catalog.html} catalog file}}. xml-maven-plugin-1.0/src/site/apt/transformation.apt0000644000175000017500000002263111526203237022154 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ---------------------- Transforming XML files ---------------------- Transforming XML files To transform XML files by applying XSLT stylesheets, use the "xml:transform" goal is used. It is configured through a section like the following in your POM: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform xml it4.xsl ... +---------------------------------------------------------------------------------- The example would transform all files in the directory "xml" by applying the stylesheet "it4.xml". The output would be written to the directory "${project.build.directory}/generated-resources/xml/xslt" (usually "target/generated-resources/xml/xslt"). Goal properties The "xml:transform" goal offers the following configurable properties: *--------------------+-----------------------------------------------------------------+ | Property Name | Description | *--------------------+-----------------------------------------------------------------+ | basedir | The base directory, which is used for interpreting relative | | | paths. Defaults to the project directory, in which the POM | | | resides. | *--------------------+-----------------------------------------------------------------+ | catalogs | A set of catalog files, which configure the entity resolver. | | | For example, it allows to map public ID's or external URL's to | | | local files. Multiple catalog files are supported. In other | | | words, to configure a single catalog file, you would need a | | | section like this: | | | | | | \ | | | \mycatalog.xml\ | | | \ | | | | | | The interpretation of catalog files is done by the Apache XML | | | resolver. See | | | {{{http://xml.apache.org/commons/components/resolver/resolver-article.html}this}} | | | article for details on catalog files and their formats. | *--------------------+-----------------------------------------------------------------+ | transformationSets | A transformation set configures a set of XML files, which are | | | transformed by applying a common XSLT stylesheet. If you want | | | apply multiple stylesheets, use multiple transformation sets. | | | See the above example, which specifies a single transformation | | | The various child elements of a \ section | | | listed in the following section. | *--------------------+-----------------------------------------------------------------+ Transformation Set Configuration A transformation set is configured through several child elements: *---------------------+-----------------------------------------------------------------+ | Element Name | Description | *---------------------+-----------------------------------------------------------------+ | attributes | Specifies attributes, which are being set on the transformer | | | factory by invoking the setAttribute(String, Object) method. | *---------------------+-----------------------------------------------------------------+ | addToClasspath | Specifies, whether the output directory is being added to the | | | to the classpath. Defaults to true. | *---------------------+-----------------------------------------------------------------+ | dir | Sets the name of a directory, which is scanned for the files, | | | which are being validated. | *---------------------+-----------------------------------------------------------------+ | excludes | Specifies a pattern of files, which are being excluded. By | | | default, no files are excluded. The pattern is relative to | | | the directory given by "dir". This element may be repeated | | | as much as needed. | *---------------------+-----------------------------------------------------------------+ | features | Specifies features, which are being set on the transformer | | | factory by invoking the setFeature(String,boolean) method. | *---------------------+-----------------------------------------------------------------+ | forceCreation | If 'true', no up-to-date check is performed and | | | the transformation is always performed. | | | Defaults to "${xml.forceCreation}" or 'false'. | *---------------------+-----------------------------------------------------------------+ | includes | Specifies a pattern of files, which are being included. By | | | default, all files are included. The pattern is relative to | | | the directory given by "dir". This element may be repeated | | | as much as needed. | *---------------------+-----------------------------------------------------------------+ | otherDepends | A list of of extra input files or URLs to consider during | | | the up-to-date check, useful for when resolving remote files. | | | By default it always considers: | | | 1. input files, | | | 2. XSLT file, | | | 3. catalog files, and | | | 4. the pom.xml file of the project executing this plugin. | *---------------------+-----------------------------------------------------------------+ | outputDir | Specifies the name of the output directory, where the generated | | | files are being placed. Defaults to | | | "${project.build.directory}/generated-resources/xml/xslt". | | | Usually, this is equivalent to | | | "target/generated-resources/xml/xslt". | *---------------------+-----------------------------------------------------------------+ | outputProperties | A list of name/value pairs, which are used to invoke the method | | | <<>> on the transformer. For details, | | | see {{{./examples/transform-outputProperties.html}this example}}. | *---------------------+-----------------------------------------------------------------+ | skipDefaultExcludes | Specifies whether the maven's default exludes should NOT | | | be added to the excludes list. | *---------------------+-----------------------------------------------------------------+ | stylesheet | Specifies the stylesheet, which is being used for transforming | | | the fileset. A stylesheet must be specified, there is no | | | default. | *---------------------+-----------------------------------------------------------------+ xml-maven-plugin-1.0/src/site/apt/examples/0000755000175000017500000000000012137716637020226 5ustar eugeneeugenexml-maven-plugin-1.0/src/site/apt/examples/transform-change-regexp.apt0000644000175000017500000001034311526203237025447 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ----------------------------------------------- Use regular expressions to transform file names ----------------------------------------------- Use regular expressions to transform file names A particularly powerfule file mapper deserves more detailed description: It's the regular expression file mapper. This file mapper uses regular expressions to identify certain pieces in the input file name. This piece, or these pieces are replaced with a replacement pattern. Let's first design a configuration snippet, which would transform all files in the directory <<>> by applying the stylesheet <<>>. The created files would have the extension <<<.fo>>>, rather than <<<.xml>>>. (We could very well achieve the same by using the <<>>, as demonstrated in {{{./transform-change-extension.html}this example}}.) +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl \.gif$ .jpg ... +---------------------------------------------------------------------------------- Let's have a look at some other examples. We omit most of the details, except for the pattern and the replacement, which are the important parts: +---------------------------------------------------------------------------------- ^(.*)\.gif$ $1.jpg +---------------------------------------------------------------------------------- This example is identical with the previous. However, it demonstrates the use of . The contents of <<<(.*)>>> are captured and inserted by using the group term <<<$1>>>. You might have multiple groups and use the terms <<<$2>>>, <<<$3>>>, and so on. +---------------------------------------------------------------------------------- a b +---------------------------------------------------------------------------------- This example replaces the <> a with a b. Nothing special here, except that you might like to replace <> a's instead. Here's how to do it: +---------------------------------------------------------------------------------- a b true +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/transform-change-extension.apt0000644000175000017500000000443511526203237026176 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ------------------------------------------- Change the extension of the generated files ------------------------------------------- Change the extension of the generated files The following configuration snippet would transform all files in the directory <<>> by applying the stylesheet <<>>. The created files would have the extension <<<.fo>>>, rather than <<<.xml>>>. +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl .fo ... +---------------------------------------------------------------------------------- Btw, the same could be achieved the much more powerful and generic RegExpFileMapper, which you find explained in more detail in {{{./transform-change-regexp.html}another example}}. xml-maven-plugin-1.0/src/site/apt/examples/transform-basic.apt0000644000175000017500000000347111526203237024017 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ----------------------------------------------------- Transforming XML files by applying an XSLT stylesheet ----------------------------------------------------- Transforming XML files by applying an XSLT stylesheet The following configuration snippet would transform all files in the directory <<>> by applying the stylesheet <<>>. +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl ... +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/catalog.apt0000644000175000017500000001360011526203237022332 0ustar eugeneeugene~~ ~~ ~~ Copyright 2011 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. ~~ ~~ ------------- Catalog files ------------- Catalog files It is not unusual that XML parsers or stylesheet processors try to access external resources. For example if you specify an external schema, the XML parser might try to load the external schema in order to validate your XML file: +-------------------------------------------------------------------------- ... +-------------------------------------------------------------------------- In this example the XML parser would likely attempt to load an XML schema from <<>>. Another example might be the use of a DTD: +--------------------------------------------------------------------------
A sample document.
+-------------------------------------------------------------------------- In this case, the XML parser would likely attempt to connect to <<>>. This is all very well, if you are connected to the Internet, with suitably configured proxy servers. But if that is not the case, then you will likely encounter trouble. The solution is using local copies of these external resources and a catalog file. This is best explained by an example catalog file: +-------------------------------------------------------------------------- +-------------------------------------------------------------------------- The example shows to things: * If the XML parser is searching for a file with a <> of <<<--COUNTER-->>>, then the catalog advises to use the local file <<<./doc-schema.xsd>>> instead. * If the XML parser or stylesheet processor is searching for a file with the <> <<>>, then the catalog requests to use the local file <<<./schema-for-xslt20.xsd>>> instead. It doesn't matter whether you use the public id or the system id. The important thing to know is what the respective public id and the system id are. In our first example, we had a public id of <<>> (the namespace URI) and a system id of <<>> (the URL from which to actually load the schema). In the second example, the public id was <<<--COUNTER-->> and the system id <<>>. In other words, we might as well rewrite our catalog file like this: +-------------------------------------------------------------------------- +-------------------------------------------------------------------------- We might as well use only public id's or system id's. How to use a catalog file To use a catalog file, you must specify it in your POM. +-------------------------------------------------------------------------- org.codehaus.mojo xml-maven-plugin 1.0 src/main/xml doc1.xml src/main/xml/catalog.xml +-------------------------------------------------------------------------- In this example, the catalog file would be stored in <<>>. To use a catalog file for transformation, just use the same <<>> element in your <<>> section. Relative paths in the catalog file An important point to make: How are relative paths in the catalog file interpreted? Suggest that the catalog file is stored in <<>> and the catalog file contains the following entry: +-------------------------------------------------------------------------- +-------------------------------------------------------------------------- The answer is that the URI is interpreted relative to the catalog files. In other words, the <<>> is stored in <<>> and not in <<<${basedir}/sample.dtd>>>. xml-maven-plugin-1.0/src/site/apt/examples/transform-saxon.apt0000644000175000017500000000533511526203237024067 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ----------------------------------- Using an alternative XSLT processor ----------------------------------- Using an alternative XSLT processor An alternative XSLT processor is important, if you want to use XSLT 2.0 stylesheets or if you would like to work around a bug in your JRE's stylesheet processor. As of this writing, {{{http://saxon.sourceforge.net/}Saxon}} is the only XSLT 2.0 compliant processor, so we take this as an example. Changing the XSLT processor is as simple as specifying it as a dependency: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl net.sf.saxon saxon 8.7 ... +---------------------------------------------------------------------------------- If you would like to know, which XSLT processor and/or version you are actually using, add code like the following to your stylesheet: +---------------------------------------------------------------------------------- XSLT Version = XSLT Vendor = XSLT Vendor URL = +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/validate-schema.apt0000644000175000017500000000345011526203237023751 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ------------------------------------------------------ Checking, whether XML files are matching an XML Schema ------------------------------------------------------ Checking, whether XML files are matching an XML Schema The following configuration snippet would check, whether all files in the directory <<>> are matching the schema <<>>. +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin validate src/main/xsd src/main/xmlschema.xml ... +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/validate-well-formedness.apt0000644000175000017500000000323311526203237025616 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ------------------------------------------- Checking, whether XML files are well formed ------------------------------------------- Checking, whether XML files are well formed The following configuration snippet would check, whether all files in the directory <<>> are well formed: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin validate src/main/xml ... +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/transform-parameters.apt0000644000175000017500000000353411526203237025101 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ----------------------------- Setting stylesheet parameters ----------------------------- Setting stylesheet parameters The following configuration snippet would set the stylesheet parameter <<>> to <<>>: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl MyParam true ... +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/examples/transform-outputProperties.apt0000644000175000017500000000366511526203237026360 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ------------------------------------------ Setting a transformers output properties ------------------------------------------ Setting a transformers output properties The following configuration snippet would set the output property <<>> to <<>>: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin transform src/main/xml src/main/stylesheet.xsl omit-xml-declaration yes ... +---------------------------------------------------------------------------------- xml-maven-plugin-1.0/src/site/apt/validation.apt0000644000175000017500000001740511526203237021243 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ -------------------- Validating XML files -------------------- Validating XML files To validate XML files, the "xml:validate" goal is used. It is configured through a section like the following in your POM: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin validate xml xsd xmlschema.xml ... +---------------------------------------------------------------------------------- The example would check all files in the directory "xml" for well formedness. Additionally, it would validate all files in the directory "xsd" against the schema "xmlschema.xml". Goal properties The "xml:validate" goal offers the following configurable properties: *----------------+-----------------------------------------------------------------+ | Property Name | Description | *----------------+-----------------------------------------------------------------+ | basedir | The base directory, which is used for interpreting relative | | | paths. Defaults to the project directory, in which the POM | | | resides. | *----------------+-----------------------------------------------------------------+ | catalogs | A set of catalog files, which configure the entity resolver. | | | For example, it allows to map public ID's or external URL's to | | | local files. Multiple catalog files are supported. In other | | | words, to configure a single catalog file, you would need a | | | section like this: | | | | | | \ | | | \mycatalog.xml\ | | | \ | | | | | | The interpretation of catalog files is done by the Apache XML | | | resolver. See | | | {{{http://xml.apache.org/commons/components/resolver/resolver-article.html}this}} | | | article for details on catalog files and their formats. | *----------------+-----------------------------------------------------------------+ | validationSets | A validation set configures a set of XML files, which are | | | validated against a common XML schema. If you want to validate | | | against multiple schemata, use one validation set per schema. | | | See the above example, which specifies two validation sets. | | | The various child elements of a \ section are | | | listed in the following section. | *----------------+-----------------------------------------------------------------+ Validation Set Configuration A validation set is configured through several child elements: *---------------------+-----------------------------------------------------------------+ | Element Name | Description | *---------------------+-----------------------------------------------------------------+ | publicId | The schemas public ID. May be null, if the schema is loaded | | | through its system ID or if the documents are being validated | | | for wellformedness only. | *---------------------+-----------------------------------------------------------------+ | systemId | The schemas system ID. May be null, if the schema is loaded | | | through its public ID or if the documents are being validated | | | for wellformedness only. | *---------------------+-----------------------------------------------------------------+ | schemaLanguage | The schema language. Defaults to XML Schema. See | | | {{{http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html}this}} | | | description for other possible values. | *---------------------+-----------------------------------------------------------------+ | validating | If the documents are being validated for wellformedness only: | | | Sets, whether the parser should be validating. (In other words: | | | Whether documents must contain a document type or xml schema | | | declaration.) The property is ignored otherwise. The default | | | value is false. | *---------------------+-----------------------------------------------------------------+ | dir | Sets the name of a directory, which is scanned for the files, | | | which are being validated. | *---------------------+-----------------------------------------------------------------+ | includes | Specifies a pattern of files, which are being included. By | | | default, all files are included. The pattern is relative to | | | the directory given by "dir". This element may be repeated | | | as much as needed. | *---------------------+-----------------------------------------------------------------+ | excludes | Specifies a pattern of files, which are being excluded. By | | | default, no files are excluded. The pattern is relative to | | | the directory given by "dir". This element may be repeated | | | as much as needed. | *---------------------+-----------------------------------------------------------------+ | skipDefaultExcludes | Specifies whether the maven's default exludes should NOT | | | be added to the excludes list. | *---------------------+-----------------------------------------------------------------+ xml-maven-plugin-1.0/src/site/apt/usage.apt0000644000175000017500000000452511526203237020214 0ustar eugeneeugene~~ ~~ ~~ Copyright 2005 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. ~~ ~~ ----- Usage ----- Usage The plugin offers goals for validating and transforming XML files. Basically, the plugin is used as follows: +---------------------------------------------------------------------------------- ... org.codehaus.mojo xml-maven-plugin ... ... ... +---------------------------------------------------------------------------------- In the above example, the goal would be either of <<>>, or <<>>. {{{./transformation.html}Transformation}} and {{{./validation.html}Validation}} are described on separate pages. Using snapshot versions Snapshot versions (development builds) are available from the {{{http://snapshots.repository.codehaus.org}Codehaus Snapshot Repository}}. This repository must be configured in your POM, if you'd like to use a snapshot version. Configration of the snapshot repository is described in the page on the {{{http://mojo.codehaus.org/using-sandbox-plugins.html}Mojo Sandbox}}. Using a proxy server It is not unusual, that an XML parser attempts to load documents from external servers. In a corporate environment, this will likely work only, if a proxy server is used. The plugin accepts the standard Maven proxy configuration. See the {{{http://maven.apache.org/guides/mini/guide-proxies.html}Mini guide on proxy configuration}} for details. xml-maven-plugin-1.0/src/main/0000755000175000017500000000000012137716636015603 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/0000755000175000017500000000000012137716636016524 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/0000755000175000017500000000000012137716636017313 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/0000755000175000017500000000000012137716636021106 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/0000755000175000017500000000000012137716636022052 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/0000755000175000017500000000000012137716636022652 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/validation/0000755000175000017500000000000012137716636025004 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/validation/ValidationSet.java0000644000175000017500000001271610773161441030414 0ustar eugeneeugenepackage org.codehaus.mojo.xml.validation; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; /** * An instance of this class is used to specify a set of files, * which are validated against a common schema. */ public class ValidationSet { private String publicId; private String systemId; private String schemaLanguage; private boolean validating; private File dir; private String[] includes; private String[] excludes; private boolean skipDefaultExcludes; /** * Returns a directory, which is scanned for files to validate. */ public File getDir() { return this.dir; } /** * Returns patterns of files, which are being excluded from * the validation set. */ public String[] getExcludes() { return excludes; } /** * Returns patterns of files, which are being included into * the validation set. */ public String[] getIncludes() { return includes; } /** * Returns the schemas public ID. May be null, if the schema is * loaded through its system ID or if the documents are being * validated for wellformedness only. */ public String getPublicId() { return publicId; } /** * Returns the schema language. May be null, if the documents * are being validated for wellformedness only, or if the default * schema language (W3C XML Schema) is being used. See * http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html * for possible values. */ public String getSchemaLanguage() { return schemaLanguage; } /** * Returns the schemas system ID. May be null, if the schema is * loaded through its public ID or if the documents are being * validated for wellformedness only. */ public String getSystemId() { return systemId; } /** * Returns, whether Maven's default excludes are being ignored. * Defaults to false (Default excludes are being used). */ public boolean isSkipDefaultExcludes() { return skipDefaultExcludes; } /** * If the documents are being validated for wellformedness only: * Returns, whether the parser should be validating. (In * other words: Whether documents must contain a document type * or xml schema declaration.) The property is ignored otherwise. * The default value is false. */ public boolean isValidating() { return validating; } /** * Sets a directory, which is scanned for files to validate. */ public void setDir( File pDir ) { dir = pDir; } /** * Sets patterns of files, which are being excluded from * the validation set. */ public void setExcludes( String[] pExcludes ) { excludes = pExcludes; } /** * Sets patterns of files, which are being included into * the validation set. */ public void setIncludes( String[] pIncludes ) { includes = pIncludes; } /** * Sets the schemas public ID. May be null, if the schema is * loaded through its system ID or if the documents are being * validated for wellformedness only. */ public void setPublicId( String pPublicId ) { publicId = pPublicId; } /** * Sets the schema language. May be null, if the documents * are being validated for wellformedness only, or if the default * schema language (W3C XML Schema) is being used. See * http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html * for possible values. */ public void setSchemaLanguage( String pSchemaLanguage ) { schemaLanguage = pSchemaLanguage; } /** * Sets, whether Maven's default excludes are being ignored. * Defaults to false (Default excludes are being used). */ public void setSkipDefaultExcludes( boolean pSkipDefaultExcludes ) { skipDefaultExcludes = pSkipDefaultExcludes; } /** * Sets the schemas system ID. May be null, if the schema is * loaded through its public ID or if the documents are being * validated for wellformedness only. */ public void setSystemId( String pSystemId ) { systemId = pSystemId; } /** * If the documents are being validated for wellformedness only: * Sets, whether the parser should be validating. (In * other words: Whether documents must contain a document type * or xml schema declaration.) The property is ignored otherwise. * The default value is false. */ public void setValidating( boolean pValidating ) { validating = pValidating; } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/TransformMojo.java0000644000175000017500000005432511526025436026316 0ustar eugeneeugenepackage org.codehaus.mojo.xml; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.xml.transform.Source; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.xml.transformer.NameValuePair; import org.codehaus.mojo.xml.transformer.TransformationSet; import org.codehaus.plexus.components.io.filemappers.FileMapper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.xml.sax.InputSource; /** * The TransformMojo is used for transforming a set of files using a common stylesheet. * * @goal transform * @phase generate-resources */ public class TransformMojo extends AbstractXmlMojo { /** * Specifies one or more sets of files, which are being * transformed. * @parameter */ private TransformationSet[] transformationSets; /** * Whether creating the transformed files should be forced. * @parameter expression="${xml.forceCreation}" default-value="false" */ private boolean forceCreation; /** * Transformer factory use. By default, the systems default transformer * factory is used. * If you use this feature you must use at least jdk 1.6 * @parameter expression="${xml.transformerFactory}" */ private String transformerFactory; private void setFeature( TransformerFactory pTransformerFactory, String name, Boolean value ) throws MojoExecutionException { // Try to use the method setFeature, which isn't available until JAXP 1.3 Method m; try { m = pTransformerFactory.getClass().getMethod( "setFeature", new Class[]{ String.class, boolean.class } ); } catch ( NoSuchMethodException e ) { m = null; } if ( m == null ) { // Not available, try to use setAttribute pTransformerFactory.setAttribute( name, value ); } else { try { m.invoke( pTransformerFactory, new Object[]{ name, value } ); } catch ( IllegalAccessException e ) { throw new MojoExecutionException( e.getMessage(), e ); } catch ( InvocationTargetException e ) { Throwable t = e.getTargetException(); throw new MojoExecutionException( t.getMessage(), t ); } } } private Templates getTemplate( Resolver pResolver, Source stylesheet, TransformationSet transformationSet ) throws MojoExecutionException, MojoFailureException { TransformerFactory tf = getTransformerFactory(); if ( pResolver != null ) { tf.setURIResolver( pResolver ); } NameValuePair[] features = transformationSet.getFeatures(); if ( features != null ) { for ( int i = 0; i < features.length; i++ ) { final NameValuePair feature = features[i]; final String name = feature.getName(); if ( name == null || name.length() == 0 ) { throw new MojoFailureException( "A features name is missing or empty." ); } final String value = feature.getValue(); if ( value == null ) { throw new MojoFailureException( "No value specified for feature " + name ); } setFeature( tf, name, Boolean.valueOf( value ) ); } } NameValuePair[] attributes = transformationSet.getAttributes(); if ( attributes != null ) { for ( int i = 0; i < attributes.length; i++ ) { final NameValuePair attribute = attributes[i]; final String name = attribute.getName(); if ( name == null || name.length() == 0 ) { throw new MojoFailureException( "An attributes name is missing or empty." ); } final String value = attribute.getValue(); if ( value == null ) { throw new MojoFailureException( "No value specified for attribute " + name ); } tf.setAttribute( name, value ); } } try { return tf.newTemplates( stylesheet ); } catch ( TransformerConfigurationException e ) { throw new MojoExecutionException( "Failed to parse stylesheet " + stylesheet + ": " + e.getMessage(), e ); } } /** * Creates a new instance of {@link TransformerFactory}. */ private TransformerFactory getTransformerFactory( ) throws MojoFailureException, MojoExecutionException { if ( transformerFactory == null ) { return TransformerFactory.newInstance(); } try { return newTransformerFactory( transformerFactory, Thread.currentThread().getContextClassLoader() ); } catch ( NoSuchMethodException exception ) { throw new MojoFailureException( "JDK6 required when using transformerFactory parameter" ); } catch ( IllegalAccessException exception ) { throw new MojoExecutionException( "Cannot instantiate transformer factory", exception ); } catch ( InvocationTargetException exception ) { throw new MojoExecutionException( "Cannot instantiate transformer factory", exception ); } } // public for use by unit test public static TransformerFactory newTransformerFactory( String factoryClassName, ClassLoader classLoader ) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // use reflection to avoid JAXP 1.4 (and hence JDK6) requirement Class[] methodTypes = new Class[] { String.class, ClassLoader.class }; Method method = TransformerFactory.class.getDeclaredMethod( "newInstance", methodTypes ); Object[] methodArgs = new Object[] { factoryClassName, classLoader }; return (TransformerFactory) method.invoke( null, methodArgs ); } private File getFile( File pDir, String pFile ) { if ( new File( pFile ).isAbsolute() ) { throw new IllegalStateException( "Output/Input file names must not be absolute." ); } return new File( pDir, pFile ); } private File getDir( File pDir ) { if ( pDir == null ) { return getBasedir(); } return asAbsoluteFile( pDir ); } private void addToClasspath( File pOutputDir ) { MavenProject project = getProject(); for ( Iterator iter = project.getResources().iterator(); iter.hasNext(); ) { Resource resource = (Resource) iter.next(); if ( resource.getDirectory().equals( pOutputDir ) ) { return; } } Resource resource = new Resource(); resource.setDirectory( pOutputDir.getPath() ); resource.setFiltering( false ); project.addResource( resource ); } private File getOutputDir( File pOutputDir ) { if ( pOutputDir == null ) { MavenProject project = getProject(); String dir = project.getBuild().getDirectory(); if ( dir == null ) { throw new IllegalStateException( "The projects build directory is null." ); } dir += "/generated-resources/xml/xslt"; return asAbsoluteFile( new File( dir ) ); } return asAbsoluteFile( pOutputDir ); } private static String getAllExMsgs( Throwable ex, boolean includeExName ) { StringBuffer sb = new StringBuffer( ( includeExName ? ex.toString() : ex.getLocalizedMessage() ) ); while ( ( ex = ex.getCause() ) != null ) { sb.append( "\nCaused by: " + ex.toString() ); } return sb.toString(); } /** * * @param files the fileNames or URLs to scan their lastModified timestamp. * @param oldest if true, returns the latest modificationDate of all files, * otherwise returns the earliest. * @return the older or younger last modification timestamp of all files. */ protected long findLastModified( List/**/files, boolean oldest ) { long timeStamp = ( oldest ? Long.MIN_VALUE : Long.MAX_VALUE ); for ( Iterator it = files.iterator(); it.hasNext(); ) { Object no = it.next(); if ( no != null ) { long fileModifTime; if ( no instanceof File ) { fileModifTime = ( (File) no ).lastModified(); } else // either URL or filePath { String sdep = no.toString(); try { URL url = new URL( sdep ); URLConnection uCon = url.openConnection(); uCon.setUseCaches( false ); fileModifTime = uCon.getLastModified(); } catch ( MalformedURLException e ) { fileModifTime = new File( sdep ).lastModified(); } catch ( IOException ex ) { fileModifTime = ( oldest ? Long.MIN_VALUE : Long.MAX_VALUE ); getLog().warn( "Skipping URL '" + no + "' from up-to-date check due to error while opening connection: " + getAllExMsgs( ex, true ) ); } } getLog().debug( ( oldest ? "Depends " : "Produces " ) + no + ": " + new Date( fileModifTime ) ); if ( ( fileModifTime > timeStamp ) ^ !oldest ) { timeStamp = fileModifTime; } } // end if file null. } // end filesloop if ( timeStamp == Long.MIN_VALUE ) { // no older file found return Long.MAX_VALUE; // assume re-execution required. } else if ( timeStamp == Long.MAX_VALUE ) { // no younger file found return Long.MIN_VALUE; // assume re-execution required. } return timeStamp; } /** * @return true to indicate results are up-to-date, that is, when the latest * from input files is earlier than the younger from the output * files (meaning no re-execution required). */ protected boolean isUpdToDate( List dependsFiles, List producesFiles ) { // The older timeStamp of all input files; long inputTimeStamp = findLastModified( dependsFiles, true ); // The younger of all destination files. long destTimeStamp = producesFiles == null ? Long.MIN_VALUE : findLastModified( producesFiles, false ); getLog().debug( "Depends timeStamp: " + inputTimeStamp + ", produces timestamp: " + destTimeStamp ); return inputTimeStamp < destTimeStamp; } private void transform( Transformer pTransformer, File input, File output, Resolver pResolver ) throws MojoExecutionException { File dir = output.getParentFile(); dir.mkdirs(); getLog().info( "Transforming file: " + input.getPath() ); FileOutputStream fos = null; try { final boolean transformInPlace = output.equals( input ); File tmpOutput = null; if ( transformInPlace ) { tmpOutput = File.createTempFile( "xml-maven-plugin", "xml" ); tmpOutput.deleteOnExit(); fos = new FileOutputStream( tmpOutput ); } else { fos = new FileOutputStream( output ); } final String parentFile = input.getParent() == null ? null : input.getParentFile().toURI().toURL().toExternalForm(); pTransformer.transform( pResolver.resolve( input.toURI().toURL().toExternalForm(), parentFile ), new StreamResult( fos ) ); fos.close(); fos = null; if ( transformInPlace ) { FileUtils.copyFile( tmpOutput, output ); /* tmpOutput is a temporary file */ tmpOutput.delete(); } } catch ( IOException e ) { throw new MojoExecutionException( "Failed to create output file " + output.getPath() + ": " + e.getMessage(), e ); } catch ( TransformerException e ) { throw new MojoExecutionException( "Failed to transform input file " + input.getPath() + ": " + e.getMessage(), e ); } finally { if ( fos != null ) { try { fos.close(); } catch ( Throwable t ) { /* Ignore me */ } } } } private File getOutputFile( File targetDir, String pName, FileMapper[] pFileMappers ) { String name = pName; if ( pFileMappers != null ) { for ( int i = 0; i < pFileMappers.length; i++ ) { name = pFileMappers[i].getMappedFileName( name ); } } return getFile( targetDir, name ); } private void transform( Resolver pResolver, TransformationSet pTransformationSet ) throws MojoExecutionException, MojoFailureException { String[] fileNames = getFileNames( pTransformationSet.getDir(), pTransformationSet.getIncludes(), getExcludes( pTransformationSet.getExcludes(), pTransformationSet.isSkipDefaultExcludes() ) ); if ( fileNames == null || fileNames.length == 0 ) { getLog().warn( "No files found for transformation by stylesheet " + pTransformationSet.getStylesheet() ); return; } String stylesheetName = pTransformationSet.getStylesheet(); if ( stylesheetName == null ) { getLog().warn( "No stylesheet configured." ); return; } final URL stylesheetUrl = getResource( stylesheetName ); Templates template; InputStream stream = null; try { stream = stylesheetUrl.openStream(); InputSource isource = new InputSource( stream ); isource.setSystemId( stylesheetUrl.toExternalForm() ); template = getTemplate( pResolver, new SAXSource( isource ), pTransformationSet ); stream.close(); stream = null; } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } finally { IOUtil.close( stream ); } int filesTransformed = 0; File inputDir = getDir( pTransformationSet.getDir() ); File outputDir = getOutputDir( pTransformationSet.getOutputDir() ); for ( int i = 0; i < fileNames.length; i++ ) { final Transformer t; File input = getFile( inputDir, fileNames[i] ); File output = getOutputFile( outputDir, fileNames[i], pTransformationSet.getFileMappers() ); // Perform up-to-date-check. boolean needsTransform = forceCreation; if ( !needsTransform ) { List dependsFiles = new ArrayList(); List producesFiles = new ArrayList(); // Depends from pom.xml file for when project configuration changes. dependsFiles.add( getProject().getFile() ); if ( "file".equals( stylesheetUrl.getProtocol() ) ) { dependsFiles.add( new File( stylesheetUrl.getFile() ) ); } List catalogFiles = new ArrayList(); List catalogUrls = new ArrayList(); setCatalogs( catalogFiles, catalogUrls ); dependsFiles.addAll( catalogFiles ); dependsFiles.add( input ); File[] files = asFiles( getBasedir(), pTransformationSet.getOtherDepends() ); for ( int j = 0; j < files.length; j++ ) { dependsFiles.add( files[j] ); } producesFiles.add( output ); needsTransform = !isUpdToDate( dependsFiles, producesFiles ); } if ( !needsTransform ) { getLog().debug( "Skipping XSL transformation. File " + fileNames[i] + " is up-to-date." ); } else { filesTransformed++; // Perform transformation. try { t = newTransformer( template, pTransformationSet ); t.setURIResolver( pResolver ); NameValuePair[] parameters = pTransformationSet.getParameters(); if ( parameters != null ) { for ( int j = 0; j < parameters.length; j++ ) { NameValuePair key = parameters[j]; t.setParameter( key.getName(), key.getValue() ); } } transform( t, input, output, pResolver ); } catch ( TransformerConfigurationException e ) { throw new MojoExecutionException( "Failed to create Transformer: " + e.getMessage(), e ); } } } // end file loop if ( filesTransformed > 0 ) { getLog().info( "Transformed " + filesTransformed + " file(s)." ); } if ( pTransformationSet.isAddedToClasspath() ) { addToClasspath( pTransformationSet.getOutputDir() ); } } private Transformer newTransformer( Templates template, TransformationSet pTransformationSet ) throws TransformerConfigurationException, MojoExecutionException, MojoFailureException { Transformer t = template.newTransformer(); NameValuePair[] properties = pTransformationSet.getOutputProperties(); if ( properties != null ) { for ( int i = 0; i < properties.length; i++ ) { final String name = properties[i].getName(); if ( name == null || "".equals( name ) ) { throw new MojoFailureException( "Missing or empty output property name" ); } final String value = properties[i].getValue(); if ( value == null ) { throw new MojoFailureException( "Missing value for output property " + name ); } try { t.setOutputProperty( name, value ); } catch ( IllegalArgumentException e ) { throw new MojoExecutionException( "Unsupported property name or value: " + name + " => " + value + e.getMessage(), e ); } } } return t; } /** * Called by Maven to run the plugin. */ public void execute() throws MojoExecutionException, MojoFailureException { if ( transformationSets == null || transformationSets.length == 0 ) { throw new MojoFailureException( "No TransformationSets configured." ); } Object oldProxySettings = activateProxy(); try { Resolver resolver = getResolver( ); for ( int i = 0; i < transformationSets.length; i++ ) { TransformationSet transformationSet = transformationSets[i]; resolver.setValidating( transformationSet.isValidating() ); transform( resolver, transformationSet ); } } finally { passivateProxy( oldProxySettings ); } } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/ValidateMojo.java0000644000175000017500000002761211416654001026065 0ustar eugeneeugenepackage org.codehaus.mojo.xml; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import javax.xml.XMLConstants; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.codehaus.mojo.xml.validation.ValidationSet; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; /** * The ValidatorMojo's task is the validation of XML files against a given schema. * * @goal validate * @phase test */ public class ValidateMojo extends AbstractXmlMojo { /** * Specifies a set of document types, which are being * validated. * @parameter */ private ValidationSet[] validationSets; /** * Reads a validation sets schema. * @param pResolver The resolver to use for loading external entities. * @param pValidationSet The validation set to configure. * @return The validation sets schema, if any, or null. * @throws MojoExecutionException Loading the schema failed. */ private Schema getSchema( Resolver pResolver, ValidationSet pValidationSet ) throws MojoExecutionException { final String publicId = pValidationSet.getPublicId(); final String systemId = pValidationSet.getSystemId(); if ( ( publicId == null || "".equals( publicId ) ) && ( systemId == null || "".equals( systemId ) ) ) { return null; } getLog().debug( "Loading schema with public Id " + publicId + ", system Id " + systemId ); InputSource inputSource = null; if ( pResolver != null ) { try { inputSource = pResolver.resolveEntity( publicId, systemId ); } catch ( SAXException e ) { throw new MojoExecutionException( e.getMessage(), e ); } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } if ( inputSource == null ) { inputSource = new InputSource(); inputSource.setPublicId( publicId ); inputSource.setSystemId( systemId ); } final SAXSource saxSource = new SAXSource( inputSource ); String schemaLanguage = pValidationSet.getSchemaLanguage(); if ( schemaLanguage == null || "".equals( schemaLanguage ) ) { schemaLanguage = XMLConstants.W3C_XML_SCHEMA_NS_URI; } try { SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage ); if ( pResolver != null ) { schemaFactory.setResourceResolver( pResolver ); } return schemaFactory.newSchema( saxSource ); } catch ( SAXException e ) { throw new MojoExecutionException( "Failed to load schema with public ID " + publicId + ", system ID " + systemId + ": " + e.getMessage(), e ); } } /** * Called for parsing or validating a single file. * @param pResolver The resolver to use for loading external entities. * @param pValidationSet The parsers or validators configuration. * @param pSchema The schema to use. * @param pFile The file to parse or validate. * @throws MojoExecutionException Parsing or validating the file failed. */ private void validate( final Resolver pResolver, ValidationSet pValidationSet, Schema pSchema, File pFile ) throws MojoExecutionException { try { if ( pSchema == null ) { getLog().debug( "Parsing " + pFile.getPath() ); parse( pResolver, pValidationSet, pFile ); } else { getLog().debug( "Validating " + pFile.getPath() ); Validator validator = pSchema.newValidator(); if ( pResolver != null ) { validator.setResourceResolver( pResolver ); } validator.validate( new StreamSource( pFile ) ); } } catch ( SAXParseException e ) { final String publicId = e.getPublicId(); final String systemId = e.getSystemId(); final int lineNum = e.getLineNumber(); final int colNum = e.getColumnNumber(); final String location; if ( publicId == null && systemId == null && lineNum == -1 && colNum == -1 ) { location = ""; } else { final StringBuffer loc = new StringBuffer(); String sep = ""; if ( publicId != null ) { loc.append( "Public ID " ); loc.append( publicId ); sep = ", "; } if ( systemId != null ) { loc.append( sep ); loc.append( systemId ); sep = ", "; } if ( lineNum != -1 ) { loc.append( sep ); loc.append( "line " ); loc.append( lineNum ); sep = ", "; } if ( colNum != -1 ) { loc.append( sep ); loc.append( " column " ); loc.append( colNum ); sep = ", "; } location = loc.toString(); } final String msg = "While parsing " + pFile.getPath() + ( "".equals( location ) ? "" : ", at " + location ) + ": " + e.getMessage(); throw new MojoExecutionException( msg, e ); } catch ( Exception e ) { throw new MojoExecutionException( "While parsing " + pFile + ": " + e.getMessage(), e ); } } /** * Creates a new instance of {@link SAXParserFactory}. * @param pValidationSet The parser factories configuration. * @return A new SAX parser factory. */ private SAXParserFactory newSAXParserFactory( ValidationSet pValidationSet ) { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating( pValidationSet.isValidating() ); if ( pValidationSet.isValidating() ) { try { spf.setFeature( "http://apache.org/xml/features/validation/schema", true ); } catch ( SAXException e ) { // Ignore this } catch ( ParserConfigurationException e ) { // Ignore this } } else { try { spf.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false ); } catch ( SAXException e ) { // Ignore this } catch ( ParserConfigurationException e ) { // Ignore this } } spf.setNamespaceAware( true ); return spf; } /** * Called for validating a single file. * @param pResolver The resolver to use for loading external entities. * @param pValidationSet The validators configuration. * @param pFile The file to validate. * @throws IOException An I/O error occurred. * @throws SAXException Parsing the file failed. * @throws ParserConfigurationException Creating an XML parser failed. */ private void parse( Resolver pResolver, ValidationSet pValidationSet, File pFile ) throws IOException, SAXException, ParserConfigurationException { XMLReader xr = newSAXParserFactory( pValidationSet ).newSAXParser().getXMLReader(); if ( pResolver != null ) { xr.setEntityResolver( pResolver ); } xr.setErrorHandler( new ErrorHandler() { public void error( SAXParseException pException ) throws SAXException { throw pException; } public void fatalError( SAXParseException pException ) throws SAXException { throw pException; } public void warning( SAXParseException pException ) throws SAXException { throw pException; } } ); xr.parse( pFile.toURI().toURL().toExternalForm() ); } /** * Called for validating a set of XML files against a common schema. * @param pResolver The resolver to use for loading external entities. * @param pValidationSet The set of XML files to validate. * @throws MojoExecutionException Validating the set of files failed. * @throws MojoFailureException A configuration error was detected. */ private void validate( Resolver pResolver, ValidationSet pValidationSet ) throws MojoExecutionException, MojoFailureException { final Schema schema = getSchema( pResolver, pValidationSet ); final File[] files = getFiles( pValidationSet.getDir(), pValidationSet.getIncludes(), getExcludes( pValidationSet.getExcludes(), pValidationSet.isSkipDefaultExcludes() ) ); if ( files.length == 0 ) { getLog().info( "No matching files found for ValidationSet with public ID " + pValidationSet.getPublicId() + ", system ID " + pValidationSet.getSystemId() + "." ); } for ( int i = 0; i < files.length; i++ ) { validate( pResolver, pValidationSet, schema, files[i] ); } } /** * Called by Maven for executing the Mojo. * @throws MojoExecutionException Running the Mojo failed. * @throws MojoFailureException A configuration error was detected. */ public void execute() throws MojoExecutionException, MojoFailureException { if ( validationSets == null || validationSets.length == 0 ) { throw new MojoFailureException( "No ValidationSets configured." ); } Object oldProxySettings = activateProxy(); try { Resolver resolver = getResolver(); for ( int i = 0; i < validationSets.length; i++ ) { ValidationSet validationSet = validationSets[i]; resolver.setValidating( validationSet.isValidating() ); validate( resolver, validationSet ); } } finally { passivateProxy( oldProxySettings ); } } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/LSInputImpl.java0000644000175000017500000000507410773161441025673 0ustar eugeneeugenepackage org.codehaus.mojo.xml; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.InputStream; import java.io.Reader; import org.w3c.dom.ls.LSInput; /** * Implementation of {@link LSInput}, for use by the {@link Resolver}. */ class LSInputImpl implements LSInput { private String baseURI, encoding, systemId, publicId, stringData; private InputStream byteStream; private Reader characterStream; private boolean certifiedText; public String getBaseURI() { return baseURI; } public InputStream getByteStream() { return byteStream; } public boolean getCertifiedText() { return certifiedText; } public Reader getCharacterStream() { return characterStream; } public String getEncoding() { return encoding; } public String getPublicId() { return publicId; } public String getStringData() { return stringData; } public String getSystemId() { return systemId; } public void setBaseURI( String pBaseURI ) { baseURI = pBaseURI; } public void setByteStream( InputStream pByteStream ) { byteStream = pByteStream; } public void setCertifiedText( boolean pCertifiedText ) { certifiedText = pCertifiedText; } public void setCharacterStream( Reader pCharacterStream ) { characterStream = pCharacterStream; } public void setEncoding( String pEncoding ) { encoding = pEncoding; } public void setPublicId( String pPublicId ) { publicId = pPublicId; } public void setStringData( String pStringData ) { stringData = pStringData; } public void setSystemId( String pSystemId ) { systemId = pSystemId; } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/AbstractXmlMojo.java0000644000175000017500000002540111517547436026571 0ustar eugeneeugenepackage org.codehaus.mojo.xml; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.FileResourceLoader; import org.codehaus.plexus.resource.loader.ResourceNotFoundException; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; /** Abstract base class for the plugins Mojo's. */ public abstract class AbstractXmlMojo extends AbstractMojo { /** * @parameter expression="${project}" * @required * @readonly */ private MavenProject project; /** * The system settings for Maven. This is the instance resulting from * merging global- and user-level settings files. * * @parameter expression="${settings}" * @required * @readonly */ private Settings settings; /** * The base directory, relative to which directory names are * interpreted. * * @parameter expression="${basedir}" * @required * @readonly */ private File basedir; /** An XML catalog file, or URL, which is being used to resolve * entities. * @parameter */ private String[] catalogs; /** * Plexus resource manager used to obtain XSL. * * @component * @required * @readonly */ private ResourceManager locator; private boolean locatorInitialized; /** * Returns the maven project. */ protected MavenProject getProject() { return project; } /** * Returns the projects base directory. */ protected File getBasedir() { return basedir; } /** * Converts the given file into an file with an absolute * path. */ protected File asAbsoluteFile( File f ) { if ( f.isAbsolute() ) { return f; } return new File( getBasedir(), f.getPath() ); } /** * Returns the plugins catalog files. */ protected void setCatalogs( List pCatalogFiles, List pCatalogUrls ) { if ( catalogs == null || catalogs.length == 0 ) { return; } for ( int i = 0; i < catalogs.length; i++ ) { try { URL url = new URL( catalogs[i] ); pCatalogUrls.add( url ); } catch ( MalformedURLException e ) { pCatalogFiles.add( asAbsoluteFile( new File( catalogs[i] ) ) ); } } } /** * Creates a new resolver. */ protected Resolver getResolver() throws MojoExecutionException { List catalogFiles = new ArrayList(); List catalogUrls = new ArrayList(); setCatalogs( catalogFiles, catalogUrls ); return new Resolver( getBasedir(), catalogFiles, catalogUrls, getLocator(), getLog().isDebugEnabled() ); } /** * Scans a directory for files and returns a set of path names. */ protected String[] getFileNames( File pDir, String[] pIncludes, String[] pExcludes ) throws MojoFailureException { if ( pDir == null ) { throw new MojoFailureException( "A ValidationSet or TransformationSet" + " requires a nonempty 'dir' child element." ); } final File dir = asAbsoluteFile( pDir ); if ( !dir.isDirectory() ) { getLog().warn( "The directory " + dir.getPath() + ", which is a base directory of a ValidationSet or TransformationSet, does not exist." ); return new String[0]; } final DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir( dir ); if ( pIncludes != null && pIncludes.length > 0 ) { ds.setIncludes( pIncludes ); } if ( pExcludes != null && pExcludes.length > 0 ) { ds.setExcludes( pExcludes ); } ds.scan(); return ds.getIncludedFiles(); } /** * Converts the given set of file names into a set of {@link File} * instances. The file names may be relative to the given base directory. */ protected File[] asFiles( File pDir, String[] pFileNames ) { if ( pFileNames == null ) { return new File[0]; } File dir = asAbsoluteFile( pDir ); File[] result = new File[pFileNames.length]; for ( int i = 0; i < pFileNames.length; i++ ) { result[i] = new File( dir, pFileNames[i] ); } return result; } /** * Scans a directory for files and returns a set of {@link File} instances. */ protected File[] getFiles( File pDir, String[] pIncludes, String[] pExcludes ) throws MojoFailureException { return asFiles( pDir, getFileNames( pDir, pIncludes, pExcludes ) ); } /** * Calculates the exclusions to use when searching files. */ protected String[] getExcludes( String[] origExcludes, boolean skipDefaultExcludes ) { if ( skipDefaultExcludes ) { return origExcludes; } String[] defaultExcludes = FileUtils.getDefaultExcludes(); if ( origExcludes == null || origExcludes.length == 0 ) { return defaultExcludes; } String[] result = new String[origExcludes.length + defaultExcludes.length]; System.arraycopy( origExcludes, 0, result, 0, origExcludes.length ); System.arraycopy( defaultExcludes, 0, result, origExcludes.length, defaultExcludes.length ); return result; } private boolean isEmpty( String value ) { return value == null || value.trim().length() == 0; } private void setProperty( List pProperties, String pKey, String pValue ) { if ( pProperties != null ) { pProperties.add( pKey ); pProperties.add( System.getProperty( pKey ) ); } if ( pValue == null ) { System.getProperties().remove( pKey ); } else { System.setProperty( pKey, pValue ); } } /** * Called to install the plugins proxy settings. */ protected Object activateProxy() { if ( settings == null ) { return null; } final Proxy proxy = settings.getActiveProxy(); if ( proxy == null ) { return null; } final List properties = new ArrayList(); final String protocol = proxy.getProtocol(); final String prefix = isEmpty( protocol ) ? "" : ( protocol + "." ); final String host = proxy.getHost(); final String hostProperty = prefix + "proxyHost"; final String hostValue = isEmpty( host ) ? null : host; setProperty( properties, hostProperty, hostValue ); final int port = proxy.getPort(); final String portProperty = prefix + "proxyPort"; final String portValue = ( port == 0 || port == -1 ) ? null : String.valueOf( port ); setProperty( properties, portProperty, portValue ); final String username = proxy.getUsername(); final String userProperty = prefix + "proxyUser"; final String userValue = isEmpty( username ) ? null : username; setProperty( properties, userProperty, userValue ); final String password = proxy.getPassword(); final String passwordProperty = prefix + "proxyPassword"; final String passwordValue = isEmpty( password ) ? null : password; setProperty( properties, passwordProperty, passwordValue ); final String nonProxyHosts = proxy.getNonProxyHosts(); final String nonProxyHostsProperty = prefix + "nonProxyHosts"; final String nonProxyHostsValue = isEmpty( nonProxyHosts ) ? null : nonProxyHosts.replace( ',' , '|' ); setProperty( properties, nonProxyHostsProperty, nonProxyHostsValue ); getLog().debug( "Proxy settings: " + hostProperty + "=" + hostValue + ", " + portProperty + "=" + portValue + ", " + userProperty + "=" + userValue + ", " + passwordProperty + "=" + (passwordValue == null ? "null" : "") + ", " + nonProxyHostsProperty + "=" + nonProxyHostsValue ); return properties; } /** * Called to restore the proxy settings, which have been installed * when the plugin was invoked. */ protected void passivateProxy( Object pProperties ) { if ( pProperties == null ) { return; } final List properties = (List) pProperties; for ( Iterator iter = properties.iterator(); iter.hasNext(); ) { final String key = (String) iter.next(); final String value = (String) iter.next(); setProperty( null, key, value ); } } protected URL getResource( String pResource ) throws MojoFailureException { try { return getLocator().getResource( pResource ).getURL(); } catch ( ResourceNotFoundException exception ) { throw new MojoFailureException( "Could not find stylesheet: " + pResource ); } catch ( IOException e ) { throw new MojoFailureException( "Error while locating resource: " + pResource ); } } protected ResourceManager getLocator() { if ( !locatorInitialized ) { locator.addSearchPath( FileResourceLoader.ID, getBasedir().getAbsolutePath() ); locatorInitialized = true; } return locator; } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/Resolver.java0000644000175000017500000002464111526025436025315 0ustar eugeneeugenepackage org.codehaus.mojo.xml; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.UndeclaredThrowableException; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; import javax.xml.transform.URIResolver; import javax.xml.transform.sax.SAXSource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.xml.resolver.CatalogManager; import org.apache.xml.resolver.tools.CatalogResolver; import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.ResourceNotFoundException; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.ext.EntityResolver2; /** * An implementation of {@link org.xml.sax.EntityResolver}, * {@link URIResolver}, and {@link LSResourceResolver}, * based on the Apache catalog resolver. */ public class Resolver implements EntityResolver2, URIResolver, LSResourceResolver { private final ResourceManager locator; private final File baseDir; private final CatalogResolver resolver; private boolean validating; /** Creates a new instance. * @param pFiles A set of files with catalog definitions to load * @throws MojoExecutionException An error occurred while loading the resolvers catalogs. */ Resolver( File pBaseDir, List pFiles, List pUrls, ResourceManager pLocator, boolean pLogging ) throws MojoExecutionException { baseDir = pBaseDir; locator = pLocator; CatalogManager manager = new CatalogManager(); manager.setIgnoreMissingProperties( true ); if ( pLogging ) { System.err.println("Setting resolver verbosity to maximum."); manager.setVerbosity( Integer.MAX_VALUE ); } resolver = new CatalogResolver( manager ); for ( int i = 0; i < pFiles.size(); i++ ) { File file = (File) pFiles.get( i ); try { resolver.getCatalog().parseCatalog( file.getPath() ); } catch ( IOException e ) { throw new MojoExecutionException( "Failed to parse catalog file: " + file.getPath() + ": " + e.getMessage(), e ); } } for ( int i = 0; i < pUrls.size(); i++ ) { URL url = (URL) pUrls.get( i ); try { resolver.getCatalog().parseCatalog( url ); } catch ( IOException e ) { throw new MojoExecutionException( "Failed to parse catalog URL: " + url + ": " + e.getMessage(), e ); } } } /** * Implementation of {@link org.xml.sax.EntityResolver#resolveEntity(String, String)}. */ public InputSource resolveEntity( String pPublicId, String pSystemId ) throws SAXException, IOException { final InputSource source = resolver.resolveEntity( pPublicId, pSystemId ); if ( source != null ) { return source; } URL url = resolve( pSystemId ); if ( url != null ) { return asInputSource( url ); } return null; } private InputSource asInputSource( URL url ) throws IOException { InputSource isource = new InputSource( url.openStream() ); isource.setSystemId( url.toExternalForm() ); return isource; } /** * Implementation of {@link URIResolver#resolve(String, String)}. */ public Source resolve( String pHref, String pBase ) throws TransformerException { final Source source = resolver.resolve( pHref, pBase ); if ( source != null ) { return source; } URL url = resolve( pHref ); if ( url != null ) { try { return asSaxSource( asInputSource( url ) ); } catch ( IOException e ) { throw new TransformerException( e ); } catch ( SAXException e ) { throw new TransformerException( e ); } catch ( ParserConfigurationException e ) { throw new TransformerException( e ); } } return null; } private Source asSaxSource( InputSource isource ) throws SAXException, ParserConfigurationException { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setValidating( validating ); spf.setNamespaceAware( true ); XMLReader xmlReader = spf.newSAXParser().getXMLReader(); xmlReader.setEntityResolver( this ); return new SAXSource( xmlReader, isource ); } private final LSInput newLSInput( InputSource pSource ) { final LSInputImpl lsInput = new LSInputImpl(); lsInput.setByteStream( pSource.getByteStream() ); lsInput.setCharacterStream( pSource.getCharacterStream() ); lsInput.setPublicId( lsInput.getPublicId() ); lsInput.setSystemId( pSource.getSystemId() ); lsInput.setEncoding( pSource.getEncoding() ); return lsInput; } /** * Implementation of {@link LSResourceResolver#resolveResource(String, String, String, String, String)}. */ public LSInput resolveResource( String pType, String pNamespaceURI, String pPublicId, String pSystemId, String pBaseURI ) { if ( pPublicId != null ) { final InputSource isource = resolver.resolveEntity( pPublicId, pSystemId ); if ( isource != null ) { return newLSInput( isource ); } } InputSource isource = resolver.resolveEntity( pNamespaceURI, pSystemId ); if ( isource != null ) { return newLSInput( isource ); } URL url = resolve( pSystemId ); if ( url != null ) { try { isource = asInputSource( url ); } catch ( IOException e ) { throw new UndeclaredThrowableException( e ); } } return newLSInput( isource ); } /** * Sets, whether the Resolver should create validating parsers. */ public void setValidating ( boolean pValidating ) { validating = pValidating; } /** * Returns, whether the Resolver should create validating parsers. */ public boolean isValidating ( ) { return validating; } private URL resolveAsResource( String pResource ) { return Thread.currentThread().getContextClassLoader().getResource( pResource ); } private URL resolveAsFile( String pResource ) { File f = new File( baseDir, pResource ); if ( !f.isFile() ) { f = new File( pResource ); if ( !f.isFile() ) { return null; } } try { return f.toURI().toURL(); } catch ( MalformedURLException e ) { return null; } } private URL resolveAsURL( String pResource ) { InputStream stream = null; try { final URL url = new URL( pResource ); stream = url.openStream(); stream.close(); stream = null; return url; } catch ( IOException e ) { return null; } finally { if ( stream != null ) { try { stream.close(); } catch ( Throwable t ) { // Ignore me } } } } /** * Attempts to resolve the given URI. */ public URL resolve( String pResource ) { if ( pResource == null ) { return null; } if ( pResource.startsWith( "resource:" ) ) { String res = pResource.substring( "resource:".length() ); return resolveAsResource( res ); } URL url = resolveAsResource( pResource ); if ( url == null ) { url = resolveAsURL( pResource ); if ( url == null ) { url = resolveAsFile( pResource ); } } try { return locator.getResource( pResource ).getURL(); } catch ( ResourceNotFoundException e ) { return null; } catch ( IOException e ) { return null; } } /** * Implementation of {@link EntityResolver2#getExternalSubset(String, String)} */ public InputSource getExternalSubset( String name, String baseURI ) throws SAXException, IOException { return null; } /** * Implementation of {@link EntityResolver2#resolveEntity(String, String, String, String)} */ public InputSource resolveEntity( String pName, String pPublicId, String pBaseURI, String pSystemId ) throws SAXException, IOException { final InputSource source = resolver.resolveEntity( pPublicId, pSystemId ); if ( source != null ) { return source; } URL url = resolve( pSystemId ); if ( url != null ) { return asInputSource( url ); } return null; } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/transformer/0000755000175000017500000000000012137716636025214 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/transformer/TransformationSet.java0000644000175000017500000001616411517153174031542 0ustar eugeneeugenepackage org.codehaus.mojo.xml.transformer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.File; import org.codehaus.plexus.components.io.filemappers.FileMapper; /** * An instance of this class is used to specify a set of files, * which are transformed by a common XSLT stylesheet. */ public class TransformationSet { private String stylesheet; private File dir; private File outputDir; private boolean addedToClasspath; private String[] includes; private String[] excludes; private boolean skipDefaultExcludes; private String[] otherDepends; private NameValuePair[] parameters; private NameValuePair[] features; private NameValuePair[] attributes; private NameValuePair[] outputProperties; private FileMapper[] fileMappers; private boolean validating; /** * Sets patterns of files, which are being excluded from * the transformation set. */ public void setExcludes( String[] pExcludes ) { excludes = pExcludes; } /** * Sets patterns of files, which are being included into * the transformation set. */ public void setIncludes( String[] pIncludes ) { includes = pIncludes; } /** * Sets patterns of additional files, which are being considered * for the uptodate check. */ public void setOtherDepends( String[] pOtherDepends ) { otherDepends = pOtherDepends; } /** * Sets the stylesheet parameters. */ public void setParameters( NameValuePair[] pParameters ) { parameters = pParameters; } /** * Returns a directory, which is scanned * for files to transform. */ public File getDir() { return dir; } /** * Returns patterns of files, which are being excluded from * the transformation set. */ public String[] getExcludes() { return excludes; } /** * Returns patterns of files, which are being included into * the transformation set. */ public String[] getIncludes() { return includes; } /** * Returns patterns of additional files, which are being considered * for the uptodate check. */ public String[] getOtherDepends() { return otherDepends; } /** * Returns the output directory, * where the generated files are being placed. Defaults to * {project.build.directory}/generated-resources/xml/xslt. */ public File getOutputDir() { return outputDir; } /** * Returns the stylesheet parameters. */ public NameValuePair[] getParameters() { return parameters; } /** * Returns the XSLT stylesheet, which is being used to control * the transformation. */ public String getStylesheet() { return stylesheet; } /** * Returns, whether the output directory is added to the classpath. * Defaults to false. */ public boolean isAddedToClasspath() { return addedToClasspath; } /** * Returns, whether Maven's default excludes are being ignored. * Defaults to false (Default excludes are being used). */ public boolean isSkipDefaultExcludes() { return skipDefaultExcludes; } /** * Sets, whether the output directory is added to the classpath. * Defaults to false. */ public void setAddedToClasspath( boolean pAddedToClasspath ) { addedToClasspath = pAddedToClasspath; } /** * Sets the name of a directory, which is scanned * for files to transform. */ public void setDir( File pDir ) { dir = pDir; } /** * Sets the output directory, * where the generated files are being placed. Defaults to * {project.build.directory}/generated-resources/xml/xslt. */ public void setOutputDir( File pOutputDir ) { outputDir = pOutputDir; } /** * Sets, whether Maven's default excludes are being ignored. * Defaults to false (Default excludes are being used). */ public void setSkipDefaultExcludes( boolean pSkipDefaultExcludes ) { skipDefaultExcludes = pSkipDefaultExcludes; } /** * Sets the XSLT stylesheet, which is being used to control * the transformation. */ public void setStylesheet( String pStylesheet ) { stylesheet = pStylesheet; } /** * Returns a set of file mappers, which are being used to * convert the generated files name. */ public FileMapper[] getFileMappers() { return fileMappers; } /** * Sets a set of file mappers, which are being used to * convert the generated files name. */ public void setFileMappers( FileMapper[] pFileMappers ) { fileMappers = pFileMappers; } /** * Returns, whether the transformer should create validating XML parsers * for reading XML documents. The default value is false. */ public boolean isValidating() { return validating; } /** * Sets, whether the transformer should create validating XML parsers * for reading XML documents. The default value is false. */ public void setValidating( boolean pValidating ) { validating = pValidating; } /** * Returns the transformers output properties. */ public NameValuePair[] getOutputProperties() { return outputProperties; } /** * Sets the transformers output properties. */ public void setOutputProperties( NameValuePair[] pOutputProperties ) { outputProperties = pOutputProperties; } /** * Returns the features, which should be set on the transformer factory. */ public NameValuePair[] getFeatures() { return features; } /** * Sets the features, which should be set on the transformer factory. */ public void setFeatures( NameValuePair[] pFeatures ) { features = pFeatures; } /** * Returns the attributes, which should be set on the transformer factory. */ public NameValuePair[] getAttributes() { return attributes; } /** * Sets the attributes, which should be set on the transformer factory. */ public void setAttributes( NameValuePair[] pAttributes ) { attributes = pAttributes; } } xml-maven-plugin-1.0/src/main/java/org/codehaus/mojo/xml/transformer/NameValuePair.java0000644000175000017500000000271310773161441030543 0ustar eugeneeugenepackage org.codehaus.mojo.xml.transformer; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /** * An instance of this class is used to specify an output property. */ public class NameValuePair { private String name, value; /** * Returns the parameter name. */ public String getName() { return this.name; } /** * Sets the parameter name. */ public void setName( String pName ) { name = pName; } /** * Returns the parameter value. */ public String getValue() { return this.value; } /** * Sets the parameter value. */ public void setValue( String pValue ) { value = pValue; } } xml-maven-plugin-1.0/src/main/checkstyle/0000755000175000017500000000000012137716636017741 5ustar eugeneeugenexml-maven-plugin-1.0/src/main/checkstyle/maven-header.txt0000644000175000017500000000166210773161441023033 0ustar eugeneeugene^package ^\s*$ ^/\*\s*$ ^ \* Licensed to the Apache Software Foundation \(ASF\) under one\s*$ ^ \* or more contributor license agreements. See the NOTICE file\s*$ ^ \* distributed with this work for additional information\s*$ ^ \* regarding copyright ownership. The ASF licenses this file\s*$ ^ \* to you under the Apache License, Version 2.0 \(the\s*$ ^ \* "License"\)\; you may not use this file except in compliance\s*$ ^ \* with the License. You may obtain a copy of the License at\s*$ ^ \*\s*$ ^ \*\s+http://www\.apache\.org/licenses/LICENSE-2\.0\s*$ ^ \*\s*$ ^ \* Unless required by applicable law or agreed to in writing,\s*$ ^ \* software distributed under the License is distributed on an\s*$ ^ \* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\s*$ ^ \* KIND, either express or implied. See the License for the\s*$ ^ \* specific language governing permissions and limitations\s*$ ^ \* under the License.\s*$ ^ \*/\s*$ ^\s*$ xml-maven-plugin-1.0/src/it/0000755000175000017500000000000012137716637015274 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/0000755000175000017500000000000012137716637015776 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/pom.xml0000644000175000017500000000345411415151740017303 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it6 0.1 Maven XML Plugin IT 1 Integration Test 1 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform src/main/xml src/main/xsl/it4.xsl .fo xml-maven-plugin-1.0/src/it/it6/src/0000755000175000017500000000000012137716637016565 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/src/main/0000755000175000017500000000000012137716637017511 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/src/main/xsl/0000755000175000017500000000000012137716637020317 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/src/main/xsl/it4.xsl0000644000175000017500000000144611415151740021536 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it6/src/main/xml/0000755000175000017500000000000012137716637020311 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it6/src/main/xml/doc1.xml0000644000175000017500000000127211415151740021645 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it6/invoker.properties0000644000175000017500000000004411415151740021551 0ustar eugeneeugeneinvoker.goals = clean xml:transform xml-maven-plugin-1.0/src/it/mojo-1438-validate/0000755000175000017500000000000012137716637020424 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/pom.xml0000644000175000017500000000346211416654001021727 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it11 0.1 Maven XML Plugin IT 11 Integration Test 11 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ validate src/main/xml --COUNTER-- src/main/xml/catalog.xml xml-maven-plugin-1.0/src/it/mojo-1438-validate/src/0000755000175000017500000000000012137716637021213 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/0000755000175000017500000000000012137716637022137 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/xsd/0000755000175000017500000000000012137716637022735 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/xsd/schema.xsd0000644000175000017500000000173311416654001024702 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/xml/0000755000175000017500000000000012137716637022737 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/xml/doc1.xml0000644000175000017500000000142411416654001024271 0ustar eugeneeugene
A sample document.
xml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/xml/catalog.xml0000644000175000017500000000170211416654001025054 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/dtd/0000755000175000017500000000000012137716637022712 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-validate/src/main/dtd/sample.dtd0000644000175000017500000000006411416654001024651 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-validate/invoker.properties0000644000175000017500000000006711425334344024210 0ustar eugeneeugeneinvoker.goals = clean test invoker.java.version = 1.6+ xml-maven-plugin-1.0/src/it/it2/0000755000175000017500000000000012137716637015772 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it2/pom.xml0000644000175000017500000000247211415151740017276 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it2 0.1 Maven XML Plugin IT 2 Integration Test 2 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ src/main/xml xml-maven-plugin-1.0/src/it/it2/src/0000755000175000017500000000000012137716637016561 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it2/src/main/0000755000175000017500000000000012137716637017505 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it2/src/main/xml/0000755000175000017500000000000012137716637020305 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it2/src/main/xml/doc1.xml0000644000175000017500000000127111415151740021640 0ustar eugeneeugene A sample document, on which validation should report a problem. xml-maven-plugin-1.0/src/it/it2/invoker.properties0000644000175000017500000000007411415151740021550 0ustar eugeneeugeneinvoker.goals = xml:validate invoker.buildResult = failure xml-maven-plugin-1.0/src/it/it1/0000755000175000017500000000000012137716637015771 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it1/pom.xml0000644000175000017500000000273711415151740017301 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it1 0.1 Maven XML Plugin IT 1 Integration Test 1 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ validate src/main/xml xml-maven-plugin-1.0/src/it/it1/src/0000755000175000017500000000000012137716637016560 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it1/src/main/0000755000175000017500000000000012137716637017504 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it1/src/main/xml/0000755000175000017500000000000012137716637020304 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it1/src/main/xml/doc1.xml0000644000175000017500000000127211415151740021640 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it1/invoker.properties0000644000175000017500000000003511415151740021544 0ustar eugeneeugeneinvoker.goals = xml:validate xml-maven-plugin-1.0/src/it/settings.xml0000644000175000017500000000317411415151740017645 0ustar eugeneeugene it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true xml-maven-plugin-1.0/src/it/it5/0000755000175000017500000000000012137716637015775 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it5/pom.xml0000644000175000017500000000337211415151740017301 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it5 0.1 Maven XML Plugin IT 5 Integration Test 5 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform src/main/xml src/main/xsl/it5.xsl aParameter parameter passed in xml-maven-plugin-1.0/src/it/it5/src/0000755000175000017500000000000012137716637016564 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it5/src/main/0000755000175000017500000000000012137716637017510 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it5/src/main/xsl/0000755000175000017500000000000012137716637020316 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it5/src/main/xsl/it5.xsl0000644000175000017500000000155011415151740021532 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it5/src/main/xml/0000755000175000017500000000000012137716637020310 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it5/src/main/xml/doc1.xml0000644000175000017500000000127211415151740021644 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it5/invoker.properties0000644000175000017500000000004411415151740021550 0ustar eugeneeugeneinvoker.goals = clean xml:transform xml-maven-plugin-1.0/src/it/it9/0000755000175000017500000000000012137716637016001 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/pom.xml0000644000175000017500000000277211415151740017310 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it9 0.1 Maven XML Plugin IT 9 Integration Test 9 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ src/main/xml xml-maven-plugin-1.0/src/it/it9/src/0000755000175000017500000000000012137716637016570 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/0000755000175000017500000000000012137716637017514 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/xml/0000755000175000017500000000000012137716637020314 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/xml/doc1.xml0000644000175000017500000000155311415151740021652 0ustar eugeneeugene ]> A sample document, which should be validatable without any problems. &it9a1; &it9a2; xml-maven-plugin-1.0/src/it/it9/src/main/resources/0000755000175000017500000000000012137716637021526 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/0000755000175000017500000000000012137716637022315 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/codehaus/0000755000175000017500000000000012137716637024110 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/codehaus/mojo/0000755000175000017500000000000012137716637025054 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/codehaus/mojo/xml/0000755000175000017500000000000012137716637025654 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/codehaus/mojo/xml/test/0000755000175000017500000000000012137716637026633 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it9/src/main/resources/org/codehaus/mojo/xml/test/it9a.xml0000644000175000017500000000117211415151740030206 0ustar eugeneeugene it9a xml-maven-plugin-1.0/src/it/it9/invoker.properties0000644000175000017500000000002511415151740021553 0ustar eugeneeugeneinvoker.goals = test xml-maven-plugin-1.0/src/it/mojo-1438-transform/0000755000175000017500000000000012137716637020646 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/pom.xml0000644000175000017500000000352111416654001022145 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it10 0.1 Maven XML Plugin IT 10 Integration Test 10 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform src/main/xml src/main/xsl/it10.xsl src/main/xml/catalog.xml xml-maven-plugin-1.0/src/it/mojo-1438-transform/src/0000755000175000017500000000000012137716637021435 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/0000755000175000017500000000000012137716637022361 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/xsl/0000755000175000017500000000000012137716637023167 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/xsl/it10.xsl0000644000175000017500000000175011416654001024460 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/xml/0000755000175000017500000000000012137716637023161 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/xml/doc1.xml0000644000175000017500000000140311416654001024510 0ustar eugeneeugene
A sample document.
xml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/xml/catalog.xml0000644000175000017500000000135111416654001025276 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/dtd/0000755000175000017500000000000012137716637023134 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/mojo-1438-transform/src/main/dtd/sample.dtd0000644000175000017500000000006411416654001025073 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/mojo-1438-transform/invoker.properties0000644000175000017500000000004411416654001024420 0ustar eugeneeugeneinvoker.goals = clean xml:transform xml-maven-plugin-1.0/src/it/it4/0000755000175000017500000000000012137716637015774 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it4/pom.xml0000644000175000017500000000305411415151740017275 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it4 0.1 Maven XML Plugin IT 4 Integration Test 4 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform src/main/xml src/main/xsl/it4.xsl xml-maven-plugin-1.0/src/it/it4/src/0000755000175000017500000000000012137716637016563 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it4/src/main/0000755000175000017500000000000012137716637017507 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it4/src/main/xsl/0000755000175000017500000000000012137716637020315 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it4/src/main/xsl/it4.xsl0000644000175000017500000000144611415151740021534 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it4/src/main/xml/0000755000175000017500000000000012137716637020307 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it4/src/main/xml/doc1.xml0000644000175000017500000000127211415151740021643 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it4/invoker.properties0000644000175000017500000000004311415151740021546 0ustar eugeneeugeneinvoker.goals = clean xml:transformxml-maven-plugin-1.0/src/it/it8/0000755000175000017500000000000012137716637016000 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it8/pom.xml0000644000175000017500000000403111415151740017275 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it8 0.1 Maven XML Plugin IT 8 Integration Test 8 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform net.sf.saxon.TransformerFactoryImpl src/main/xml src/main/xsl/it8.xsl net.sf.saxon saxon 8.7 xml-maven-plugin-1.0/src/it/it8/src/0000755000175000017500000000000012137716637016567 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it8/src/main/0000755000175000017500000000000012137716637017513 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it8/src/main/xsl/0000755000175000017500000000000012137716637020321 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it8/src/main/xsl/it8.xsl0000644000175000017500000000175011415151740021542 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it8/src/main/xml/0000755000175000017500000000000012137716637020313 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it8/src/main/xml/doc1.xml0000644000175000017500000000127011415151740021645 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it8/invoker.properties0000644000175000017500000000010011415151740021544 0ustar eugeneeugeneinvoker.goals = clean xml:transform invoker.java.version = 1.6+ xml-maven-plugin-1.0/src/it/it7/0000755000175000017500000000000012137716637015777 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it7/pom.xml0000644000175000017500000000371311415151740017302 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it7 0.1 Maven XML Plugin IT 7 Integration Test 7 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ transform src/main/xml src/main/xsl/it7.xsl omit-xml-declaration yes xml-maven-plugin-1.0/src/it/it7/src/0000755000175000017500000000000012137716637016566 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it7/src/main/0000755000175000017500000000000012137716637017512 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it7/src/main/xsl/0000755000175000017500000000000012137716637020320 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it7/src/main/xsl/it7.xsl0000644000175000017500000000144611415151740021542 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it7/src/main/xml/0000755000175000017500000000000012137716637020312 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it7/src/main/xml/doc1.xml0000644000175000017500000000127211415151740021646 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/it/it7/invoker.properties0000644000175000017500000000004411415151740021552 0ustar eugeneeugeneinvoker.goals = clean xml:transform xml-maven-plugin-1.0/src/it/it3/0000755000175000017500000000000012137716637015773 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it3/pom.xml0000644000175000017500000000305311415151740017273 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it3 0.1 Maven XML Plugin IT 3 Integration Test 3 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin @pom.version@ src/main/xml doc1.xml --COUNTER-- src/main/xml/catalog.xml xml-maven-plugin-1.0/src/it/it3/src/0000755000175000017500000000000012137716637016562 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it3/src/main/0000755000175000017500000000000012137716637017506 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it3/src/main/xsd/0000755000175000017500000000000012137716637020304 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it3/src/main/xsd/schema.xsd0000644000175000017500000000200711415151740022245 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it3/src/main/xml/0000755000175000017500000000000012137716637020306 5ustar eugeneeugenexml-maven-plugin-1.0/src/it/it3/src/main/xml/doc1.xml0000644000175000017500000000123711415151740021643 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it3/src/main/xml/catalog.xml0000644000175000017500000000136611415151740022432 0ustar eugeneeugene xml-maven-plugin-1.0/src/it/it3/invoker.properties0000644000175000017500000000003511415151740021546 0ustar eugeneeugeneinvoker.goals = xml:validate xml-maven-plugin-1.0/src/changes/0000755000175000017500000000000012137716637016270 5ustar eugeneeugenexml-maven-plugin-1.0/src/changes/changes.xml0000644000175000017500000001417411526203432020412 0ustar eugeneeugene Changes in the Maven XML Plugin Disabled proxy password logging. Also reduced logging level of proxy info from "info" to "debug". The ResourceManager is now used when loading stylesheets or resolving included files, thus enabling use of classpath resources. Documentation fix: Replace ReplaceRegExpFileMapper with RegExpFileMapper. Catalogs can now be specified as URL's, not only as files. The resolver does now attempt to use the namespace URI and not only the public ID. Add support for in-place transformation. Added catalog file example to the docs. External DTD's are no longer downloaded when checking for well formedness. Provide log output with log-level INFO for the processing of any input file. Added the possibility to set a transformers output properties. If a transformation sets or validation sets base directory is missing, then a warning is logged now, and the build no longer fails. This allows to configure the plugin in a parent POM. It is now configurable, whether the Resolver creates validating parsers. A parameter for specifying the transformer implementation has been added. Added support for the resource: protocol. Fixed a misleading error message. Add support for XSLT parameters when transforming. SAXSource is now used instead of StreamSource, in order to ensure that the resolver is used. XML schema validation wasn't turned on by the ValidateMojo. The plugin does now honor the Maven proxy settings. Added support for file mappers when transforming files. Added docs for using an XSLT 2.0 compliant processor. Added support for resolving resources through the classloader. Add use of the default excludes. Also add the configuration parameter skipDefaultExcludes for turning them off. Absolute paths have been unsupported. The plugin does now check, whether the generated files are uptodate. Initial release xml-maven-plugin-1.0/src/test/0000755000175000017500000000000012137716636015636 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/0000755000175000017500000000000012137716636016557 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/0000755000175000017500000000000012137716636017346 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/codehaus/0000755000175000017500000000000012137716636021141 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/0000755000175000017500000000000012137716636022105 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/xml/0000755000175000017500000000000012137716636022705 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/xml/test/0000755000175000017500000000000012137716636023664 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/xml/test/AbstractXmlMojoTestCase.java0000644000175000017500000000543211137427364031234 0ustar eugeneeugene/* * 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. */ package org.codehaus.mojo.xml.test; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.maven.model.Build; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; import org.codehaus.mojo.xml.AbstractXmlMojo; import org.codehaus.mojo.xml.TransformMojo; import org.w3c.dom.Document; import org.xml.sax.SAXException; public abstract class AbstractXmlMojoTestCase extends AbstractMojoTestCase { protected abstract String getGoal(); protected AbstractXmlMojo newMojo( String pDir ) throws Exception { File testPom = new File( new File( getBasedir(), pDir ), "pom.xml" ); AbstractXmlMojo vm = (AbstractXmlMojo) lookupMojo( getGoal(), testPom ); setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) ); final Build build = new Build(); build.setDirectory( "target" ); MavenProjectStub project = new MavenProjectStub() { public Build getBuild() { return build; } }; setVariableValueToObject( vm, "project", project ); return vm; } protected void runTest( final String pDir ) throws Exception { newMojo( pDir ).execute(); } protected Document parse( File pFile ) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating( false ); dbf.setNamespaceAware( true ); return dbf.newDocumentBuilder().parse( pFile ); } protected boolean java1_6_Aware() throws IllegalAccessException, InvocationTargetException { try { TransformMojo.newTransformerFactory( "net.sf.saxon.TransformerFactoryImpl", Thread.currentThread() .getContextClassLoader() ); return true; } catch ( NoSuchMethodException e ) { return false; } } } xml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/xml/test/ValidateMojoTest.java0000644000175000017500000000360410773161441027740 0ustar eugeneeugenepackage org.codehaus.mojo.xml.test; /* * 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. */ import org.apache.maven.plugin.MojoExecutionException; import org.xml.sax.SAXParseException; /** Test case for the {@link ValidateMojo}. */ public class ValidateMojoTest extends AbstractXmlMojoTestCase { protected String getGoal() { return "validate"; } /** * Builds the it1 test project. */ public void testIt1() throws Exception { runTest( "src/test/it1" ); } /** * Builds the it2 test project. */ public void testIt2() throws Exception { try { runTest( "src/test/it2" ); fail( "Expected exception" ); } catch ( MojoExecutionException e ) { Throwable t = e.getCause(); assertNotNull( t ); assertTrue( t instanceof SAXParseException ); SAXParseException ex = (SAXParseException) t; assertEquals( 20, ex.getLineNumber() ); } } /** * Builds the it3 test project. */ public void testIt3() throws Exception { runTest( "src/test/it3" ); } /** * Builds the it9 test project. */ public void testIt9() throws Exception { runTest( "src/test/it9" ); } } xml-maven-plugin-1.0/src/test/java/org/codehaus/mojo/xml/test/TransformMojoTest.java0000644000175000017500000002263311526025436030165 0ustar eugeneeugene/* * 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. */ package org.codehaus.mojo.xml.test; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.codehaus.mojo.xml.TransformMojo; import org.codehaus.mojo.xml.transformer.TransformationSet; import org.codehaus.plexus.components.io.filemappers.FileExtensionMapper; import org.codehaus.plexus.util.FileUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; /** * Test case for the {@link TransformMojo}. */ public class TransformMojoTest extends AbstractXmlMojoTestCase { protected String getGoal() { return "transform"; } /** * Common code for the it4, it6 and it10 test projects. */ public void runTestIt4( String dir, String targetFile ) throws Exception { TransformMojo mojo = (TransformMojo) newMojo( dir ); mojo.execute(); Document doc1 = parse( new File( dir, "xml/doc1.xml" ) ); doc1.normalize(); Document doc2 = parse( new File( dir, "target/generated-resources/xml/xslt/" + targetFile ) ); doc2.normalize(); Element doc1Element = doc1.getDocumentElement(); assertEquals( "doc1", doc1Element.getLocalName() ); assertNull( doc1Element.getNamespaceURI() ); Element doc2Element = doc2.getDocumentElement(); assertEquals( "doc2", doc2Element.getLocalName() ); assertNull( doc2Element.getNamespaceURI() ); Node text1 = doc1Element.getFirstChild(); assertNotNull( text1 ); assertNull( text1.getNextSibling() ); assertEquals( Node.TEXT_NODE, text1.getNodeType() ); Node text2 = doc2Element.getFirstChild(); assertNotNull( text2 ); assertNull( text2.getNextSibling() ); assertEquals( Node.TEXT_NODE, text2.getNodeType() ); assertEquals( text1.getNodeValue(), text2.getNodeValue() ); } /** * Builds the it4 test project. */ public void testIt4() throws Exception { runTestIt4( "src/test/it4", "doc1.xml" ); } /** * Builds the it5 test project. */ public void testIt5() throws Exception { final String dir = "src/test/it5"; runTest( dir ); Document doc1 = parse( new File( dir, "xml/doc1.xml" ) ); doc1.normalize(); Document doc2 = parse( new File( dir, "target/generated-resources/xml/xslt/doc1.xml" ) ); doc2.normalize(); Element doc1Element = doc1.getDocumentElement(); assertEquals( "doc1", doc1Element.getLocalName() ); assertNull( doc1Element.getNamespaceURI() ); Element doc2Element = doc2.getDocumentElement(); assertEquals( "doc2", doc2Element.getLocalName() ); assertNull( doc2Element.getNamespaceURI() ); Node text1 = doc1Element.getFirstChild(); assertNotNull( text1 ); assertNull( text1.getNextSibling() ); assertEquals( Node.TEXT_NODE, text1.getNodeType() ); Node text2 = doc2Element.getFirstChild(); assertNotNull( text2 ); assertNull( text2.getNextSibling() ); assertEquals( Node.TEXT_NODE, text2.getNodeType() ); assertEquals(text2.getNodeValue(), "parameter passed in"); } /** * Builds the it6 test project. */ public void testIt6() throws Exception { FileExtensionMapper fileExtensionMapper = new FileExtensionMapper(); fileExtensionMapper.setTargetExtension( ".fo" ); runTestIt4( "src/test/it6", "doc1.fo" ); } private String read( File file ) throws IOException { final StringBuffer sb = new StringBuffer(); final Reader reader = new InputStreamReader( new FileInputStream( file ), "UTF-8" ); final char[] buffer = new char[ 4096 ]; for ( ;; ) { final int res = reader.read( buffer ); if ( res == -1 ) { break; } if ( res > 0 ) { sb.append( buffer, 0, res ); } } reader.close(); return sb.toString(); } /** * Builds the it7 test project. */ public void testIt7() throws Exception { final File dir = new File( "src/test/it7" ); final File target = new File( dir, "target/generated-resources/xml/xslt/doc1.xml" ); TransformMojo mojo = (TransformMojo) newMojo( dir.getPath() ); FileUtils.fileDelete( target.getPath() ); mojo.execute(); String result = read( target ); assertFalse( result.startsWith( "\n" + "\n" + "\n" + "\n" + "\n"; final StringWriter sw = new StringWriter(); final Transformer t = TransformMojo.newTransformerFactory( org.apache.xalan.processor.TransformerFactoryImpl.class.getName(), getClass().getClassLoader()).newTransformer( new StreamSource( new StringReader( xsl ) ) ); t.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" ); t.transform( new DOMSource( contextNode ), new StreamResult( sw ) ); return sw.toString(); } /** * Builds the it7 test project. */ public void testIt8() throws Exception { if ( !java1_6_Aware() ) { System.out.println( " skip test due to non compliance jvm version need 1.6" ); return; } final String dir = "src/test/it8"; runTest( dir ); Document doc1 = parse( new File( dir, "target/generated-resources/xml/xslt/doc1.xml" ) ); assertEquals("SAXON 8.7 from Saxonica", eval( doc1, "/root/vendor" ) ); assertEquals("http://www.saxonica.com/", eval( doc1, "/root/vendor-url" ) ); assertEquals("2.0", eval( doc1, "/root/version" ) ); } /** * Builds the it10 test project. */ public void testIt10() throws Exception { runTestIt4( "src/test/it10", "doc1.xml" ); } /** * Builds the it11 test project, tests in-place modification. */ public void testIt11() throws Exception { String projectPath = "src/test/it11"; File projectDirectory = new File( getBasedir(), projectPath ); File targetDirectory = new File( projectPath, "target" ); if ( targetDirectory.exists() ){ FileUtils.cleanDirectory( targetDirectory ); } File xmlInputDirectory = new File( projectDirectory, "xml" ); File xmlOutputDirectory = new File( targetDirectory, "generated-resources/xml/xslt" ); /* copy to target since that is in an SCM-ignored directory */ FileUtils.copyDirectory( xmlInputDirectory, xmlOutputDirectory, "*.xml" , null ); TransformMojo mojo = (TransformMojo) newMojo( projectPath ); mojo.execute(); String fileToTransform = "doc1.xml"; Document doc1 = parse( new File( xmlInputDirectory, fileToTransform ) ); doc1.normalize(); Document doc2 = parse( new File( xmlOutputDirectory, fileToTransform ) ); doc2.normalize(); Element doc1Element = doc1.getDocumentElement(); assertEquals( "doc1", doc1Element.getLocalName() ); assertNull( doc1Element.getNamespaceURI() ); Element doc2Element = doc2.getDocumentElement(); assertEquals( "doc2", doc2Element.getLocalName() ); assertNull( doc2Element.getNamespaceURI() ); Node text1 = doc1Element.getFirstChild(); assertNotNull( text1 ); assertNull( text1.getNextSibling() ); assertEquals( Node.TEXT_NODE, text1.getNodeType() ); Node text2 = doc2Element.getFirstChild(); assertNotNull( text2 ); assertNull( text2.getNextSibling() ); assertEquals( Node.TEXT_NODE, text2.getNodeType() ); assertEquals( text1.getNodeValue(), text2.getNodeValue() ); } } xml-maven-plugin-1.0/src/test/it11/0000755000175000017500000000000012137716636016414 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it11/it11.xsl0000644000175000017500000000147411526025436017720 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it11/pom.xml0000644000175000017500000000314211526025436017721 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it10 0.1 Maven XML Plugin IT 10 Integration Test 10 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 transform target/generated-resources/xml/xslt it11.xsl xml-maven-plugin-1.0/src/test/it11/xml/0000755000175000017500000000000012137716636017214 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it11/xml/doc1.xml0000644000175000017500000000131411526025436020553 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it6/0000755000175000017500000000000012137716636016340 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it6/pom.xml0000644000175000017500000000343410773161441017651 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it6 0.1 Maven XML Plugin IT 1 Integration Test 1 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 1.0-beta-2-SNAPSHOT transform xml it4.xsl .fo xml-maven-plugin-1.0/src/test/it6/xml/0000755000175000017500000000000012137716636017140 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it6/xml/doc1.xml0000644000175000017500000000127210773161441020502 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it6/it4.xsl0000644000175000017500000000147410741756731017575 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it2/0000755000175000017500000000000012137716636016334 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it2/pom.xml0000644000175000017500000000244710773161441017650 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it2 0.1 Maven XML Plugin IT 2 Integration Test 2 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 xml xml-maven-plugin-1.0/src/test/it2/xml/0000755000175000017500000000000012137716636017134 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it2/xml/doc1.xml0000644000175000017500000000127110773161441020475 0ustar eugeneeugene A sample document, on which validation should report a problem. xml-maven-plugin-1.0/src/test/it1/0000755000175000017500000000000012137716636016333 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it1/pom.xml0000644000175000017500000000273410773161441017646 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it1 0.1 Maven XML Plugin IT 1 Integration Test 1 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 1.0-beta-2-SNAPSHOT validate xml xml-maven-plugin-1.0/src/test/it1/xml/0000755000175000017500000000000012137716636017133 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it1/xml/doc1.xml0000644000175000017500000000127210773161441020475 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it10/0000755000175000017500000000000012137716636016413 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it10/pom.xml0000644000175000017500000000260611517153174017725 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it10 0.1 Maven XML Plugin IT 10 Integration Test 10 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 xml org/codehaus/mojo/xml/test/it10a.xsl xml-maven-plugin-1.0/src/test/it10/xml/0000755000175000017500000000000012137716636017213 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it10/xml/doc1.xml0000644000175000017500000000127211517153174020556 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it5/0000755000175000017500000000000012137716636016337 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it5/pom.xml0000644000175000017500000000323610773161441017650 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it5 0.1 Maven XML Plugin IT 5 Integration Test 5 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 transform xml it5.xsl aParameter parameter passed in xml-maven-plugin-1.0/src/test/it5/it5.xsl0000644000175000017500000000154210741756731017571 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it5/xml/0000755000175000017500000000000012137716636017137 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it5/xml/doc1.xml0000644000175000017500000000127210773161441020501 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it9/0000755000175000017500000000000012137716636016343 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it9/pom.xml0000644000175000017500000000274711137545704017665 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it9 0.1 Maven XML Plugin IT 9 Integration Test 9 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 xml xml-maven-plugin-1.0/src/test/it9/xml/0000755000175000017500000000000012137716636017143 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it9/xml/doc1.xml0000644000175000017500000000155310773161441020507 0ustar eugeneeugene ]> A sample document, which should be validatable without any problems. &it9a1; &it9a2; xml-maven-plugin-1.0/src/test/it4/0000755000175000017500000000000012137716636016336 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it4/pom.xml0000644000175000017500000000301410773161441017641 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it4 0.1 Maven XML Plugin IT 4 Integration Test 4 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 transform xml it4.xsl xml-maven-plugin-1.0/src/test/it4/xml/0000755000175000017500000000000012137716636017136 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it4/xml/doc1.xml0000644000175000017500000000127210773161441020500 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it4/it4.xsl0000644000175000017500000000147410741756731017573 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it8/0000755000175000017500000000000012137716636016342 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it8/pom.xml0000644000175000017500000000401111137545704017646 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it8 0.1 Maven XML Plugin IT 8 Integration Test 8 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 1.0-beta-2-SNAPSHOT transform net.sf.saxon.TransformerFactoryImpl xml it8.xsl net.sf.saxon saxon 8.7 xml-maven-plugin-1.0/src/test/it8/xml/0000755000175000017500000000000012137716636017142 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it8/xml/doc1.xml0000644000175000017500000000127010773161441020502 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it8/it8.xsl0000644000175000017500000000175010735354426017576 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/resources/0000755000175000017500000000000012137716636017650 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/0000755000175000017500000000000012137716636020437 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/codehaus/0000755000175000017500000000000012137716636022232 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/codehaus/mojo/0000755000175000017500000000000012137716636023176 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/codehaus/mojo/xml/0000755000175000017500000000000012137716636023776 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/codehaus/mojo/xml/test/0000755000175000017500000000000012137716636024755 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/resources/org/codehaus/mojo/xml/test/it9a.xml0000644000175000017500000000117210773161441026336 0ustar eugeneeugene it9a xml-maven-plugin-1.0/src/test/resources/org/codehaus/mojo/xml/test/it10a.xsl0000644000175000017500000000144611517153174026421 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it7/0000755000175000017500000000000012137716636016341 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it7/it7.xsl0000644000175000017500000000144610741756731017600 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it7/pom.xml0000644000175000017500000000361411137545704017655 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it7 0.1 Maven XML Plugin IT 7 Integration Test 7 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin transform xml it7.xsl omit-xml-declaration yes xml-maven-plugin-1.0/src/test/it7/xml/0000755000175000017500000000000012137716636017141 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it7/xml/doc1.xml0000644000175000017500000000127210773161441020503 0ustar eugeneeugene A sample document, which should be validatable without any problems. xml-maven-plugin-1.0/src/test/it3/0000755000175000017500000000000012137716636016335 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it3/pom.xml0000644000175000017500000000265410773161441017651 0ustar eugeneeugene 4.0.0 org.codehaus.mojo.xml it3 0.1 Maven XML Plugin IT 3 Integration Test 3 for the Maven XML Plugin org.codehaus.mojo xml-maven-plugin 0.2 xml --COUNTER-- catalog.xml xml-maven-plugin-1.0/src/test/it3/schema.xsd0000644000175000017500000000200711146102603020272 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it3/xml/0000755000175000017500000000000012137716636017135 5ustar eugeneeugenexml-maven-plugin-1.0/src/test/it3/xml/doc1.xml0000644000175000017500000000123710773161441020500 0ustar eugeneeugene xml-maven-plugin-1.0/src/test/it3/catalog.xml0000644000175000017500000000135710773161441020467 0ustar eugeneeugene