You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2008/05/26 20:17:07 UTC

svn commit: r660260 - in /cxf/trunk: maven-plugins/ maven-plugins/wsdl-validator-plugin/ maven-plugins/wsdl-validator-plugin/src/ maven-plugins/wsdl-validator-plugin/src/main/ maven-plugins/wsdl-validator-plugin/src/main/java/ maven-plugins/wsdl-valida...

Author: bimargulies
Date: Mon May 26 11:17:04 2008
New Revision: 660260

URL: http://svn.apache.org/viewvc?rev=660260&view=rev
Log:
A maven plugin that runs the wsdl validator. 

Added:
    cxf/trunk/maven-plugins/wsdl-validator-plugin/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml   (with props)
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java   (with props)
    cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java   (with props)
Modified:
    cxf/trunk/maven-plugins/pom.xml
    cxf/trunk/testutils/pom.xml

Modified: cxf/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/pom.xml?rev=660260&r1=660259&r2=660260&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/pom.xml (original)
+++ cxf/trunk/maven-plugins/pom.xml Mon May 26 11:17:04 2008
@@ -34,6 +34,7 @@
     <modules>
         <module>codegen-plugin</module>
         <module>java2ws-plugin</module>
+        <module>wsdl-validator-plugin</module>
         <module>corba</module>
         <module>archetypes</module>
         <module>eclipse-plugin-generator</module>

Added: cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml?rev=660260&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml (added)
+++ cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml Mon May 26 11:17:04 2008
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!--
+  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 xmlns="http://maven.apache.org/POM/4.0.0" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
+         http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.cxf</groupId>
+    <artifactId>cxf-wsdl-validator-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+    <version>2.1.1-SNAPSHOT</version>
+    <name>Apache CXF WSDL Validator Maven2 Plugin</name>
+    <url>http://cxf.apache.org</url>
+
+
+    <parent>
+        <groupId>org.apache.cxf</groupId>
+        <artifactId>cxf-parent</artifactId>
+        <version>2.1.1-SNAPSHOT</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-tools-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-common-utilities</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-tools-validator</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+                     
+    </dependencies>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/wsdl-validator-plugin</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/cxf/trunk/maven-plugins/wsdl-validator-plugin</developerConnection>
+    </scm>
+
+</project>
\ No newline at end of file

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java?rev=660260&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java (added)
+++ cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java Mon May 26 11:17:04 2008
@@ -0,0 +1,89 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.maven_plugin;
+
+import java.io.File;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.cxf.tools.validator.WSDLValidator;
+
+public final class CodegenUtils {
+    
+    static long timestamp;
+    
+    private CodegenUtils() {
+        //not constructed
+    }
+    
+    public static long getCodegenTimestamp() {
+        if (timestamp != 0) {
+            return timestamp;
+        }
+        
+        getClassTime(CodegenUtils.class);
+        getClassTime(WSDLValidator.class);
+
+        
+        return timestamp;
+    }
+
+    private static void getClassTime(Class class1) {
+        String str = "/" + class1.getName().replace('.', '/') + ".class";
+        URL url = class1.getResource(str);
+        if (url != null) {
+            while ("jar".equals(url.getProtocol())) {
+                str = url.getPath();
+                if (str.lastIndexOf("!") != -1) {
+                    str = str.substring(0, str.lastIndexOf("!"));
+                }
+                try {
+                    url = new URL(str);
+                } catch (MalformedURLException e) {
+                    return;
+                }
+            }
+            try {
+                if (url.getPath().endsWith(".class")) {
+                    timestamp = new File(url.toURI()).lastModified();
+                } else {
+                    JarFile jar = new JarFile(url.getPath());
+                    Enumeration entries = jar.entries();
+                    while (entries.hasMoreElements()) {
+                        JarEntry entry = (JarEntry)entries.nextElement();
+                        if (!entry.isDirectory()
+                            && !entry.getName().startsWith("META")
+                            && entry.getTime() > timestamp) {
+                            
+                            timestamp = entry.getTime();
+                        }                    
+                    }
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+}

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/CodegenUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java?rev=660260&view=auto
==============================================================================
--- cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java (added)
+++ cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java Mon May 26 11:17:04 2008
@@ -0,0 +1,182 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.maven_plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.tools.common.toolspec.ToolRunner;
+import org.apache.cxf.tools.validator.WSDLValidator;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal wsdlvalidator
+ * @description CXF WSDL Validation
+ */
+public class WSDLValidatorMojo extends AbstractMojo {
+    /**
+     * @parameter
+     */
+    private Boolean verbose;
+
+    /**
+     * @parameter
+     */
+    private Boolean quiet;
+
+
+    /**
+     * @parameter expression="${cxf.wsdlRoot}" default-value="${basedir}/src/main/resources/wsdl"
+     */
+    private File wsdlRoot;
+    
+    /**
+     * @parameter expression="${cxf.testWsdlRoot}" default-value="${basedir}/src/test/resources/wsdl"
+     */
+    private File testWsdlRoot;
+    
+    /**
+     * Directory in which the "DONE" markers are saved that 
+     * @parameter expression="${cxf.markerDirectory}" 
+     *            default-value="${project.build.directory}/cxf-wsdl-validator-markers"
+     */
+    private File markerDirectory;
+    /**
+     * A list of wsdl files to include. Can contain ant-style wildcards and double wildcards. Defaults to
+     * *.wsdl
+     * 
+     * @parameter
+     */
+    private String includes[];
+    /**
+     * A list of wsdl files to exclude. Can contain ant-style wildcards and double wildcards.
+     * 
+     * @parameter
+     */
+    private String excludes[];
+
+    private String getIncludeExcludeString(String[] arr) {
+        if (arr == null) {
+            return "";
+        }
+        StringBuilder str = new StringBuilder();
+
+        if (arr != null) {
+            for (String s : arr) {
+                if (str.length() > 0) {
+                    str.append(',');
+                }
+                str.append(s);
+            }
+        }
+        return str.toString();
+    }
+    
+    private List<File> getWsdlFiles(File dir)
+        throws MojoExecutionException {
+
+        List<String> exList = new ArrayList<String>();
+        if (excludes != null) {
+            exList.addAll(Arrays.asList(excludes));
+        }
+        exList.addAll(Arrays.asList(org.codehaus.plexus.util.FileUtils.getDefaultExcludes()));
+
+        String inc = getIncludeExcludeString(includes);
+        String ex = getIncludeExcludeString(exList.toArray(new String[exList.size()]));
+
+        try {
+            List newfiles = org.codehaus.plexus.util.FileUtils.getFiles(dir, inc, ex);
+            return CastUtils.cast(newfiles);
+        } catch (IOException exc) {
+            throw new MojoExecutionException(exc.getMessage(), exc);
+        }
+    }
+    
+    private void processWsdl(File file, long cgtimestamp) throws MojoExecutionException {
+        
+        // If URL to WSDL, replace ? and & since they're invalid chars for file names
+        File doneFile =
+            new File(markerDirectory, "." + file.getName().replace('?', '_').replace('&', '_') + ".DONE");
+        boolean doWork = cgtimestamp > doneFile.lastModified();
+        if (!doneFile.exists()) {
+            doWork = true;
+        } else if (file.lastModified() > doneFile.lastModified()) {
+            doWork = true;
+        } 
+
+        if (doWork) {
+            doneFile.delete();
+            
+            List<String> list = new ArrayList<String>();
+
+            // verbose arg
+            if (verbose != null && verbose.booleanValue()) {
+                list.add("-verbose");
+            }
+
+            // quiet arg
+            if (quiet != null && quiet.booleanValue()) {
+                list.add("-quiet");
+            }
+
+            getLog().debug("Calling wsdlvalidator with args: " + list);
+            try {
+                list.add(file.getCanonicalPath());
+                String[] pargs = list.toArray(new String[list.size()]);
+                ToolRunner.runTool(WSDLValidator.class, WSDLValidator.class
+                                   .getResourceAsStream("wsdlvalidator.xml"), false, pargs);
+                doneFile.createNewFile();
+            } catch (Throwable e) {
+                getLog().debug(e);
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+        }
+    }
+
+    public void execute() throws MojoExecutionException {
+        if (includes == null) {
+            includes = new String[] {
+                "*.wsdl"
+            };
+        }
+        
+        markerDirectory.mkdirs();
+        
+        List<File> wsdls = new ArrayList<File>();
+        if (wsdlRoot != null && wsdlRoot.exists()) {
+            wsdls.addAll(getWsdlFiles(wsdlRoot));
+        }
+        if (testWsdlRoot != null && testWsdlRoot.exists()) {
+            wsdls.addAll(getWsdlFiles(testWsdlRoot));
+        }
+
+        long timestamp = CodegenUtils.getCodegenTimestamp();
+        for (File wsdl : wsdls) {
+            processWsdl(wsdl, timestamp);
+        }
+
+
+    }
+}

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/maven-plugins/wsdl-validator-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDLValidatorMojo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/testutils/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/pom.xml?rev=660260&r1=660259&r2=660260&view=diff
==============================================================================
--- cxf/trunk/testutils/pom.xml (original)
+++ cxf/trunk/testutils/pom.xml Mon May 26 11:17:04 2008
@@ -160,6 +160,23 @@
             </plugin>
             <plugin>
                 <groupId>org.apache.cxf</groupId>
+                <artifactId>cxf-wsdl-validator-plugin</artifactId>
+                <version>${project.version}</version>
+                <configuration>
+                   <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>validate</id>
+                        <phase>validate</phase>
+                        <goals>
+                          <goal>wsdlvalidator</goal>
+                        </goals>
+                    </execution>
+                  </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.cxf</groupId>
                 <artifactId>cxf-codegen-plugin</artifactId>
                 <version>${project.version}</version>
                 <executions>