Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the destination folder of wsdl2java configurable #1089

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-cxf.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ endif::add-copy-button-to-env-var[]
|


a|icon:lock[title=Fixed at build time] [[quarkus-cxf_quarkus.cxf.codegen.wsdl2java.output-directory]]`link:#quarkus-cxf_quarkus.cxf.codegen.wsdl2java.output-directory[quarkus.cxf.codegen.wsdl2java.output-directory]`


[.description]
--
A directory into which the generated files will be written, either absolute or relative to the current Maven or Gradle module directory.

The default value is build tool dependent: for Maven, it is typically `target/generated-sources/wsdl2java`, while for Gradle it is `build/classes/java/quarkus-generated-sources/wsdl2java`.

Quarkus tooling is only able to set up the default value as a source folder for the given build tool. If you set this to a custom path it is up to you to make sure that your build tool recognizes the path a as source folder.

Also, if you choose a path outside `target` directory for Maven or outside `build` directory for Gradle, you need to take care for cleaning stale resources generated by previous builds. E.g. if you change the value of `package-names` option from `org.foo` to `org.bar` you need to take care for the removal of the removal of the old package `org.foo`.

This will be passed as option `-d` to `wsdl2java`

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_CXF_CODEGEN_WSDL2JAVA_OUTPUT_DIRECTORY+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_CXF_CODEGEN_WSDL2JAVA_OUTPUT_DIRECTORY+++`
endif::add-copy-button-to-env-var[]
--|string
|


a|icon:lock[title=Fixed at build time] [[quarkus-cxf_quarkus.cxf.codegen.wsdl2java.package-names]]`link:#quarkus-cxf_quarkus.cxf.codegen.wsdl2java.package-names[quarkus.cxf.codegen.wsdl2java.package-names]`


Expand Down Expand Up @@ -554,6 +579,31 @@ endif::add-copy-button-to-env-var[]
|


a|icon:lock[title=Fixed at build time] [[quarkus-cxf_quarkus.cxf.codegen.wsdl2java.-named-parameter-sets-.output-directory]]`link:#quarkus-cxf_quarkus.cxf.codegen.wsdl2java.-named-parameter-sets-.output-directory[quarkus.cxf.codegen.wsdl2java."named-parameter-sets".output-directory]`


[.description]
--
A directory into which the generated files will be written, either absolute or relative to the current Maven or Gradle module directory.

The default value is build tool dependent: for Maven, it is typically `target/generated-sources/wsdl2java`, while for Gradle it is `build/classes/java/quarkus-generated-sources/wsdl2java`.

Quarkus tooling is only able to set up the default value as a source folder for the given build tool. If you set this to a custom path it is up to you to make sure that your build tool recognizes the path a as source folder.

Also, if you choose a path outside `target` directory for Maven or outside `build` directory for Gradle, you need to take care for cleaning stale resources generated by previous builds. E.g. if you change the value of `package-names` option from `org.foo` to `org.bar` you need to take care for the removal of the removal of the old package `org.foo`.

This will be passed as option `-d` to `wsdl2java`

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_CXF_CODEGEN_WSDL2JAVA__NAMED_PARAMETER_SETS__OUTPUT_DIRECTORY+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_CXF_CODEGEN_WSDL2JAVA__NAMED_PARAMETER_SETS__OUTPUT_DIRECTORY+++`
endif::add-copy-button-to-env-var[]
--|string
|


a|icon:lock[title=Fixed at build time] [[quarkus-cxf_quarkus.cxf.codegen.wsdl2java.-named-parameter-sets-.package-names]]`link:#quarkus-cxf_quarkus.cxf.codegen.wsdl2java.-named-parameter-sets-.package-names[quarkus.cxf.codegen.wsdl2java."named-parameter-sets".package-names]`


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ public interface Wsdl2JavaParameterSet {
*/
public Optional<List<String>> excludes();

/**
* A directory into which the generated files will be written, either absolute or relative to the current Maven
* or Gradle module directory.
* <p>
* The default value is build tool dependent: for Maven, it is typically
* {@code target/generated-sources/wsdl2java}, while for Gradle it is
* {@code build/classes/java/quarkus-generated-sources/wsdl2java}.
* <p>
* Quarkus tooling is only able to set up the default value as a source folder for the given build tool.
* If you set this to a custom path it is up to you to make sure that your build tool recognizes the path
* a as source folder.
* <p>
* Also, if you choose a path outside {@code target} directory for Maven or outside
* {@code build} directory for Gradle, you need to take care for cleaning stale resources generated by previous
* builds. E.g. if you change the value of {@code package-names} option from {@code org.foo} to {@code org.bar}
* you need to take care for the removal of the removal of the old package {@code org.foo}.
* <p>
* This will be passed as option {@code -d} to {@code wsdl2java}
*
* @since 2.6.0
*/
public Optional<String> outputDirectory();

/**
* A comma separated list of tokens; each token can be one of the following:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {

// TODO once https://github.com/quarkusio/quarkus/pull/35963 reaches us we can replace the above with
// final Wsdl2JavaConfig config = context.config().getValue("quarkus.cxf", CxfBuildTimeConfig.class)
// .codegen().wsdl2java();
// .codegen().wsdl2java();

if (!config.enabled()) {
log.info("Skipping " + this.getClass() + " invocation on user's request");
Expand Down Expand Up @@ -122,14 +122,13 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
}
}

static boolean wsdl2java(Path projectDir, Path inputDir, Wsdl2JavaParameterSet params, Path outDir, String prefix,
static boolean wsdl2java(Path projectDir, Path inputDir, Wsdl2JavaParameterSet params, Path defaultOutDir, String prefix,
Map<String, String> processedFiles) {

return scan(inputDir, params.includes(), params.excludes(), prefix, processedFiles, (Path wsdlFile) -> {
final Wsdl2JavaParams wsdl2JavaParams = new Wsdl2JavaParams(
projectDir,
inputDir, outDir, wsdlFile,
params);
defaultOutDir, wsdlFile, params);
if (log.isInfoEnabled()) {
log.info(wsdl2JavaParams.appendLog(new StringBuilder("Running wsdl2java")).toString());
}
Expand Down Expand Up @@ -199,16 +198,14 @@ static Path absModuleRoot(final Path inputDir) {

static class Wsdl2JavaParams {
private final Path projectDir;
private final Path inputDir;
private final Path outDir;
private final Path defaultOutDir;
private final Path wsdlFile;
private final Wsdl2JavaParameterSet params;

public Wsdl2JavaParams(Path projectDir, Path inputDir, Path outDir, Path wsdlFile, Wsdl2JavaParameterSet params) {
public Wsdl2JavaParams(Path projectDir, Path defaultOutDir, Path wsdlFile, Wsdl2JavaParameterSet params) {
super();
this.projectDir = projectDir;
this.inputDir = inputDir;
this.outDir = outDir;
this.defaultOutDir = defaultOutDir;
this.wsdlFile = wsdlFile;
this.params = params;
}
Expand Down Expand Up @@ -237,8 +234,8 @@ static List<String> absolutizeBindings(Path projectDir, List<String> additionalP
}

public StringBuilder appendLog(StringBuilder sb) {
// final Path moduleRoot = absModuleRoot(inputDir);
// render(path -> moduleRoot.relativize(path).toString(), value -> sb.append(' ').append(value));
// final Path moduleRoot = absModuleRoot(inputDir);
// render(path -> moduleRoot.relativize(path).toString(), value -> sb.append(' ').append(value));
render(Path::toString, value -> sb.append(' ').append(value));
return sb;
}
Expand All @@ -251,7 +248,12 @@ public String[] toParameterArray() {

void render(Function<Path, String> pathTransformer, Consumer<String> paramConsumer) {
paramConsumer.accept("-d");
paramConsumer.accept(pathTransformer.apply(outDir));
final Optional<String> outputDirectory = params.outputDirectory();
paramConsumer.accept(
pathTransformer.apply(
outputDirectory.isEmpty()
? defaultOutDir
: projectDir.resolve(outputDirectory.get())));

Stream.of(Wsdl2JavaParameterSet.class.getDeclaredMethods())
.sorted(Comparator.comparing(Method::getName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Wsdl2JavaParamsTest {
void wsdl2JavaParamsNone() {
assertParams(
proxy(
"outputDirectory", Optional.empty(),
"packageNames", Optional.empty(),
"serviceName", Optional.empty(),
"bindings", Optional.empty(),
Expand All @@ -43,6 +44,7 @@ void wsdl2JavaParamsNone() {
void wsdl2JavaParams() {
assertParams(
proxy(
"outputDirectory", Optional.of("foo/bar"),
"packageNames", Optional.of(Arrays.asList("com.foo", "com.bar")),
"serviceName", Optional.of("HelloService"),
"bindings", Optional.of(Arrays.asList("src/main/resources/b1.xml", "src/main/resources/b2.xml")),
Expand All @@ -55,7 +57,7 @@ void wsdl2JavaParams() {
"bareMethods", Optional.of(Arrays.asList("bare1", "bare2")),
"mimeMethods", Optional.of(Arrays.asList("mime1", "mime2")),
"additionalParams", Optional.of(Arrays.asList("-keep", "-dex", "true"))),
"-d", "/path/to/project/target/classes",
"-d", "/path/to/project/foo/bar",
"-asyncMethods", "hello,goodBye",
"-bareMethods", "bare1,bare2",
"-b", "/path/to/project/src/main/resources/b1.xml",
Expand Down Expand Up @@ -97,12 +99,10 @@ void assertParams(Wsdl2JavaParameterSet params, String... expectedParams) {

Path projectDir = Paths.get("/path/to/project");
Path wsdlFile = projectDir.resolve("src/main/resources/my.wsdl");
Path inputDir = projectDir.resolve("src/main/resources");
Path outDir = projectDir.resolve("target/classes");
final Wsdl2JavaParams wsdl2JavaParams = new Wsdl2JavaParams(
projectDir,
inputDir, outDir, wsdlFile,
params);
outDir, wsdlFile, params);
Assertions.assertThat(wsdl2JavaParams.toParameterArray()).containsExactly(expectedParams);

}
Expand Down
18 changes: 18 additions & 0 deletions integration-tests/wsdl2java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-test-sources/wsdl2java-custom</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
quarkus.cxf.codegen.wsdl2java.includes = **.wsdl
quarkus.cxf.codegen.wsdl2java.output-directory = target/generated-test-sources/wsdl2java-custom
quarkus.cxf.codegen.wsdl2java.wsdl-location = classpath:wsdl/CalculatorService.wsdl
quarkus.cxf.codegen.wsdl2java.xjc = bg,dv,javadoc,property-listener,ts,wsdlextension
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void codegenTests() throws IOException {

/* Make sure that the java files were generated */
final Path calculatorService_Service = Paths.get(
"target/generated-test-sources/wsdl2java/org/jboss/eap/quickstarts/wscalculator/calculator/CalculatorService_Service.java");
"target/generated-test-sources/wsdl2java-custom/org/jboss/eap/quickstarts/wscalculator/calculator/CalculatorService_Service.java");
Assertions.assertThat(calculatorService_Service)
.isRegularFile()
.content(StandardCharsets.UTF_8).contains("wsdlLocation = \"classpath:wsdl/CalculatorService.wsdl\"");
Expand Down Expand Up @@ -77,7 +77,7 @@ void defaultGenerated() {
void javadocGenerated() {
/* Make sure that the java files were generated */
final Path calculatorService_Service = Paths.get(
"target/generated-test-sources/wsdl2java/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
"target/generated-test-sources/wsdl2java-custom/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
Assertions.assertThat(calculatorService_Service)
.isRegularFile()
.content(StandardCharsets.UTF_8).contains("This text should appear in JavaDoc of result");
Expand All @@ -87,7 +87,7 @@ void javadocGenerated() {
void getBooleanGenerated() {
/* Make sure that the java files were generated */
final Path calculatorService_Service = Paths.get(
"target/generated-test-sources/wsdl2java/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
"target/generated-test-sources/wsdl2java-custom/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
Assertions.assertThat(calculatorService_Service)
.isRegularFile()
.content(StandardCharsets.UTF_8).contains("public boolean getEven() {");
Expand All @@ -97,7 +97,7 @@ void getBooleanGenerated() {
void extensibilityElementGenerated() {
/* Make sure that the java files were generated */
final Path calculatorService_Service = Paths.get(
"target/generated-test-sources/wsdl2java/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
"target/generated-test-sources/wsdl2java-custom/org/jboss/eap/quickstarts/wscalculator/calculator/Result.java");
Assertions.assertThat(calculatorService_Service)
.isRegularFile()
.content(StandardCharsets.UTF_8).contains("implements ExtensibilityElement");
Expand Down