cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1378989 - in /cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java: Option.java WSDL2JavaMojo.java
Date Thu, 30 Aug 2012 15:30:36 GMT
Author: dkulp
Date: Thu Aug 30 15:30:36 2012
New Revision: 1378989

URL: http://svn.apache.org/viewvc?rev=1378989&view=rev
Log:
[CXF-4490] cxf-codegen-plugin does not detect changes in WSDL loaded from classpath

Attempt to resolve classpath and jar URIs prior to checking timestamps on
the WSDL file. Also change dependencies from Files to Strings and perform
timestamp checking on them in the same way as the WSDL itself.

Modified:
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java?rev=1378989&r1=1378988&r2=1378989&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
Thu Aug 30 15:30:36 2012
@@ -20,11 +20,13 @@
 package org.apache.cxf.maven_plugin.wsdl2java;
 
 import java.io.File;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.cxf.common.util.URIParserUtil;
 
 public class Option {
     static final String DEFAULT_BINDING_FILE_PATH = "src" + File.separator + "main"
@@ -87,7 +89,7 @@ public class Option {
      * A set of dependent files used to detect that the generator must process WSDL, even

      * if generator marker files are up to date.
      */
-    File dependencies[];
+    String dependencies[];
 
     /**
      * Redundant directories to be deleted after code generation
@@ -239,14 +241,27 @@ public class Option {
     public void setNamespaceExcludes(List<String> namespaceExcludes) {
         this.namespaceExcludes = namespaceExcludes;
     }
-    public void setDependencies(File files[]) {
-        dependencies = files;
+    public void setDependencies(String dependencies[]) {
+        this.dependencies = dependencies;
     }
 
-    public File[] getDependencies() {
+    public String[] getDependencies() {
         return dependencies;
     }
 
+    public URI[] getDependencyURIs(URI baseURI) {
+        if (dependencies == null) {
+            return null;
+        }
+        URI[] uris = new URI[dependencies.length];
+        for (int i = 0; i < dependencies.length; i++) {
+            File file = new File(dependencies[i]);
+            uris[i] = file.exists() ? file.toURI() : baseURI
+                    .resolve(URIParserUtil.escapeChars(dependencies[i]));
+        }
+        return uris;
+    }
+
     public void setDeleteDirs(File files[]) {
         redundantDirs = files;
     }
@@ -496,7 +511,7 @@ public class Option {
         extraargs.addAll(defaultOptions.extraargs);
         xjcargs.addAll(defaultOptions.xjcargs);
         bindingFiles.addAll(defaultOptions.getBindingFiles());
-        dependencies = mergeList(dependencies, defaultOptions.dependencies, File.class);
+        dependencies = mergeList(dependencies, defaultOptions.dependencies, String.class);
         redundantDirs = mergeList(redundantDirs, defaultOptions.redundantDirs, File.class);
         packagenames.addAll(defaultOptions.packagenames);
         namespaceExcludes.addAll(defaultOptions.namespaceExcludes);

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1378989&r1=1378988&r2=1378989&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
Thu Aug 30 15:30:36 2012
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
@@ -32,6 +33,7 @@ import java.util.Set;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.maven_plugin.AbstractCodegenMoho;
 import org.apache.cxf.maven_plugin.GenericWsdlOption;
@@ -211,16 +213,7 @@ public class WSDL2JavaMojo extends Abstr
     protected boolean shouldRun(GenericWsdlOption genericWsdlOption, 
                                 File doneFile, URI wsdlURI) {
         WsdlOption wsdlOption = (WsdlOption) genericWsdlOption;
-        long timestamp = 0;
-        if ("file".equals(wsdlURI.getScheme())) {
-            timestamp = new File(wsdlURI).lastModified();
-        } else {
-            try {
-                timestamp = wsdlURI.toURL().openConnection().getDate();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
+        long timestamp = getTimestamp(wsdlURI);
         boolean doWork = false;
         if (!doneFile.exists()) {
             doWork = true;
@@ -229,11 +222,14 @@ public class WSDL2JavaMojo extends Abstr
         } else if (wsdlOption.isDefServiceName()) {
             doWork = true;
         } else {
-            File files[] = wsdlOption.getDependencies();
-            if (files != null) {
-                for (int z = 0; z < files.length; ++z) {
-                    if (files[z].lastModified() > doneFile.lastModified()) {
+            URI dependencies[] = wsdlOption.getDependencyURIs(project
+                    .getBasedir().toURI());
+            if (dependencies != null) {
+                for (int z = 0; z < dependencies.length; ++z) {
+                    long dependencyTimestamp = getTimestamp(dependencies[z]);
+                    if (dependencyTimestamp > doneFile.lastModified()) {
                         doWork = true;
+                        break;
                     }
                 }
             }
@@ -241,6 +237,61 @@ public class WSDL2JavaMojo extends Abstr
         return doWork;
     }
 
+    /**
+     * Finds the timestamp for a given URI. Calls {@link #getBaseFileURI(URI)} prior to the
timestamp
+     * check in order to handle "classpath" and "jar" URIs.
+     * 
+     * @param uri the URI to timestamp
+     * @return a timestamp
+     */
+    protected long getTimestamp(URI uri) {
+        long timestamp = 0;
+        URI baseURI = getBaseFileURI(uri);
+        if ("file".equals(baseURI.getScheme())) {
+            timestamp = new File(baseURI).lastModified();
+        } else {
+            try {
+                timestamp = baseURI.toURL().openConnection().getDate();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+        return timestamp;
+    }
+
+    /**
+     * Finds the base file URI that 'contains' the given URI. If the URI can not be resolved
to a file URI
+     * then the original URI is returned. This method currently attempts to resolve only
"classpath" and
+     * "jar" URIs.
+     * 
+     * @param uri the URI to resolve
+     * @return uri a file URI if the original URI is contained in a file, otherwise the original
URI
+     */
+    protected URI getBaseFileURI(URI uri) {
+        if ("classpath".equals(uri.getScheme())) {
+            URL resource = ClassLoaderUtils.getResource(uri.toString().substring(10), getClass());
+            if (resource != null) {
+                try {
+                    return getBaseFileURI(resource.toURI());
+                } catch (URISyntaxException e) {
+                    // ignore
+                }
+            }
+        } else if ("jar".equals(uri.getScheme())) {
+            String jarUrl = uri.toString();
+            int embeddedUrlEndIndex = jarUrl.lastIndexOf("!/");
+            if (embeddedUrlEndIndex != -1) {
+                String embeddedUrl = jarUrl.substring(4, embeddedUrlEndIndex);
+                try {
+                    return getBaseFileURI(new URI(embeddedUrl));
+                } catch (URISyntaxException e) {
+                    // ignore
+                }
+            }
+        }
+        return uri;
+    }
+
     protected List<String> generateCommandLine(GenericWsdlOption wsdlOption)
         throws MojoExecutionException {
         List<String> ret = super.generateCommandLine(wsdlOption);
@@ -268,7 +319,7 @@ public class WSDL2JavaMojo extends Abstr
         doneFile.delete();
 
         try {
-            File file = new File(wsdlURI);
+            File file = new File(getBaseFileURI(wsdlURI));
             if (file.exists()) {
                 buildContext.removeMessages(file);
             }
@@ -276,8 +327,12 @@ public class WSDL2JavaMojo extends Abstr
             //ignore
         }
         if (wsdlOption.getDependencies() != null) {
-            for (File f : wsdlOption.getDependencies()) {
-                buildContext.removeMessages(f);
+            for (URI dependency : wsdlOption.getDependencyURIs(project
+                    .getBasedir().toURI())) {
+                URI baseDependency = getBaseFileURI(dependency);
+                if ("file".equals(baseDependency.getScheme())) {
+                    buildContext.removeMessages(new File(baseDependency));
+                }
             }
         }
         



Mime
View raw message