Skip to content

Commit

Permalink
Change bindingFiles into a configurableFileCollection for better lazy…
Browse files Browse the repository at this point in the history
… evaluation of configurations
  • Loading branch information
bjornvester committed Jun 18, 2023
1 parent 0eb1635 commit 19fe642
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ e.g. like this:

```kotlin
plugins {
id("com.github.bjornvester.xjc") version "1.8.0"
id("com.github.bjornvester.xjc") version "1.8.1"
}
```

Expand All @@ -44,7 +44,7 @@ Here is a list of all available properties:
| xsdDir | DirectoryProperty | "$projectDir/src<br>/main/resources" | The directory holding the xsd files to compile. |
| includes | ListProperty\<String> | \[empty\] | An optional include pattern for the files in the xsdDir property |
| excludes | ListProperty\<String> | \[empty\] | An optional exclude pattern for the files in the xsdDir property |
| bindingFiles | FileCollection | xsdDir.asFileTree.matching<br> { include("**/*.xjb") } | The binding files to use in the schema compiler |
| bindingFiles | ConfigurableFileCollection | xsdDir.asFileTree.matching<br> { include("**/*.xjb") } | The binding files to use in the schema compiler |
| outputJavaDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/java" | The output directory for the generated Java sources.<br>Note that it will be deleted when running XJC. |
| outputResourcesDir | DirectoryProperty | "$buildDir/generated<br>/sources/xjc/resources" | The output directory for the generated resources (if any).<br>Note that it will be deleted when running XJC. |
| useJakarta | Provider\<Boolean> | true | Set to use the `jakarta` namespace. If false, uses the `javax` namespace. This value determines the default version of XJC and the JAXB binding provider. |
Expand Down Expand Up @@ -175,7 +175,7 @@ You can also provide your own binding files (or custom episode files) through th

```kotlin
xjc {
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") } // Files with an .xjb extension in the "src/main/xjb" directory
bindingFiles.setFrom(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }) // Files with an .xjb extension in the "src/main/xjb" directory
}
```

Expand Down Expand Up @@ -243,7 +243,7 @@ Lastly, for both `jakarta` and `javax`, configure the plugin to use the binding

```kotlin
xjc {
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }
bindingFiles.setFrom(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") })
}
```

Expand Down
6 changes: 2 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "com.github.bjornvester"
version = "1.8.0"
version = "1.8.1"

repositories {
mavenCentral()
Expand Down Expand Up @@ -45,9 +45,7 @@ gradlePlugin {
displayName = "Gradle XJC plugin"
tags.set(listOf("xjc", "jaxb", "xsd"))
description = """Changes:
|- Fixed an issue with specifying binding files.
|- Fixed an issue with missing logging output from XJC.
|- Removed the xsdFiles configuration and added an includes and excludes configuration.""".trimMargin()
|- Fixed another issue with custom location of binding files.""".trimMargin()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

xjc {
xsdDir.set(layout.projectDirectory.dir("src/main/xsd"))
bindingFiles = layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") }
bindingFiles.setFrom(layout.projectDirectory.dir("src/main/xjb").asFileTree.matching { include("**/*.xjb") })
}

dependencies {
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/com/github/bjornvester/xjc/XjcExtension.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.bjornvester.xjc

import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.file.FileCollection
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import javax.inject.Inject
Expand All @@ -12,14 +11,14 @@ open class XjcExtension @Inject constructor(objects: ObjectFactory, layout: Proj
val addCompilationDependencies = objects.property(Boolean::class.java).convention(true)

override val name = "Defaults"
override val xsdDir = objects.directoryProperty().convention(layout.projectDirectory.dir("src/main/resources"))
final override val xsdDir = objects.directoryProperty().convention(layout.projectDirectory.dir("src/main/resources"))
override val includes = objects.listProperty(String::class.java).convention(listOf("**/*.xsd"))
override val excludes = objects.listProperty(String::class.java)
override val outputJavaDir = objects.directoryProperty().convention(layout.buildDirectory.dir("generated/sources/xjc/java"))
override val outputResourcesDir = objects.directoryProperty().convention(layout.buildDirectory.dir("generated/sources/xjc/resources"))
override val defaultPackage = objects.property(String::class.java)
override val generateEpisode = objects.property(Boolean::class.java).convention(false)
override var bindingFiles: FileCollection = xsdDir.asFileTree.matching { include("**/*.xjb") }
override val bindingFiles = objects.fileCollection().from(xsdDir.asFileTree.matching { include("**/*.xjb") })
override val options = objects.listProperty(String::class.java)
override val markGenerated = objects.property(Boolean::class.java).convention(false)

Expand All @@ -34,7 +33,7 @@ open class XjcExtension @Inject constructor(objects: ObjectFactory, layout: Proj
outputResourcesDir.convention(layout.buildDirectory.dir("generated/sources/xjc-$name/resources"))
defaultPackage.convention(this@XjcExtension.defaultPackage)
generateEpisode.convention(this@XjcExtension.generateEpisode)
bindingFiles = this@XjcExtension.bindingFiles
bindingFiles.setFrom(this@XjcExtension.bindingFiles)
options.convention(this@XjcExtension.options)
markGenerated.convention(this@XjcExtension.markGenerated)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.bjornvester.xjc

import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property

Expand All @@ -14,7 +14,7 @@ interface XjcExtensionGroup {
val outputResourcesDir: DirectoryProperty
val defaultPackage: Property<String>
val generateEpisode: Property<Boolean>
var bindingFiles: FileCollection
val bindingFiles: ConfigurableFileCollection
val options: ListProperty<String>
val markGenerated: Property<Boolean>
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/bjornvester/xjc/XjcPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class XjcPlugin : Plugin<Project> {
xjcConfiguration.from(project.configurations.named(XJC_CONFIGURATION_NAME))
xjcBindConfiguration.from(project.configurations.named(XJC_BIND_CONFIGURATION_NAME))
xjcPluginsConfiguration.from(project.configurations.named(XJC_PLUGINS_CONFIGURATION_NAME))
bindingFiles = group.bindingFiles
bindingFiles.setFrom(group.bindingFiles)

val sourceSets = project.properties["sourceSets"] as SourceSetContainer

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/github/bjornvester/xjc/XjcTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ open class XjcTask @Inject constructor(
@Optional
@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
var bindingFiles = getXjcExtension().bindingFiles
val bindingFiles = getXjcExtension().bindingFiles

@get:Input
val options: ListProperty<String> = objectFactory.listProperty(String::class.java).convention(getXjcExtension().options)
Expand Down

0 comments on commit 19fe642

Please sign in to comment.