Author: dkulp Date: Wed Sep 2 14:33:32 2009 New Revision: 810524 URL: http://svn.apache.org/viewvc?rev=810524&view=rev Log: Merged revisions 810510 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r810510 | dkulp | 2009-09-02 10:11:00 -0400 (Wed, 02 Sep 2009) | 9 lines Merged revisions 810376 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r810376 | cschneider | 2009-09-02 02:45:04 -0400 (Wed, 02 Sep 2009) | 1 line Refactored for better readability ........ ................ Added: cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java - copied unchanged from r810510, cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ClassLoaderSwitcher.java Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Wed Sep 2 14:33:32 2009 @@ -1,2 +1,2 @@ -/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402,794404,794735,794797,794799,794803,795161-795162,796300-796301,796598,797449,797452-797453,797460,797463-797464,797521-797522,797584-797585,797645,797652,797701,797884,797886,798348-798350,798568,798574-798575,798577-798578,798586,798608,798655,798752,798942,799444,799449,799738,799740,800514-800516,801382-801384,803960,803962,803979,804005,805925-805927,805929,806606,806612,806617,806662,808478,808484,808491,808495,808505,808527,808533-808534,808536,808539,809693,809717,809748,809784,809787-809801,810203-810224,810231,810236,810509,810515 -/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297,794396,794728,794778-794780,794892,795160,796022-796023,796593,796780,797194,797231-797233,797442,797505,797517,797581-797582,797640,797651,797699,797882-797883,798344-798346,798479,798533,798551,798557,798561-798562,798570,798573,798584,798654,798749,798929,799439,799448,799637,799724,799792,800453,800497,801380-801381,802892,803129,803689,804002,804276,805784,805907,805909,806020-806021,806405,806576,806603-806604,806631,806633,806922,807748,807807,808035,808069,808085,808731,809083,809162,809417-809626,809631,809663,809706,809738,809962,810349,810513 +/cxf/branches/2.2.x-fixes:743446,753380,753397,753421,754585,755365,757499,757859,757899,757935,757951,758195,758303,758308,758378,758690,758910,759890,759961,759963-759964,759966,760029,760073,760150,760171,760178,760198,760212,760456,760468,760582,760938,761094,761113,761120,761317,761759,761789,762393,762518,762567,763200,763272,763495,763854,763931,763942,763953,764033-764034,764581,764599-764606,764887,765357,766013,766058,766100-766101,766763,766770,766860,766962-766963,767159,767191,767927,771416,772143,772402,772658,772714,773009-773010,773027,773049,773146,773581,773691,773693,774446-774496,774558,774760,774851,774979,775423,776024-776025,776218,776429,776459,777189,777224,777243,777481,777505,777572,777580,780033,780184,780213,780421,780664,780800,780902,780911,781497,781841,782733,782735-782736,783099,783407,784064,784197,785293,785296,785298-785299,785301,785656,786158,786587,786589,786591-786592,786640,787272,787276,787282-787283,787285,787295,787307,787324,7873 67,788824-788825,788827-788828,788830,789423,789429,789707,789709-789710,789712,789721,789905,789908,789910,789912,790295,790646-790647,790651,790654-790655,790659,791948,791950,791952,791955,792276,792288,792291,792992,792995,792998,794402,794404,794735,794797,794799,794803,795161-795162,796300-796301,796598,797449,797452-797453,797460,797463-797464,797521-797522,797584-797585,797645,797652,797701,797884,797886,798348-798350,798568,798574-798575,798577-798578,798586,798608,798655,798752,798942,799444,799449,799738,799740,800514-800516,801382-801384,803960,803962,803979,804005,805925-805927,805929,806606,806612,806617,806662,808478,808484,808491,808495,808505,808527,808533-808534,808536,808539,809693,809717,809748,809784,809787-809801,810203-810224,810231,810236,810509-810510,810515 +/cxf/trunk:782181,782728-782730,783097,783396,784059,784181,784895,785279-785282,785468,786142,786271,786395,786582-786583,786638,786647,787269,787277-787279,787290,787305,787323,787366,788060,788187,788703,788774,788820,789371,789420,789527-789529,789704-789705,789896,789898-789900,790294,790637-790644,791354,791538,791753,791947,792261-792263,792684,792975,792985,794297,794396,794728,794778-794780,794892,795160,796022-796023,796593,796780,797194,797231-797233,797442,797505,797517,797581-797582,797640,797651,797699,797882-797883,798344-798346,798479,798533,798551,798557,798561-798562,798570,798573,798584,798654,798749,798929,799439,799448,799637,799724,799792,800453,800497,801380-801381,802892,803129,803689,804002,804276,805784,805907,805909,806020-806021,806405,806576,806603-806604,806631,806633,806922,807748,807807,808035,808069,808085,808731,809083,809162,809417-809626,809631,809663,809706,809738,809962,810349,810376,810513 Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java?rev=810524&r1=810523&r2=810524&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java (original) +++ cxf/branches/2.1.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Wed Sep 2 14:33:32 2009 @@ -20,22 +20,15 @@ package org.apache.cxf.maven_plugin; import java.io.File; -import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; -import org.apache.cxf.helpers.CastUtils; import org.apache.cxf.tools.common.ToolContext; import org.apache.cxf.tools.wsdlto.WSDLToJava; -import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; @@ -45,7 +38,7 @@ * @phase generate-sources * @description CXF WSDL To Java Tool * @requiresDependencyResolution test -*/ + */ public class WSDL2JavaMojo extends AbstractMojo { /** * @parameter expression="${cxf.testSourceRoot}" @@ -53,7 +46,9 @@ File testSourceRoot; /** - * @parameter expression="${cxf.sourceRoot}" + * Path where the generated sources should be placed + * + * @parameter expression="${cxf.sourceRoot}" * default-value="${project.build.directory}/generated/src/main/java" * @required */ @@ -73,6 +68,7 @@ /** * Default options to be used when a wsdl has not had it's options explicitly specified. + * * @parameter */ Option defaultOptions; @@ -86,40 +82,53 @@ * @parameter expression="${cxf.wsdlRoot}" default-value="${basedir}/src/main/resources/wsdl" */ File wsdlRoot; - + /** * @parameter expression="${cxf.testWsdlRoot}" default-value="${basedir}/src/test/resources/wsdl" */ File testWsdlRoot; - + /** - * Directory in which the "DONE" markers are saved that - * @parameter expression="${cxf.markerDirectory}" + * Directory in which the "DONE" markers are saved that + * + * @parameter expression="${cxf.markerDirectory}" * default-value="${project.build.directory}/cxf-codegen-plugin-markers" */ File markerDirectory; /** - * Use the compile classpath rather than the test classpath for execution - * useful if the test dependencies clash with those of wsdl2java + * Use the compile classpath rather than the test classpath for execution useful if the test dependencies + * clash with those of wsdl2java + * * @parameter expression="${cxf.useCompileClasspath}" default-value="false" */ boolean useCompileClasspath; - + /** - * A list of wsdl files to include. Can contain ant-style wildcards and double wildcards. - * Defaults to *.wsdl + * A list of wsdl files to include. Can contain ant-style wildcards and double wildcards. Defaults to + * *.wsdl + * * @parameter */ String includes[]; + /** - * A list of wsdl files to exclude. Can contain ant-style wildcards and double wildcards. + * A list of wsdl files to exclude. Can contain ant-style wildcards and double wildcards. + * * @parameter */ String excludes[]; - - private List<WsdlOption> getWsdlOptionsFromDir(final File root, - final File output) + + /** + * Create WsdlOption objects for each wsdl file found in the root dir. includes, excludes filter which + * files are considered. The defaultOptions will be applied. + * + * @param root Base directory to search + * @param output + * @return + * @throws MojoExecutionException + */ + private List<WsdlOption> getWsdlOptionsFromDir(final File root, final File output) throws MojoExecutionException { List<WsdlOption> options = new ArrayList<WsdlOption>(); for (WsdlOption o : new WsdlOptionLoader().load(root, includes, excludes, defaultOptions)) { @@ -132,128 +141,107 @@ } return options; } - - private void mergeOptions(List<WsdlOption> options) { + + /** + * Try to find a file matching the given wsdlPath (either absolutely, relatively to the current dir or to + * the project base dir) + * + * @param wsdlPath + * @return wsdl file + */ + private File getFileFromWsdlPath(String wsdlPath) { + File file = null; + try { + URI uri = new URI(wsdlPath); + if (uri.isAbsolute()) { + file = new File(uri); + } + } catch (Exception e) { + // ignore + } + if (file == null || !file.exists()) { + file = new File(wsdlPath); + } + if (!file.exists()) { + file = new File(project.getBasedir(), wsdlPath); + } + return file; + } + + /** + * Merge WsdlOptions that point to the same file by adding the extraargs to the first option and deleting + * the second from the options list + * + * @param options + */ + private void mergeOptions(List<WsdlOption> effectiveWsdlOptions, WsdlOption[] explicitWsdlOptions) { File outputDirFile = testSourceRoot == null ? sourceRoot : testSourceRoot; - for (WsdlOption o : wsdlOptions) { + for (WsdlOption o : explicitWsdlOptions) { if (o.getOutputDir() == null) { o.setOutputDir(outputDirFile); } - - File file = new File(o.getWsdl()); - if (!file.exists()) { - file = new File(project.getBasedir(), o.getWsdl()); - } + + File file = getFileFromWsdlPath(o.getWsdl()); if (file.exists()) { file = file.getAbsoluteFile(); - for (WsdlOption o2 : options) { - File file2 = null; - try { - URI uri = new URI(o2.getWsdl()); - if (uri.isAbsolute()) { - file2 = new File(uri); - } - } catch (Exception e) { - //ignore - } - if (file2 == null || !file2.exists()) { - file2 = new File(o2.getWsdl()); - } - if (file2 == null || !file2.exists()) { - file2 = new File(project.getBasedir(), o2.getWsdl()); - } - if (file2.exists() - && file2.getAbsoluteFile().equals(file)) { + for (WsdlOption o2 : effectiveWsdlOptions) { + File file2 = getFileFromWsdlPath(o2.getWsdl()); + if (file2.exists() && file2.getAbsoluteFile().equals(file)) { o.getExtraargs().addAll(0, o2.getExtraargs()); - options.remove(o2); + effectiveWsdlOptions.remove(o2); break; } } } - options.add(0, o); - } + effectiveWsdlOptions.add(0, o); + } } - - public void execute() throws MojoExecutionException { - if (includes == null) { - includes = new String[] {"*.wsdl"}; - } - - File classesDir = new File(classesDirectory); - classesDir.mkdirs(); - markerDirectory.mkdirs(); - - List<WsdlOption> options = new ArrayList<WsdlOption>(); + + /** + * @return effective WsdlOptions + * @throws MojoExecutionException + */ + private WsdlOption[] createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions() + throws MojoExecutionException { + List<WsdlOption> effectiveWsdlOptions = new ArrayList<WsdlOption>(); if (wsdlRoot != null && wsdlRoot.exists()) { - options.addAll(getWsdlOptionsFromDir(wsdlRoot, sourceRoot)); + effectiveWsdlOptions.addAll(getWsdlOptionsFromDir(wsdlRoot, sourceRoot)); } if (testWsdlRoot != null && testWsdlRoot.exists()) { - options.addAll(getWsdlOptionsFromDir(testWsdlRoot, testSourceRoot)); + effectiveWsdlOptions.addAll(getWsdlOptionsFromDir(testWsdlRoot, testSourceRoot)); } if (wsdlOptions != null) { - mergeOptions(options); + mergeOptions(effectiveWsdlOptions, wsdlOptions); } - wsdlOptions = options.toArray(new WsdlOption[options.size()]); + return effectiveWsdlOptions.toArray(new WsdlOption[effectiveWsdlOptions.size()]); + } - if (wsdlOptions.length == 0) { - getLog().info("Nothing to generate"); - return; + public void execute() throws MojoExecutionException { + if (includes == null) { + includes = new String[] { + "*.wsdl" + }; } - List<URL> urlList = new ArrayList<URL>(); - StringBuffer buf = new StringBuffer(); + File classesDir = new File(classesDirectory); + classesDir.mkdirs(); + markerDirectory.mkdirs(); - try { - urlList.add(classesDir.toURI().toURL()); - if (!useCompileClasspath) { - urlList.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL()); - } - } catch (MalformedURLException e) { - //ignore - } - - buf.append(classesDir.getAbsolutePath()); - buf.append(File.pathSeparatorChar); - if (!useCompileClasspath) { - buf.append(project.getBuild().getOutputDirectory()); - buf.append(File.pathSeparatorChar); - } - List artifacts = useCompileClasspath ? project.getCompileArtifacts() : project.getTestArtifacts(); - for (Artifact a : CastUtils.cast(artifacts, Artifact.class)) { - try { - if (a.getFile() != null - && a.getFile().exists()) { - urlList.add(a.getFile().toURI().toURL()); - buf.append(a.getFile().getAbsolutePath()); - buf.append(File.pathSeparatorChar); - //System.out.println(" " + a.getFile().getAbsolutePath()); - } - } catch (MalformedURLException e) { - //ignore - } + WsdlOption[] effectiveWsdlOptions = createWsdlOptionsFromWsdlFilesAndExplicitWsdlOptions(); + + if (effectiveWsdlOptions.length == 0) { + getLog().info("Nothing to generate"); + return; } - - ClassLoader origContext = Thread.currentThread().getContextClassLoader(); - URLClassLoader loader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), - origContext); - String newCp = buf.toString(); - - getLog().debug("Classpath: " + urlList.toString()); - - //with some VM's, creating an XML parser (which we will do to parse wsdls) - //will set some system properties that then interferes with mavens - //dependency resolution. (OSX is the major culprit here) - //We'll save the props and then set them back later. - Map<Object, Object> origProps = new HashMap<Object, Object>(System.getProperties()); - - String cp = System.getProperty("java.class.path"); + + ClassLoaderSwitcher classLoaderSwitcher = new ClassLoaderSwitcher(getLog()); boolean result = true; - + try { - Thread.currentThread().setContextClassLoader(loader); - System.setProperty("java.class.path", newCp); - for (WsdlOption o : wsdlOptions) { + classLoaderSwitcher.switchClassLoader(project, useCompileClasspath, classesDir); + + for (WsdlOption o : effectiveWsdlOptions) { processWsdl(o); File dirs[] = o.getDeleteDirs(); @@ -261,24 +249,15 @@ for (int idx = 0; idx < dirs.length; ++idx) { result = result && deleteDir(dirs[idx]); } - } + } } } finally { - //cleanup as much as we can. + // cleanup as much as we can. Bus bus = BusFactory.getDefaultBus(false); if (bus != null) { bus.shutdown(true); } - Thread.currentThread().setContextClassLoader(origContext); - System.setProperty("java.class.path", cp); - - Map<Object, Object> newProps = new HashMap<Object, Object>(System.getProperties()); - for (Object o : newProps.keySet()) { - if (!origProps.containsKey(o)) { - System.clearProperty(o.toString()); - } - } - System.getProperties().putAll(origProps); + classLoaderSwitcher.restoreClassLoader(); org.apache.cxf.tools.wsdlto.core.PluginLoader.unload(); } if (project != null && sourceRoot != null && sourceRoot.exists()) { @@ -292,11 +271,10 @@ } private void processWsdl(WsdlOption wsdlOption) throws MojoExecutionException { - + File outputDirFile = wsdlOption.getOutputDir(); outputDirFile.mkdirs(); - - + String wsdlLocation = wsdlOption.getWsdl(); File wsdlFile = new File(wsdlLocation); URI basedir = project.getBasedir().toURI(); @@ -306,7 +284,7 @@ } else { wsdlURI = basedir.resolve(wsdlLocation); } - + String doneFileName = wsdlURI.toString(); if (doneFileName.startsWith(basedir.toString())) { doneFileName = doneFileName.substring(basedir.toString().length()); @@ -314,13 +292,12 @@ // If URL to WSDL, replace ? and & since they're invalid chars for file names // Not to mention slashes. - - doneFileName = doneFileName.replace('?', '_') - .replace('&', '_').replace('/', '_').replace('\\', '_').replace(':', '_'); - - File doneFile = - new File(markerDirectory, "." + doneFileName + ".DONE"); - + + doneFileName = doneFileName.replace('?', '_').replace('&', '_').replace('/', '_').replace('\\', '_') + .replace(':', '_'); + + File doneFile = new File(markerDirectory, "." + doneFileName + ".DONE"); + long timestamp = 0; if ("file".equals(wsdlURI.getScheme())) { timestamp = new File(wsdlURI).lastModified(); @@ -328,10 +305,10 @@ try { timestamp = wsdlURI.toURL().openConnection().getDate(); } catch (Exception e) { - //ignore + // ignore } } - + boolean doWork = false; if (!doneFile.exists()) { doWork = true; @@ -389,7 +366,7 @@ } } - // -d specify the dir for generated source code + // -d specify the dir for generated source code list.add("-d"); list.add(outputDirFile.toString()); @@ -438,7 +415,7 @@ list.add("-dns"); list.add(wsdlOption.getDefaultNamespacePackageMapping().toString()); } - if (wsdlOption.getServiceName() != null) { + if (wsdlOption.getServiceName() != null) { list.add("-sn"); list.add(wsdlOption.getServiceName()); } @@ -454,7 +431,7 @@ Object value = it.next(); if (value == null) { value = ""; // Maven makes empty tags into null - // instead of empty strings. + // instead of empty strings. } list.add(value.toString()); } @@ -467,7 +444,7 @@ list.add("-wsdlList"); } if (getLog().isDebugEnabled() && !list.contains("-verbose")) { - list.add("-verbose"); + list.add("-verbose"); } list.add(wsdlURI.toString()); return list;
