├── .gitattributes
├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle.kts
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── integration-test
├── build.gradle.kts
├── buildSrc
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ ├── com.github.bjornvester.wsdl2java.internal.java-conventions-cxf3.gradle.kts
│ │ ├── com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4.gradle.kts
│ │ └── com.github.bjornvester.wsdl2java.internal.java-conventions.gradle.kts
├── cxf3
│ ├── bindings-datetime-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ ├── bindings
│ │ │ │ └── bindings.xml
│ │ │ └── resources
│ │ │ │ └── HelloDateTimeService.wsdl
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── bjornvester
│ │ │ └── wsdl2java
│ │ │ ├── HelloWorldImpl.java
│ │ │ └── HelloWorldTest.java
│ ├── generated-annotation-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ └── resources
│ │ │ │ └── HelloWorldService.wsdl
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── bjornvester
│ │ │ └── wsdl2java
│ │ │ ├── HelloWorldImpl.java
│ │ │ └── MarkGeneratedTest.java
│ └── xjc-plugins-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ ├── main
│ │ └── resources
│ │ │ └── HelloXjcPluginService.wsdl
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── bjornvester
│ │ └── wsdl2java
│ │ ├── HelloWorldImpl.java
│ │ └── HelloWorldTest.java
├── cxf4
│ ├── bindings-datetime-test-jakarta
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ ├── bindings
│ │ │ │ └── bindings.xml
│ │ │ └── resources
│ │ │ │ └── HelloDateTimeService.wsdl
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── bjornvester
│ │ │ └── wsdl2java
│ │ │ ├── HelloWorldImpl.java
│ │ │ └── HelloWorldTest.java
│ ├── filter-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── bjornvester
│ │ │ │ └── wsdl2java
│ │ │ │ ├── HelloWorldAbstractImpl.java
│ │ │ │ └── HelloWorldNestedImpl.java
│ │ │ └── wsdl
│ │ │ ├── HelloWorldAbstractService.wsdl
│ │ │ ├── HelloWorldInvalidService.wsdl
│ │ │ └── nested
│ │ │ └── HelloWorldNestedService.wsdl
│ ├── grouping-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ └── resources
│ │ │ │ ├── HelloWorldAService.wsdl
│ │ │ │ └── HelloWorldBService.wsdl
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── bjornvester
│ │ │ └── wsdl2java
│ │ │ └── GroupingTest.java
│ ├── includes-options-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ └── resources
│ │ │ │ ├── HelloWorldAService.wsdl
│ │ │ │ └── HelloWorldBService.wsdl
│ │ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── bjornvester
│ │ │ └── wsdl2java
│ │ │ └── IncludesWithOptionsTest.java
│ └── utf8-test
│ │ ├── build.gradle.kts
│ │ └── src
│ │ ├── main
│ │ └── resources
│ │ │ └── HelloUtf8ÆØÅService.wsdl
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── bjornvester
│ │ └── wsdl2java
│ │ ├── HelloWorldImpl.java
│ │ └── HelloWorldTest.java
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
├── settings.gradle.kts
└── src
├── main
└── kotlin
│ └── com
│ └── github
│ └── bjornvester
│ └── wsdl2java
│ ├── Wsdl2JavaPlugin.kt
│ ├── Wsdl2JavaPluginExtension.kt
│ ├── Wsdl2JavaPluginExtensionGroup.kt
│ ├── Wsdl2JavaTask.kt
│ ├── Wsdl2JavaWorker.kt
│ └── Wsdl2JavaWorkerParams.kt
└── test
└── kotlin
└── com
└── github
└── bjornvester
└── IntegrationTest.kt
/.gitattributes:
--------------------------------------------------------------------------------
1 | text eol=lf
2 | *.bat eol=crlf
3 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - name: Checkout the repository
11 | uses: actions/checkout@v3 # https://github.com/actions/checkout
12 | - name: Validate the Gradle wrapper
13 | uses: gradle/wrapper-validation-action@v1 # https://github.com/gradle/wrapper-validation-action
14 | - name: Set up JDK 17
15 | uses: actions/setup-java@v3 # https://github.com/actions/setup-java
16 | with:
17 | distribution: temurin
18 | java-version: 17
19 | - name: Set encoding and print version information
20 | run: |
21 | export LANG=C.UTF-8
22 | locale
23 | ./gradlew --version
24 | - name: Build with Gradle (this action caches various parts as well)
25 | uses: gradle/gradle-build-action@v2 # https://github.com/gradle/gradle-build-action
26 | with:
27 | arguments: check
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | /**/.gradle/
3 | /**/build/
4 | /**/out/
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Bjørn Mølgård Vester
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://plugins.gradle.org/plugin/com.github.bjornvester.xjc)
2 | [](https://github.com/bjornvester/wsdl2java-gradle-plugin/actions)
3 |
4 | # wsdl2java-gradle-plugin
5 |
6 | A Gradle plugin for generating Java classes from WSDL files through CXF.
7 |
8 | ## Requirements and main features
9 |
10 | * The plugin requires Gradle 7.6 or later. (Tested with Gradle 7 and 8.)
11 | * For using the Jakarta namespace (default), the plugin requires Java 17 or greater. For the older javax namespace, you can use Java 8, 11 or 17.
12 | * It supports the Gradle build cache (enabled by setting `org.gradle.caching=true` in your gradle.properties file).
13 | * It supports the Gradle configuration cache (enabled by setting `org.gradle.configuration-cache=true` in your gradle.properties file").
14 | * It supports project relocation for the build cache (e.g. you move your project to a new path, or make a new copy/clone of it).
15 | This is especially useful in a CI context, where you might clone PRs and/or branches for a repository in their own locations.
16 | Note, however, that there is an issue in an Apache library called `org.apache.ws.xmlschema:xmlschema-core` that might break this - see below for details.
17 | * It supports parallel execution (enabled with `org.gradle.parallel=true` in your gradle.properties file), though it does not itself run anything in parallel.
18 |
19 | ## Configuration
20 |
21 | Apply the plugin ID "com.github.bjornvester.wsdl2java" as specific in the [Gradle Plugin portal page](https://plugins.gradle.org/plugin/com.github.bjornvester.wsdl2java), e.g. like this:
22 |
23 | ```kotlin
24 | plugins {
25 | id("com.github.bjornvester.wsdl2java") version "2.0.2"
26 | }
27 | ```
28 |
29 | Put your WSDL and referenced XSD files somewhere in your src/main/resource directory.
30 | By default, the plugin will create Java classes for all the WSDL files in the resource directory.
31 |
32 | The generated code will by default end up in the directory build/generated/sources/wsdl2java folder.
33 |
34 | You can configure the plugin using the "wsdl2java" extension like this:
35 |
36 | ```kotlin
37 | wsdl2java {
38 | // Set properties here...
39 | }
40 | ```
41 |
42 | Here is a list of all available properties:
43 |
44 | | Property | Type | Default | Description |
45 | |----------------------------|-----------------------|--------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
46 | | wsdlDir | DirectoryProperty | "$projectDir/src
/main/resources" | The directory holding the WSDL and referenced XSD files to compile. |
47 | | includes | ListProperty\ | \["**/*.wsdl"] | Inclusion filers (Ant style) for which WSDLs to include. |
48 | | includesWithOptions | Map\ | \[not set\] | Inclusion filters like above, but with individual options. See below. |
49 | | generatedSourceDir | DirectoryProperty | "$buildDir/generated
/sources/wsdl2java/java" | The output directory for the generated Java sources.
Note that it will be deleted when running XJC. |
50 | | bindingFile | RegularFileProperty | \[not set\] | A binding file to use in the schema compiler. |
51 | | useJakarta | Provider\ | true | Set to use the `jakarta` namespace. If false, uses the `javax` namespace. This value also determines the default version of CXF. |
52 | | cxfVersion | Provider\ | "4.0.2" for jakarta / 3.5.6 for javax | The version of CXF to use. Use a version >= 4 for `jakarta` and below for `javax`. |
53 | | verbose | Provider\ | \[not set\] | Enables verbose output from CXF. If not set, it will be be enabled only on the info logging level. |
54 | | markGenerated | Provider\ | "no" | Adds the @Generated annotation to the generated sources. See below for details as there are some gotchas with this. |
55 | | generatedStyle | Provider\ | "default" | If using the @Generated annotation, select the type can be overridden by this. See below for details. |
56 | | suppressGeneratedDate | Provider\ | true | Suppresses generating dates in CXF. Default is true to support reproducible builds and to work with the build cache. |
57 | | packageName | Provider\ | \[not set\] | Sets the package name for the generated sources |
58 | | options | ListProperty\ | \[empty\] | Additional options to pass to the tool. See [here](https://cxf.apache.org/docs/wsdl-to-java.html) for details. |
59 | | addCompilationDependencies | Provider\ | true | Adds dependencies to the `implementation` configuration for compiling the generated sources. These includes `jakarta.xml.ws:jakarta.xml.ws-api`, `jakarta.jws:jakarta.jws-api` and possibly `jakarta.annotation:jakarta.annotation-api`. |
60 |
61 | ### Configure the CXF version
62 |
63 | You can specify the version of CXF used for code generation like this:
64 |
65 | ```kotlin
66 | wsdl2java {
67 | cxfVersion.set("4.0.2")
68 | }
69 | ```
70 |
71 | ### Configure included WSDL files
72 |
73 | By default, the plugin will find all WSDL files in the `wsdlDir` directory, which defaults to `src/main/resources`.
74 | It is important that if you change this, you change it to a folder that contain all resources (e.g. both WSDL and XSDs).
75 | Otherwise, if you make changes to files outside this folder, Gradle will not see them and thus might consider the task
76 | up-to-date.
77 |
78 | The plugin will set the `wsdlLocation` property of the `@WebServiceClient` to the path for the WSDL file relative to
79 | the `wsdlDir` directory.
80 | If you change `wsdlDir` in a way where this no longer makes sense, you need to set the option yourself.
81 | If you have multiple WSDL files, see the section on additional options.
82 |
83 | If you have multiple WSDL files and want to only run the tool on some of them, you can use the `includes` property.
84 | Example:
85 |
86 | ```kotlin
87 | // Only if different from the default 'src/main/resources'
88 | wsdlDir.set(layout.projectDirectory.dir("src/main/wsdl"))
89 |
90 | // For Kotlin DSL
91 | includes.set(
92 | listOf(
93 | "src/main/wsdls/MyFirstService.wsdl",
94 | "src/main/wsdls/MySecondService.wsdl"
95 | )
96 | )
97 | ```
98 |
99 | ```groovy
100 | // For Groovy DSL
101 | includes = [
102 | "src/main/wsdls/MyFirstService.wsdl",
103 | "src/main/wsdls/MySecondService.wsdl"
104 | ]
105 | ```
106 |
107 | ### Configure additional options
108 |
109 | Besides the options given in the `wsdl2java` extension, you can provide additional options directly to CXF (and XJC)
110 | through the `options` property:
111 |
112 | ```kotlin
113 | // For Kotlin DSL
114 | includes.set(
115 | listOf(
116 | "xjc-no-header",
117 | "xjc-npa"
118 | )
119 | )
120 |
121 | // For Groovy DSL
122 | includes = [
123 | "xjc-no-header",
124 | "xjc-npa"
125 | ]
126 | ```
127 |
128 | See [here](https://cxf.apache.org/docs/wsdl-to-java.html) for the available options.
129 |
130 | #### Configure additional options for individual WSDL files
131 |
132 | It is possible to pass options for individual WSDL files.
133 | This is important especially if you need to explicitly configure the `wsdlLocation` option, as it doesn't make to have
134 | the same location in all files.
135 | (But note that if you leave it out, the plugin will guess it based on the file location.)
136 |
137 | ```kotlin
138 | // For Kotlin DSL
139 | includesWithOptions.set(
140 | mapOf(
141 | "**/ServiceA.wsdl" to listOf("-wsdlLocation", "https://example.com/service-a?wsdl"),
142 | "**/ServiceB.wsdl" to listOf("-wsdlLocation", "https://example.com/service-b?wsdl")
143 | )
144 | )
145 | ```
146 |
147 | ```groovy
148 | // For Groovy DSL
149 | includes = [
150 | "**/ServiceA.wsdl": ["-wsdlLocation", "https://example.com/service-a?wsdl"],
151 | "**/ServiceB.wsdl": ["-wsdlLocation", "https://example.com/service-b?wsdl"]
152 | ]
153 | ```
154 |
155 | ### Configure the output directory
156 |
157 | You can optionally specify the directory for the generated source through the `generatedSourceDir` property, which
158 | defaults to `$buildDir/generated/sources/wsdl2java/java`.
159 | Example:
160 |
161 | ```kotlin
162 | wsdl2java {
163 | generatedSourceDir.set(layout.projectDirectory.dir("src/generated/wsdl2java"))
164 | }
165 | ```
166 |
167 | Note that the directory will be wiped completely on each run, so don't put other source files in it.
168 |
169 | ### Configure binding files
170 |
171 | A binding file can be added like this:
172 |
173 | ```kotlin
174 | wsdl2java {
175 | bindingFile.set(layout.projectDirectory.file("src/main/bindings/binding.xjb"))
176 | }
177 | ```
178 |
179 | If you get a warning on maximum enum member size, you can raise the maximum like this:
180 |
181 | ```xml
182 |
183 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | ```
193 |
194 | If you are using the older `javax` namespace instead of `jakarta`, set the `jxb` attribute to `http://java.sun.com/xml/ns/jaxb` instead and the version to 2.1.
195 |
196 | If you like to use the Java Date/Time API instead of the more clunky GregorianCalendar class, you can
197 | use [threeten-jaxb](https://github.com/threeten-jaxb/threeten-jaxb) library with a binding file like example below.
198 |
199 | ```kotlin
200 | dependencies {
201 | implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0")
202 | }
203 |
204 | wsdl2java {
205 | bindingFile.set(layout.projectDirectory.file("src/main/bindings/bindings.xjb"))
206 | }
207 | ```
208 |
209 | ```xml
210 |
211 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 | ```
225 |
226 | In the above, for `javax`, use version 1.2.0 and the binding attributes to `xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1"`.
227 |
228 | Note that at the moment, it is not possible to specify more than one binding file in the extension. If you require this,
229 | use the `-b` option.
230 |
231 | ### Configuring package names
232 |
233 | The package name for the generated resources can be configured with the `packageName` field:
234 |
235 | ```kotlin
236 | wsdl2java {
237 | packageName.set("com.github.bjornvester.wsdl2java.group1")
238 | }
239 |
240 | ```
241 |
242 | ### Configure encoding
243 |
244 | If your WSDL files include non-ANSI characters, you should set the corresponding file encoding in your gradle.properties
245 | file. E.g.:
246 |
247 | ```properties
248 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
249 | ```
250 |
251 | If you are on a POSIX operating system (e.g. Linux), you may in addition to this need to set your operating system
252 | locale to one that supports your encoding.
253 | Otherwise, Java (and therefore also Gradle and CXF) may not be able to create files with names outside of what your
254 | default locale supports.
255 | Especially some Docker images, like the Java ECR images from AWS, are by default set to a locale supporting ASCII only.
256 | If this is the case for you, and you want to use UTF-8, you could export an environment variable like this:
257 |
258 | ```shell script
259 | export LANG=C.UTF-8
260 | ```
261 |
262 | ### Using javax instead of the jakarta namespace
263 |
264 | To use the older javax namespace in the generated files, set the `useJakarta` property to `false.
265 |
266 | ```kotlin
267 | wsdl2java {
268 | useJakarta.set(false)
269 | }
270 | ```
271 |
272 | ### Activating (third party) XJC plugins
273 |
274 | To use third party plugins for the underlying XJC tool, supply the relevant dependencies to the `xjcPlugins`
275 | configuration.
276 | Then set the plugin options through the `options` property.
277 |
278 | For example, to use the "Equals" and "Hashcode" plugin from
279 | the [JAXB2 Basics](https://github.com/highsource/jaxb2-basics) project, configure the following:
280 |
281 | ```kotlin
282 | dependencies {
283 | // For CXF 3 and javax only (does not work with CXF 4 and jakarta):
284 | implementation("org.jvnet.jaxb2_commons:jaxb2-basics-runtime:0.13.1")
285 | xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics:0.13.1")
286 | }
287 |
288 | wsdl2java {
289 | options.addAll("-xjc-Xequals", "-xjc-XhashCode")
290 | }
291 | ```
292 |
293 | Note that the example above is for CXF 3 and the older `javax` namespace.
294 | There is a fork [here](https://github.com/patrodyne/hisrc-basicjaxb) that you may try for CXF 4 and the `jakarta` namespace.
295 |
296 | ### Enabling the use of the @Generated annotation
297 |
298 | CXF (and the underlying XJC tool) can add a `@Generated` annotation to the generated source code.
299 | This is a source annotation useful for marking classes as generated by a tool.
300 | It can also be used by some static code analytic tools to skip these classes.
301 | You can set it by the `markGenerated` configuration:
302 |
303 | ```kotlin
304 | wsdl2java {
305 | markGenerated.set(true)
306 | }
307 | ```
308 |
309 | While very useful in theory, there are some gotchas with this annotation.
310 | One is that it is a source code annotation and thus won't work with tools that work with byte code (like JaCoCo).
311 | Another is that here are actually three `@Generated` annotations.
312 |
313 | * The first is `javax.annotation.Generated` and is available in the JDK up til and including Java 8. It is also included in the `javax.annotation:javax.annotation-api` dependency.
314 | * The second is `javax.annotation.processing.Generated` and is available in the JDK from Java 9.
315 | * the third is `jakarta.annotation.Generated` and is included in the `jakarta.annotation:jakarta.annotation-api` dependency.
316 |
317 | XJC 3 uses the first, and XJC 4+ uses the third.
318 |
319 | Because your tools may only support a particular version of the `@Generated` annotation, you can select which one through the `generatedStyle` configuration.
320 | Supported values are: `default`, `jdk8`, `jdk9` and `jakarta`.
321 | Example:
322 |
323 | ```kotlin
324 | dependencies {
325 | // The dependency below is only needed if using the Java 8 version of @Generated (through "jdk8") on Java 9 or later
326 | implementation("javax.annotation:javax.annotation-api:1.3.2")
327 | }
328 |
329 | wsdl2java {
330 | markGenerated.set("jdk8")
331 | }
332 | ```
333 |
334 | The plugin will also, by default, strip any timestamps from the `@Generated` annotations.
335 | This is to support reproducible builds and the Gradle cache.
336 | This can be disabled by the `suppressGeneratedDate` configuration:
337 |
338 | ```kotlin
339 | wsdl2java {
340 | suppressGeneratedDate.set(false)
341 | }
342 | ```
343 |
344 | ## Groups
345 | If the `includesWithOptions` is not enough, you can also make groups of WSDL files, each having their own extension.
346 | This is done like this:
347 |
348 | ```kotlin
349 | wsdl2java {
350 | groups {
351 | register("group1") {
352 | includes.set(listOf("**/HelloWorldAService.wsdl"))
353 | options.set(listOf("-wsdlLocation", "MyLocationA"))
354 | packageName.set("com.github.bjornvester.wsdl2java.group1")
355 | }
356 | register("group2") {
357 | includes.set(listOf("**/HelloWorldBService.wsdl"))
358 | options.set(listOf("-wsdlLocation", "MyLocationB"))
359 | packageName.set("com.github.bjornvester.wsdl2java.group2")
360 | }
361 | }
362 | }
363 | ```
364 |
365 | In order to avoid generating resources with the same name but different content (for instance like the generated `ObjectFactory` class), you should make sure each group use its own package name.
366 |
367 | ## Other
368 |
369 | The plugin will add the following two dependencies to your `implementation` configuration:
370 |
371 | ```
372 | jakarta.xml.ws:jakarta.xml.ws-api:2.3.3
373 | jakarta.jws:jakarta.jws-api:1.1.1
374 | ```
375 |
376 | These are required to compile the generated code.
377 | However, depending on your runtime platform, you may want to exclude them and instead either put them in the `compileOnly` configuration, or use whatever libraries that are
378 | provided by the platform.
379 |
380 | There are full examples available in the integration-test directory.
381 |
382 | If you need to compile additional XML schemas (xsd files) not directly referenced by the wsdl files, you can use
383 | the [com.github.bjornvester.xjc](https://plugins.gradle.org/plugin/com.github.bjornvester.xjc) plugin in addition.
384 |
385 | ## Limitations
386 |
387 | ### CXF does not check for unique names in generated resources
388 |
389 | The CXF tool will overwrite generated classes from multiple WSDL files if they have the same qualified name.
390 | Especially the `ObjectFactory` class might be overwritten, which is very annoying.
391 |
392 | ### CXF does not generate resources in a deterministic way
393 |
394 | When CXF generates an `ObjectFactory` class, the order of the methods are not deterministic, but depend on the absolute path of the input files.
395 | This may cause misses in the Gradle build cache, which may propagate to downstream projects, resulting in long build times.
396 | See https://issues.apache.org/jira/browse/XMLSCHEMA-65 for more information.
397 |
398 | ## Contributions
399 |
400 | I often feel a bit stretched out in terms of maintaining this and my other projects.
401 | For that reason, I might not respond to issues and PRs very often.
402 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl`
3 | id("java-gradle-plugin")
4 | id("com.gradle.plugin-publish") version "1.2.0"
5 | }
6 |
7 | group = "com.github.bjornvester"
8 | version = "2.0.2"
9 |
10 | repositories {
11 | mavenCentral()
12 | }
13 |
14 | java {
15 | toolchain {
16 | languageVersion.set(JavaLanguageVersion.of(8))
17 | }
18 | }
19 |
20 | // The integration test folder is an input to the unit test in the root project
21 | // Register these files as inputs
22 | tasks.withType().configureEach {
23 | inputs
24 | .files(layout.projectDirectory.dir("integration-test").asFileTree.matching {
25 | exclude("**/build/**")
26 | exclude("**/gradle/**")
27 | })
28 | .withPathSensitivity(PathSensitivity.RELATIVE)
29 | useJUnitPlatform()
30 | systemProperty("GRADLE_ROOT_FOLDER", projectDir.absolutePath)
31 | systemProperty("GRADLE_PLUGIN_VERSION", version)
32 | }
33 |
34 | tasks.withType {
35 | gradleVersion = "latest"
36 | }
37 |
38 | dependencies {
39 | compileOnly("org.apache.cxf:cxf-tools-wsdlto-core:4.0.2")
40 | testImplementation("commons-io:commons-io:2.13.0")
41 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
42 | testImplementation("org.junit.jupiter:junit-jupiter-params")
43 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
44 | }
45 |
46 | gradlePlugin {
47 | website.set("https://github.com/bjornvester/wsdl2java-gradle-plugin")
48 | vcsUrl.set("https://github.com/bjornvester/wsdl2java-gradle-plugin")
49 | plugins {
50 | create("wsdl2JavaPlugin") {
51 | id = "com.github.bjornvester.wsdl2java"
52 | displayName = "Gradle Wsdl2Java plugin"
53 | tags.set(listOf("wsdl2java", "cxf", "wsimport"))
54 | implementationClass = "com.github.bjornvester.wsdl2java.Wsdl2JavaPlugin"
55 | description = "Changes:\n" +
56 | " - Fixed missing task dependency on wsdl2java from sourcesJar"
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
2 | org.gradle.warning.mode=fail
3 | org.gradle.priority=low
4 | org.gradle.parallel=true
5 | org.gradle.caching=true
6 | org.gradle.configuration-cache=true
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bjornvester/wsdl2java-gradle-plugin/45a0e66ac7bfdddb2128ebe13c96da8456e33692/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4 | networkTimeout=10000
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87 |
88 | # Use the maximum available, or set MAX_FD != -1 to use that value.
89 | MAX_FD=maximum
90 |
91 | warn () {
92 | echo "$*"
93 | } >&2
94 |
95 | die () {
96 | echo
97 | echo "$*"
98 | echo
99 | exit 1
100 | } >&2
101 |
102 | # OS specific support (must be 'true' or 'false').
103 | cygwin=false
104 | msys=false
105 | darwin=false
106 | nonstop=false
107 | case "$( uname )" in #(
108 | CYGWIN* ) cygwin=true ;; #(
109 | Darwin* ) darwin=true ;; #(
110 | MSYS* | MINGW* ) msys=true ;; #(
111 | NONSTOP* ) nonstop=true ;;
112 | esac
113 |
114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
115 |
116 |
117 | # Determine the Java command to use to start the JVM.
118 | if [ -n "$JAVA_HOME" ] ; then
119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
120 | # IBM's JDK on AIX uses strange locations for the executables
121 | JAVACMD=$JAVA_HOME/jre/sh/java
122 | else
123 | JAVACMD=$JAVA_HOME/bin/java
124 | fi
125 | if [ ! -x "$JAVACMD" ] ; then
126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
127 |
128 | Please set the JAVA_HOME variable in your environment to match the
129 | location of your Java installation."
130 | fi
131 | else
132 | JAVACMD=java
133 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
134 |
135 | Please set the JAVA_HOME variable in your environment to match the
136 | location of your Java installation."
137 | fi
138 |
139 | # Increase the maximum file descriptors if we can.
140 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
141 | case $MAX_FD in #(
142 | max*)
143 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
144 | # shellcheck disable=SC3045
145 | MAX_FD=$( ulimit -H -n ) ||
146 | warn "Could not query maximum file descriptor limit"
147 | esac
148 | case $MAX_FD in #(
149 | '' | soft) :;; #(
150 | *)
151 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
152 | # shellcheck disable=SC3045
153 | ulimit -n "$MAX_FD" ||
154 | warn "Could not set maximum file descriptor limit to $MAX_FD"
155 | esac
156 | fi
157 |
158 | # Collect all arguments for the java command, stacking in reverse order:
159 | # * args from the command line
160 | # * the main class name
161 | # * -classpath
162 | # * -D...appname settings
163 | # * --module-path (only if needed)
164 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
165 |
166 | # For Cygwin or MSYS, switch paths to Windows format before running java
167 | if "$cygwin" || "$msys" ; then
168 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
169 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
170 |
171 | JAVACMD=$( cygpath --unix "$JAVACMD" )
172 |
173 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
174 | for arg do
175 | if
176 | case $arg in #(
177 | -*) false ;; # don't mess with options #(
178 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
179 | [ -e "$t" ] ;; #(
180 | *) false ;;
181 | esac
182 | then
183 | arg=$( cygpath --path --ignore --mixed "$arg" )
184 | fi
185 | # Roll the args list around exactly as many times as the number of
186 | # args, so each arg winds up back in the position where it started, but
187 | # possibly modified.
188 | #
189 | # NB: a `for` loop captures its iteration list before it begins, so
190 | # changing the positional parameters here affects neither the number of
191 | # iterations, nor the values presented in `arg`.
192 | shift # remove old arg
193 | set -- "$@" "$arg" # push replacement arg
194 | done
195 | fi
196 |
197 |
198 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
199 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
200 |
201 | # Collect all arguments for the java command;
202 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
203 | # shell script including quotes and variable substitutions, so put them in
204 | # double quotes to make sure that they get re-expanded; and
205 | # * put everything else in single quotes, so that it's not re-expanded.
206 |
207 | set -- \
208 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
209 | -classpath "$CLASSPATH" \
210 | org.gradle.wrapper.GradleWrapperMain \
211 | "$@"
212 |
213 | # Stop when "xargs" is not available.
214 | if ! command -v xargs >/dev/null 2>&1
215 | then
216 | die "xargs is not available"
217 | fi
218 |
219 | # Use "xargs" to parse quoted args.
220 | #
221 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
222 | #
223 | # In Bash we could simply go:
224 | #
225 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
226 | # set -- "${ARGS[@]}" "$@"
227 | #
228 | # but POSIX shell has neither arrays nor command substitution, so instead we
229 | # post-process each arg (as a line of input to sed) to backslash-escape any
230 | # character that might be a shell metacharacter, then use eval to reverse
231 | # that process (while maintaining the separation between arguments), and wrap
232 | # the whole thing up as a single "set" statement.
233 | #
234 | # This will of course break if any of these variables contains a newline or
235 | # an unmatched quote.
236 | #
237 |
238 | eval "set -- $(
239 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
240 | xargs -n1 |
241 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
242 | tr '\n' ' '
243 | )" '"$@"'
244 |
245 | exec "$JAVACMD" "$@"
246 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/integration-test/build.gradle.kts:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bjornvester/wsdl2java-gradle-plugin/45a0e66ac7bfdddb2128ebe13c96da8456e33692/integration-test/build.gradle.kts
--------------------------------------------------------------------------------
/integration-test/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | `kotlin-dsl`
3 | }
4 |
5 | repositories {
6 | gradlePluginPortal()
7 | }
8 |
9 | java {
10 | toolchain {
11 | languageVersion.set(JavaLanguageVersion.of(8))
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/integration-test/buildSrc/src/main/kotlin/com.github.bjornvester.wsdl2java.internal.java-conventions-cxf3.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions")
4 | }
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | implementation(platform("org.apache.cxf:cxf-bom:3.5.6"))
12 | }
13 |
14 | java {
15 | toolchain {
16 | languageVersion.set(JavaLanguageVersion.of(8))
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/integration-test/buildSrc/src/main/kotlin/com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions")
4 | }
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | implementation(platform("org.apache.cxf:cxf-bom:4.0.2"))
12 | testRuntimeOnly("jakarta.xml.bind:jakarta.xml.bind-api:3.0.1")
13 | }
14 |
15 | java {
16 | toolchain {
17 | languageVersion.set(JavaLanguageVersion.of(17))
18 | }
19 | }
--------------------------------------------------------------------------------
/integration-test/buildSrc/src/main/kotlin/com.github.bjornvester.wsdl2java.internal.java-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("java")
3 | }
4 |
5 | repositories {
6 | mavenCentral()
7 | }
8 |
9 | // Default dependencies
10 | dependencies {
11 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
12 | testImplementation("org.apache.cxf:cxf-rt-frontend-jaxws")
13 | testImplementation("com.github.tomakehurst:wiremock:2.27.2") // Note that wiremock can't be upgraded to a higher version, nor use the jdk8 variant, as some transitive libraries will not be compatible with this version of CXF
14 |
15 | testRuntimeOnly("org.apache.cxf:cxf-rt-transports-http")
16 | testRuntimeOnly("org.apache.cxf:cxf-rt-transports-http-jetty")
17 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
18 | testRuntimeOnly("org.slf4j:slf4j-simple:1.7.36")
19 | }
20 |
21 | tasks.test {
22 | useJUnitPlatform()
23 | }
24 |
25 | java {
26 | withSourcesJar()
27 | }
28 |
--------------------------------------------------------------------------------
/integration-test/cxf3/bindings-datetime-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf3")
4 | }
5 |
6 | dependencies {
7 | implementation("io.github.threeten-jaxb:threeten-jaxb-core:1.2")
8 | }
9 |
10 | wsdl2java {
11 | bindingFile.set(layout.projectDirectory.file("src/main/bindings/bindings.xml"))
12 | useJakarta.set(false)
13 | }
14 |
--------------------------------------------------------------------------------
/integration-test/cxf3/bindings-datetime-test/src/main/bindings/bindings.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
9 |
10 |
--------------------------------------------------------------------------------
/integration-test/cxf3/bindings-datetime-test/src/main/resources/HelloDateTimeService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf3/bindings-datetime-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloWorld;
4 | import com.github.bjornvester.SayHi;
5 | import com.github.bjornvester.SayHiResponse;
6 |
7 | public class HelloWorldImpl implements HelloWorld {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf3/bindings-datetime-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloWorld;
4 | import com.github.bjornvester.SayHi;
5 | import com.github.bjornvester.SayHiResponse;
6 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
7 | import org.junit.jupiter.api.AfterEach;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import javax.xml.ws.Endpoint;
11 | import java.time.OffsetDateTime;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertTrue;
14 |
15 | class HelloWorldTest {
16 | String serviceAddress = "http://localhost:8801/HelloWorldService";
17 | Endpoint endpoint;
18 |
19 | @AfterEach
20 | void stopEndpoint() {
21 | if (endpoint != null) {
22 | endpoint.stop();
23 | }
24 | }
25 |
26 | @Test
27 | void testServerClient() {
28 | // Create server
29 | endpoint = Endpoint.publish(serviceAddress, new HelloWorldImpl());
30 |
31 | // Create client
32 | JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
33 | factory.setServiceClass(HelloWorld.class);
34 | factory.setAddress(serviceAddress);
35 | HelloWorld client = (HelloWorld) factory.create();
36 |
37 | // Call the service
38 | SayHi sayHi = new SayHi();
39 | sayHi.setArg0(OffsetDateTime.now());
40 | SayHiResponse response = client.sayHi(sayHi);
41 | assertTrue(response.getReturn().contains("Hi"));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/integration-test/cxf3/generated-annotation-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf3")
4 | }
5 |
6 | dependencies {
7 | implementation("javax.annotation:javax.annotation-api:1.3.2") // For the @Generated annotation from JDK8 but running in JDK9+
8 | testImplementation("commons-io:commons-io:2.8.0")
9 | }
10 |
11 | wsdl2java {
12 | useJakarta.set(false)
13 | markGenerated.set(true)
14 | generatedStyle.set("jdk8")
15 | }
16 |
--------------------------------------------------------------------------------
/integration-test/cxf3/generated-annotation-test/src/main/resources/HelloWorldService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf3/generated-annotation-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.example.markgenerated.HelloWorld;
4 | import com.github.bjornvester.example.markgenerated.SayHi;
5 | import com.github.bjornvester.example.markgenerated.SayHiResponse;
6 |
7 | public class HelloWorldImpl implements HelloWorld {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf3/generated-annotation-test/src/test/java/com/github/bjornvester/wsdl2java/MarkGeneratedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.IOException;
7 | import java.nio.charset.StandardCharsets;
8 | import java.nio.file.Files;
9 | import java.nio.file.Path;
10 | import java.nio.file.Paths;
11 | import java.util.concurrent.atomic.AtomicInteger;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertEquals;
14 | import static org.junit.jupiter.api.Assertions.assertFalse;
15 |
16 | class MarkGeneratedTest {
17 | AtomicInteger filesWithGeneratedAnnotation = new AtomicInteger(0);
18 |
19 | @Test
20 | void testMarkGenerated() throws IOException {
21 | Files.walk(Paths.get("."))
22 | .filter(path -> path.toString().contains("markgenerated") && path.getFileName().toString().endsWith(".java"))
23 | .forEach(this::checkGeneratedAnnotations);
24 |
25 | assertEquals(5, filesWithGeneratedAnnotation.get(), "Unexpected number of source files found with the @Generated annotation");
26 | }
27 |
28 | private void checkGeneratedAnnotations(final Path path) {
29 | try {
30 | String javaFile = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
31 | if (javaFile.contains("@Generated")) {
32 | filesWithGeneratedAnnotation.incrementAndGet();
33 | assertFalse(javaFile.contains("date = "), String.format("Source file %s contains a date", path));
34 | }
35 | } catch (IOException e) {
36 | throw new RuntimeException(e);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/integration-test/cxf3/xjc-plugins-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf3")
4 | }
5 |
6 | dependencies {
7 | implementation("org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1")
8 | xjcPlugins("org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1")
9 | }
10 |
11 | wsdl2java {
12 | options.addAll("-xjc-Xequals", "-xjc-XhashCode")
13 | useJakarta.set(false)
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf3/xjc-plugins-test/src/main/resources/HelloXjcPluginService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf3/xjc-plugins-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.example.xjcplugins.HelloWorld;
4 | import com.github.bjornvester.example.xjcplugins.SayHi;
5 | import com.github.bjornvester.example.xjcplugins.SayHiResponse;
6 |
7 | public class HelloWorldImpl implements HelloWorld {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf3/xjc-plugins-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.example.xjcplugins.HelloWorld;
4 | import com.github.bjornvester.example.xjcplugins.SayHi;
5 | import com.github.bjornvester.example.xjcplugins.SayHiResponse;
6 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
7 | import org.junit.jupiter.api.AfterEach;
8 | import org.junit.jupiter.api.Test;
9 | import org.jvnet.jaxb2_commons.lang.Equals2;
10 | import org.jvnet.jaxb2_commons.lang.HashCode2;
11 |
12 | import javax.xml.ws.Endpoint;
13 |
14 | import static org.junit.jupiter.api.Assertions.assertTrue;
15 |
16 | class HelloWorldTest {
17 | String serviceAddress = "http://localhost:8802/HelloWorldService";
18 | Endpoint endpoint;
19 |
20 | @AfterEach
21 | void stopEndpoint() {
22 | if (endpoint != null) {
23 | endpoint.stop();
24 | }
25 | }
26 |
27 | @Test
28 | void testServerClient() {
29 | // Create server
30 | endpoint = Endpoint.publish(serviceAddress, new HelloWorldImpl());
31 |
32 | // Create client
33 | JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
34 | factory.setServiceClass(HelloWorld.class);
35 | factory.setAddress(serviceAddress);
36 | HelloWorld client = (HelloWorld) factory.create();
37 |
38 | // Call the service
39 | SayHi sayHi = new SayHi();
40 | sayHi.setArg0("Joe");
41 | SayHiResponse response = client.sayHi(sayHi);
42 | assertTrue(response.getReturn().contains("Hi"));
43 |
44 | // Check the plugins
45 | assertTrue(sayHi instanceof Equals2);
46 | assertTrue(sayHi instanceof HashCode2);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/integration-test/cxf4/bindings-datetime-test-jakarta/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4")
4 | }
5 |
6 | dependencies {
7 | implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0")
8 | }
9 |
10 | wsdl2java {
11 | bindingFile.set(layout.projectDirectory.file("src/main/bindings/bindings.xml"))
12 | }
13 |
--------------------------------------------------------------------------------
/integration-test/cxf4/bindings-datetime-test-jakarta/src/main/bindings/bindings.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
9 |
10 |
--------------------------------------------------------------------------------
/integration-test/cxf4/bindings-datetime-test-jakarta/src/main/resources/HelloDateTimeService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/bindings-datetime-test-jakarta/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloWorld;
4 | import com.github.bjornvester.SayHi;
5 | import com.github.bjornvester.SayHiResponse;
6 |
7 | public class HelloWorldImpl implements HelloWorld {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf4/bindings-datetime-test-jakarta/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloWorld;
4 | import com.github.bjornvester.SayHi;
5 | import com.github.bjornvester.SayHiResponse;
6 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
7 | import org.junit.jupiter.api.AfterEach;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import jakarta.xml.ws.Endpoint;
11 | import java.time.OffsetDateTime;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertTrue;
14 |
15 | class HelloWorldTest {
16 | String serviceAddress = "http://localhost:8803/HelloWorldService";
17 | Endpoint endpoint;
18 |
19 | @AfterEach
20 | void stopEndpoint() {
21 | if (endpoint != null) {
22 | endpoint.stop();
23 | }
24 | }
25 |
26 | @Test
27 | void testServerClient() {
28 | // Create server
29 | endpoint = Endpoint.publish(serviceAddress, new HelloWorldImpl());
30 |
31 | // Create client
32 | JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
33 | factory.setServiceClass(HelloWorld.class);
34 | factory.setAddress(serviceAddress);
35 | HelloWorld client = (HelloWorld) factory.create();
36 |
37 | // Call the service
38 | SayHi sayHi = new SayHi();
39 | sayHi.setArg0(OffsetDateTime.now());
40 | SayHiResponse response = client.sayHi(sayHi);
41 | assertTrue(response.getReturn().contains("Hi"));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4")
4 | }
5 |
6 | wsdl2java {
7 | wsdlDir.set(layout.projectDirectory.dir("src/main/wsdl"))
8 | includes.set(
9 | listOf(
10 | "HelloWorldAbstractService.wsdl",
11 | "nested/HelloWorldNestedService.wsdl"
12 | )
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/src/main/java/com/github/bjornvester/wsdl2java/HelloWorldAbstractImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.example._abstract.HelloWorldAbstract;
4 | import com.github.bjornvester.example._abstract.SayHi;
5 | import com.github.bjornvester.example._abstract.SayHiResponse;
6 |
7 | public class HelloWorldAbstractImpl implements HelloWorldAbstract {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/src/main/java/com/github/bjornvester/wsdl2java/HelloWorldNestedImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.example.nested.HelloWorldNested;
4 | import com.github.bjornvester.example.nested.SayHi;
5 | import com.github.bjornvester.example.nested.SayHiResponse;
6 |
7 | public class HelloWorldNestedImpl implements HelloWorldNested {
8 | @Override
9 | public SayHiResponse sayHi(SayHi request) {
10 | SayHiResponse response = new SayHiResponse();
11 | response.setReturn("Hi, " + request.getArg0());
12 | return response;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/src/main/wsdl/HelloWorldAbstractService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/src/main/wsdl/HelloWorldInvalidService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/integration-test/cxf4/filter-test/src/main/wsdl/nested/HelloWorldNestedService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/grouping-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4")
4 | }
5 |
6 | dependencies {
7 | testImplementation("commons-io:commons-io:2.8.0")
8 | }
9 |
10 | wsdl2java {
11 | groups {
12 | register("group1") {
13 | includes.set(listOf("**/HelloWorldAService.wsdl"))
14 | options.set(listOf("-wsdlLocation", "MyLocationA"))
15 | packageName.set("com.github.bjornvester.wsdl2java.group1")
16 | }
17 | register("group2") {
18 | includes.set(listOf("**/HelloWorldBService.wsdl"))
19 | options.set(listOf("-wsdlLocation", "MyLocationB"))
20 | packageName.set("com.github.bjornvester.wsdl2java.group2")
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/integration-test/cxf4/grouping-test/src/main/resources/HelloWorldAService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/grouping-test/src/main/resources/HelloWorldBService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/grouping-test/src/test/java/com/github/bjornvester/wsdl2java/GroupingTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.IOException;
7 | import java.nio.charset.StandardCharsets;
8 | import java.nio.file.Files;
9 | import java.nio.file.Path;
10 | import java.nio.file.Paths;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertTrue;
13 |
14 | class GroupingTest {
15 | boolean foundA = false;
16 | boolean foundB = false;
17 |
18 | @Test
19 | void testIndividualOptions() throws IOException {
20 | Files.walk(Paths.get("."))
21 | .filter(path ->
22 | path.toString().contains("generated") && path.getFileName().toString().endsWith(".java"))
23 | .forEach(this::checkWsdlLocation);
24 |
25 | assertTrue(foundA, "Did not find service A");
26 | assertTrue(foundB, "Did not find service B");
27 | }
28 |
29 | private void checkWsdlLocation(final Path path) {
30 | if (path.getFileName().toString().equals("HelloWorldAService.java")) {
31 | foundA = true;
32 | verifyWsdlLocationParam(path, "MyLocationA");
33 | } else if (path.getFileName().toString().equals("HelloWorldBService.java")) {
34 | foundB = true;
35 | verifyWsdlLocationParam(path, "MyLocationB");
36 | }
37 | }
38 |
39 | private void verifyWsdlLocationParam(final Path path, final String expectedValue) {
40 | try {
41 | String javaFile = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
42 | assertTrue(javaFile.contains("wsdlLocation = \"" + expectedValue + "\""),
43 | String.format("Source file %s did not contain the expected wsdlLocation '%s'", path, expectedValue));
44 | } catch (IOException e) {
45 | throw new RuntimeException(e);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/integration-test/cxf4/includes-options-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4")
4 | }
5 |
6 | dependencies {
7 | testImplementation("commons-io:commons-io:2.8.0")
8 | }
9 |
10 | wsdl2java {
11 | includesWithOptions.set(mapOf(
12 | "**/HelloWorldAService.wsdl" to listOf("-wsdlLocation", "MyLocationA"),
13 | "**/HelloWorldBService.wsdl" to listOf("-wsdlLocation", "MyLocationB")
14 | ))
15 | }
16 |
--------------------------------------------------------------------------------
/integration-test/cxf4/includes-options-test/src/main/resources/HelloWorldAService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/includes-options-test/src/main/resources/HelloWorldBService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/includes-options-test/src/test/java/com/github/bjornvester/wsdl2java/IncludesWithOptionsTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import org.apache.commons.io.FileUtils;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.IOException;
7 | import java.nio.charset.StandardCharsets;
8 | import java.nio.file.Files;
9 | import java.nio.file.Path;
10 | import java.nio.file.Paths;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertTrue;
13 |
14 | class IncludesWithOptionsTest {
15 | boolean foundA = false;
16 | boolean foundB = false;
17 |
18 | @Test
19 | void testIndividualOptions() throws IOException {
20 | Files.walk(Paths.get("."))
21 | .filter(path ->
22 | path.toString().contains("includes_with_options") && path.getFileName().toString().endsWith(".java"))
23 | .forEach(this::checkWsdlLocation);
24 |
25 | assertTrue(foundA, "Did not find service A");
26 | assertTrue(foundB, "Did not find service B");
27 | }
28 |
29 | private void checkWsdlLocation(final Path path) {
30 | if (path.getFileName().toString().equals("HelloWorldAService.java")) {
31 | foundA = true;
32 | verifyWsdlLocationParam(path, "MyLocationA");
33 | } else if (path.getFileName().toString().equals("HelloWorldBService.java")) {
34 | foundB = true;
35 | verifyWsdlLocationParam(path, "MyLocationB");
36 | }
37 | }
38 |
39 | private void verifyWsdlLocationParam(final Path path, final String expectedValue) {
40 | try {
41 | String javaFile = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
42 | assertTrue(javaFile.contains("wsdlLocation = \"" + expectedValue + "\""),
43 | String.format("Source file %s did not contain the expected wsdlLocation '%s'", path, expectedValue));
44 | } catch (IOException e) {
45 | throw new RuntimeException(e);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/integration-test/cxf4/utf8-test/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.github.bjornvester.wsdl2java")
3 | id("com.github.bjornvester.wsdl2java.internal.java-conventions-cxf4")
4 | }
5 |
--------------------------------------------------------------------------------
/integration-test/cxf4/utf8-test/src/main/resources/HelloUtf8ÆØÅService.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/integration-test/cxf4/utf8-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloUtf8ÆØÅPortType;
4 | import com.github.bjornvester.RequestÆØÅ;
5 | import com.github.bjornvester.ResponseÆØÅ;
6 |
7 | public class HelloWorldImpl implements HelloUtf8ÆØÅPortType {
8 |
9 | @Override
10 | public ResponseÆØÅ utf8OperationWithCharsÆØÅ(final RequestÆØÅ parameters) {
11 | ResponseÆØÅ response = new ResponseÆØÅ();
12 | response.setReturn("Hi, " + parameters.getArg0());
13 | return response;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/integration-test/cxf4/utf8-test/src/test/java/com/github/bjornvester/wsdl2java/HelloWorldTest.java:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java;
2 |
3 | import com.github.bjornvester.HelloUtf8ÆØÅPortType;
4 | import com.github.bjornvester.RequestÆØÅ;
5 | import com.github.bjornvester.ResponseÆØÅ;
6 | import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
7 | import org.junit.jupiter.api.AfterEach;
8 | import org.junit.jupiter.api.Test;
9 |
10 | import jakarta.xml.ws.Endpoint;
11 |
12 | import static org.junit.jupiter.api.Assertions.assertEquals;
13 |
14 | class HelloWorldTest {
15 | String serviceAddress = "http://localhost:8804/HelloWorldService";
16 | Endpoint endpoint;
17 |
18 | @AfterEach
19 | void stopEndpoint() {
20 | if (endpoint != null) {
21 | endpoint.stop();
22 | }
23 | }
24 |
25 | @Test
26 | void testServerClient() {
27 | // Create server
28 | endpoint = Endpoint.publish(serviceAddress, new HelloWorldImpl());
29 |
30 | // Create client
31 | JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
32 | factory.setServiceClass(HelloUtf8ÆØÅPortType.class);
33 | factory.setAddress(serviceAddress);
34 | HelloUtf8ÆØÅPortType client = (HelloUtf8ÆØÅPortType) factory.create();
35 |
36 | // Call the service
37 | RequestÆØÅ param = new RequestÆØÅ();
38 | param.setArg0("ÆØÅ");
39 | ResponseÆØÅ response = client.utf8OperationWithCharsÆØÅ(param);
40 | assertEquals(response.getReturn(), "Hi, ÆØÅ");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/integration-test/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
2 | org.gradle.priority=low
3 | org.gradle.parallel=true
4 | org.gradle.caching=true
5 | org.gradle.configuration-cache=true
6 |
--------------------------------------------------------------------------------
/integration-test/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bjornvester/wsdl2java-gradle-plugin/45a0e66ac7bfdddb2128ebe13c96da8456e33692/integration-test/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/integration-test/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4 | networkTimeout=10000
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/integration-test/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | # This is normally unused
84 | # shellcheck disable=SC2034
85 | APP_BASE_NAME=${0##*/}
86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
87 |
88 | # Use the maximum available, or set MAX_FD != -1 to use that value.
89 | MAX_FD=maximum
90 |
91 | warn () {
92 | echo "$*"
93 | } >&2
94 |
95 | die () {
96 | echo
97 | echo "$*"
98 | echo
99 | exit 1
100 | } >&2
101 |
102 | # OS specific support (must be 'true' or 'false').
103 | cygwin=false
104 | msys=false
105 | darwin=false
106 | nonstop=false
107 | case "$( uname )" in #(
108 | CYGWIN* ) cygwin=true ;; #(
109 | Darwin* ) darwin=true ;; #(
110 | MSYS* | MINGW* ) msys=true ;; #(
111 | NONSTOP* ) nonstop=true ;;
112 | esac
113 |
114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
115 |
116 |
117 | # Determine the Java command to use to start the JVM.
118 | if [ -n "$JAVA_HOME" ] ; then
119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
120 | # IBM's JDK on AIX uses strange locations for the executables
121 | JAVACMD=$JAVA_HOME/jre/sh/java
122 | else
123 | JAVACMD=$JAVA_HOME/bin/java
124 | fi
125 | if [ ! -x "$JAVACMD" ] ; then
126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
127 |
128 | Please set the JAVA_HOME variable in your environment to match the
129 | location of your Java installation."
130 | fi
131 | else
132 | JAVACMD=java
133 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
134 |
135 | Please set the JAVA_HOME variable in your environment to match the
136 | location of your Java installation."
137 | fi
138 |
139 | # Increase the maximum file descriptors if we can.
140 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
141 | case $MAX_FD in #(
142 | max*)
143 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
144 | # shellcheck disable=SC3045
145 | MAX_FD=$( ulimit -H -n ) ||
146 | warn "Could not query maximum file descriptor limit"
147 | esac
148 | case $MAX_FD in #(
149 | '' | soft) :;; #(
150 | *)
151 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
152 | # shellcheck disable=SC3045
153 | ulimit -n "$MAX_FD" ||
154 | warn "Could not set maximum file descriptor limit to $MAX_FD"
155 | esac
156 | fi
157 |
158 | # Collect all arguments for the java command, stacking in reverse order:
159 | # * args from the command line
160 | # * the main class name
161 | # * -classpath
162 | # * -D...appname settings
163 | # * --module-path (only if needed)
164 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
165 |
166 | # For Cygwin or MSYS, switch paths to Windows format before running java
167 | if "$cygwin" || "$msys" ; then
168 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
169 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
170 |
171 | JAVACMD=$( cygpath --unix "$JAVACMD" )
172 |
173 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
174 | for arg do
175 | if
176 | case $arg in #(
177 | -*) false ;; # don't mess with options #(
178 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
179 | [ -e "$t" ] ;; #(
180 | *) false ;;
181 | esac
182 | then
183 | arg=$( cygpath --path --ignore --mixed "$arg" )
184 | fi
185 | # Roll the args list around exactly as many times as the number of
186 | # args, so each arg winds up back in the position where it started, but
187 | # possibly modified.
188 | #
189 | # NB: a `for` loop captures its iteration list before it begins, so
190 | # changing the positional parameters here affects neither the number of
191 | # iterations, nor the values presented in `arg`.
192 | shift # remove old arg
193 | set -- "$@" "$arg" # push replacement arg
194 | done
195 | fi
196 |
197 |
198 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
199 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
200 |
201 | # Collect all arguments for the java command;
202 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
203 | # shell script including quotes and variable substitutions, so put them in
204 | # double quotes to make sure that they get re-expanded; and
205 | # * put everything else in single quotes, so that it's not re-expanded.
206 |
207 | set -- \
208 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
209 | -classpath "$CLASSPATH" \
210 | org.gradle.wrapper.GradleWrapperMain \
211 | "$@"
212 |
213 | # Stop when "xargs" is not available.
214 | if ! command -v xargs >/dev/null 2>&1
215 | then
216 | die "xargs is not available"
217 | fi
218 |
219 | # Use "xargs" to parse quoted args.
220 | #
221 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
222 | #
223 | # In Bash we could simply go:
224 | #
225 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
226 | # set -- "${ARGS[@]}" "$@"
227 | #
228 | # but POSIX shell has neither arrays nor command substitution, so instead we
229 | # post-process each arg (as a line of input to sed) to backslash-escape any
230 | # character that might be a shell metacharacter, then use eval to reverse
231 | # that process (while maintaining the separation between arguments), and wrap
232 | # the whole thing up as a single "set" statement.
233 | #
234 | # This will of course break if any of these variables contains a newline or
235 | # an unmatched quote.
236 | #
237 |
238 | eval "set -- $(
239 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
240 | xargs -n1 |
241 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
242 | tr '\n' ' '
243 | )" '"$@"'
244 |
245 | exec "$JAVACMD" "$@"
246 |
--------------------------------------------------------------------------------
/integration-test/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%"=="" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%"=="" set DIRNAME=.
29 | @rem This is normally unused
30 | set APP_BASE_NAME=%~n0
31 | set APP_HOME=%DIRNAME%
32 |
33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35 |
36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38 |
39 | @rem Find java.exe
40 | if defined JAVA_HOME goto findJavaFromJavaHome
41 |
42 | set JAVA_EXE=java.exe
43 | %JAVA_EXE% -version >NUL 2>&1
44 | if %ERRORLEVEL% equ 0 goto execute
45 |
46 | echo.
47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48 | echo.
49 | echo Please set the JAVA_HOME variable in your environment to match the
50 | echo location of your Java installation.
51 |
52 | goto fail
53 |
54 | :findJavaFromJavaHome
55 | set JAVA_HOME=%JAVA_HOME:"=%
56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57 |
58 | if exist "%JAVA_EXE%" goto execute
59 |
60 | echo.
61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62 | echo.
63 | echo Please set the JAVA_HOME variable in your environment to match the
64 | echo location of your Java installation.
65 |
66 | goto fail
67 |
68 | :execute
69 | @rem Setup the command line
70 |
71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72 |
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if %ERRORLEVEL% equ 0 goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | set EXIT_CODE=%ERRORLEVEL%
85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87 | exit /b %EXIT_CODE%
88 |
89 | :mainEnd
90 | if "%OS%"=="Windows_NT" endlocal
91 |
92 | :omega
93 |
--------------------------------------------------------------------------------
/integration-test/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version ("0.5.0")
3 | }
4 |
5 | includeBuild("..")
6 |
7 | include(
8 | // Note that the lines below are modified by the unit test in the root project.
9 | // Be careful making changes.
10 | "cxf4:bindings-datetime-test-jakarta",
11 | "cxf4:filter-test",
12 | "cxf4:grouping-test",
13 | "cxf4:includes-options-test",
14 | "cxf4:utf8-test",
15 |
16 | "cxf3:bindings-datetime-test",
17 | "cxf3:generated-annotation-test",
18 | "cxf3:xjc-plugins-test"
19 | )
20 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0")
3 | }
4 |
5 | rootProject.name = "wsdl2java-gradle-plugin"
6 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaPlugin.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPluginExtension.Companion.GENERATED_STYLE_JDK9
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.Project
6 | import org.gradle.api.artifacts.Configuration
7 | import org.gradle.api.artifacts.Dependency
8 | import org.gradle.api.plugins.JavaPlugin
9 | import org.gradle.api.plugins.JavaPluginExtension
10 | import org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME
11 | import org.gradle.api.tasks.SourceSetContainer
12 | import org.gradle.api.tasks.TaskProvider
13 | import org.gradle.jvm.toolchain.JavaToolchainService
14 | import org.gradle.util.GradleVersion
15 |
16 | class Wsdl2JavaPlugin : Plugin {
17 | companion object {
18 | const val MINIMUM_GRADLE_VERSION = "7.6"
19 | const val PLUGIN_ID = "com.github.bjornvester.wsdl2java"
20 | const val WSDL2JAVA_TASK_NAME = "wsdl2java"
21 | const val WSDL2JAVA_EXTENSION_NAME = "wsdl2java"
22 | const val WSDL2JAVA_CONFIGURATION_NAME = "wsdl2java"
23 | const val XJC_PLUGINS_CONFIGURATION_NAME = "xjcPlugins"
24 | }
25 |
26 | override fun apply(project: Project) {
27 | project.logger.info("Applying $PLUGIN_ID to project ${project.name}")
28 | verifyGradleVersion()
29 | project.plugins.apply(JavaPlugin::class.java)
30 | val extension = project.extensions.create(WSDL2JAVA_EXTENSION_NAME, Wsdl2JavaPluginExtension::class.java)
31 | val wsdl2JavaConfiguration = createResolvableConfiguration(project, WSDL2JAVA_CONFIGURATION_NAME)
32 | createResolvableConfiguration(project, XJC_PLUGINS_CONFIGURATION_NAME)
33 |
34 | wsdl2JavaConfiguration.defaultDependencies {
35 | addLater(extension.cxfVersion.map { project.dependencies.create("org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:$it") })
36 | addLater(extension.cxfVersion.map { project.dependencies.create("org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:$it") })
37 | addLater(extension.useJakarta.map { if (it) "3.0.1" else "2.3.3" }.map { project.dependencies.create("jakarta.xml.ws:jakarta.xml.ws-api:$it") })
38 | addLater(extension.useJakarta.map { if (it) "2.1.1" else "1.3.5" }.map { project.dependencies.create("jakarta.annotation:jakarta.annotation-api:$it") })
39 | add(project.dependencies.create("org.slf4j:slf4j-simple:1.7.36"))
40 | }
41 |
42 | project.configurations.named(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME) {
43 | // The listProperty thing is a work-around for https://github.com/gradle/gradle/issues/13255
44 | dependencies.addAllLater(project.objects.listProperty(Dependency::class.java).convention(extension.addCompilationDependencies.map {
45 | val deps = listOf().toMutableList()
46 | if (it) {
47 | val wsApiVersion = if (extension.useJakarta.get()) "3.0.1" else "2.3.3"
48 | val jwsApiVersion = if (extension.useJakarta.get()) "3.0.0" else "1.1.1"
49 | deps.add(project.dependencies.create("jakarta.xml.ws:jakarta.xml.ws-api:$wsApiVersion"))
50 | deps.add(project.dependencies.create("jakarta.jws:jakarta.jws-api:$jwsApiVersion"))
51 | if (extension.markGenerated.get() && extension.generatedStyle.get() != GENERATED_STYLE_JDK9) {
52 | val annotationsApiVersion = if (extension.useJakarta.get()) "2.1.1" else "1.3.5"
53 | deps.add(project.dependencies.create("jakarta.annotation:jakarta.annotation-api:$annotationsApiVersion"))
54 | }
55 | }
56 | deps
57 | }))
58 | }
59 |
60 | val defaultTask = addWsdl2JavaTask(WSDL2JAVA_TASK_NAME, project, extension)
61 |
62 | extension.groups.all {
63 | defaultTask.configure {
64 | enabled = false
65 | }
66 |
67 | addWsdl2JavaTask(WSDL2JAVA_TASK_NAME + name.replaceFirstChar(Char::titlecase), project, this)
68 | }
69 | }
70 |
71 | private fun addWsdl2JavaTask(name: String, project: Project, group: Wsdl2JavaPluginExtensionGroup): TaskProvider {
72 | val wsdl2JavaTask = project.tasks.register(name, Wsdl2JavaTask::class.java) {
73 | wsdlInputDir.convention(group.wsdlDir)
74 | includes.convention(group.includes)
75 | includesWithOptions.convention(group.includesWithOptions)
76 | bindingFile.convention(group.bindingFile)
77 | options.convention(group.options)
78 | verbose.convention(group.verbose)
79 | suppressGeneratedDate.convention(group.suppressGeneratedDate)
80 | markGenerated.convention(group.markGenerated)
81 | sourcesOutputDir.convention(group.generatedSourceDir)
82 | packageName.convention(group.packageName)
83 | wsdl2JavaConfiguration.from(project.configurations.named(WSDL2JAVA_CONFIGURATION_NAME))
84 | xjcPluginsConfiguration.from(project.configurations.named(XJC_PLUGINS_CONFIGURATION_NAME))
85 |
86 | val toolchainService = project.extensions.getByType(JavaToolchainService::class.java)
87 | val currentJavaToolchain = project.extensions.getByType(JavaPluginExtension::class.java).toolchain
88 | val currentJvmLauncherProvider = toolchainService.launcherFor(currentJavaToolchain)
89 | javaLauncher.convention(currentJvmLauncherProvider)
90 | }
91 |
92 | val sourceSets = project.properties["sourceSets"] as SourceSetContainer
93 | sourceSets.named(MAIN_SOURCE_SET_NAME) {
94 | java.srcDir(wsdl2JavaTask)
95 | }
96 |
97 | return wsdl2JavaTask
98 | }
99 |
100 | private fun verifyGradleVersion() {
101 | if (GradleVersion.current() < GradleVersion.version(MINIMUM_GRADLE_VERSION)) {
102 | throw UnsupportedOperationException(
103 | "Plugin $PLUGIN_ID requires at least Gradle $MINIMUM_GRADLE_VERSION, " +
104 | "but you are using ${GradleVersion.current().version}"
105 | )
106 | }
107 | }
108 |
109 | private fun createResolvableConfiguration(project: Project, name: String): Configuration {
110 | return project.configurations.maybeCreate(name).apply {
111 | isCanBeConsumed = false
112 | isCanBeResolved = true
113 | isVisible = false
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaPluginExtension.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import org.gradle.api.NamedDomainObjectContainer
4 | import org.gradle.api.file.ProjectLayout
5 | import org.gradle.api.model.ObjectFactory
6 | import org.gradle.api.provider.Property
7 | import javax.inject.Inject
8 |
9 | open class Wsdl2JavaPluginExtension @Inject constructor(objects: ObjectFactory, layout: ProjectLayout) : Wsdl2JavaPluginExtensionGroup {
10 | val useJakarta = objects.property(Boolean::class.java).convention(true)
11 | val cxfVersion = objects.property(String::class.java).convention(useJakarta.map { if (it) "4.0.2" else "3.5.6" })
12 | val addCompilationDependencies: Property = objects.property(Boolean::class.java).convention(true)
13 | val useProcessIsolation: Property = objects.property(Boolean::class.java).convention(true)
14 |
15 | override val name = "Defaults"
16 | override val wsdlDir = objects.directoryProperty().convention(layout.projectDirectory.dir("src/main/resources"))
17 | override val includes = objects.listProperty(String::class.java).convention(listOf("**/*.wsdl"))
18 | override val includesWithOptions = objects.mapProperty(String::class.java, List::class.java)
19 | override val bindingFile = objects.fileProperty()
20 | override val generatedSourceDir = objects.directoryProperty().convention(layout.buildDirectory.dir("generated/sources/wsdl2java/java"))
21 | override val options = objects.listProperty(String::class.java)
22 | override val verbose = objects.property(Boolean::class.java)
23 | override val suppressGeneratedDate = objects.property(Boolean::class.java).convention(true)
24 | override val markGenerated = objects.property(Boolean::class.java).convention(false)
25 | override val generatedStyle = objects.property(String::class.java).convention(GENERATED_STYLE_DEFAULT)
26 | override val packageName = objects.property(String::class.java)
27 |
28 | val groups: NamedDomainObjectContainer = objects.domainObjectContainer(Wsdl2JavaPluginExtensionGroup::class.java)
29 |
30 | init {
31 | groups.configureEach {
32 | wsdlDir.convention(this@Wsdl2JavaPluginExtension.wsdlDir)
33 | includes.convention(this@Wsdl2JavaPluginExtension.includes)
34 | includesWithOptions.convention(this@Wsdl2JavaPluginExtension.includesWithOptions)
35 | bindingFile.convention(this@Wsdl2JavaPluginExtension.bindingFile)
36 | generatedSourceDir.convention(layout.buildDirectory.dir("generated/sources/wsdl2java-$name/java"))
37 | options.convention(this@Wsdl2JavaPluginExtension.options)
38 | verbose.convention(this@Wsdl2JavaPluginExtension.verbose)
39 | suppressGeneratedDate.convention(this@Wsdl2JavaPluginExtension.suppressGeneratedDate)
40 | markGenerated.convention(this@Wsdl2JavaPluginExtension.markGenerated)
41 | generatedStyle.convention(this@Wsdl2JavaPluginExtension.generatedStyle)
42 | packageName.convention(this@Wsdl2JavaPluginExtension.packageName)
43 | }
44 | }
45 |
46 | companion object {
47 | @JvmStatic
48 | val GENERATED_STYLE_DEFAULT = "default"
49 |
50 | @JvmStatic
51 | val GENERATED_STYLE_JDK8 = "jdk8"
52 |
53 | @JvmStatic
54 | val GENERATED_STYLE_JDK9 = "jdk9"
55 |
56 | @JvmStatic
57 | val GENERATED_STYLE_JAKARTA = "jakarta"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaPluginExtensionGroup.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import org.gradle.api.file.DirectoryProperty
4 | import org.gradle.api.file.RegularFileProperty
5 | import org.gradle.api.provider.ListProperty
6 | import org.gradle.api.provider.MapProperty
7 | import org.gradle.api.provider.Property
8 |
9 | interface Wsdl2JavaPluginExtensionGroup {
10 | val name: String
11 | val wsdlDir: DirectoryProperty
12 | val includes: ListProperty
13 | val includesWithOptions: MapProperty>
14 | val bindingFile: RegularFileProperty
15 | val generatedSourceDir: DirectoryProperty
16 | val options: ListProperty
17 | val verbose: Property
18 | val suppressGeneratedDate: Property
19 | val markGenerated: Property
20 | val generatedStyle: Property
21 | val packageName: Property
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaTask.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPlugin.Companion.WSDL2JAVA_EXTENSION_NAME
4 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPluginExtension.Companion.GENERATED_STYLE_DEFAULT
5 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPluginExtension.Companion.GENERATED_STYLE_JAKARTA
6 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPluginExtension.Companion.GENERATED_STYLE_JDK8
7 | import com.github.bjornvester.wsdl2java.Wsdl2JavaPluginExtension.Companion.GENERATED_STYLE_JDK9
8 | import org.gradle.api.DefaultTask
9 | import org.gradle.api.GradleException
10 | import org.gradle.api.file.DirectoryProperty
11 | import org.gradle.api.internal.file.FileOperations
12 | import org.gradle.api.model.ObjectFactory
13 | import org.gradle.api.plugins.BasePlugin
14 | import org.gradle.api.provider.Property
15 | import org.gradle.api.tasks.*
16 | import org.gradle.jvm.toolchain.JavaLauncher
17 | import org.gradle.process.JavaForkOptions
18 | import org.gradle.workers.WorkerExecutor
19 | import javax.inject.Inject
20 |
21 | @CacheableTask
22 | abstract class Wsdl2JavaTask @Inject constructor(
23 | private val workerExecutor: WorkerExecutor,
24 | private val fileOperations: FileOperations,
25 | objects: ObjectFactory
26 | ) : DefaultTask() {
27 | @get:InputDirectory
28 | @get:PathSensitive(PathSensitivity.RELATIVE)
29 | val wsdlInputDir = objects.directoryProperty().convention(getWsdl2JavaExtension().wsdlDir)
30 |
31 | @get:Input
32 | val includes = objects.listProperty(String::class.java).convention(getWsdl2JavaExtension().includes)
33 |
34 | @get:Input
35 | val includesWithOptions = objects.mapProperty(String::class.java, List::class.java).convention(getWsdl2JavaExtension().includesWithOptions)
36 |
37 | @get:InputFile
38 | @get:PathSensitive(PathSensitivity.RELATIVE)
39 | @Optional
40 | val bindingFile = objects.fileProperty().convention(getWsdl2JavaExtension().bindingFile)
41 |
42 | @get:Input
43 | @Optional
44 | val options = objects.listProperty(String::class.java).convention(getWsdl2JavaExtension().options)
45 |
46 | @get:Input
47 | @Optional
48 | val verbose = objects.property(Boolean::class.java).convention(getWsdl2JavaExtension().verbose)
49 |
50 | @get:Input
51 | val suppressGeneratedDate = objects.property(Boolean::class.java).convention(getWsdl2JavaExtension().suppressGeneratedDate)
52 |
53 | @get:Input
54 | @Optional
55 | val markGenerated = objects.property(Boolean::class.java).convention(getWsdl2JavaExtension().markGenerated)
56 |
57 | @get:Input
58 | @Optional
59 | val generatedStyle = objects.property(String::class.java).convention(getWsdl2JavaExtension().generatedStyle)
60 |
61 | @get:Input
62 | @Optional
63 | val packageName = objects.property(String::class.java).convention(getWsdl2JavaExtension().packageName)
64 |
65 | @get:Classpath
66 | val wsdl2JavaConfiguration = objects.fileCollection()
67 |
68 | @get:Classpath
69 | val xjcPluginsConfiguration = objects.fileCollection()
70 |
71 | @get:OutputDirectory
72 | val sourcesOutputDir: DirectoryProperty = objects.directoryProperty().convention(getWsdl2JavaExtension().generatedSourceDir)
73 |
74 | @Optional
75 | @get:Nested
76 | val javaLauncher: Property = objects.property(JavaLauncher::class.java)
77 |
78 | @get:Input
79 | @Optional
80 | val useProcessIsolation = objects.property(Boolean::class.java).convention(getWsdl2JavaExtension().useProcessIsolation)
81 |
82 |
83 | init {
84 | group = BasePlugin.BUILD_GROUP
85 | description = "Generates Java classes from WSDL files."
86 | }
87 |
88 | @TaskAction
89 | fun doCodeGeneration() {
90 | validateOptions()
91 |
92 | fileOperations.delete(sourcesOutputDir)
93 | fileOperations.mkdir(sourcesOutputDir)
94 |
95 | val workerExecutor = if (useProcessIsolation.get()) {
96 | workerExecutor.processIsolation {
97 | configureForkOptions(forkOptions)
98 | classpath.from(wsdl2JavaConfiguration).from(xjcPluginsConfiguration)
99 | }
100 | } else {
101 | workerExecutor.classLoaderIsolation {
102 | // More restricted, but allows attaching a debugger to the worker instance
103 | classpath.from(wsdl2JavaConfiguration).from(xjcPluginsConfiguration)
104 | }
105 | }
106 |
107 | val defaultArgs = buildDefaultArguments()
108 | val wsdlToArgs = mutableMapOf>()
109 |
110 | if (includesWithOptions.isPresent && includesWithOptions.get().isNotEmpty()) {
111 | includesWithOptions.get().forEach { (includePattern, includeOptions) ->
112 | addWsdlToArgs(listOf(includePattern), defaultArgs + includeOptions as List, wsdlToArgs)
113 | }
114 | } else {
115 | addWsdlToArgs(includes.get(), defaultArgs, wsdlToArgs)
116 | }
117 |
118 | // Note that we don't run the CXF tool on each WSDL file as the build might be configured with parallel execution
119 | // This could be a problem if multiple WSDLs references the same schemas as CXF might try and write to the same files
120 | workerExecutor.submit(Wsdl2JavaWorker::class.java) {
121 | this.wsdlToArgs = wsdlToArgs
122 | outputDir = sourcesOutputDir.get()
123 | generatedStyle = this@Wsdl2JavaTask.generatedStyle.get()
124 | removeDateFromGeneratedAnnotation = (markGenerated.get() && suppressGeneratedDate.get())
125 | }
126 | }
127 |
128 | private fun configureForkOptions(forkOptions: JavaForkOptions) {
129 | if (javaLauncher.isPresent) {
130 | forkOptions.executable = javaLauncher.get().executablePath.asFile.absolutePath
131 | }
132 |
133 | /*
134 | All gradle worker processes have Xerces2 on the classpath.
135 | This version of Xerces does not support checking for external file access (even if not used).
136 | This causes it to log a bunch of stack traces on the form:
137 | -- Property "http://javax.xml.XMLConstants/property/accessExternalSchema" is not supported by used JAXP implementation.
138 | To avoid this, we fork the worker API to a separate process where we can set system properties to select which implementation of a SAXParser to use.
139 | The JDK comes with an internal implementation of a SAXParser, also based on Xerces, but supports the properties to control external file access.
140 | */
141 | forkOptions.systemProperties = mapOf("javax.xml.parsers.DocumentBuilderFactory" to "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", "javax.xml.parsers.SAXParserFactory" to "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl", "javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema" to "org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory", "javax.xml.accessExternalSchema" to "all")
142 |
143 | if (logger.isDebugEnabled) {
144 | // This adds debugging information on the XJC method used to find and load services (plugins)
145 | forkOptions.systemProperties["com.sun.tools.xjc.Options.findServices"] = ""
146 | }
147 |
148 | // Set encoding
149 | // This is a work-around for https://github.com/gradle/gradle/issues/13843
150 | // It should be fixed in Gradle 8.3, but we still need to support older versions
151 | forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8")
152 | }
153 |
154 | private fun addWsdlToArgs(
155 | includePattern: List?,
156 | defaultArgs: List,
157 | wsdlToArgs: MutableMap>
158 | ) {
159 | wsdlInputDir
160 | .asFileTree
161 | .matching { if (includePattern != null) include(includePattern) }
162 | .forEach { wsdlFile ->
163 | val computedArgs = mutableListOf()
164 | computedArgs.addAll(defaultArgs)
165 |
166 | if (!computedArgs.contains("-wsdlLocation")) {
167 | computedArgs.addAll(
168 | listOf(
169 | "-wsdlLocation",
170 | wsdlFile.relativeTo(wsdlInputDir.asFile.get()).invariantSeparatorsPath
171 | )
172 | )
173 | }
174 |
175 | computedArgs.add(wsdlFile.path)
176 | wsdlToArgs[wsdlFile.path] = computedArgs
177 | }
178 | }
179 |
180 | private fun buildDefaultArguments(): MutableList {
181 | val defaultArgs = mutableListOf(
182 | "-xjc-disableXmlSecurity",
183 | "-autoNameResolution",
184 | "-d",
185 | sourcesOutputDir.get().toString()
186 | )
187 |
188 | if (suppressGeneratedDate.get()) {
189 | defaultArgs.add("-suppress-generated-date")
190 | }
191 |
192 | if (markGenerated.get()) {
193 | defaultArgs.add("-mark-generated")
194 | }
195 |
196 | if (packageName.isPresent && packageName.get().isNotBlank()) {
197 | defaultArgs.addAll(listOf("-p", packageName.get()))
198 | }
199 |
200 | // Add the verbose parameter if explicitly configured to true, or if not set but info logging is enabled
201 | if (verbose.getOrElse(false) || (!verbose.isPresent && logger.isInfoEnabled)) {
202 | defaultArgs.add("-verbose")
203 | }
204 |
205 | if (bindingFile.isPresent) {
206 | defaultArgs.addAll(
207 | listOf(
208 | "-b",
209 | bindingFile.get().asFile.absolutePath
210 | )
211 | )
212 | }
213 |
214 | if (options.isPresent) {
215 | defaultArgs.addAll(options.get())
216 | }
217 |
218 | return defaultArgs
219 | }
220 |
221 | private fun validateOptions() {
222 | val supportedGeneratedStyleValues = listOf(GENERATED_STYLE_DEFAULT, GENERATED_STYLE_JDK8, GENERATED_STYLE_JDK9, GENERATED_STYLE_JAKARTA)
223 | if (generatedStyle.get() !in supportedGeneratedStyleValues) {
224 | throw GradleException("The property 'markGenerated' had an invalid value '${markGenerated.get()}'. Supported values are: $supportedGeneratedStyleValues")
225 | }
226 |
227 | if (options.isPresent || includesWithOptions.isPresent) {
228 | val prohibitedOptions = mapOf(
229 | "-verbose" to "Configured through the 'verbose' property",
230 | "-d" to "Configured through the 'generatedSourceDir' property",
231 | "-p" to "Configured through the 'packageName' property",
232 | "-suppress-generated-date" to "Configured through the 'suppressGeneratedDate' property",
233 | "-mark-generated" to "Configured through the 'markGenerated' property",
234 | "-autoNameResolution" to "Configured automatically and cannot currently be overridden"
235 | )
236 |
237 | // Note that we allow specifying binding file(s) through the -b parameter, as we otherwise can't configure individual bindings pr. wsdl
238 |
239 | (options.getOrElse(emptyList()) + includesWithOptions.getOrElse(emptyMap()).values).forEach { option ->
240 | if (prohibitedOptions.containsKey(option)) {
241 | throw GradleException("The option '$option' is not allowed in this plugin. Reason: ${prohibitedOptions[option]}")
242 | }
243 | }
244 | }
245 | }
246 |
247 | private fun getWsdl2JavaExtension() = project.extensions.getByName(WSDL2JAVA_EXTENSION_NAME) as Wsdl2JavaPluginExtension
248 | }
249 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaWorker.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import org.apache.cxf.tools.common.ToolContext
4 | import org.apache.cxf.tools.wsdlto.WSDLToJava
5 | import org.gradle.api.GradleException
6 | import org.gradle.workers.WorkAction
7 | import org.slf4j.Logger
8 | import org.slf4j.LoggerFactory
9 |
10 | abstract class Wsdl2JavaWorker : WorkAction {
11 | private val logger: Logger = LoggerFactory.getLogger(Wsdl2JavaWorker::class.java)
12 |
13 | override fun execute() {
14 | parameters.wsdlToArgs.forEach { (wsdlPath, args) ->
15 | logger.info("Running WSDLToJava tool on file {} with args: {}", wsdlPath, args)
16 |
17 | try {
18 | WSDLToJava(args.toTypedArray()).run(ToolContext())
19 | } catch (e: Exception) {
20 | // We can't propagate the exception as it might contain classes from CXF which are not available outside the worker execution context
21 | // Also, for some reason, we can't even log the error as it sometimes fails with:
22 | // java.io.StreamCorruptedException: invalid type code: 0C
23 | // Seems like a bug in Gradle, possible when the error message contain multiple lines
24 | // Until we have found the cause of it, we print directly to System.out
25 | logger.error("Failed to generate sources from WSDL:")
26 | e.printStackTrace()
27 | throw GradleException("Failed to generate Java sources from WSDL. See the log for details.")
28 | }
29 | }
30 |
31 | fixGeneratedAnnotations()
32 | }
33 |
34 | private fun fixGeneratedAnnotations() {
35 | if (parameters.generatedStyle != Wsdl2JavaPluginExtension.GENERATED_STYLE_DEFAULT || parameters.removeDateFromGeneratedAnnotation) {
36 | parameters.outputDir.asFileTree.forEach {
37 | logger.debug("Fixing the @Generated annotation in file {}", it)
38 | var source = it.readText()
39 |
40 | when (parameters.generatedStyle) {
41 | Wsdl2JavaPluginExtension.GENERATED_STYLE_JDK8 -> {
42 | source = source.replaceFirst("import jakarta.annotation.Generated", "import javax.annotation.Generated")
43 | }
44 | Wsdl2JavaPluginExtension.GENERATED_STYLE_JDK9 -> {
45 | source = source.replaceFirst("import jakarta.annotation.Generated", "import javax.annotation.processing.Generated")
46 | source = source.replaceFirst("import javax.annotation.Generated", "import javax.annotation.processing.Generated")
47 | }
48 | Wsdl2JavaPluginExtension.GENERATED_STYLE_JAKARTA -> {
49 | source = source.replaceFirst("import javax.annotation.Generated", "jakarta.annotation.Generated")
50 | }
51 | }
52 |
53 | if (parameters.removeDateFromGeneratedAnnotation) {
54 | // Remove the "date" part from the @Generated annotation
55 | // Input example: @Generated(value = "org.apache.cxf.tools.wsdlto.WSDLToJava", date = "2021-05-15T21:18:42.272+02:00", comments = "Apache CXF 3.4.3")
56 | // Note that the 'value' property may contain classes in the 'com.sun.tools.xjc' namespace
57 | // Also note that the date and comments field may be switched, depending on the version.
58 | val generatedPattern = """(@Generated\(value = .*?"), date = "[^"]*"([^)]*\))"""
59 | source = source.replace(Regex(generatedPattern), "$1$2")
60 | }
61 |
62 | it.writeText(source)
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaWorkerParams.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester.wsdl2java
2 |
3 | import org.gradle.api.file.Directory
4 | import org.gradle.workers.WorkParameters
5 |
6 | interface Wsdl2JavaWorkerParams : WorkParameters {
7 | var wsdlToArgs: Map>
8 | var outputDir: Directory
9 | var removeDateFromGeneratedAnnotation: Boolean
10 | var generatedStyle: String
11 | }
12 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/github/bjornvester/IntegrationTest.kt:
--------------------------------------------------------------------------------
1 | package com.github.bjornvester
2 |
3 | import org.apache.commons.io.FileUtils
4 | import org.gradle.testkit.runner.GradleRunner
5 | import org.gradle.util.GradleVersion
6 | import org.junit.jupiter.api.io.TempDir
7 | import org.junit.jupiter.params.ParameterizedTest
8 | import org.junit.jupiter.params.provider.Arguments
9 | import org.junit.jupiter.params.provider.MethodSource
10 | import java.io.File
11 | import java.lang.management.ManagementFactory
12 | import java.util.stream.Stream
13 |
14 | open class IntegrationTest {
15 | @ParameterizedTest(name = "Test plugin with Gradle version {0}")
16 | @MethodSource("provideVersions")
17 | fun thePluginWorks(gradleVersion: String, @TempDir tempDir: File) {
18 | runGenericBuild(gradleVersion, tempDir)
19 | }
20 |
21 | private fun runGenericBuild(gradleVersion: String, tempDir: File) {
22 | copyIntegrationTestProject(tempDir)
23 |
24 | // Remove the "includedBuild" declaration from the settings file
25 | tempDir.resolve(SETTINGS_FILE).writeText(tempDir.resolve(SETTINGS_FILE).readText().replace("includeBuild(\"..\")", ""))
26 |
27 | if (GradleVersion.version(gradleVersion) < GradleVersion.version("8.1")) {
28 | // The Gradle configuration cache was not stable until version 8.1
29 | tempDir.resolve(PROPERTIES_FILE)
30 | .writeText(tempDir.resolve(PROPERTIES_FILE).readText().replace("org.gradle.configuration-cache=true", ""))
31 | }
32 |
33 | GradleRunner
34 | .create()
35 | .forwardOutput()
36 | .withProjectDir(tempDir)
37 | .withPluginClasspath()
38 | .withArguments("clean", "check", "-i", "-s", "--no-build-cache")
39 | .withGradleVersion(gradleVersion)
40 | .withDebug(isDebuggerAttached())
41 | .build()
42 | }
43 |
44 | private fun copyIntegrationTestProject(tempDir: File) {
45 | val rootFolder = File(System.getProperty("GRADLE_ROOT_FOLDER"))
46 | val integrationTestDir = rootFolder.resolve("integration-test")
47 | val ignoredDirNames = arrayOf("out", ".gradle", "build")
48 |
49 | FileUtils.copyDirectory(integrationTestDir, tempDir) { copiedResource ->
50 | ignoredDirNames.none { ignoredDir ->
51 | copiedResource.isDirectory && copiedResource.name.toString() == ignoredDir
52 | }
53 | }
54 | }
55 |
56 | private fun isDebuggerAttached(): Boolean {
57 | return ManagementFactory.getRuntimeMXBean().inputArguments.toString().indexOf("-agentlib:jdwp") > 0
58 | }
59 |
60 | companion object {
61 | const val SETTINGS_FILE = "settings.gradle.kts"
62 | const val PROPERTIES_FILE = "gradle.properties"
63 |
64 | @JvmStatic
65 | @Suppress("unused")
66 | fun provideVersions(): Stream? {
67 | return Stream.of(
68 | // Test various versions of Gradle
69 | Arguments.of("7.6.1"), // Minimum required version of Gradle
70 | Arguments.of("8.1.1")
71 | )
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------