Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0C6CD992 for ; Tue, 4 Sep 2012 16:07:53 +0000 (UTC) Received: (qmail 19383 invoked by uid 500); 4 Sep 2012 16:07:53 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 19332 invoked by uid 500); 4 Sep 2012 16:07:53 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 19324 invoked by uid 99); 4 Sep 2012 16:07:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Sep 2012 16:07:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Sep 2012 16:07:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 64BB72388993; Tue, 4 Sep 2012 16:07:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1380716 - in /cxf/branches/2.6.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:07:09 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120904160709.64BB72388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Sep 4 16:07:08 2012 New Revision: 1380716 URL: http://svn.apache.org/viewvc?rev=1380716&view=rev Log: 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.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java Modified: cxf/branches/2.6.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.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java?rev=1380716&r1=1380715&r2=1380716&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java (original) +++ cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/Option.java Tue Sep 4 16:07:08 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 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.6.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.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1380716&r1=1380715&r2=1380716&view=diff ============================================================================== --- cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java (original) +++ cxf/branches/2.6.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java Tue Sep 4 16:07:08 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 generateCommandLine(GenericWsdlOption wsdlOption) throws MojoExecutionException { List 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)); + } } }