You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/12/03 23:01:50 UTC
svn commit: r886939 - in /cxf/branches/2.2.x-fixes: ./
maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/
Author: dkulp
Date: Thu Dec 3 22:01:49 2009
New Revision: 886939
URL: http://svn.apache.org/viewvc?rev=886939&view=rev
Log:
Merged revisions 882468 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r882468 | cschneider | 2009-11-20 04:44:22 -0500 (Fri, 20 Nov 2009) | 1 line
Refactoring and documentation
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
Propchange: cxf/branches/2.2.x-fixes/
('svn:mergeinfo' removed)
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.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.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java?rev=886939&r1=886938&r2=886939&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WSDL2JavaMojo.java Thu Dec 3 22:01:49 2009
@@ -193,29 +193,6 @@
private ArtifactResolver artifactResolver;
/**
- * 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)) {
- if (o.getOutputDir() == null) {
- o.setOutputDir(output);
- }
- if (!options.contains(o)) {
- options.add(o);
- }
- }
- return options;
- }
-
- /**
* Try to find a file matching the given wsdlPath (either absolutely, relatively to the current dir or to
* the project base dir)
*
@@ -287,10 +264,14 @@
throws MojoExecutionException {
List<WsdlOption> effectiveWsdlOptions = new ArrayList<WsdlOption>();
if (wsdlRoot != null && wsdlRoot.exists() && !disableDirectoryScan) {
- effectiveWsdlOptions.addAll(getWsdlOptionsFromDir(wsdlRoot, sourceRoot));
+ effectiveWsdlOptions.addAll(WsdlOptionLoader.loadWsdlOptionsFromFiles(wsdlRoot, includes,
+ excludes, defaultOptions,
+ sourceRoot));
}
if (testWsdlRoot != null && testWsdlRoot.exists() && !disableDirectoryScan) {
- effectiveWsdlOptions.addAll(getWsdlOptionsFromDir(testWsdlRoot, testSourceRoot));
+ effectiveWsdlOptions.addAll(WsdlOptionLoader.loadWsdlOptionsFromFiles(testWsdlRoot, includes,
+ excludes, defaultOptions,
+ testSourceRoot));
}
mergeOptions(effectiveWsdlOptions);
downloadRemoteWsdls(effectiveWsdlOptions);
@@ -298,7 +279,7 @@
}
@SuppressWarnings("unchecked")
- public Artifact resolveRemoteWsdlArtifact(List remoteRepos, Artifact artifact)
+ private Artifact resolveRemoteWsdlArtifact(List remoteRepos, Artifact artifact)
throws MojoExecutionException {
/**
@@ -333,7 +314,7 @@
return artifact;
}
- public void downloadRemoteWsdls(List<WsdlOption> effectiveWsdlOptions) throws MojoExecutionException {
+ private void downloadRemoteWsdls(List<WsdlOption> effectiveWsdlOptions) throws MojoExecutionException {
List remoteRepos;
try {
remoteRepos = ProjectUtils.buildArtifactRepositories(repositories, artifactRepositoryFactory,
Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java?rev=886939&r1=886938&r2=886939&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlArtifact.java Thu Dec 3 22:01:49 2009
@@ -19,6 +19,9 @@
package org.apache.cxf.maven_plugin;
+/**
+ * Represents a wsdl file that is stored in a maven repository
+ */
public class WsdlArtifact {
private String groupId;
private String artifactId;
Modified: cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java?rev=886939&r1=886938&r2=886939&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java (original)
+++ cxf/branches/2.2.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/WsdlOptionLoader.java Thu Dec 3 22:01:49 2009
@@ -32,9 +32,47 @@
public final class WsdlOptionLoader {
private static final String WSDL_OPTIONS = "-options$";
private static final String WSDL_BINDINGS = "-binding-?\\d*.xml$";
-
- private String getIncludeExcludeString(String[] arr) {
+ private WsdlOptionLoader() {
+ }
+
+ /**
+ * Scan files in a directory and generate one wsdlOption per file found. Extra args for code generation
+ * can be defined in a file that is named like the wsdl file and ends in -options. Binding files can be
+ * defined in files named like the wsdl file and end in -binding-*.xml
+ *
+ * @param wsdlBasedir
+ * @param includes file name patterns to include
+ * @param excludes file name patterns to exclude
+ * @param defaultOptions options that should be used if no special file is given
+ * @return list of one WsdlOption object for each wsdl found
+ * @throws MojoExecutionException
+ */
+ public static List<WsdlOption> loadWsdlOptionsFromFiles(File wsdlBasedir, String includes[],
+ String excludes[], Option defaultOptions,
+ File defaultOutputDir)
+ throws MojoExecutionException {
+
+ if (wsdlBasedir == null) {
+ return new ArrayList<WsdlOption>();
+ }
+
+ if (!wsdlBasedir.exists()) {
+ throw new MojoExecutionException(wsdlBasedir + " does not exist");
+ }
+
+ List<File> wsdlFiles = getWsdlFiles(wsdlBasedir, includes, excludes);
+ List<WsdlOption> wsdlOptions = new ArrayList<WsdlOption>();
+ for (File wsdl : wsdlFiles) {
+ WsdlOption wsdlOption = generateWsdlOptionFromFile(wsdl, defaultOptions, defaultOutputDir);
+ if (wsdlOption != null) {
+ wsdlOptions.add(wsdlOption);
+ }
+ }
+ return wsdlOptions;
+ }
+
+ private static String joinWithComma(String[] arr) {
if (arr == null) {
return "";
}
@@ -50,40 +88,19 @@
}
return str.toString();
}
-
- public List<WsdlOption> load(String wsdlRoot) throws MojoExecutionException {
- return load(new File(wsdlRoot), new String[] {"*.wsdl"}, null, null);
- }
- public List<WsdlOption> load(File wsdlBasedir,
- String includes[],
- String excludes[],
- Option defaultOptions)
+ private static List<File> getWsdlFiles(File dir, String includes[], String excludes[])
throws MojoExecutionException {
-
- if (wsdlBasedir == null) {
- return new ArrayList<WsdlOption>();
- }
-
- if (!wsdlBasedir.exists()) {
- throw new MojoExecutionException(wsdlBasedir + " does not exist");
- }
- return findJobs(wsdlBasedir, getWsdlFiles(wsdlBasedir, includes, excludes), defaultOptions);
- }
-
- private List<File> getWsdlFiles(File dir, String includes[], String excludes[])
- 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()]));
-
+
+ String inc = joinWithComma(includes);
+ String ex = joinWithComma(exList.toArray(new String[exList.size()]));
+
try {
List newfiles = org.codehaus.plexus.util.FileUtils.getFiles(dir, inc, ex);
return CastUtils.cast(newfiles);
@@ -92,69 +109,68 @@
}
}
- private File getOptions(File dir, String pattern) {
- List<File> files = FileUtils.getFiles(dir, pattern);
- if (files.size() > 0) {
- return files.iterator().next();
+ private static String[] readOptionsFromFile(File dir, String wsdlName) throws MojoExecutionException {
+ String[] noOptions = new String[] {};
+ List<File> files = FileUtils.getFiles(dir, wsdlName + WSDL_OPTIONS);
+ if (files.size() <= 0) {
+ return noOptions;
+ }
+ File optionsFile = files.iterator().next();
+ if (optionsFile == null || !optionsFile.exists()) {
+ return noOptions;
+ }
+ try {
+ List<String> lines = FileUtils.readLines(optionsFile);
+ if (lines.size() <= 0) {
+ return noOptions;
+ }
+ return lines.iterator().next().split(" ");
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error reading options from file "
+ + optionsFile.getAbsolutePath(), e);
}
- return null;
- }
-
- private List<File> getBindingFiles(File dir, String pattern) {
- return FileUtils.getFiles(dir, pattern);
}
- protected List<WsdlOption> findJobs(File dir, List<File> wsdlFiles, Option defaultOptions) {
- List<WsdlOption> jobs = new ArrayList<WsdlOption>();
+ protected static WsdlOption generateWsdlOptionFromFile(final File wsdl, final Option defaultOptions,
+ File defaultOutputDir)
+ throws MojoExecutionException {
- for (File wsdl : wsdlFiles) {
- if (wsdl == null || !wsdl.exists()) {
- continue;
- }
+ if (wsdl == null || !wsdl.exists()) {
+ return null;
+ }
- String wsdlName = wsdl.getName();
- int idx = wsdlName.toLowerCase().lastIndexOf(".wsdl");
- if (idx == -1) {
- idx = wsdlName.lastIndexOf('.');
- }
- if (idx != -1) {
- wsdlName = wsdlName.substring(0, idx);
- File options = getOptions(dir, wsdlName + WSDL_OPTIONS);
- List<File> bindings = getBindingFiles(dir, wsdlName + WSDL_BINDINGS);
-
- jobs.add(generateWsdlOption(wsdl, bindings, options, defaultOptions));
- }
+ final String wsdlFileName = wsdl.getName();
+ int idx = wsdlFileName.toLowerCase().lastIndexOf(".wsdl");
+ if (idx == -1) {
+ idx = wsdlFileName.lastIndexOf('.');
+ }
+ if (idx == -1) {
+ return null;
}
- return jobs;
- }
- protected WsdlOption generateWsdlOption(final File wsdl,
- final List<File> bindingFiles,
- final File options,
- final Option defaultOptions) {
- WsdlOption wsdlOption = new WsdlOption();
-
- if (options != null && options.exists()) {
- try {
- List<String> lines = FileUtils.readLines(options);
- if (lines.size() > 0) {
- wsdlOption.getExtraargs().addAll(Arrays.asList(lines.iterator().next().split(" ")));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ final WsdlOption wsdlOption = new WsdlOption();
+ final String wsdlName = wsdlFileName.substring(0, idx);
+
+ final String[] options = readOptionsFromFile(wsdl.getParentFile(), wsdlName);
+ if (options.length > 0) {
+ wsdlOption.getExtraargs().addAll(Arrays.asList(options));
} else if (defaultOptions != null) {
// no options specified use the defaults
defaultOptions.copyOptions(wsdlOption);
}
-
+
+ List<File> bindingFiles = FileUtils.getFiles(wsdl.getParentFile(), wsdlName + WSDL_BINDINGS);
if (bindingFiles != null) {
for (File binding : bindingFiles) {
wsdlOption.addBindingFile(binding);
}
}
wsdlOption.setWsdl(wsdl.toURI().toString());
-
+
+ if (wsdlOption.getOutputDir() == null) {
+ wsdlOption.setOutputDir(defaultOutputDir);
+ }
+
return wsdlOption;
}
-}
\ No newline at end of file
+}