Skip to content

Commit

Permalink
bjornvester#10 add encoding option
Browse files Browse the repository at this point in the history
  • Loading branch information
lkoe committed May 21, 2021
1 parent e1ba046 commit dfa7fec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ wsdl2java {

Here is a list of all available properties:

| Property | Type | Default | Description |
| Property | Type | Default | Description |
|-----------------------|-----------------------|--------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| wsdlDir | DirectoryProperty | "$projectDir/src<br>/main/resources" | The directory holding the WSDL and referenced XSD files to compile. |
| includes | ListProperty\<String> | \["**/*.wsdl"] | The inclusion filer (Ant style) for which WSDLs to include |
Expand All @@ -42,7 +42,8 @@ Here is a list of all available properties:
| cxfVersion | Provider\<String> | "3.4.3" | The version of CXF to use. |
| verbose | Provider\<Boolean> | true | Enables verbose output from CXF. |
| suppressGeneratedDate | Provider\<Boolean> | true | Suppresses generating dates in CXF. Default is true to support reproducible builds and to work with the build cache. |
| markGenerated | Provider\<String> | "no" | Adds the @Generated annotation to the generated sources. See below for details as there are some gotchas with this. | |
| markGenerated | Provider\<String> | "no" | Adds the @Generated annotation to the generated sources. See below for details as there are some gotchas with this. |
| encoding | Provider\<String> | `encoding` option of the `compileJava` Task | The encoding of generated Java sources. |
| options | ListProperty\<String> | \[empty\] | Additional options to pass to the tool. See [here](https://cxf.apache.org/docs/wsdl-to-java.html) for details. |


Expand Down Expand Up @@ -137,12 +138,26 @@ wsdl2java {
```

### Configure encoding
If your WSDL files include non-ANSI characters, you should set the corresponding file encoding in your gradle.properties file. E.g.:
If your WSDL files include non-ANSI characters, you should set the corresponding `encoding` property:

```properties
org.gradle.jvmargs=-Dfile.encoding=UTF-8
```kotlin
wsdl2java {
encoding.set("UTF-8")
}
```

Note that if this option is not set, the encoding defaults to the encoding setting configured at the `compileJava` task.

```kotlin
tasks {
compileJava {
options.encoding = "UTF-8"
}
}
```

If that is also not set, files will ultimately be generated with the platform encoding, which may produce undesired results.

If you are on a POSIX operating system (e.g. Linux), you may in addition to this need to set your operating system locale to one that supports your encoding.
Otherwise, Java (and therefore also Gradle and CXF) may not be able to create files with names outside of what your default locale supports.
Especially some Docker images, like the Java ECR images from AWS, are by default set to a locale supporting ASCII only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ open class Wsdl2JavaPluginExtension @Inject constructor(objects: ObjectFactory,
val verbose = objects.property(Boolean::class.java).convention(true)
val suppressGeneratedDate = objects.property(Boolean::class.java).convention(true)
val markGenerated = objects.property(String::class.java).convention(MARK_GENERATED_NO)
val encoding = objects.property(String::class.java)

companion object {
@JvmStatic
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/com/github/bjornvester/wsdl2java/Wsdl2JavaTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.internal.file.FileOperations
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.*
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.workers.WorkerExecutor
import javax.inject.Inject

Expand Down Expand Up @@ -50,6 +53,10 @@ open class Wsdl2JavaTask @Inject constructor(
@Optional
val markGenerated = objects.property(String::class.java).convention(getWsdl2JavaExtension().markGenerated)

@get:Input
@Optional
val encoding = objects.property(String::class.java).convention(getWsdl2JavaExtension().encoding)

@get:Classpath
val wsdl2JavaConfiguration = project.configurations.named(WSDL2JAVA_CONFIGURATION_NAME)

Expand Down Expand Up @@ -157,6 +164,17 @@ open class Wsdl2JavaTask @Inject constructor(
defaultArgs.add("-verbose")
}

if (encoding.isPresent) {
defaultArgs.addAll(listOf("-encoding", encoding.get()))
} else {
// JavaCompile.options.encoding is nullable so task.map{} cannot be effectively used
// https://github.com/gradle/gradle/issues/12388
val javaCompile = project.tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, JavaCompile::class.java).get()
javaCompile.options.encoding?.let {
defaultArgs.addAll(listOf("-encoding", it))
}
}

if (bindingFile.isPresent) {
defaultArgs.addAll(
listOf(
Expand All @@ -181,6 +199,7 @@ open class Wsdl2JavaTask @Inject constructor(
if (options.isPresent) {
val prohibitedOptions = mapOf(
"-verbose" to "Configured through the 'verbose' property",
"-encoding" to "Configured through the 'encoding' property",
"-d" to "Configured through the 'generatedSourceDir' property",
"-b" to "Configured through the 'bindingFile' property",
"-suppress-generated-date" to "Configured through the 'suppressGeneratedDate' property",
Expand Down

0 comments on commit dfa7fec

Please sign in to comment.