Make pom:validate work whether namespace is declared or not
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@325997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
b589af1595
commit
7d846069e1
4 files changed
+108
-6
No files matched your search
+10
-5
@@ -65,15 +65,20 @@
|
||||
|
||||
<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"/>
|
||||
<!-- x:parse doesn't work if <project> contains namespace? -->
|
||||
<!--<x:parse var="parsedPom" xml="${pomAsFile}"/>
|
||||
<x:set var="extends" select="$parsedPom/project/extend"/>-->
|
||||
<j:new className="org.apache.maven.PomUtils" var="pomUtils"/>
|
||||
<j:setProperties object="${pomUtils}" file="${pomAsFile}"/>
|
||||
<j:set var="extends" value="${pomUtils.extend()}"/>
|
||||
<j:set var="parent" value="${pomUtils.getParent()}"/>
|
||||
</j:if>
|
||||
|
||||
<x:if select="$extends">
|
||||
<j:if test="${extends == 'true'}">
|
||||
<log:warn>
|
||||
<j:whitespace>
|
||||
*** WARNING ***
|
||||
*** The current pom extends <x:expr select="$parsedPom/project/extend"/>
|
||||
*** The current pom extends ${parent}
|
||||
*** This parent pom has to be validated separately!
|
||||
</j:whitespace>
|
||||
</log:warn>
|
||||
@@ -93,7 +98,7 @@
|
||||
</j:file>
|
||||
</j:if>
|
||||
<j:set var="xsd" value="${plugin.resources}/xsd/pom-extend-3.xsd"/>
|
||||
</x:if>
|
||||
</j:if>
|
||||
|
||||
<log:info>Using xsd file: ${xsd}</log:info>
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
-->
|
||||
|
||||
<project>
|
||||
<project xmlns="http://maven.apache.org/POM/3.0.0">
|
||||
<extend>../plugin-parent/project.xml</extend>
|
||||
<pomVersion>3</pomVersion>
|
||||
<id>maven-pom-plugin</id>
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package org.apache.maven;
|
||||
|
||||
/* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import javax.xml.parsers.*;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.*;
|
||||
|
||||
/**
|
||||
* Some utility methods.
|
||||
* @author <a href="mailto:ltheussl@apache.org">Lukas Theussl</a>
|
||||
*/
|
||||
public class PomUtils
|
||||
{
|
||||
private File file;
|
||||
private String parent;
|
||||
|
||||
/** The parent.
|
||||
* @return The parent
|
||||
*/
|
||||
public String getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
/** The file.
|
||||
* @return The file
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file.
|
||||
* @param newFile The file to set
|
||||
*/
|
||||
public void setFile(File newFile)
|
||||
{
|
||||
this.file = newFile;
|
||||
}
|
||||
|
||||
/** The file.
|
||||
* @return True if the file contains <extend>.
|
||||
*/
|
||||
public boolean extend()
|
||||
{
|
||||
Document doc = parseXmlFile(file, false);
|
||||
NodeList list = doc.getElementsByTagName("extend");
|
||||
boolean extend = false;
|
||||
if ( list.getLength() > 0 )
|
||||
{
|
||||
extend = true;
|
||||
Element element = (Element) list.item(0);
|
||||
try
|
||||
{
|
||||
Node firstChild = element.getFirstChild();
|
||||
parent = firstChild.getNodeValue();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
return extend;
|
||||
}
|
||||
|
||||
private Document parseXmlFile(File filename, boolean validating)
|
||||
{
|
||||
try
|
||||
{
|
||||
DocumentBuilderFactory factory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
factory.setValidating(validating);
|
||||
Document doc = factory.newDocumentBuilder().parse(filename);
|
||||
return doc;
|
||||
} catch (SAXException e) {
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
-->
|
||||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<xs:element name="project" type="Model">
|
||||
<xs:annotation>
|
||||
<xs:documentation source="version">3.0.0+</xs:documentation>
|
||||
|
||||
Reference in new issue
Block a user