You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2005/10/18 00:56:05 UTC
svn commit: r325997 - in /maven/maven-1/plugins/trunk/pom: plugin.jelly
project.xml src/main/org/apache/maven/PomUtils.java
src/plugin-resources/xsd/pom-strict-3.xsd
Author: ltheussl
Date: Mon Oct 17 15:56:00 2005
New Revision: 325997
URL: http://svn.apache.org/viewcvs?rev=325997&view=rev
Log:
Make pom:validate work whether namespace is declared or not
Added:
maven/maven-1/plugins/trunk/pom/src/main/org/apache/maven/PomUtils.java
Modified:
maven/maven-1/plugins/trunk/pom/plugin.jelly
maven/maven-1/plugins/trunk/pom/project.xml
maven/maven-1/plugins/trunk/pom/src/plugin-resources/xsd/pom-strict-3.xsd
Modified: maven/maven-1/plugins/trunk/pom/plugin.jelly
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pom/plugin.jelly?rev=325997&r1=325996&r2=325997&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/pom/plugin.jelly (original)
+++ maven/maven-1/plugins/trunk/pom/plugin.jelly Mon Oct 17 15:56:00 2005
@@ -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>
Modified: maven/maven-1/plugins/trunk/pom/project.xml
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pom/project.xml?rev=325997&r1=325996&r2=325997&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/pom/project.xml (original)
+++ maven/maven-1/plugins/trunk/pom/project.xml Mon Oct 17 15:56:00 2005
@@ -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>
Added: maven/maven-1/plugins/trunk/pom/src/main/org/apache/maven/PomUtils.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pom/src/main/org/apache/maven/PomUtils.java?rev=325997&view=auto
==============================================================================
--- maven/maven-1/plugins/trunk/pom/src/main/org/apache/maven/PomUtils.java (added)
+++ maven/maven-1/plugins/trunk/pom/src/main/org/apache/maven/PomUtils.java Mon Oct 17 15:56:00 2005
@@ -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;
+ }
+}
Modified: maven/maven-1/plugins/trunk/pom/src/plugin-resources/xsd/pom-strict-3.xsd
URL: http://svn.apache.org/viewcvs/maven/maven-1/plugins/trunk/pom/src/plugin-resources/xsd/pom-strict-3.xsd?rev=325997&r1=325996&r2=325997&view=diff
==============================================================================
--- maven/maven-1/plugins/trunk/pom/src/plugin-resources/xsd/pom-strict-3.xsd (original)
+++ maven/maven-1/plugins/trunk/pom/src/plugin-resources/xsd/pom-strict-3.xsd Mon Oct 17 15:56:00 2005
@@ -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>