diff --git a/maven-plugins/codegen-plugin/src/it/README.md b/maven-plugins/codegen-plugin/src/it/README.md index f42b1694748..6f741582dbc 100644 --- a/maven-plugins/codegen-plugin/src/it/README.md +++ b/maven-plugins/codegen-plugin/src/it/README.md @@ -15,3 +15,9 @@ wsdl-artifact-resolution ------------------------ Verifies that a wsdlArtifact from local repository is properly resolved for codegen. + +wsdl-classpath-resolution +------------------------ + +Verifies that using wsdlRoot with "classpath;" will generate Java classes with valid classpath +URLs instead of the local file URL. \ No newline at end of file diff --git a/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/Cxf5052Service-1.0.0.wsdl b/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/Cxf5052Service-1.0.0.wsdl new file mode 100644 index 00000000000..327cafcff46 --- /dev/null +++ b/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/Cxf5052Service-1.0.0.wsdl @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/pom.xml b/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/pom.xml new file mode 100644 index 00000000000..825c288153d --- /dev/null +++ b/maven-plugins/codegen-plugin/src/it/wsdl-classpath-resolution/pom.xml @@ -0,0 +1,69 @@ + + 4.0.0 + + org.apache.cxf + cxf5052-codegen + 1.0.0-SNAPSHOT + jar + cxf5052-codegen + + + org.apache.cxf.cxf5052 + Cxf5052Service + 1.0.0 + + + + + + maven-install-plugin + 2.5.2 + + + initialize + + install-file + + + ${wsdl.groupid} + ${wsdl.artifactid} + ${wsdl.version} + wsdl + Cxf5052Service-1.0.0.wsdl + + + + + + org.apache.cxf + cxf-codegen-plugin + 3.2.3-SNAPSHOT + + + generate-sources + generate-sources + + ${basedir} + + **/*.wsdl + + + + -impl + -server + -client + -verbose + -validate + + classpath;${basedir} + + + + wsdl2java + + + + + + + diff --git a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WsdlOption.java b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WsdlOption.java index ec8646484d0..437e459ac4a 100644 --- a/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WsdlOption.java +++ b/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WsdlOption.java @@ -263,4 +263,35 @@ public String getUri() { public void setUri(String uri) { wsdl = uri; } + + /** + * Calls {@link Option#merge(Option)} and checks afterwards, if a classpath + * replacement string has been set as default option.
+ *
+ * A classpath replacement string in the format + * "classpath;/path/to/replace/" will be processed to replace the local + * file-Url of the WSDL-files with the classpath URL.
+ *
+ * Example: "file:/path/to/package1/package2/myservice.wsdl" will be converted + * to "classpath:/package1/package2/myservice.wsdl", if "classpath;/path/to/" + * has been set
+ * + * @see org.apache.cxf.maven_plugin.wsdl2java.Option#merge(org.apache.cxf.maven_plugin.wsdl2java.Option) + */ + @Override + public void merge(Option defaultOptions) { + super.merge(defaultOptions); + if (!isSetWsdlLocation() && defaultOptions.isSetWsdlLocation()) { + String defaultWsdlLocation = defaultOptions.getWsdlLocation(); + if (defaultWsdlLocation != null && defaultWsdlLocation.startsWith("classpath;")) { + try { + String[] replacer = defaultWsdlLocation.split(";"); + String filePath = new File(replacer[1]).toURI().toURL().toExternalForm(); + this.wsdlLocation = this.getWsdl().replace(filePath, "classpath:/"); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } }