cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1380730 - in /cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java: Option.java WSDL2JavaMojo.java
Date Tue, 04 Sep 2012 16:17:27 GMT
Author: dkulp
Date: Tue Sep  4 16:17:26 2012
New Revision: 1380730

URL: http://svn.apache.org/viewvc?rev=1380730&view=rev
Log:
Merged revisions 1380716 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1380716 | dkulp | 2012-09-04 12:07:08 -0400 (Tue, 04 Sep 2012) | 14 lines

  Merged revisions 1378989 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1378989 | dkulp | 2012-08-30 11:30:36 -0400 (Thu, 30 Aug 2012) | 6 lines

    [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/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
    cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java

Modified: cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java?rev=1380730&r1=1380729&r2=1380730&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
(original)
+++ cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java
Tue Sep  4 16:17:26 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.tools.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/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1380730&r1=1380729&r2=1380730&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
(original)
+++ cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
Tue Sep  4 16:17:26 2012
@@ -21,6 +21,8 @@ package org.apache.cxf.maven_plugin.wsdl
 
 import java.io.File;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
@@ -29,6 +31,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.maven_plugin.AbstractCodegenMoho;
 import org.apache.cxf.maven_plugin.GenericWsdlOption;
 import org.apache.cxf.tools.common.ToolContext;
@@ -141,16 +144,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;
@@ -159,11 +153,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;
                     }
                 }
             }
@@ -171,6 +168,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);



Mime
View raw message