maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r680563 - in /maven/plugins/trunk/maven-changes-plugin: ./ src/main/java/org/apache/maven/plugin/changes/ src/main/java/org/apache/maven/plugin/changes/schema/ src/main/mdo/ src/test/java/org/apache/maven/plugin/changes/ src/test/unit/
Date Mon, 28 Jul 2008 23:32:12 GMT
Author: olamy
Date: Mon Jul 28 16:32:11 2008
New Revision: 680563

URL: http://svn.apache.org/viewvc?rev=680563&view=rev
Log:
[MCHANGES-86] Create a changes-validate mojo


Added:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml   (with props)
    maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml   (with props)
Modified:
    maven/plugins/trunk/maven-changes-plugin/pom.xml
    maven/plugins/trunk/maven-changes-plugin/src/main/mdo/changes.mdo
    maven/plugins/trunk/maven-changes-plugin/src/test/unit/changes.xml

Modified: maven/plugins/trunk/maven-changes-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/pom.xml?rev=680563&r1=680562&r2=680563&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-changes-plugin/pom.xml Mon Jul 28 16:32:11 2008
@@ -131,6 +131,44 @@
             <model>src/main/mdo/changes.mdo</model>
           </models>
         </configuration>
+        <executions>
+          <execution>
+            <id>generate-xsd</id>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>xsd</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${project.build.outputDirectory}/META-INF/changes/xsd</outputDirectory>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>      
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3.5</version>
+        <executions>
+          <execution>
+            <id>create-component-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>merge</id>
+            <configuration>
+              <output>${project.build.outputDirectory}/META-INF/plexus/components.xml</output>
+              <descriptors>
+                <descriptor>src/main/resources/META-INF/plexus/components.xml</descriptor>
+              </descriptors>
+            </configuration>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>merge-descriptors</goal>
+            </goals>
+          </execution>
+        </executions>
       </plugin>      
     </plugins>
   </build>
@@ -172,7 +210,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
-      <version>1.0-alpha-30</version>
+      <version>1.0-alpha-9-stable-1</version>
     </dependency>
     <dependency>
       <groupId>plexus</groupId>
@@ -295,6 +333,19 @@
       <version>1.5</version>
     </dependency>
     
+    <!-- schema validation dependencies : jaxp 1.3 is not included with jdk 1.4 (start
with 1.5) -->
+    <dependency>
+      <groupId>xml-apis</groupId>
+      <artifactId>xml-apis</artifactId>
+      <version>1.3.04</version>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.8.1</version>
+    </dependency>
+    
+    <!-- test dependencies -->
     <dependency>
       <groupId>org.apache.maven.plugin-testing</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,130 @@
+package org.apache.maven.plugin.changes;
+
+/*
+ * 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.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.plugin.changes.schema.ChangesSchemaValidator;
+import org.apache.maven.plugin.changes.schema.SchemaValidatorException;
+import org.apache.maven.plugin.changes.schema.XmlValidationHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * Goal which validate changes file
+ * 
+ * @goal changes-validate
+ * 
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 28 juil. 2008
+ * @version $Id$
+ * @since 2.1
+ */
+public class ChangesValidatorMojo
+    extends AbstractMojo
+{
+
+    /**
+     * The path of the <code>changes.xml</code> file that will be converted into
an HTML report.
+     *
+     * @parameter expression="${changes.xmlPath}" default-value="src/changes/changes.xml"
+     */
+    private File xmlPath;
+    
+    /**
+     * The changes xsd version.
+     *
+     * @parameter expression="${changes.xsdVersion}" default-value="1.0.0"
+     */
+    private String changesXsdVersion;
+    
+    /**
+     * 
+     * @component role="org.apache.maven.plugin.changes.schema.ChangesSchemaValidator" roleHint="default"
+     *  
+     */
+    private ChangesSchemaValidator changesSchemaValidator;
+    
+    /**
+     * Mojo failure if validation failed. If not and validation failed only a warning will
be logged.
+     *
+     * @parameter expression="${changes.validate.failed}" default-value="false"
+     */    
+    private boolean failOnError;
+    
+    /** 
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+
+        if ( !xmlPath.exists() )
+        {
+            getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist."
);
+            return;
+        }
+
+        try
+        {
+            XmlValidationHandler xmlValidationHandler = changesSchemaValidator
+                .validateXmlWithSchema( xmlPath, changesXsdVersion, failOnError );
+            boolean hasErrros = !xmlValidationHandler.getErrors().isEmpty();
+            if ( hasErrros )
+            {
+                logSchemaValidation( xmlValidationHandler.getErrors() );
+                if ( failOnError )
+                {
+                    throw new MojoExecutionException( "changes.xml file " + xmlPath.getAbsolutePath()
+                        + " is not valid see previous errors" );
+                }
+                else
+                {
+                    getLog().info( " skip previous validation errors due failOnError false
" );
+                }
+            }
+        }
+        catch ( SchemaValidatorException e )
+        {
+            if ( failOnError )
+            {
+                throw new MojoExecutionException( "failed to validate changes.xml file "
+ xmlPath.getAbsolutePath()
+                    + " : " + e.getMessage(), e );
+            }
+        }
+    }
+
+    private void logSchemaValidation( List /*SAXException*/errors )
+    {
+        getLog().error( "failed to validate changes " + xmlPath.getAbsolutePath() );
+        getLog().error( "validation errors : " );
+        for ( Iterator iterator = errors.iterator(); iterator.hasNext(); )
+        {
+            SAXException error = (SAXException) iterator.next();
+            getLog().error( error.getMessage() );
+        }
+    }
+
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/ChangesValidatorMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,41 @@
+package org.apache.maven.plugin.changes.schema;
+
+/*
+ * 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;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 28 juil. 2008
+ * @version $Id$
+ */
+public interface ChangesSchemaValidator
+{
+    /**
+     * @param file
+     * @param schemaVersion
+     * @param failOnValidationError if false SchemaValidatorException will not be throw 
+     * @return {@link XmlValidationHandler}
+     * @throws SchemaValidatorException
+     */
+    public XmlValidationHandler validateXmlWithSchema( File file, String schemaVersion, boolean
failOnValidationError )
+        throws SchemaValidatorException;
+    
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/ChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,141 @@
+package org.apache.maven.plugin.changes.schema;
+
+/*
+ * 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.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.codehaus.plexus.util.FastMap;
+import org.xml.sax.SAXException;
+
+/**
+ * 
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 28 juil. 2008
+ * @version $Id$
+ * 
+ * @plexus.component role="org.apache.maven.plugin.changes.schema.ChangesSchemaValidator"
role-hint="default"
+ */
+public class DefaultChangesSchemaValidator
+    implements ChangesSchemaValidator
+{
+
+    /** property schema */
+    public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";    
+    
+    public static final String CHANGES_SCHEMA_PATH = "META-INF/changes/xsd/";
+    
+    private Map compiledSchemas = new FastMap();
+
+    public XmlValidationHandler validateXmlWithSchema( File file, String schemaVersion, boolean
failOnValidationError )
+        throws SchemaValidatorException
+    {
+        try
+        {
+            String schemaPath = CHANGES_SCHEMA_PATH + "changes-" + schemaVersion + ".xsd";
+            
+            Schema schema = getSchema( schemaPath );
+            
+            Validator validator = schema.newValidator();
+            
+            XmlValidationHandler baseHandler = new XmlValidationHandler( failOnValidationError
);
+            
+            validator.setErrorHandler( baseHandler );
+            
+            validator.validate( new StreamSource( new FileReader( file ) ) );
+            
+            return baseHandler;
+        }
+        catch ( IOException e )
+        {
+            throw new SchemaValidatorException( "IOException : " + e.getMessage(), e );
+        }
+        catch ( SAXException e )
+        {
+            throw new SchemaValidatorException( "SAXException : " + e.getMessage(), e );
+        }
+        catch ( Exception e )
+        {
+            throw new SchemaValidatorException( "Exception : " + e.getMessage(), e );
+        }
+    }
+
+    public Schema getSchema( String schemaPath )
+        throws SAXException
+    {
+        if ( this.compiledSchemas.containsKey( schemaPath ) )
+        {
+            return (Schema) this.compiledSchemas.get( schemaPath );
+        }
+        Schema schema = this.compileJAXPSchema( schemaPath );
+        
+        this.compiledSchemas.put( schemaPath, schema );
+        
+        return schema;
+    }
+
+    /**
+     * @param uriSchema
+     * @return Schema
+     * @throws Exception
+     */
+    private Schema compileJAXPSchema( String uriSchema )
+        throws SAXException, NullPointerException
+    {
+
+        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(
uriSchema );
+
+        if ( is == null )
+        {
+            throw new NullPointerException(" impossible to load schema with path " + uriSchema
);
+        }
+
+        //newInstance de SchemaFactory not ThreadSafe
+        return SchemaFactory.newInstance( W3C_XML_SCHEMA ).newSchema( new StreamSource( is
) );
+
+    }
+
+    /**
+     * @see com.accor.commons.xmlschemas.SchemaValidator#loadSchema(java.lang.String)
+     */
+    public void loadSchema( String uriSchema )
+        throws SchemaValidatorException
+    {
+        try
+        {
+            this.getSchema( uriSchema );
+        }
+        catch ( SAXException e )
+        {
+            throw new SchemaValidatorException( "SAXException : " + e.getMessage(), e );
+        }
+
+    }    
+
+
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,40 @@
+package org.apache.maven.plugin.changes.schema;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 28 juil. 2008
+ * @version $Id$
+ */
+public class SchemaValidatorException
+    extends Exception
+{
+    
+    /**
+     * @param message
+     * @param cause
+     */
+    public SchemaValidatorException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/SchemaValidatorException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,147 @@
+package org.apache.maven.plugin.changes.schema;
+
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 28 juil. 2008
+ * @version $Id$
+ */
+public class XmlValidationHandler
+    extends DefaultHandler
+{
+   
+    private boolean parsingError = false;
+
+    private List /* SAXParseException */errors = new ArrayList();
+
+    private List /* SAXParseException */fatalErrors = new ArrayList();
+
+    private List /* SAXParseException */warnings = new ArrayList();
+
+    private boolean failOnValidationError;
+
+    /**
+     * see name
+     */
+    public XmlValidationHandler( boolean failOnValidationError )
+    {
+        this.failOnValidationError = failOnValidationError;
+    }
+
+    /**
+     * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+     */
+    public void error( SAXParseException excp )
+        throws SAXException
+    {
+        this.setErrorParsing( true );
+        this.errors.add( excp );
+        if ( this.failOnValidationError )
+        {
+            throw new SAXException( excp.getMessage(), excp );
+        }
+    }
+
+    /**
+     * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+     */
+    public void fatalError( SAXParseException excp )
+        throws SAXException
+    {
+        this.fatalErrors.add( excp );
+        if ( this.failOnValidationError )
+        {
+            throw new SAXException( excp.getMessage(), excp );
+        }
+    }
+
+    /**
+     * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+     */
+    public void warning( SAXParseException excp )
+        throws SAXException
+    {
+        this.warnings.add( excp );
+    }
+
+    /**
+     * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
+     */
+    public void startElement( String uri, String localName, String qName, Attributes attributes
)
+        throws SAXException
+    {
+        // nothing
+    }
+
+    /**
+     * @return Returns the errorParsing.
+     */
+    public boolean isErrorParsing()
+    {
+        return this.parsingError;
+    }
+
+    /**
+     * @param error The errorParsing to set.
+     */
+    public void setErrorParsing( boolean error )
+    {
+        this.parsingError = error;
+    }
+
+    public List /* SAXParseException */getErrors()
+    {
+        return errors;
+    }
+
+    public void setErrors( List errors )
+    {
+        this.errors = errors;
+    }
+
+    public List /* SAXParseException */getFatalErrors()
+    {
+        return fatalErrors;
+    }
+
+    public void setFatalErrors( List fatalErrors )
+    {
+        this.fatalErrors = fatalErrors;
+    }
+
+    public List /* SAXParseException */ getWarnings()
+    {
+        return warnings;
+    }
+
+    public void setWarnings( List warnings )
+    {
+        this.warnings = warnings;
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/XmlValidationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/mdo/changes.mdo
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/mdo/changes.mdo?rev=680563&r1=680562&r2=680563&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/mdo/changes.mdo (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/mdo/changes.mdo Mon Jul 28 16:32:11
2008
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 
-<model>
+<model xsd.namespace="http://maven.apache.org/changes/1.0.0" xsd.target-namespace="http://maven.apache.org/changes/1.0.0">
   <id>changes</id>
   <name>Changes</name>
   <description>
@@ -180,7 +180,7 @@
             ]]>
           </description>
         </field>
-        <field xml.attribute="true">
+        <field xml.attribute="true" xml.tagName="due-to">
           <name>dueTo</name>
           <version>1.0.0</version>
           <type>String</type>
@@ -188,7 +188,7 @@
             Name of the person to be credited for this change. This can be used when a patch
is submitted by a non-committer.
           </description>
         </field>
-        <field xml.attribute="true">
+        <field xml.attribute="true" xml.tagName="due-to-email">
           <name>dueToEmail</name>
           <version>1.0.0</version>
           <type>String</type>

Added: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
Mon Jul 28 16:32:11 2008
@@ -0,0 +1,85 @@
+package org.apache.maven.plugin.changes;
+
+/*
+ * 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.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 29 juil. 2008
+ * @version $Id$
+ */
+public class ChangesValidatorMojoTest
+    extends AbstractMojoTestCase
+{
+
+    protected ChangesValidatorMojo mojo;
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        File pom = new File( getBasedir(), "/src/test/unit/plugin-config.xml" );
+        mojo = (ChangesValidatorMojo) lookupMojo( "changes-validate", pom );
+    }    
+    
+    public void testValidationSuccess()
+        throws Exception
+    {
+        File changesXml = new File( getBasedir(), "/src/test/unit/changes.xml" );
+        setVariableValueToObject( mojo, "xmlPath", changesXml );
+        setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
+        mojo.execute();
+    }
+
+    public void testValidationFailedWithMojoFailure()
+        throws Exception
+    {
+        File changesXml = new File( getBasedir(), "/src/test/unit/non-valid-changes.xml"
);
+        setVariableValueToObject( mojo, "xmlPath", changesXml );
+        setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
+        setVariableValueToObject( mojo, "failOnError", Boolean.TRUE );
+        try
+        {
+            mojo.execute();
+            fail( " a MojoExecutionException should occur here changes file is not valid
and failOnError is true " );
+        }
+        catch ( MojoExecutionException e )
+        {
+            // we except exception here
+        }
+    }
+    
+    public void testValidationFailedWithNoMojoFailure()
+        throws Exception
+    {
+        File changesXml = new File( getBasedir(), "/src/test/unit/non-valid-changes.xml"
);
+        setVariableValueToObject( mojo, "xmlPath", changesXml );
+        setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
+        setVariableValueToObject( mojo, "failOnError", Boolean.FALSE );
+        mojo.execute();
+
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/changes/ChangesValidatorMojoTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Modified: maven/plugins/trunk/maven-changes-plugin/src/test/unit/changes.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/unit/changes.xml?rev=680563&r1=680562&r2=680563&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/unit/changes.xml (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/unit/changes.xml Mon Jul 28 16:32:11
2008
@@ -16,33 +16,31 @@
 specific language governing permissions and limitations
 under the License.
 -->
-
-<document>
-  <properties>
-    <title>Changes report Project</title>
-    <author email="zloug@toto.com">Mr Zloug</author>
-  </properties>
-  <body>
-    <release version="1.1" date="2005-03-01" description="Subsequent release">
-      <action dev="me" type="add">
+<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/changes/1.0.0">
+	<properties>
+		<title>Changes report Project</title>
+		<author email="zloug@toto.com">Mr Zloug</author>
+	</properties>
+	<body>
+		<release version="1.1" date="2005-03-01" description="Subsequent release">
+			<action dev="me" type="add">
         Added additional documentation on how to configure the plugin.
       </action>
-      <action dev="me" type="fix" issue="MCHANGES-88">
+			<action dev="me" type="fix" issue="MCHANGES-88">
         Enable retrieving component-specific issues.
       </action>
-      <action dev="me" type="fix" issue="1212" system="qc">
+			<action dev="me" type="fix" issue="1212" system="qc">
         Enable retrieving component-specific issues.
-      </action>      
-      <action dev="jruiz" type="remove" due-to="others" due-to-email="users@users.com">
+      </action>
+			<action dev="jruiz" type="remove" due-to="others" due-to-email="users@users.com">
         The element type " link " must be terminated by the matching end-tag.
         Deleted the erroneous code.
       </action>
-    </release>
-
-    <release version="1.0" date="2005-01-01" description="First release">
-      <action dev="me" type="update" date="2008-01-01">
+		</release>
+		<release version="1.0" date="2005-01-01" description="First release">
+			<action dev="me" type="update" date="2008-01-01">
         Uploaded documentation on how to use the plugin.
       </action>
-    </release>
-  </body>
-</document>
\ No newline at end of file
+		</release>
+	</body>
+</document>

Added: maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml (added)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml Mon Jul 28
16:32:11 2008
@@ -0,0 +1,26 @@
+<!--
+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.
+-->
+
+<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/changes/1.0.0">
+  <properties>
+    <atitle>Changes report Project</atitle>
+    <author email="zloug@toto.com">Mr Zloug</author>
+  </properties>
+  
+</document>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/non-valid-changes.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml?rev=680563&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml Mon Jul 28 16:32:11
2008
@@ -0,0 +1,31 @@
+<!--
+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.
+-->
+
+<project>
+  <name>changes-plugin-test</name>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-changes-plugin</artifactId>
+        <configuration>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/unit/plugin-config.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message