maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r703144 [1/5] - in /maven/doxia/doxia/trunk: doxia-core/ doxia-core/src/test/java/org/apache/maven/doxia/xsd/ doxia-modules/doxia-module-fml/src/main/resources/ doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/...
Date Thu, 09 Oct 2008 11:57:46 GMT
Author: vsiveton
Date: Thu Oct  9 04:57:45 2008
New Revision: 703144

URL: http://svn.apache.org/viewvc?rev=703144&view=rev
Log:
DOXIA-123: Create an xdoc DTD or XSD for maven 2

o added FML and XDoc xsd 
o added test cases to validate existing files with new namespaces

Added:
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/resources/
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/resources/fml-1.0.xsd
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlValidatorTest.java
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/resources/
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/resources/xdoc-2.0.xsd
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocValidatorTest.java
  (with props)
Modified:
    maven/doxia/doxia/trunk/doxia-core/pom.xml

Modified: maven/doxia/doxia/trunk/doxia-core/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/pom.xml?rev=703144&r1=703143&r2=703144&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/pom.xml (original)
+++ maven/doxia/doxia/trunk/doxia-core/pom.xml Thu Oct  9 04:57:45 2008
@@ -49,6 +49,38 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
     </dependency>
+
+    <!-- test -->
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+      <version>2.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-api</artifactId>
+      <version>1.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-manager-plexus</artifactId>
+      <version>1.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-svn-commons</artifactId>
+      <version>1.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-provider-svnexe</artifactId>
+      <version>1.1</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Added: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java?rev=703144&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
(added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
Thu Oct  9 04:57:45 2008
@@ -0,0 +1,296 @@
+package org.apache.maven.doxia.xsd;
+
+/*
+ * 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.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.manager.ScmManager;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * Abstract class to validate XML files with Doxia namespaces.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ * @since 1.0
+ */
+public abstract class AbstractXmlValidatorTest
+    extends PlexusTestCase
+{
+    /** The vm line separator */
+    protected static final String EOL = System.getProperty( "line.separator" );
+
+    /** XMLReader to validate xml file */
+    private XMLReader xmlReader;
+
+    /** The scm manager */
+    private ScmManager scmManager;
+
+    /** {@inheritDoc} */
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        for ( Iterator it = getScmRepositoryWrapper().iterator(); it.hasNext(); )
+        {
+            ScmRepositoryWrapper wrapper = (ScmRepositoryWrapper) it.next();
+
+            if ( !wrapper.getCheckoutDir().exists() )
+            {
+                wrapper.getCheckoutDir().mkdirs();
+                getScmManager().checkOut( getScmManager().makeScmRepository( wrapper.getScmRepository()
),
+                                          new ScmFileSet( wrapper.getCheckoutDir() ) );
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+
+        scmManager = null;
+
+        xmlReader = null;
+    }
+
+    /**
+     * @return non null list of ScmRepositoryWrapper
+     */
+    protected abstract List getScmRepositoryWrapper();
+
+    /**
+     * @param wrapper not null
+     * @return a list of files in a given wrapper to be validated
+     * @throws IOException if any
+     */
+    protected abstract List getXmlFiles( ScmRepositoryWrapper wrapper )
+        throws IOException;
+
+    /**
+     * @param content xml content not null
+     * @return xml content with the wanted Doxia namespace
+     */
+    protected abstract String addNamespaces( String content );
+
+    /**
+     * Test xml files with namespace.
+     *
+     * @throws Exception if any
+     */
+    public void testXmlFilesWithDoxiaNamespaces()
+        throws Exception
+    {
+        for ( Iterator it = getScmRepositoryWrapper().iterator(); it.hasNext(); )
+        {
+            ScmRepositoryWrapper wrapper = (ScmRepositoryWrapper) it.next();
+
+            for ( Iterator it2 = getXmlFiles( wrapper ).iterator(); it2.hasNext(); )
+            {
+                File f = (File) it2.next();
+
+                List errors = parseXML( f );
+
+                for ( Iterator it3 = errors.iterator(); it3.hasNext(); )
+                {
+                    String message = (String) it3.next();
+
+                    if ( message.length() != 0 )
+                    {
+                        // Exclude some xhtml errors
+                        if ( message.indexOf( "Message: cvc-complex-type.4: Attribute 'alt'
must appear on element 'img'." ) == -1
+                            && message.indexOf( "Message: cvc-complex-type.2.4.a:
Invalid content starting with element" ) == -1
+                            && message.indexOf( "Message: cvc-datatype-valid.1.2.1:"
) == -1  // Doxia allow space
+                            && message.indexOf( "Message: cvc-attribute.3:" ) ==
-1 ) // Doxia allow space
+                        {
+                            fail( f.getAbsolutePath() + EOL + message );
+                        }
+                        else
+                        {
+                            if ( getContainer().getLogger().isDebugEnabled() )
+                            {
+                                getContainer().getLogger().debug( f.getAbsolutePath() + EOL
+ message );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // ----------------------------------------------------------------------
+    // Private method
+    // ----------------------------------------------------------------------
+
+    private ScmManager getScmManager()
+        throws Exception
+    {
+        if ( scmManager == null )
+        {
+            scmManager = (ScmManager) lookup( ScmManager.ROLE );
+        }
+
+        return scmManager;
+    }
+
+    private XMLReader getXMLReader()
+    {
+        if ( xmlReader == null )
+        {
+            try
+            {
+                xmlReader = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser"
);
+                xmlReader.setFeature( "http://xml.org/sax/features/validation", true );
+                xmlReader.setFeature( "http://apache.org/xml/features/validation/schema",
true );
+                MessagesErrorHandler errorHandler = new MessagesErrorHandler();
+                xmlReader.setErrorHandler( errorHandler );
+            }
+            catch ( SAXNotRecognizedException e )
+            {
+                throw new AssertionFailedError( "SAXNotRecognizedException: " + e.getMessage()
);
+            }
+            catch ( SAXNotSupportedException e )
+            {
+                throw new AssertionFailedError( "SAXNotSupportedException: " + e.getMessage()
);
+            }
+            catch ( SAXException e )
+            {
+                throw new AssertionFailedError( "SAXException: " + e.getMessage() );
+            }
+        }
+
+        return xmlReader;
+    }
+
+    private List parseXML( File f )
+        throws IOException, SAXException
+    {
+        Reader reader = ReaderFactory.newXmlReader( f );
+        String content = IOUtil.toString( reader );
+        content = addNamespaces( content );
+
+        MessagesErrorHandler errorHandler = (MessagesErrorHandler) getXMLReader().getErrorHandler();
+
+        getXMLReader().parse( new InputSource( new ByteArrayInputStream( content.getBytes()
) ) );
+
+        return errorHandler.getMessages();
+    }
+
+    private static class MessagesErrorHandler
+        extends DefaultHandler
+    {
+        private final List messages;
+
+        public MessagesErrorHandler()
+        {
+            messages = new ArrayList();
+        }
+
+        /** {@inheritDoc} */
+        public void warning( SAXParseException e )
+            throws SAXException
+        {
+            addMessage( "Warning:", e );
+        }
+
+        /** {@inheritDoc} */
+        public void error( SAXParseException e )
+            throws SAXException
+        {
+            addMessage( "Error:", e );
+        }
+
+        /** {@inheritDoc} */
+        public void fatalError( SAXParseException e )
+            throws SAXException
+        {
+            addMessage( "Fatal error:", e );
+        }
+
+        private void addMessage( String pre, SAXParseException e )
+        {
+            StringBuffer message = new StringBuffer();
+
+            message.append( pre ).append( EOL );
+            message.append( "  Public ID: " + e.getPublicId() ).append( EOL );
+            message.append( "  System ID: " + e.getSystemId() ).append( EOL );
+            message.append( "  Line number: " + e.getLineNumber() ).append( EOL );
+            message.append( "  Column number: " + e.getColumnNumber() ).append( EOL );
+            message.append( "  Message: " + e.getMessage() ).append( EOL );
+
+            messages.add( message.toString() );
+        }
+
+        protected List getMessages()
+        {
+            return messages;
+        }
+    }
+
+    protected static class ScmRepositoryWrapper
+    {
+        private final String scmRepository;
+
+        private final File checkoutDir;
+
+        public ScmRepositoryWrapper( String scmRepository, File checkoutDir )
+        {
+            this.scmRepository = scmRepository;
+            this.checkoutDir = checkoutDir;
+        }
+
+        /**
+         * @return the scmRepository
+         */
+        public String getScmRepository()
+        {
+            return scmRepository;
+        }
+
+        /**
+         * @return the checkoutDir
+         */
+        public File getCheckoutDir()
+        {
+            return checkoutDir;
+        }
+    }
+}

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/xsd/AbstractXmlValidatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message