New attempt at pom:validate:
Every pom that does not extend another one (a root pom) has to comply
with the schema ${plugin.resources}/xsd/pom-strict-3.xsd (this needs review).
Running "pom:validate" on a child pom
will create another schema ${plugin.resources}/xsd/pom-extend-3.xsd
(if this doesn't exist already) via an xslt transformation using the
stylesheet ${plugin.resources}/xsl/pom-extend-3.xsl. This just replaces
all 'minOccurs="1"' attributes in pom-strict-3.xsd by 'minOccurs="0"'.
Namespace is still a problem, I removed it from the xsd (xml:parse seems not
to work on documents with namespace declarations?).
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@312982 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
d693e4b1fe
commit
1e2fd4c5a0
5 files changed
+1632
-9
No files matched your search
+38
-9
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
* Copyright 2001-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.
|
||||
@@ -25,6 +25,8 @@
|
||||
xmlns:plugin="plugin"
|
||||
xmlns:util="jelly:util"
|
||||
xmlns:ant="jelly:ant"
|
||||
xmlns:x="jelly:xml"
|
||||
xmlns:log="jelly:log"
|
||||
xmlns:artifact="artifact">
|
||||
|
||||
<!-- set up pom tag library -->
|
||||
@@ -59,14 +61,41 @@
|
||||
name="pom:validate"
|
||||
description="Validate the Maven XML project descriptor">
|
||||
|
||||
<j:set var="xsd"
|
||||
value="${maven.home}/maven-project-${pom.pomVersion}.xsd"/>
|
||||
<util:file var="xsdAsFile" name="${xsd}"/>
|
||||
<j:if test="${not(xsdAsFile.exists())}">
|
||||
<j:set var="xsd"
|
||||
value="${maven.home}/maven-project.xsd"/>
|
||||
<j:set var="xsd" value="${plugin.resources}/xsd/pom-strict-3.xsd"/>
|
||||
|
||||
<util:file var="pomAsFile" name="${pom.file.canonicalPath}" />
|
||||
<j:if test="${pomAsFile != null}">
|
||||
<x:parse var="parsedPom" xml="${pomAsFile}"/>
|
||||
<x:set var="extends" select="$parsedPom/project/extend"/>
|
||||
</j:if>
|
||||
<echo>xsd file: ${xsd}</echo>
|
||||
|
||||
<x:if select="$extends">
|
||||
<log:warn>
|
||||
<j:whitespace>
|
||||
*** WARNING ***
|
||||
*** The current pom extends <x:expr select="$parsedPom/project/extend"/>
|
||||
*** This parent pom has to be validated separately!
|
||||
</j:whitespace>
|
||||
</log:warn>
|
||||
<j:set var="available" value="false"/>
|
||||
<util:available file="${plugin.resources}/xsd/pom-extend-3.xsd">
|
||||
<j:set var="available" value="true"/>
|
||||
</util:available>
|
||||
<j:if test="${available == 'false'}">
|
||||
<j:set var="xsl" value="${plugin.resources}/xsl/pom-extend-3.xsl"/>
|
||||
<x:transform
|
||||
xslt="file://${xsl}"
|
||||
xml="file://${xsd}"
|
||||
var="tmpVar"
|
||||
validate="false"/>
|
||||
<j:file name="${plugin.resources}/xsd/pom-extend-3.xsd">
|
||||
<x:copyOf select="$tmpVar"/>
|
||||
</j:file>
|
||||
</j:if>
|
||||
<j:set var="xsd" value="${plugin.resources}/xsd/pom-extend-3.xsd"/>
|
||||
</x:if>
|
||||
|
||||
<log:info>Using xsd file: ${xsd}</log:info>
|
||||
|
||||
<plugin:validate-xml
|
||||
schema="${xsd}"
|
||||
@@ -84,7 +113,7 @@
|
||||
<j:set var="notices" value="${contentvalidator.execute()}"/>
|
||||
|
||||
<j:forEach var="notice" items="${notices}">
|
||||
<echo>${notice.Level} : ${notice.Section} : ${notice.Message}</echo>
|
||||
<log:info>${notice.Level} : ${notice.Section} : ${notice.Message}</log:info>
|
||||
</j:forEach>
|
||||
|
||||
</goal>
|
||||
|
||||
@@ -87,6 +87,11 @@
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.4-dev-8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-jelly</groupId>
|
||||
<artifactId>commons-jelly-tags-log</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven</artifactId>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,17 @@
|
||||
Every pom that does not extend another one (a 'root' pom) has to comply
|
||||
with the schema ${plugin.resources}/xsd/pom-strict-3.xsd.
|
||||
|
||||
Running "pom:validate" on a child pom (a pom that extends another one)
|
||||
will create another schema ${plugin.resources}/xsd/pom-extend-3.xsd
|
||||
(if this doesn't exist already) via an xslt transformation using the
|
||||
stylesheet ${plugin.resources}/xsl/pom-extend-3.xsl. This just replaces
|
||||
all 'minOccurs="1"' attributes in pom-strict-3.xsd by 'minOccurs="0"'.
|
||||
|
||||
|
||||
Note:
|
||||
|
||||
* Every element that is required in a root pom but is not obligatory
|
||||
in a child pom, needs a 'minOccurs="1"'.
|
||||
|
||||
* Elements that are required in both parent and child poms, must not have
|
||||
a 'minOccurs' attribute (so they default to 1).
|
||||
@@ -0,0 +1,38 @@
|
||||
<!--
|
||||
/*
|
||||
* Copyright 2001-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.
|
||||
*/
|
||||
-->
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
|
||||
|
||||
<xsl:output method="xml" indent="yes" />
|
||||
|
||||
<xsl:template match="*|text()|@*">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@*"/>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="*[@minOccurs]">
|
||||
<xsl:copy>
|
||||
<xsl:apply-templates select="@*"/>
|
||||
<xsl:attribute name="minOccurs">0</xsl:attribute>
|
||||
<xsl:apply-templates/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Reference in new issue
Block a user