├── .github ├── requirements.txt ├── renovate.json └── workflows │ ├── wait-for-checks.yml │ ├── quality-renovate.yml │ ├── quality-ci.yml │ ├── gradle-wrapper-validation.yml │ ├── demo-java-ci.yml │ ├── plugin-release-ci.yml │ ├── delete-workflow-runs.yml │ └── plugin-build-ci.yml ├── .gitattributes ├── .gitignore ├── internal ├── common │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── utils.kt ├── plugins │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ ├── org │ │ │ └── jsonschema2dataclass │ │ │ │ └── internal │ │ │ │ └── plugin │ │ │ │ ├── base │ │ │ │ ├── GitVersionPlugin.kt │ │ │ │ ├── SettingEnterpriseAccept.kt │ │ │ │ └── GitVersion.kt │ │ │ │ ├── lib │ │ │ │ ├── LibraryPlugin.kt │ │ │ │ ├── GradlePlugin.kt │ │ │ │ ├── KotlinToolchain.kt │ │ │ │ └── ProcessorVersionPlugin.kt │ │ │ │ └── publishing │ │ │ │ ├── signing.kt │ │ │ │ ├── PublishingPlugin.kt │ │ │ │ └── publishing.kt │ │ │ └── EnableFeaturePreviewQuietly.kt │ └── build.gradle.kts └── settings.gradle.kts ├── gradle.properties ├── demo └── java │ ├── gradle.properties │ ├── classpath │ ├── schema │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── resources │ │ │ └── schema │ │ │ └── bar.json │ ├── custom-rule-factory │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── jsonschema2dataclass │ │ │ └── example │ │ │ ├── CustomRuleFactory.java │ │ │ └── CustomFormatRule.java │ ├── custom-rule-factory-apply │ │ ├── src │ │ │ └── main │ │ │ │ └── resources │ │ │ │ └── json │ │ │ │ └── custom-factory.json │ │ ├── gradle.properties │ │ └── build.gradle.kts │ └── schema-reference │ │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── schema │ │ │ └── foo.json │ │ └── build.gradle.kts │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── kotlin │ ├── src │ │ └── main │ │ │ ├── kotlin │ │ │ └── org │ │ │ │ └── js2d │ │ │ │ └── AddressWork.kt │ │ │ └── resources │ │ │ └── json │ │ │ ├── external_dependencies.json │ │ │ └── address.json │ └── build.gradle.kts │ ├── groovy │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── js2d │ │ │ │ └── AddressWork.java │ │ │ └── resources │ │ │ └── json │ │ │ ├── external_dependencies.json │ │ │ └── address.json │ └── build.gradle │ ├── model-publish │ ├── src │ │ └── main │ │ │ └── resources │ │ │ └── json │ │ │ ├── external_dependencies.json │ │ │ └── address.json │ └── build.gradle.kts │ ├── build.gradle.kts │ ├── settings.gradle.kts │ └── gradlew.bat ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── processors.toml ├── libs.dependencies.toml ├── plugins.dependencies.toml └── init.gradle.kts ├── plugin-gradle ├── common │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ └── org │ │ │ └── jsonschema2dataclass │ │ │ ├── ext │ │ │ ├── package-info.java │ │ │ └── Js2pExtension.kt │ │ │ └── internal │ │ │ ├── Js2dProcessor.kt │ │ │ ├── RegisterTasks.kt │ │ │ └── task │ │ │ ├── Consts.kt │ │ │ └── Js2dGeneratorTaskBase.kt │ └── build.gradle.kts ├── compat │ ├── kotlin │ │ ├── build.gradle.kts │ │ └── src │ │ │ └── main │ │ │ └── kotlin │ │ │ └── org │ │ │ └── jsonschema2dataclass │ │ │ └── internal │ │ │ └── compat │ │ │ └── kotlin │ │ │ ├── TestsNeeded.kt │ │ │ └── KotlinCompat.kt │ └── java │ │ ├── build.gradle.kts │ │ └── src │ │ └── main │ │ └── kotlin │ │ └── org │ │ └── jsonschema2dataclass │ │ └── internal │ │ └── compat │ │ └── java │ │ └── JavaPluginRegistration.kt ├── processors │ └── jsonschema2pojo │ │ ├── src │ │ ├── main │ │ │ └── kotlin │ │ │ │ └── org │ │ │ │ └── jsonschema2dataclass │ │ │ │ └── internal │ │ │ │ └── js2p │ │ │ │ ├── Js2pGenerationTask.kt │ │ │ │ ├── Js2pWorker.kt │ │ │ │ ├── Js2pProcessor.kt │ │ │ │ └── Js2pWokerConfig.kt │ │ └── test │ │ │ └── kotlin │ │ │ └── org │ │ │ └── jsonschema2dataclass │ │ │ └── internal │ │ │ ├── Randomizer.kt │ │ │ └── js2p │ │ │ ├── WorkerConvertTest.kt │ │ │ ├── Randomizer.kt │ │ │ └── SimpleGenerationConfig.kt │ │ └── build.gradle.kts └── plugin │ ├── src │ ├── main │ │ └── kotlin │ │ │ └── org │ │ │ └── jsonschema2dataclass │ │ │ ├── internal │ │ │ ├── Checks.kt │ │ │ └── TaskGeneration.kt │ │ │ └── Js2dPlugin.kt │ └── test │ │ └── kotlin │ │ └── org │ │ └── jsonschema2dataclass │ │ └── js2p │ │ ├── TestUtils.kt │ │ ├── internal │ │ └── NameGeneratorTest.kt │ │ ├── GradleVersions.kt │ │ ├── TestCasesGenerator.kt │ │ └── JavaTaskFunctionalTest.kt │ └── build.gradle.kts ├── docs ├── migration │ ├── migration.adoc │ ├── migration_5.adoc │ └── migration_6.adoc └── usage │ ├── index.adoc │ ├── basic.adoc │ ├── basic_5.adoc │ ├── basic_2.adoc │ ├── basic_3.adoc │ ├── basic_4.adoc │ └── basic_6.adoc ├── .pre-commit-config.yaml ├── .editorconfig ├── settings.gradle.kts ├── README.adoc └── gradlew.bat /.github/requirements.txt: -------------------------------------------------------------------------------- 1 | pre-commit==4.5.0 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | gradlew text eol=lf 2 | gradlew.bat text eol=crlf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.hprof 2 | .idea 3 | .gradle 4 | build 5 | local.properties 6 | -------------------------------------------------------------------------------- /internal/common/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl-base` 3 | } 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 2 | org.gradle.warning.mode=all 3 | org.gradle.priority=low 4 | -------------------------------------------------------------------------------- /demo/java/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 2 | org.gradle.warning.mode=all 3 | org.gradle.priority=low 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/java/classpath/schema/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | tasks.named("jar") { 6 | enabled = true 7 | } 8 | -------------------------------------------------------------------------------- /demo/java/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jsonschema2dataclass/js2d-gradle/HEAD/demo/java/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/ext/package-info.java: -------------------------------------------------------------------------------- 1 | /** All Gradle Extensions are defined here. */ 2 | package org.jsonschema2dataclass.ext; 3 | -------------------------------------------------------------------------------- /docs/migration/migration.adoc: -------------------------------------------------------------------------------- 1 | = Migration guide list 2 | 3 | * xref:migration_5.adoc[Migration from 4.x and below to 5.0] 4 | * xref:migration_6.adoc[Migration from 5.x to 6.0] 5 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | } 4 | 5 | dependencies { 6 | compileOnly("org.jsonschema2pojo:jsonschema2pojo-core:1.2.2") 7 | } 8 | -------------------------------------------------------------------------------- /demo/java/kotlin/src/main/kotlin/org/js2d/AddressWork.kt: -------------------------------------------------------------------------------- 1 | import example.Address 2 | 3 | class AddressWork { 4 | fun work() { 5 | val address = Address() 6 | address.setRegion("Region") 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory-apply/src/main/resources/json/custom-factory.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "base64-field": { 4 | "format": "base64", 5 | "type": "string" 6 | } 7 | }, 8 | "type": "object" 9 | } 10 | -------------------------------------------------------------------------------- /plugin-gradle/compat/kotlin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl-base` 3 | id("org.jsonschema2dataclass.internal.library") 4 | } 5 | 6 | base.archivesName.set("jsonschema2dataclass-kotlin-compat") 7 | description = "Plugin Kotlin Compat: Kotlin compatibility functions" 8 | -------------------------------------------------------------------------------- /demo/java/groovy/src/main/java/org/js2d/AddressWork.java: -------------------------------------------------------------------------------- 1 | package org.js2d; 2 | 3 | import example.Address; 4 | 5 | public class AddressWork { 6 | public void work() { 7 | Address address = new Address(); 8 | address.setRegion("Region"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /plugin-gradle/common/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl-base` 3 | id("org.jsonschema2dataclass.internal.library") 4 | } 5 | 6 | base.archivesName.set("jsonschema2dataclass-plugin-common") 7 | description = "Common processor compatibility layer: Compatibility layer for schema processors." 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /demo/java/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /demo/java/groovy/src/main/resources/json/external_dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "An example on how to reference pre-existing classes", 3 | "properties": { 4 | "a_joda_time_object": { 5 | "existingJavaType": "org.joda.time.DateTime", 6 | "type": "object" 7 | } 8 | }, 9 | "type": "object" 10 | } 11 | -------------------------------------------------------------------------------- /demo/java/kotlin/src/main/resources/json/external_dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "An example on how to reference pre-existing classes", 3 | "properties": { 4 | "a_joda_time_object": { 5 | "existingJavaType": "org.joda.time.DateTime", 6 | "type": "object" 7 | } 8 | }, 9 | "type": "object" 10 | } 11 | -------------------------------------------------------------------------------- /demo/java/model-publish/src/main/resources/json/external_dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "An example on how to reference pre-existing classes", 3 | "properties": { 4 | "a_joda_time_object": { 5 | "existingJavaType": "org.joda.time.DateTime", 6 | "type": "object" 7 | } 8 | }, 9 | "type": "object" 10 | } 11 | -------------------------------------------------------------------------------- /gradle/processors.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | # Jsonschema2pojo processor 3 | # Versions: https://github.com/joelittlejohn/jsonschema2pojo/releases 4 | processor-jsonschema2pojo = "1.2.2" 5 | 6 | [libraries] 7 | # Plugin Schema processors 8 | jsonschema2pojo = {module = "org.jsonschema2pojo:jsonschema2pojo-core", version.ref="processor-jsonschema2pojo"} 9 | -------------------------------------------------------------------------------- /demo/java/classpath/schema/src/main/resources/schema/bar.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "additionalProperties": false, 4 | "properties": { 5 | "id": { 6 | "type": "string" 7 | }, 8 | "name": { 9 | "type": "string" 10 | } 11 | }, 12 | "title": "Metadata", 13 | "type": "object" 14 | } 15 | -------------------------------------------------------------------------------- /plugin-gradle/compat/java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl-base` 3 | id("org.jsonschema2dataclass.internal.library") 4 | } 5 | 6 | base.archivesName.set("jsonschema2dataclass-java-plugin-compat") 7 | description = "Java Plugin Compatibility layer: Compatibility layer for Java Plugin." 8 | 9 | dependencies { 10 | implementation(projects.pluginGradle.common) 11 | } 12 | -------------------------------------------------------------------------------- /demo/java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("org.jsonschema2dataclass") version "6.0.0" apply false 3 | } 4 | 5 | subprojects { 6 | if (project.plugins.hasPlugin("java")) { 7 | project.extensions.configure { 8 | toolchain.languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion.toInt())) 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "commitMessageExtra": "from {{{currentValue}}} to {{{newValue}}}{{#if isMajor}} (major v{{{newMajor}}}){{else}}{{/if}}", 4 | "extends": [ 5 | "config:base" 6 | ], 7 | "pre-commit": { 8 | "enabled": true 9 | }, 10 | "separateMajorMinor": true, 11 | "separateMinorPatch": true, 12 | "separateMultipleMajor": true 13 | } 14 | -------------------------------------------------------------------------------- /plugin-gradle/compat/kotlin/src/main/kotlin/org/jsonschema2dataclass/internal/compat/kotlin/TestsNeeded.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.compat.kotlin 2 | 3 | @Target( 4 | AnnotationTarget.CLASS, 5 | AnnotationTarget.FUNCTION, 6 | AnnotationTarget.TYPE_PARAMETER, 7 | AnnotationTarget.VALUE_PARAMETER, 8 | AnnotationTarget.EXPRESSION, 9 | ) 10 | @Retention(AnnotationRetention.SOURCE) 11 | annotation class TestsNeeded 12 | -------------------------------------------------------------------------------- /demo/java/classpath/schema-reference/src/main/resources/schema/foo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "additionalProperties": false, 4 | "properties": { 5 | "metadata": { 6 | "$ref": "classpath:/schema/bar.json#", 7 | "existingJavaType": "com.examples.types.Metadata" 8 | }, 9 | "name": { 10 | "type": "string" 11 | } 12 | }, 13 | "title": "Foo", 14 | "type": "object" 15 | } 16 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/GitVersionPlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.base 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | /** Plugin to set project version based on git version. */ 7 | @Suppress("unused") 8 | class GitVersionPlugin : Plugin { 9 | override fun apply(project: Project) { 10 | project.version = gitVersion(project) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory-apply/gradle.properties: -------------------------------------------------------------------------------- 1 | #systemProp.sonar.host.url="http://skat-sonarqube-osm2-sonarqube.ocpt.ccta.dk" 2 | ##org.gradle.daemon=false 3 | #org.gradle.parallel=true 4 | #org.gradle.configureondemand=false 5 | #org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 6 | #org.gradle.caching=true 7 | # 8 | #dockerRepository=osm2-docker-snapshot-local.artifactory.ccta.dk/osm2 9 | # 10 | #systemProp.file.encoding=utf-8 11 | #org.gradle.console=plain 12 | # 13 | #runServiceTests=false 14 | -------------------------------------------------------------------------------- /docs/usage/index.adoc: -------------------------------------------------------------------------------- 1 | = Plugin usage and parameters documentation 2 | 3 | == Version 4.x and below 4 | 5 | Version 4.x and below has mostly the same documentation as 5.x. 6 | 7 | == Version 5.x 8 | 9 | :plugin_major: 5 10 | * xref:basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x] 11 | * xref:parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x] 12 | 13 | == Version 6.x 14 | 15 | :plugin_major: 6 16 | * xref:basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x] 17 | * xref:parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x] 18 | -------------------------------------------------------------------------------- /internal/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "Internal plugins" 2 | 3 | include(":common") 4 | include(":plugins") 5 | 6 | @Suppress("UnstableApiUsage") 7 | dependencyResolutionManagement { 8 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 9 | repositories { 10 | gradlePluginPortal() 11 | mavenCentral() 12 | } 13 | versionCatalogs { 14 | create("libs") { 15 | from(files("../gradle/libs.dependencies.toml")) 16 | } 17 | create("pluginDeps") { 18 | from(files("../gradle/plugins.dependencies.toml")) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.github/workflows/wait-for-checks.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Wait all checks 3 | 4 | on: 5 | pull_request: 6 | types: [assigned, opened, synchronize, reopened] 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | wait-all-checks: 14 | runs-on: ubuntu-latest 15 | permissions: 16 | checks: read 17 | steps: 18 | - name: Wait all GitHub checks 19 | uses: poseidon/wait-for-status-checks@v0.6.0 20 | with: 21 | token: ${{ secrets.GITHUB_TOKEN }} 22 | ignore: wait-all-checks / wait-all-checks 23 | -------------------------------------------------------------------------------- /.github/workflows/quality-renovate.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Verify Quality Checks 3 | 4 | on: 5 | 6 | pull_request: 7 | types: [assigned, opened, synchronize, reopened] 8 | paths: 9 | - .github/renovate.json 10 | - .github/workflows/renovate-verify.yml 11 | 12 | concurrency: 13 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 14 | cancel-in-progress: true 15 | 16 | jobs: 17 | verify-renovate: 18 | name: Renovate official check 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v5 22 | - uses: actions/setup-node@v6 23 | - run: npx --package renovate -c 'renovate-config-validator' 24 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory-apply/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | id("org.jsonschema2dataclass") 4 | } 5 | 6 | dependencies { 7 | jsonschema2dataclassPlugins(project(":classpath:custom-rule-factory")) 8 | 9 | implementation("com.fasterxml.jackson.core:jackson-databind:2.20.1") 10 | } 11 | 12 | jsonSchema2Pojo { 13 | executions { 14 | create("main") { 15 | klass.customRuleFactoryClass.set("org.jsonschema2dataclass.example.CustomRuleFactory") 16 | klass.annotationStyle.set("jackson2") 17 | klass.targetPackage.set("org.test") 18 | klass.nameUseTitle.set(true) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo/java/classpath/schema-reference/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-library` 3 | id("org.jsonschema2dataclass") 4 | } 5 | 6 | dependencies { 7 | jsonschema2dataclassPlugins(project(":classpath:schema")) 8 | 9 | implementation("com.fasterxml.jackson.core:jackson-databind:2.20.1") 10 | } 11 | 12 | jsonSchema2Pojo { 13 | executions { 14 | create("main") { 15 | io.source.setFrom(files("src/main/resources/schema/foo.json")) 16 | klass.annotationStyle.set("jackson2") 17 | klass.annotateGenerated.set(false) 18 | klass.targetPackage.set("org.test") 19 | klass.nameUseTitle.set(true) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo/java/groovy/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.jsonschema2dataclass' 4 | } 5 | 6 | dependencies { 7 | implementation 'javax.validation:validation-api:2.0.1.Final' 8 | implementation 'com.fasterxml.jackson.core:jackson-databind:2.20.1' 9 | 10 | // see src/main/resources/json/external_dependencies.json 11 | implementation 'joda-time:joda-time:2.14.0' 12 | } 13 | 14 | jsonSchema2Pojo { 15 | executions{ 16 | main { 17 | io.delimitersPropertyWord = '_' 18 | io.source.setFrom files("${projectDir}/src/main/resources/json") 19 | klass.annotateGenerated = false 20 | klass.targetPackage = 'example' 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/LibraryPlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.lib 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.kotlin.dsl.apply 6 | import org.jsonschema2dataclass.internal.plugin.publishing.PublishingPlugin 7 | 8 | /** 9 | * Support library basic configuration. 10 | * 11 | * Plugin configures Kotlin toolchain (Java version) and publishing to Maven Central 12 | */ 13 | @Suppress("unused") 14 | class LibraryPlugin : Plugin { 15 | override fun apply(project: Project) { 16 | project.plugins.apply(KotlinToolchain::class) 17 | project.plugins.apply(PublishingPlugin::class) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /plugin-gradle/compat/kotlin/src/main/kotlin/org/jsonschema2dataclass/internal/compat/kotlin/KotlinCompat.kt: -------------------------------------------------------------------------------- 1 | /** Kotlin compatibility shims to smooth version differences */ 2 | package org.jsonschema2dataclass.internal.compat.kotlin 3 | 4 | /** Kotlin version independent functions as we support quite wide range of Gradle. */ 5 | 6 | import java.util.Locale 7 | 8 | /** 9 | * Kotlin-independent version of making string uppercase 10 | */ 11 | @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "KotlinConstantConditions") 12 | fun String.asUppercase(): String = (this as java.lang.String).toUpperCase(Locale.ROOT) 13 | 14 | /** Kotlin-independent version of capitalization. */ 15 | fun CharSequence.capitalized(): String = this[0].toString().asUppercase() + substring(1) 16 | -------------------------------------------------------------------------------- /demo/java/kotlin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") version "2.2.21" 3 | id("org.jsonschema2dataclass") 4 | } 5 | 6 | dependencies { 7 | implementation("javax.validation:validation-api:2.0.1.Final") 8 | implementation("com.fasterxml.jackson.core:jackson-databind:2.20.1") 9 | 10 | // see src/main/resources/json/external_dependencies.json 11 | implementation("joda-time:joda-time:2.14.0") 12 | } 13 | 14 | jsonSchema2Pojo { 15 | executions { 16 | create("main") { 17 | io.delimitersPropertyWord.set("_") 18 | io.source.setFrom(files("$projectDir/src/main/resources/json")) 19 | klass.annotateGenerated.set(false) 20 | klass.targetPackage.set("example") 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/Js2dProcessor.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.artifacts.Configuration 5 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase 6 | 7 | /** Processor definition. */ 8 | interface Js2dProcessor { 9 | /** Intended task name and description. */ 10 | fun toolNameForTask(): Pair 11 | 12 | /** Class of a task for a generator. */ 13 | fun generatorTaskClass(): Class> 14 | 15 | /** Add bare minimum tooling dependencies into configuration. */ 16 | fun toolingMinimalDependencies(project: Project, configuration: Configuration) 17 | } 18 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/GradlePlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.lib 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.kotlin.dsl.apply 6 | import org.jsonschema2dataclass.internal.plugin.publishing.applySigning 7 | import pluginIds 8 | 9 | /** 10 | * Gradle Plugin basic configuration. 11 | * 12 | * Plugin configures Kotlin toolchain (Java version), and publishing 13 | */ 14 | @Suppress("unused") 15 | class GradlePlugin : Plugin { 16 | override fun apply(project: Project) { 17 | project.plugins.apply(KotlinToolchain::class) 18 | 19 | applySigning(project) 20 | project.plugins.apply(pluginIds["gradle-publish"]!!) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo/java/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "Json Schema 2 Data Class Java demos" 2 | 3 | // Groovy DSL & Groovy language 4 | include(":groovy") 5 | // Kotlin DSL & Kotlin language 6 | include(":kotlin") 7 | // Example, how to publish models and schemas 8 | include(":model-publish") 9 | // schema for schema-reference example 10 | include(":classpath:schema") 11 | // Use schemas from classpath 12 | include(":classpath:schema-reference") 13 | // Custom rule factory 14 | include(":classpath:custom-rule-factory") 15 | // How to apply custom rule factory 16 | include(":classpath:custom-rule-factory-apply") 17 | 18 | @Suppress("UnstableApiUsage") 19 | dependencyResolutionManagement { 20 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 21 | repositories { 22 | mavenCentral() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory/src/main/java/org/jsonschema2dataclass/example/CustomRuleFactory.java: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.example; 2 | 3 | import com.sun.codemodel.JType; 4 | import org.jsonschema2pojo.Annotator; 5 | import org.jsonschema2pojo.GenerationConfig; 6 | import org.jsonschema2pojo.SchemaStore; 7 | import org.jsonschema2pojo.rules.Rule; 8 | import org.jsonschema2pojo.rules.RuleFactory; 9 | 10 | public class CustomRuleFactory extends RuleFactory { 11 | public CustomRuleFactory(GenerationConfig generationConfig, Annotator annotator, SchemaStore schemaStore) { 12 | super(generationConfig, annotator, schemaStore); 13 | } 14 | 15 | public CustomRuleFactory() {} 16 | 17 | public Rule getFormatRule() { 18 | return new CustomFormatRule(this); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/EnableFeaturePreviewQuietly.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.initialization.Settings 2 | 3 | /** [Feature request](https://github.com/gradle/gradle/issues/19069) */ 4 | @Suppress("unused") 5 | fun Settings.enableFeaturePreviewQuietly(name: String, summary: String) { 6 | enableFeaturePreview(name) 7 | 8 | val logger: Any = org.gradle.util.internal.IncubationLogger::class.java 9 | .getDeclaredField("INCUBATING_FEATURE_HANDLER") 10 | .apply { isAccessible = true } 11 | .get(null) 12 | 13 | @Suppress("UNCHECKED_CAST") 14 | val features: MutableSet = org.gradle.internal.featurelifecycle.LoggingIncubatingFeatureHandler::class.java 15 | .getDeclaredField("features") 16 | .apply { isAccessible = true } 17 | .get(logger) as MutableSet 18 | 19 | features.add(summary) 20 | } 21 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pGenerationTask.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.gradle.api.tasks.CacheableTask 4 | import org.gradle.workers.WorkQueue 5 | import org.gradle.workers.WorkerExecutor 6 | import org.jsonschema2dataclass.ext.Js2pConfiguration 7 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase 8 | import javax.inject.Inject 9 | 10 | @CacheableTask 11 | internal abstract class Js2pGenerationTask @Inject constructor( 12 | workerExecutor: WorkerExecutor, 13 | ) : Js2dGeneratorTaskBase(workerExecutor) { 14 | override fun submit(workQueue: WorkQueue) { 15 | val js2pConfig = Js2pWorkerConfig.fromConfig(uuid, targetDirectory.asFile.get(), configuration) 16 | workQueue.submit(Js2pWorker::class.java) { 17 | config = js2pConfig 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /demo/java/classpath/custom-rule-factory/src/main/java/org/jsonschema2dataclass/example/CustomFormatRule.java: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.example; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.sun.codemodel.JType; 5 | import java.util.Base64; 6 | import org.jsonschema2pojo.Schema; 7 | import org.jsonschema2pojo.rules.FormatRule; 8 | import org.jsonschema2pojo.rules.RuleFactory; 9 | 10 | public class CustomFormatRule extends FormatRule { 11 | 12 | protected CustomFormatRule(RuleFactory ruleFactory) { 13 | super(ruleFactory); 14 | } 15 | 16 | @Override 17 | public JType apply(String nodeName, JsonNode node, JsonNode parent, JType baseType, Schema schema) { 18 | if ("base64".equals(node.asText())) { 19 | return baseType.owner()._ref(Base64.class); 20 | } else { 21 | return super.apply(nodeName, node, parent, baseType, schema); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /demo/java/groovy/src/main/resources/json/address.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "extended_address": "street_address", 4 | "post_office_box": "street_address" 5 | }, 6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard", 7 | "properties": { 8 | "address": { 9 | "items": "string", 10 | "type": "array" 11 | }, 12 | "country_name": { 13 | "required": true, 14 | "type": "string" 15 | }, 16 | "extended_address": { 17 | "type": "string" 18 | }, 19 | "locality": { 20 | "required": true, 21 | "type": "string" 22 | }, 23 | "post_office_box": { 24 | "type": "string" 25 | }, 26 | "postal_code": { 27 | "type": "string" 28 | }, 29 | "region": { 30 | "required": true, 31 | "type": "string" 32 | }, 33 | "street_address": { 34 | "type": "string" 35 | } 36 | }, 37 | "type": "object" 38 | } 39 | -------------------------------------------------------------------------------- /demo/java/kotlin/src/main/resources/json/address.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "extended_address": "street_address", 4 | "post_office_box": "street_address" 5 | }, 6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard", 7 | "properties": { 8 | "address": { 9 | "items": "string", 10 | "type": "array" 11 | }, 12 | "country_name": { 13 | "required": true, 14 | "type": "string" 15 | }, 16 | "extended_address": { 17 | "type": "string" 18 | }, 19 | "locality": { 20 | "required": true, 21 | "type": "string" 22 | }, 23 | "post_office_box": { 24 | "type": "string" 25 | }, 26 | "postal_code": { 27 | "type": "string" 28 | }, 29 | "region": { 30 | "required": true, 31 | "type": "string" 32 | }, 33 | "street_address": { 34 | "type": "string" 35 | } 36 | }, 37 | "type": "object" 38 | } 39 | -------------------------------------------------------------------------------- /demo/java/model-publish/src/main/resources/json/address.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "extended_address": "street_address", 4 | "post_office_box": "street_address" 5 | }, 6 | "description": "An Address following the convention of http://microformats.org/wiki/hcard", 7 | "properties": { 8 | "address": { 9 | "items": "string", 10 | "type": "array" 11 | }, 12 | "country_name": { 13 | "required": true, 14 | "type": "string" 15 | }, 16 | "extended_address": { 17 | "type": "string" 18 | }, 19 | "locality": { 20 | "required": true, 21 | "type": "string" 22 | }, 23 | "post_office_box": { 24 | "type": "string" 25 | }, 26 | "postal_code": { 27 | "type": "string" 28 | }, 29 | "region": { 30 | "required": true, 31 | "type": "string" 32 | }, 33 | "street_address": { 34 | "type": "string" 35 | } 36 | }, 37 | "type": "object" 38 | } 39 | -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/RegisterTasks.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.Project 5 | import org.gradle.api.Task 6 | import org.gradle.api.tasks.TaskProvider 7 | import org.jsonschema2dataclass.internal.task.DEFAULT_SCHEMA_PATH 8 | import java.nio.file.Path 9 | 10 | typealias ProcessorRegistrationCallback = ( 11 | suffixes: Map, 12 | registerDependencies: (taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action) -> Unit, 13 | ) -> Unit 14 | 15 | interface GradlePluginRegistration { 16 | fun defaultSchemaPath(project: Project): Path = defaultSchemaPathInternal( 17 | project, 18 | ) ?: project.file(DEFAULT_SCHEMA_PATH).toPath() 19 | 20 | fun defaultSchemaPathInternal(project: Project): Path? 21 | 22 | fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback) 23 | } 24 | -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/task/Consts.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.task 2 | 3 | /** Plugin ID to refer in messages */ 4 | const val PLUGIN_ID = "org.jsonschema2dataclass" 5 | 6 | /** Configuration name for tools */ 7 | const val JS2D_CONFIGURATION_NAME = "jsonschema2dataclass" 8 | 9 | /** Configuration to put plugin dependencies to */ 10 | const val JS2D_PLUGINS_CONFIGURATION_NAME = "jsonschema2dataclassPlugins" 11 | 12 | /** Default schema locations under project name. Should be changed */ 13 | const val DEFAULT_SCHEMA_PATH = "src/main/json" 14 | 15 | /** Default folder to store generated files under build folder */ 16 | const val DEFAULT_TARGET_FOLDER_BASE = "generated/sources/js2d" 17 | 18 | /** Extension name for jsonschema2pojo processor */ 19 | const val JS2P_EXTENSION_NAME = "jsonSchema2Pojo" 20 | 21 | /** Base task name for jsonschema2pojo processor */ 22 | const val JS2D_TASK_NAME = "generateJsonSchema2DataClass" 23 | 24 | /** Processor name to generate task names */ 25 | const val JS2P_TOOL_NAME = "Js2p" 26 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/KotlinToolchain.kt: -------------------------------------------------------------------------------- 1 | 2 | package org.jsonschema2dataclass.internal.plugin.lib 3 | 4 | import org.gradle.api.JavaVersion 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | import org.gradle.api.plugins.JavaPluginExtension 8 | import org.gradle.jvm.toolchain.JavaLanguageVersion 9 | import org.gradle.kotlin.dsl.configure 10 | 11 | /** Target java version to build plugin code with. */ 12 | private const val TARGET_JAVA_VERSION = 8 13 | 14 | /** Configure Java 8 toolchain for build Java versions >= 11. */ 15 | @Suppress("unused") 16 | class KotlinToolchain : Plugin { 17 | override fun apply(project: Project) { 18 | // Configure Java 8 toolchain for the latest JVM 19 | if (JavaVersion.current() >= JavaVersion.VERSION_11) { 20 | project.extensions.configure { 21 | withSourcesJar() 22 | toolchain.languageVersion.set(JavaLanguageVersion.of(TARGET_JAVA_VERSION)) 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/quality-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Verify Quality Checks 3 | 4 | on: 5 | pull_request: 6 | types: [assigned, opened, synchronize, reopened] 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 10 | cancel-in-progress: true 11 | 12 | env: 13 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false 14 | 15 | jobs: 16 | pre-commit: 17 | name: Pre-commit checks 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v5 21 | - uses: actions/setup-python@v6 22 | with: 23 | python-version: '3.14' 24 | cache: pip 25 | - name: Install dependencies 26 | run: | 27 | pip install -U pip setuptools wheel 28 | pip install -r .github/requirements.txt 29 | - uses: actions/cache@v4 30 | with: 31 | path: ~/.cache/pre-commit/ 32 | key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} 33 | - name: Run pre-commit hooks 34 | run: pre-commit run --all-files --show-diff-on-failure 35 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/SettingEnterpriseAccept.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.base 2 | 3 | import com.gradle.develocity.agent.gradle.DevelocityConfiguration 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.initialization.Settings 6 | import org.gradle.kotlin.dsl.findByType 7 | 8 | /** Configure Gradle Develocity plugin (former Gralde Enterprise) in settings.gradle.kts */ 9 | @Suppress("unused") 10 | class SettingEnterpriseAccept : Plugin { 11 | override fun apply(settings: Settings) { 12 | if (settings.plugins.hasPlugin("com.gradle.develocity")) { 13 | settings.extensions.findByType()?.apply { 14 | buildScan { 15 | termsOfUseUrl.set("https://gradle.com/terms-of-service") 16 | termsOfUseAgree.set("yes") 17 | publishing.onlyIf { 18 | it.buildResult.failures.isNotEmpty() 19 | } 20 | } 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/signing.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.publishing 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.kotlin.dsl.configure 5 | import org.gradle.kotlin.dsl.provideDelegate 6 | import org.gradle.plugins.signing.SigningExtension 7 | 8 | /** 9 | * -PsigningKey to gradlew, or ORG_GRADLE_PROJECT_signingKey env var 10 | * 11 | * -PsigningPassword to gradlew, or ORG_GRADLE_PROJECT_signingPassword env var 12 | */ 13 | fun applySigning(project: Project): Boolean { 14 | // val signingKeyId: String? by project // Gradle 6+ only 15 | val signingKey: String? by project 16 | val signingPassword: String? by project 17 | 18 | val credentials = if (signingKey != null && signingPassword != null) { 19 | signingKey to signingPassword 20 | } else { 21 | return false 22 | } 23 | 24 | project.plugins.apply("signing") 25 | project.configure { 26 | useInMemoryPgpKeys(credentials.first, credentials.second) 27 | } 28 | return true 29 | } 30 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl-base` 3 | id("org.jsonschema2dataclass.internal.library") 4 | id("org.jsonschema2dataclass.internal.processor-version") 5 | } 6 | 7 | base.archivesName.set("jsonschema2dataclass-processor-jsonschema2pojo") 8 | description = "Jsonschema2pojo schema processor compatibility layer: Compatibility layer for Jsonschema2pojo processor." 9 | 10 | processorVersion { 11 | library.set("jsonschema2pojo") 12 | } 13 | 14 | dependencies { 15 | compileOnly(processors.jsonschema2pojo) 16 | implementation(projects.pluginGradle.compat.kotlin) 17 | implementation(projects.pluginGradle.common) 18 | 19 | testImplementation(libs.bundles.junit.tests) 20 | testRuntimeOnly(libs.bundles.junit.runtime) 21 | testImplementation(gradleTestKit()) 22 | 23 | testImplementation(processors.jsonschema2pojo) 24 | } 25 | 26 | tasks.test { 27 | useJUnitPlatform() 28 | systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_method") 29 | systemProperty("junit.jupiter.execution.parallel.enabled", "true") 30 | } 31 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | repos: 3 | - repo: https://github.com/pre-commit/pre-commit-hooks 4 | rev: v6.0.0 5 | hooks: 6 | - id: check-case-conflict 7 | - id: check-merge-conflict 8 | - id: check-json 9 | - id: check-symlinks 10 | - id: end-of-file-fixer 11 | - id: pretty-format-json 12 | args: [--autofix] 13 | - id: trailing-whitespace 14 | - repo: https://github.com/Lucas-C/pre-commit-hooks 15 | rev: v1.5.5 16 | hooks: 17 | - id: forbid-crlf 18 | exclude: .*gradlew.bat 19 | - id: forbid-tabs 20 | - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt 21 | rev: 0.2.3 22 | hooks: 23 | - id: yamlfmt 24 | args: [--mapping, '2', --sequence, '2', --offset, '0', --width, '150'] 25 | - repo: https://github.com/python-jsonschema/check-jsonschema 26 | rev: 0.35.0 27 | hooks: 28 | - id: check-github-workflows 29 | - id: check-renovate 30 | - repo: https://github.com/eirnym/language-formatters-pre-commit-hooks 31 | rev: 2.14.2 32 | hooks: 33 | - id: pretty-format-kotlin 34 | args: [--autofix] 35 | - id: pretty-format-java 36 | args: [--autofix, --palantir] 37 | -------------------------------------------------------------------------------- /gradle/libs.dependencies.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | # JUnit 5 = JUnit Platform ([junit-api]) + JUnit Launcher ([junit-launcher]) 3 | # Changelog: https://junit.org/junit5/docs/current/release-notes/index.html 4 | junit5 = "5.14.1" 5 | junit5-platform = "1.14.1" 6 | 7 | [libraries] 8 | 9 | # Junit for testing 10 | junit-bom = { module = "org.junit:junit-bom", version.ref = "junit5" } 11 | junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" } 12 | junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit5" } 13 | 14 | # JUnit Engines: https://junit.org/junit5/docs/current/user-guide/index.html#running-tests-build-gradle-engines-configure 15 | junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit5" } 16 | 17 | # https://docs.gradle.org/8.4/userguide/upgrading_version_8.html#test_framework_implementation_dependencies 18 | junit-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit5-platform" } 19 | 20 | [bundles] 21 | junit-tests = ["junit-api", "junit-params"] 22 | junit-runtime = ["junit-engine", "junit-launcher"] 23 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/PublishingPlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.publishing 2 | 3 | import javaPluginExtension 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | import org.gradle.kotlin.dsl.configure 7 | import org.gradle.plugin.devel.GradlePluginDevelopmentExtension 8 | 9 | /** 10 | * Heavily inspired by 11 | * [net.twisterrob.gradle](https://github.com/TWiStErRob/net.twisterrob.gradle]) 12 | * publishing code 13 | * 14 | * Disable automated publishing [completed feature 15 | * request](https://github.com/gradle/gradle/issues/11611) - 16 | * not working with gradle-publish plugin version 1.0 and above 17 | * 18 | */ 19 | class PublishingPlugin : Plugin { 20 | override fun apply(project: Project) { 21 | val signing = applySigning(project) 22 | 23 | val javaPluginExtension = project.javaPluginExtension 24 | javaPluginExtension.withSourcesJar() 25 | 26 | applyPublishing(project, signing) 27 | 28 | project.plugins.withId("java-gradle-plugin") { 29 | project.configure { 30 | isAutomatedPublishing = false 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root=true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | tab_width = 4 7 | indent_size = 4 8 | indent_style = space 9 | trim_trailing_whitespace = true 10 | charset = utf-8 11 | 12 | # The JSON files contain newlines inconsistently 13 | [*.json] 14 | indent_size = 2 15 | tab_width = 2 16 | insert_final_newline = false 17 | 18 | [*.{yml,yaml}] 19 | tab_width = 2 20 | indent_size = 2 21 | 22 | [*.diff] 23 | trim_trailing_whitespace = false 24 | 25 | [COMMIT_EDITMSG] 26 | trim_trailing_whitespace = false 27 | 28 | 29 | [*.{kt,kts}] 30 | max_line_length = 120 31 | ktlint_standard_no-wildcard-imports = enabled 32 | ktlint_standard_filename = disabled 33 | ktlint_standard_multiline-expression-wrapping = disabled 34 | ktlint_standard_string-template-indent = disabled 35 | ktlint_standard_function-signature = disabled 36 | ktlint_standard_annotation = disabled 37 | ktlint_standard_parameter-list-wrapping = disabled 38 | 39 | # enable trailing commas per JetBrains recommendation 40 | # (https://kotlinlang.org/docs/coding-conventions.html#trailing-commas) 41 | ij_kotlin_allow_trailing_comma_on_call_site = true 42 | ij_kotlin_allow_trailing_comma = true 43 | ij_kotlin_name_count_to_use_star_import = 100 44 | ij_kotlin_name_count_to_use_star_import_for_members = 100 45 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "JsonSchema2DataClass" 2 | 3 | pluginManagement { 4 | includeBuild("internal") 5 | } 6 | 7 | plugins { 8 | id("com.gradle.develocity") version "4.2.2" 9 | id("org.jsonschema2dataclass.internal.settings-develocity") 10 | } 11 | 12 | enableFeaturePreviewQuietly("TYPESAFE_PROJECT_ACCESSORS", "Type-safe project accessors") 13 | 14 | // Main plugin 15 | include(":plugin-gradle:plugin") 16 | // common interfaces 17 | include(":plugin-gradle:common") 18 | 19 | // Kotlin language compatibility along Gradle versions 20 | include(":plugin-gradle:compat:kotlin") 21 | // Gradle plugin compatibility 22 | include(":plugin-gradle:compat:java") 23 | 24 | // processors: 25 | include(":plugin-gradle:processors:jsonschema2pojo") 26 | 27 | @Suppress("UnstableApiUsage") 28 | dependencyResolutionManagement { 29 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 30 | repositories { 31 | mavenCentral() 32 | } 33 | versionCatalogs { 34 | create("libs") { 35 | from(files("gradle/libs.dependencies.toml")) 36 | } 37 | create("processors") { 38 | from(files("gradle/processors.toml")) 39 | } 40 | create("pluginDeps") { 41 | from(files("gradle/plugins.dependencies.toml")) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.github/workflows/gradle-wrapper-validation.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Validate Gradle Wrapper 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | paths: 9 | - gradle/wrapper/** 10 | - demo/java/gradle/wrapper/** 11 | - .github/workflows/gradle-wrapper-validation.yml 12 | pull_request: 13 | branches: 14 | - main 15 | paths: 16 | - gradle/wrapper/** 17 | - demo/java/gradle/** 18 | - .github/workflows/gradle-wrapper-validation.yml 19 | 20 | concurrency: 21 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 22 | cancel-in-progress: true 23 | 24 | env: 25 | GRADLE_OPTS: -Dorg.gradle.daemon=false -Dkotlin.incremental=false -Dkotlin.compiler.execution.strategy=in-process 26 | 27 | jobs: 28 | validationPlugin: 29 | name: 'Wrapper validation: Plugin' 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@v5 33 | with: 34 | fetch-depth: 0 35 | - uses: gradle/wrapper-validation-action@v3 36 | validationJavaKotlinSample: 37 | name: 'Wrapper validation: Java Demo' 38 | runs-on: ubuntu-latest 39 | defaults: 40 | run: 41 | working-directory: demo/java 42 | steps: 43 | - uses: actions/checkout@v5 44 | with: 45 | fetch-depth: 0 46 | - uses: gradle/wrapper-validation-action@v3 47 | -------------------------------------------------------------------------------- /.github/workflows/demo-java-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Java Demo CI 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | tags-ignore: 9 | - '*' 10 | paths: 11 | - demo/java/** 12 | - .github/workflows/demo-java-ci.yml 13 | pull_request: 14 | types: [assigned, opened, synchronize, reopened] 15 | paths: 16 | - demo/java/** 17 | - .github/workflows/demo-java-ci.yml 18 | 19 | concurrency: 20 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 21 | cancel-in-progress: true 22 | 23 | env: 24 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false 25 | 26 | jobs: 27 | buildTest: 28 | name: Build Java Demos 29 | runs-on: ubuntu-latest 30 | defaults: 31 | run: 32 | working-directory: demo/java 33 | strategy: 34 | max-parallel: 2 35 | fail-fast: false 36 | matrix: 37 | java_version: [8, 11, 17, 19] 38 | distribution: [zulu, temurin] 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v5 42 | - name: Install JDK ${{ matrix.distribution }} ${{ matrix.java_version }} 43 | uses: actions/setup-java@v5 44 | with: 45 | distribution: ${{ matrix.distribution }} 46 | java-version: ${{ matrix.java_version }} 47 | cache: gradle 48 | - name: Build project Java Demo 49 | run: ./gradlew build -S --scan --warning-mode all 50 | -------------------------------------------------------------------------------- /gradle/plugins.dependencies.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | # https://github.com/gradle-nexus/publish-plugin/releases 3 | nexus = "2.0.0" 4 | 5 | # https://docs.gradle.com/enterprise/gradle-plugin/#release_history 6 | gradle-develocity = "4.2.2" 7 | gradle-publish = "2.0.0" 8 | 9 | # Version of Kotlin Gradle Plugin used for compilation. 10 | kotlin-build = "2.2.21" 11 | 12 | [libraries] 13 | # Plugins as libraries. Used as dependencies for other plugins. it's a bit hacky way, but serves the purpose 14 | # 15 | # WARNING: it's a bit tricky this way to handle moves as gradle doesn't publihs them. 16 | 17 | # Gradle 18 | gradle-develocity = { module = "com.gradle.develocity:com.gradle.develocity.gradle.plugin", version.ref = "gradle-develocity" } 19 | gradle-publish = { module = "com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin", version.ref = "gradle-publish" } 20 | 21 | # Kotlin 22 | kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-build" } 23 | kotlin-gradle-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin-build" } 24 | 25 | [bundles] 26 | 27 | [plugins] 28 | nexus = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus" } 29 | gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradle-publish"} 30 | kotlin-build = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-build"} 31 | # Note: internal plugins cannot be used with `alias(libs.plugins....)`, because they don't have version. 32 | -------------------------------------------------------------------------------- /demo/java/model-publish/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `maven-publish` 3 | kotlin("jvm") version "2.2.21" 4 | id("org.jsonschema2dataclass") 5 | } 6 | 7 | project.group = "com.example" 8 | project.version = "1.0" 9 | 10 | val targetJSONBaseDir = files("$projectDir/src/main/resources/json") 11 | 12 | dependencies { 13 | implementation("com.fasterxml.jackson.core:jackson-databind:2.20.1") 14 | 15 | // see src/main/resources/json/external_dependencies.json 16 | implementation("joda-time:joda-time:2.14.0") 17 | } 18 | 19 | val sourceJar = tasks.create("sourceJar") { 20 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE 21 | from(sourceSets.main.get().allJava) 22 | archiveClassifier.set("sources") 23 | dependsOn("build") 24 | } 25 | 26 | val schemasJar = tasks.create("schemasJar") { 27 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE 28 | from(targetJSONBaseDir) 29 | archiveClassifier.set("schemas") 30 | dependsOn("build") 31 | } 32 | 33 | publishing { 34 | publications { 35 | create("modulePublish") { 36 | artifact(tasks.named("jar")) 37 | artifact(sourceJar) 38 | artifact(schemasJar) 39 | artifactId = "models" 40 | } 41 | } 42 | } 43 | 44 | jsonSchema2Pojo { 45 | executions { 46 | create("main") { 47 | io.source.setFrom(targetJSONBaseDir) 48 | klass.annotateGenerated.set(false) 49 | klass.targetPackage.set(project.group.toString()) 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gradle/init.gradle.kts: -------------------------------------------------------------------------------- 1 | gradle.settingsEvaluated { 2 | val localPublishExtra = "org.jsonschema2dataclass.internal.local-publish" 3 | val localVersionExtra = "org.jsonschema2dataclass.internal.git-version" 4 | if (extra.has(localPublishExtra) && extra[localPublishExtra].toString().toBoolean()) { 5 | val localVersion = extra[localVersionExtra]!!.toString() 6 | pluginManagement { 7 | repositories { 8 | mavenCentral() 9 | gradlePluginPortal() 10 | exclusiveContent { 11 | forRepository { 12 | mavenLocal() 13 | } 14 | filter { 15 | includeGroupByRegex(".*.jsonschema2dataclass.*") 16 | } 17 | } 18 | } 19 | resolutionStrategy { 20 | eachPlugin { 21 | if (requested.id.name == "jsonschema2dataclass" && requested.version != localVersion) { 22 | useModule("org.jsonschema2dataclass:plugin:$localVersion") 23 | } 24 | } 25 | } 26 | } 27 | rootProject { 28 | buildscript { 29 | configurations.forEach { 30 | it.resolutionStrategy.eachDependency { 31 | if (requested.group == "org.jsonschema2dataclass" && requested.version != localVersion) { 32 | useVersion(localVersion) 33 | } 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/Randomizer.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal 2 | 3 | private val random = java.security.SecureRandom() // should we use .asKotlinRandom() here? 4 | private val alphaNumeric = ('a'..'z') + ('A'..'Z') + ('0'..'9') 5 | 6 | /** 7 | * Return random value from list 8 | */ 9 | fun randomValueFromList(values: List): T = values[random.nextInt(values.size)] 10 | 11 | /** 12 | * Return random value from an enum 13 | */ 14 | inline fun > randomEnum(): T = randomValueFromList(enumValues().asList()) 15 | 16 | /** 17 | * Return random alphanumeric list with length (1..11) 18 | */ 19 | fun randomString(len: Int = 10): String = 20 | List(random.nextInt(len) + 1) { randomValueFromList(alphaNumeric) }.joinToString("") 21 | 22 | /** 23 | * Create a random list with random size (0..10) and values with random len (1..11) 24 | */ 25 | fun randomList(size: Int = 10, len: Int = 10) = List(random.nextInt(size)) { randomString(len) } 26 | 27 | /** 28 | * Create a random set with random size (0..10) and values with random len (1..11) 29 | */ 30 | fun randomSet(size: Int = 10, len: Int = 10) = randomList(size, len).toSet() 31 | 32 | /** 33 | * Create a random set with random size (0..10) and keys and values with random len (1..11) 34 | */ 35 | fun randomMap(size: Int = 10, len: Int = 10) = 36 | List(random.nextInt(size)) { randomString(len) to randomString(len) }.toMap() 37 | 38 | /** 39 | * Return random boolean. 40 | */ 41 | fun randomBoolean() = random.nextBoolean() 42 | 43 | /** 44 | * Convert value to null randomly 45 | */ 46 | fun nullable(value: T): T? = if (randomBoolean()) null else value 47 | -------------------------------------------------------------------------------- /internal/common/src/main/kotlin/utils.kt: -------------------------------------------------------------------------------- 1 | 2 | import org.gradle.api.Project 3 | import org.gradle.api.artifacts.VersionCatalogsExtension 4 | import org.gradle.api.plugins.BasePluginExtension 5 | import org.gradle.api.plugins.JavaPluginExtension 6 | import org.gradle.kotlin.dsl.extra 7 | import org.gradle.kotlin.dsl.getByName 8 | 9 | val Project.basePluginExtension: BasePluginExtension 10 | get() = this.extensions.getByName("base") 11 | 12 | val Project.javaPluginExtension: JavaPluginExtension 13 | get() = this.extensions.getByName("java") 14 | 15 | val Project.versionCatalogs: VersionCatalogsExtension 16 | get() = this.extensions.getByName("versionCatalogs") 17 | 18 | fun Project.extraValue(name: String): String? = 19 | if (extra.has(name)) { 20 | extra[name].toString() 21 | } else { 22 | null 23 | } 24 | 25 | fun Project.isExtraEnabled(name: String): Boolean = 26 | project.extraValue(name)?.toBoolean() == true 27 | 28 | val pluginIds = mapOf( 29 | "kotlin-dokka" to "org.jetbrains.dokka", 30 | "nexus-publish" to "io.github.gradle-nexus.publish-plugin", 31 | "gradle-entrprise" to "com.gradle.enterprise", 32 | "gradle-publish" to "com.gradle.plugin-publish", 33 | ) 34 | 35 | /** If set, project version will be set to the value. */ 36 | const val EXTRA_GIT_VERSION_OVERRIDE = "org.jsonschema2dataclass.internal.git-version-override" 37 | 38 | /** If set, project version will be set to the value. */ 39 | const val EXTRA_GIT_VERSION_ENABLE = "org.jsonschema2dataclass.internal.git-version-enable" 40 | 41 | /** If set, gradle plugin will be prepared for a local publication. */ 42 | const val EXTRA_LOCAL_PUBLISH = "org.jsonschema2dataclass.internal.local-publish" 43 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/js2p/WorkerConvertTest.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.gradle.testfixtures.ProjectBuilder 4 | import org.jsonschema2dataclass.ext.Js2pConfiguration 5 | import org.junit.jupiter.api.DisplayName 6 | import org.junit.jupiter.api.RepeatedTest 7 | import org.junit.jupiter.api.assertAll 8 | import java.io.File 9 | import java.util.UUID 10 | 11 | private const val CONFIGURATION_NAME = "random_configuration" 12 | 13 | class WorkerConvertTest { 14 | @RepeatedTest(100) 15 | @DisplayName("single execution") 16 | fun testExtensionConversions() { 17 | // create and randomize extension, 18 | val project = ProjectBuilder.builder().build() 19 | val configuration = randomize( 20 | project.extensions.create( 21 | CONFIGURATION_NAME, 22 | Js2pConfiguration::class.java, 23 | "name", 24 | ), 25 | ) 26 | // convert to an intermediate configuration 27 | val newConfiguration = Js2pWorkerConfig.fromConfig(UUID.randomUUID(), File("/"), configuration) 28 | 29 | // generate "default" config 30 | val simpleConfig = randomizeGenerationConfig() 31 | // create a target configuration 32 | val js2pConfig = Js2pConfig( 33 | File("/"), 34 | newConfiguration.io, 35 | newConfiguration.klass, 36 | newConfiguration.constructors, 37 | newConfiguration.methods, 38 | newConfiguration.fields, 39 | newConfiguration.dateTime, 40 | simpleConfig, 41 | ) 42 | // test if all conversions are correct 43 | assertAll( 44 | { checkIfEqual(configuration, newConfiguration) }, 45 | { checkIfEqual(configuration, js2pConfig, simpleConfig) }, 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/internal/task/Js2dGeneratorTaskBase.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.task 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.file.DirectoryProperty 5 | import org.gradle.api.file.FileCollection 6 | import org.gradle.api.provider.Provider 7 | import org.gradle.api.tasks.Classpath 8 | import org.gradle.api.tasks.Internal 9 | import org.gradle.api.tasks.Nested 10 | import org.gradle.api.tasks.OutputDirectory 11 | import org.gradle.api.tasks.TaskAction 12 | import org.gradle.workers.WorkQueue 13 | import org.gradle.workers.WorkerExecutor 14 | import java.util.UUID 15 | import javax.inject.Inject 16 | 17 | abstract class Js2dGeneratorTaskBase @Inject constructor( 18 | private val workerExecutor: WorkerExecutor, 19 | ) : DefaultTask() { 20 | @get:Nested 21 | abstract var configuration: ConfigType // Should not be 22 | 23 | @get:OutputDirectory 24 | abstract val targetDirectory: DirectoryProperty 25 | 26 | @get:Internal 27 | abstract var uuid: UUID 28 | 29 | @get:Classpath 30 | val js2dConfiguration: Provider = 31 | project.configurations.named(JS2D_CONFIGURATION_NAME) 32 | 33 | @get:Classpath 34 | val js2dConfigurationPlugins: Provider = project.configurations.named( 35 | JS2D_PLUGINS_CONFIGURATION_NAME, 36 | ) 37 | 38 | abstract fun submit(workQueue: WorkQueue) 39 | 40 | @TaskAction 41 | fun action() { 42 | val workerClassPath = js2dConfiguration.get() + js2dConfigurationPlugins 43 | val workQueue = workerExecutor.processIsolation { 44 | // Set encoding (work-around for https://github.com/gradle/gradle/issues/13843) 45 | // TODO: fixed in Gradle 8.3 46 | forkOptions.environment("LANG", System.getenv("LANG") ?: "C.UTF-8") 47 | 48 | classpath.from(workerClassPath) 49 | } 50 | submit(workQueue) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.github/workflows/plugin-release-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release Plugin 3 | 4 | on: 5 | push: 6 | tags: 7 | - v[0-9]+.[0-9]+.[0-9]+ 8 | - v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+ 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false 16 | 17 | jobs: 18 | publish: 19 | name: Publish release 20 | runs-on: ubuntu-latest 21 | environment: production 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v5 25 | with: 26 | fetch-depth: 0 27 | - name: Install JDK 17 28 | uses: actions/setup-java@v5 29 | with: 30 | distribution: temurin 31 | java-version: 17 32 | cache: gradle 33 | - name: Build project 34 | run: ./gradlew build --no-daemon -Porg.jsonschema2dataclass.internal.git-version=true 35 | env: 36 | VERSION: ${{ github.ref }} 37 | - name: Find Tag 38 | id: tagger 39 | uses: jimschubert/query-tag-action@v2 40 | with: 41 | skip-unshallow: 'true' 42 | commit-ish: HEAD 43 | - name: Create Github release 44 | run: | 45 | PRE_RELEASE="" 46 | if [[ ${{steps.tagger.outputs.tag}} == *"beta"* ]]; then 47 | PRE_RELEASE="-p" 48 | fi 49 | if [[ ${{steps.tagger.outputs.tag}} == *"alpha"* ]]; then 50 | PRE_RELEASE="-p" 51 | fi 52 | if [[ ${{steps.tagger.outputs.tag}} == *"rc"* ]]; then 53 | PRE_RELEASE="-p" 54 | fi 55 | set -x 56 | hub release create $PRE_RELEASE -m "${{steps.tagger.outputs.tag}}" "${{steps.tagger.outputs.tag}}" 57 | env: 58 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 59 | VERSION: ${{steps.tagger.outputs.tag}} 60 | - name: Publish 61 | uses: burrunan/gradle-cache-action@v3.0 62 | with: 63 | remote-build-cache-proxy-enabled: false 64 | properties: | 65 | gradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} 66 | gradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} 67 | arguments: publishPlugins -s --scan --no-daemon 68 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/main/kotlin/org/jsonschema2dataclass/internal/Checks.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal 2 | 3 | import org.gradle.api.GradleException 4 | import org.gradle.api.InvalidUserDataException 5 | import org.gradle.api.Named 6 | import org.gradle.api.NamedDomainObjectContainer 7 | import org.gradle.api.Project 8 | import org.gradle.util.GradleVersion 9 | import org.jsonschema2dataclass.internal.task.PLUGIN_ID 10 | 11 | internal const val MINIMUM_GRADLE_VERSION = "6.0" 12 | 13 | /** Verify if gradle version is above minimum */ 14 | internal fun verifyGradleVersion() { 15 | if (GradleVersion.current() < GradleVersion.version(MINIMUM_GRADLE_VERSION)) { 16 | throw GradleException( 17 | "Plugin $PLUGIN_ID requires at least Gradle $MINIMUM_GRADLE_VERSION, " + 18 | "but you are using ${GradleVersion.current().version}", 19 | ) 20 | } 21 | } 22 | 23 | /** All execution names must be a valid identifiers as they are used as part of Gradle Task names */ 24 | private val executionNameRegex = "[a-z][A-Za-z0-9_]*".toRegex() 25 | 26 | /** Verify if execution names are passing the regex */ 27 | internal fun verifyExecutionNames(executions: NamedDomainObjectContainer) { 28 | executions.configureEach { 29 | if (!executionNameRegex.matches(name)) { 30 | throw InvalidUserDataException( 31 | "Plugin $PLUGIN_ID doesn't support execution name \"$name\" provided. " + 32 | "Please, rename to match regex \"$executionNameRegex\"", 33 | ) 34 | } 35 | } 36 | } 37 | 38 | /** Error message if there's no executions defined */ 39 | private const val ERROR_NO_EXECUTION = 40 | "No executions defined, behavior to with default execution has been removed " + 41 | "in plugin $PLUGIN_ID version 6.0.0. " + 42 | "Please, consider follow migration guide to upgrade plugin properly" 43 | 44 | /** Verify if executions are defined */ 45 | internal fun verifyExecutions(project: Project, executions: NamedDomainObjectContainer) { 46 | project.afterEvaluate { 47 | // this can be reported only after evaluation 48 | if (executions.size == 0) { 49 | throw InvalidUserDataException(ERROR_NO_EXECUTION) 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-gradle-plugin` // Gradle plugin base 3 | `kotlin-dsl` 4 | id("org.jsonschema2dataclass.internal.gradle-plugin") 5 | } 6 | 7 | @Suppress("UnstableApiUsage") 8 | gradlePlugin { 9 | website.set("https://github.com/jsonschema2dataclass/js2d-gradle") 10 | vcsUrl.set("https://github.com/jsonschema2dataclass/js2d-gradle.git") 11 | 12 | plugins { 13 | create("jsonschema2dataclassPlugin") { 14 | id = "org.jsonschema2dataclass" 15 | 16 | implementationClass = "org.jsonschema2dataclass.Js2dPlugin" 17 | displayName = "jsonschema2dataclass plugin" 18 | description = 19 | "A plugins that generates Java sources from Json Schema. " + 20 | "Please, see the GitHub page for details" 21 | 22 | tags.set( 23 | listOf( 24 | "json-schema", 25 | "jsonschema", 26 | "generator", 27 | "pojo", 28 | "jsonschema2pojo", 29 | "dataclass", 30 | "data", 31 | "json", 32 | "generation", 33 | "jsonschema2dataclass", 34 | "java", 35 | "kotlin", 36 | "groovy", 37 | ), 38 | ) 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | implementation(projects.pluginGradle.common) { 45 | exclude(group = "org.jetbrains.kotlin") 46 | } 47 | 48 | // Java language compatibility layer 49 | implementation(projects.pluginGradle.compat.kotlin) 50 | 51 | // Processors 52 | implementation(projects.pluginGradle.processors.jsonschema2pojo) 53 | 54 | // Gradle plugin compatibility 55 | implementation(projects.pluginGradle.compat.java) 56 | 57 | testImplementation(libs.bundles.junit.tests) 58 | testRuntimeOnly(libs.bundles.junit.runtime) 59 | testImplementation(gradleTestKit()) 60 | } 61 | 62 | tasks.test { 63 | javaLauncher = javaToolchains.launcherFor { 64 | languageVersion = JavaLanguageVersion.of(JavaVersion.current().majorVersion) 65 | } 66 | useJUnitPlatform() 67 | systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_method") 68 | systemProperty("junit.jupiter.execution.parallel.enabled", "true") 69 | } 70 | -------------------------------------------------------------------------------- /internal/plugins/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-gradle-plugin` 3 | `kotlin-dsl` 4 | } 5 | 6 | version = "1.0" 7 | 8 | gradlePlugin { 9 | plugins { 10 | create("git-version") { 11 | id = "org.jsonschema2dataclass.internal.git-version" 12 | implementationClass = "org.jsonschema2dataclass.internal.plugin.base.GitVersionPlugin" 13 | description = "Set project version based on git tags and commits." 14 | } 15 | create("kotlin-target") { 16 | id = "org.jsonschema2dataclass.internal.kotlin-target" 17 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.KotlinToolchain" 18 | description = "Set up Kotlin & Java toolchain to use Java 8." 19 | dependencies { 20 | compileOnly(pluginDeps.kotlin.gradle) 21 | } 22 | } 23 | create("settings-develocity") { 24 | id = "org.jsonschema2dataclass.internal.settings-develocity" 25 | implementationClass = "org.jsonschema2dataclass.internal.plugin.base.SettingEnterpriseAccept" 26 | description = "Agree on TOS for Gradle Scans." 27 | dependencies { 28 | compileOnly(pluginDeps.gradle.develocity) 29 | } 30 | } 31 | create("library-plugin") { 32 | id = "org.jsonschema2dataclass.internal.library" 33 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.LibraryPlugin" 34 | description = "Set up support library defaults." 35 | } 36 | create("gradle-plugin") { 37 | id = "org.jsonschema2dataclass.internal.gradle-plugin" 38 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.GradlePlugin" 39 | description = "Set up gradle plugin defaults." 40 | } 41 | create("processor-version") { 42 | id = "org.jsonschema2dataclass.internal.processor-version" 43 | implementationClass = "org.jsonschema2dataclass.internal.plugin.lib.ProcessorVersionPlugin" 44 | description = "Set up gradle plugin defaults." 45 | } 46 | create("plugin-publish") { 47 | id = "org.jsonschema2dataclass.internal.plugin-publish" 48 | implementationClass = "org.jsonschema2dataclass.internal.plugin.publishing.PublishingPlugin" 49 | description = "Set up library publishing settings." 50 | } 51 | } 52 | } 53 | 54 | dependencies { 55 | implementation(project(":common")) 56 | } 57 | -------------------------------------------------------------------------------- /.github/workflows/delete-workflow-runs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Delete old workflow runs 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | days: 7 | description: Days-worth of runs to keep for each workflow 8 | required: true 9 | default: '90' 10 | minimum_runs: 11 | description: Minimum runs to keep for each workflow 12 | required: true 13 | default: '6' 14 | delete_workflow_pattern: 15 | description: Name or filename of the workflow (if not set, all workflows are targeted) 16 | required: false 17 | delete_workflow_by_state_pattern: 18 | description: 'Filter workflows by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually' 19 | required: true 20 | default: ALL 21 | type: choice 22 | options: 23 | - ALL 24 | - active 25 | - deleted 26 | - disabled_inactivity 27 | - disabled_manually 28 | delete_run_by_conclusion_pattern: 29 | description: 'Remove runs based on conclusion: action_required, cancelled, failure, skipped, success' 30 | required: true 31 | default: ALL 32 | type: choice 33 | options: 34 | - ALL 35 | - 'Unsuccessful: action_required,cancelled,failure,skipped' 36 | - action_required 37 | - cancelled 38 | - failure 39 | - skipped 40 | - success 41 | dry_run: 42 | description: Logs simulated changes, no deletions are performed 43 | required: false 44 | 45 | jobs: 46 | del_runs: 47 | runs-on: ubuntu-latest 48 | permissions: 49 | actions: write 50 | contents: read 51 | steps: 52 | - name: Delete workflow runs 53 | uses: Mattraks/delete-workflow-runs@v2 54 | with: 55 | token: ${{ github.token }} 56 | repository: ${{ github.repository }} 57 | retain_days: ${{ github.event.inputs.days }} 58 | keep_minimum_runs: ${{ github.event.inputs.minimum_runs }} 59 | delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }} 60 | delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }} 61 | delete_run_by_conclusion_pattern: >- 62 | ${{ 63 | startsWith(github.event.inputs.delete_run_by_conclusion_pattern, 'Unsuccessful:') 64 | && 'action_required,cancelled,failure,skipped' 65 | || github.event.inputs.delete_run_by_conclusion_pattern 66 | }} 67 | dry_run: ${{ github.event.inputs.dry_run }} 68 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pWorker.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.gradle.api.logging.Logger 4 | import org.gradle.api.logging.Logging 5 | import org.gradle.workers.WorkAction 6 | import org.gradle.workers.WorkParameters 7 | import org.jsonschema2pojo.Jsonschema2Pojo 8 | import org.jsonschema2pojo.RuleLogger 9 | 10 | internal abstract class Js2pWorker : WorkAction { 11 | override fun execute() { 12 | val config = Js2pConfig( 13 | parameters.config.targetDirectory, 14 | parameters.config.io, 15 | parameters.config.klass, 16 | parameters.config.constructors, 17 | parameters.config.methods, 18 | parameters.config.fields, 19 | parameters.config.dateTime, 20 | ) 21 | val ruleLogAdapter = GradleRuleLogAdapter(Logging.getLogger(this.javaClass)) 22 | if (ruleLogAdapter.isTraceEnabled) { 23 | ruleLogAdapter.trace("[{}] Using this configuration:\n{}", parameters.config.uuid, config) 24 | } 25 | 26 | Jsonschema2Pojo.generate(config, ruleLogAdapter) 27 | } 28 | } 29 | 30 | internal interface Js2pWorkerParams : WorkParameters { 31 | var config: Js2pWorkerConfig 32 | } 33 | 34 | internal class GradleRuleLogAdapter constructor( 35 | private val logger: Logger, 36 | ) : RuleLogger { 37 | override fun isDebugEnabled(): Boolean = 38 | logger.isDebugEnabled 39 | 40 | override fun isErrorEnabled(): Boolean = 41 | logger.isErrorEnabled 42 | 43 | override fun isInfoEnabled(): Boolean = 44 | logger.isInfoEnabled 45 | 46 | override fun isTraceEnabled(): Boolean = 47 | logger.isTraceEnabled 48 | 49 | override fun isWarnEnabled(): Boolean = 50 | logger.isWarnEnabled 51 | 52 | override fun debug(msg: String?) { 53 | logger.debug(msg) 54 | } 55 | 56 | override fun error(msg: String?) { 57 | logger.debug(msg) 58 | } 59 | 60 | override fun error(msg: String?, e: Throwable?) { 61 | logger.error(msg, e) 62 | } 63 | 64 | override fun info(msg: String?) { 65 | logger.info(msg) 66 | } 67 | 68 | override fun trace(msg: String?) { 69 | logger.trace(msg) 70 | } 71 | 72 | fun trace(msg: String?, arg: Any, arg2: Any) { 73 | logger.trace(msg, arg, arg2) 74 | } 75 | 76 | override fun warn(msg: String?, e: Throwable?) { 77 | logger.warn(msg, e) 78 | } 79 | 80 | override fun warn(msg: String?) { 81 | logger.debug(msg) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pProcessor.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.gradle.api.GradleException 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import org.jsonschema2dataclass.ext.Js2pConfiguration 7 | import org.jsonschema2dataclass.internal.Js2dProcessor 8 | import org.jsonschema2dataclass.internal.task.JS2P_TOOL_NAME 9 | import org.jsonschema2dataclass.internal.task.Js2dGeneratorTaskBase 10 | import java.util.Properties 11 | import java.util.concurrent.atomic.AtomicReference 12 | import java.util.concurrent.locks.ReentrantLock 13 | 14 | private const val JS2P_TASK_DESCRIPTION = "Generates Java models from a json schema using jsonschema2pojo" 15 | 16 | private const val RESOURCE_FILE = "processor.properties" 17 | private const val PROPERTY = "processor" 18 | 19 | private val JS2PVersion = AtomicReference(null) 20 | private val readLock = ReentrantLock() 21 | 22 | class Js2pProcessor : Js2dProcessor { 23 | private fun readVersion(): String { 24 | if (JS2PVersion.get() != null) { 25 | return JS2PVersion.get()!! 26 | } 27 | readLock.lock() 28 | try { 29 | if (JS2PVersion.get() != null) { 30 | return JS2PVersion.get()!! 31 | } 32 | val stream = 33 | Js2pProcessor::class.java 34 | .classLoader 35 | .getResourceAsStream(RESOURCE_FILE) 36 | if (stream == null) { 37 | throw GradleException("jsonschema2pojo processor version must be provided") 38 | } 39 | val props = Properties() 40 | stream.use { 41 | props.load(it) 42 | } 43 | JS2PVersion.compareAndSet(null, props[PROPERTY].toString()) 44 | } finally { 45 | readLock.unlock() 46 | } 47 | 48 | if (JS2PVersion.get() == null) { 49 | throw GradleException("jsonschema2pojo processor version must be provided") 50 | } 51 | return JS2PVersion.get()!! 52 | } 53 | 54 | override fun toolNameForTask(): Pair = JS2P_TOOL_NAME to JS2P_TASK_DESCRIPTION 55 | 56 | override fun generatorTaskClass(): Class> = 57 | Js2pGenerationTask::class.java 58 | 59 | override fun toolingMinimalDependencies(project: Project, configuration: Configuration) { 60 | val version = readVersion() 61 | 62 | configuration.defaultDependencies { 63 | add(project.dependencies.create(version)) 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /.github/workflows/plugin-build-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Build Plugin CI 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | tags-ignore: 9 | - '*' 10 | paths: 11 | - plugin-gradle/** 12 | - gradle/wrapper/** 13 | - gradle/libs.dependencies.toml 14 | - gradle/processors.toml 15 | - gradle/plugins.dependencies.toml 16 | - gradlew* 17 | - internal/plugins/** 18 | - internal/common/** 19 | - internal/settings.gradle.kts 20 | - settings.gradle.kts 21 | - build.gradle.kts 22 | - gradle.properties 23 | - .github/workflows/plugin-build-ci.yml 24 | pull_request: 25 | types: [assigned, opened, synchronize, reopened] 26 | paths: 27 | - plugin-gradle/** 28 | - gradle/wrapper/** 29 | - gradle/libs.dependencies.toml 30 | - gradle/processors.toml 31 | - gradle/plugins.dependencies.toml 32 | - gradlew* 33 | - internal/plugins/** 34 | - internal/common/** 35 | - internal/settings.gradle.kts 36 | - settings.gradle.kts 37 | - build.gradle.kts 38 | - gradle.properties 39 | - .github/workflows/plugin-build-ci.yml 40 | 41 | concurrency: 42 | # Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}. 43 | # On master, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke. 44 | group: ${{ github.ref == 'refs/heads/main' && format('plugin-build-ci-main-{0}', github.sha) || format('plugin-build-ci-{0}', github.ref) }} 45 | cancel-in-progress: true 46 | 47 | env: 48 | GRADLE_OPTS: -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false 49 | 50 | jobs: 51 | build-and-test: 52 | name: Build Plugin 53 | runs-on: ubuntu-latest 54 | strategy: 55 | fail-fast: false 56 | max-parallel: 2 57 | matrix: 58 | gradleTest: [current, 8, 7] 59 | java: [21, 17] 60 | distribution: [zulu] 61 | steps: 62 | - uses: actions/checkout@v5 63 | - name: Set up JDK ${{ matrix.distribution }} ${{ matrix.java }} for gradle test ${{ matrix.gradleTest }} 64 | uses: actions/setup-java@v5 65 | with: 66 | distribution: ${{ matrix.distribution }} 67 | java-version: ${{ matrix.java }} 68 | cache: gradle 69 | 70 | - name: Run build and tests 71 | run: | 72 | if [[ "${{ matrix.gradleTest }}" == "current" ]]; then 73 | export TEST_GRADLE_VER_EXACT=current 74 | else 75 | export TEST_GRADLE_VER_MIN=${{ matrix.gradleTest }} 76 | export TEST_GRADLE_VER_MAX=$(( ${{ matrix.gradleTest }} + 1)) 77 | fi 78 | ./gradlew build -S --scan --warning-mode all --no-daemon 79 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :toc: 2 | :toc-placement: preamble 3 | :toclevels: 1 4 | :showtitle: 5 | 6 | :plugin_major: 6 7 | 8 | = Json Schema to Data Class Gradle plugin 9 | 10 | image:https://img.shields.io/github/v/release/jsonschema2dataclass/js2d-gradle[GitHub release (latest by date)] 11 | 12 | // Need some preamble to get TOC: 13 | {empty} 14 | 15 | == Introduction 16 | 17 | This plugin is aiming to take raw JSON or YAML raw files or schemas and convert definitions to Java POJOs 18 | (Plain Old Java Object). 19 | 20 | At the moment of writing documentation, it uses 21 | https://github.com/joelittlejohn/jsonschema2pojo[jsonschema2pojo] 1.2.1 library to generate classes. 22 | 23 | The `org.jsonschema2dataclass` plugin feature highlight: 24 | 25 | * Full support and testing for wide version range of versions of Java, Gradle and AGP 26 | including task caching, proper hooking and other features. 27 | + 28 | Currently, it's Java 1.8 to 19, Gradle 6.0 to 7.6 and AGP 3, 4 and 7. 29 | Additionally, plugin has beta support for Gradle 8.0 and AGP 8. 30 | 31 | * Possibility natively write Gradle scripts in Groovy and Kotlin DSLs. 32 | * Support for projects written in Kotlin and Groovy and which are using Lombok. 33 | * Possibility to run multiple executions withing a single project. 34 | + 35 | This is important for some use cases to generate different sets of models within a single project. 36 | * Some parameters are more human-writable and using native features provided by Gradle. 37 | + 38 | -- 39 | .Few examples 40 | ** `propertyWordDelimiters` is array of chars in `jsonschema2pojo`, which is not easy to write and support. 41 | ** `org.jsonschema2dataclass` uses Gradle-provided structures for all configuration parameters. 42 | -- 43 | * Plugin is not tied to the library interface and could provide more maintainable configuration presentation 44 | and wider feature range when needed. 45 | 46 | Please note, that JSON schema constrains can be quite poorly translated to JSR305 and in most cases 47 | can't replace Json Schema Validation. 48 | I suggest to use a Json Schema Validation library when possible like one 49 | https://github.com/networknt/json-schema-validator[by NetworkNT]. 50 | 51 | == Usage and migration information for {plugin_major}.x 52 | 53 | Usage and migration documentation is located in separate documents. 54 | 55 | * xref:docs/usage/basic_{plugin_major}.adoc[Basic usage for {plugin_major}.x] 56 | * xref:docs/usage/parameters_{plugin_major}.adoc[Parameters for {plugin_major}.x] 57 | * xref:docs/migration/migration_{plugin_major}.adoc[Migration guide for {plugin_major}.x] 58 | 59 | == Usage and migration information for all versions 60 | 61 | Usage and migration documentation is located in separate documents. 62 | 63 | * xref:docs/usage/index.adoc[Usage documentation for all versions] 64 | * xref:docs/migration/migration.adoc[Migration guides for all versions] 65 | -------------------------------------------------------------------------------- /plugin-gradle/compat/java/src/main/kotlin/org/jsonschema2dataclass/internal/compat/java/JavaPluginRegistration.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.compat.java 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.Project 5 | import org.gradle.api.Task 6 | import org.gradle.api.plugins.JavaPluginExtension 7 | import org.gradle.api.tasks.SourceSet 8 | import org.gradle.api.tasks.SourceSetContainer 9 | import org.gradle.api.tasks.TaskProvider 10 | import org.gradle.util.GradleVersion 11 | import org.jsonschema2dataclass.internal.GradlePluginRegistration 12 | import org.jsonschema2dataclass.internal.ProcessorRegistrationCallback 13 | import java.nio.file.Path 14 | 15 | /** 16 | * Registers a processor task using Java & Kotlin plugins. 17 | * 18 | * Additionally, this handles Lombok compatibility 19 | */ 20 | class JavaPluginRegistration : GradlePluginRegistration { 21 | private fun mainSourceSet(project: Project): SourceSet = 22 | if (GradleVersion.current() < GradleVersion.version("7.1")) { 23 | obtainJavaSourceSetContainerV6(project) 24 | } else { 25 | obtainJavaSourceSetContainerV7(project) 26 | } 27 | 28 | override fun defaultSchemaPathInternal(project: Project): Path? = 29 | mainSourceSet(project) 30 | .output 31 | .resourcesDir 32 | ?.toPath() 33 | ?.resolve("json") 34 | 35 | override fun registerPlugin(project: Project, callback: ProcessorRegistrationCallback) { 36 | val javaSourceSet = mainSourceSet(project).java 37 | 38 | callback.invoke( 39 | mapOf(), 40 | ) { taskProvider: TaskProvider, targetPath: Path?, dependsOn: Action -> 41 | taskProvider.configure { 42 | dependsOn(project.tasks.named("processResources")) 43 | } 44 | 45 | dependsOn.execute("generateEffectiveLombokConfig") 46 | 47 | if (targetPath != null) { 48 | javaSourceSet.srcDirs(taskProvider) 49 | } 50 | } 51 | } 52 | } 53 | 54 | // TODO: split this out to have better compatibility 55 | 56 | /** Obtain java source sets in Gradle 6.0 - 7.0.2 */ 57 | @Suppress("DEPRECATION") 58 | private fun obtainJavaSourceSetContainerV6(project: Project): SourceSet = 59 | obtainSourceSetContainer(project.convention.plugins["java"]!!) 60 | .named("main") 61 | .get() 62 | 63 | /** Call `getSourceSets` method existed in Gradle 6.0 - 7.0.2. */ 64 | private fun obtainSourceSetContainer(value: Any): SourceSetContainer { 65 | val method = value::class.java.getDeclaredMethod("getSourceSets") 66 | return method.invoke(value) as SourceSetContainer 67 | } 68 | 69 | /** Obtain java source sets in Gradle 7.3 and above */ 70 | private fun obtainJavaSourceSetContainerV7(project: Project): SourceSet = 71 | project 72 | .extensions 73 | .getByType(JavaPluginExtension::class.java) 74 | .sourceSets 75 | .named("main") 76 | .get() 77 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/TestUtils.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.js2p 2 | 3 | import org.gradle.testkit.runner.BuildTask 4 | import org.gradle.testkit.runner.GradleRunner 5 | import org.gradle.testkit.runner.TaskOutcome 6 | import org.jsonschema2dataclass.internal.task.JS2D_TASK_NAME 7 | import org.junit.jupiter.api.Assertions 8 | import org.junit.jupiter.api.Assertions.assertTrue 9 | import java.nio.file.Path 10 | import org.gradle.testkit.runner.BuildResult as BuildResultGradle 11 | 12 | internal const val COLON_TASK_NAME = ":$JS2D_TASK_NAME" 13 | internal const val COLON_TASK_NAME_FOR_COM = ":${JS2D_TASK_NAME}ConfigCom" 14 | internal const val COLON_TASK_NAME_FOR_ORG = ":${JS2D_TASK_NAME}ConfigOrg" 15 | 16 | fun createRunner( 17 | gradleVersion: String?, 18 | testProjectDir: Path, 19 | debug: Boolean = false, 20 | task: String = COLON_TASK_NAME, 21 | vararg arguments: String, 22 | ): GradleRunner = 23 | GradleRunner 24 | .create() 25 | .withDebug(debug) 26 | .withPluginClasspath() 27 | .withProjectDir(testProjectDir.toFile()) 28 | .withArguments(task, *arguments) 29 | .apply { 30 | if (gradleVersion != null) { 31 | withGradleVersion(gradleVersion) 32 | } 33 | } 34 | 35 | fun GradleRunner.execute(shouldFail: Boolean = false): BuildResult = 36 | BuildResult( 37 | projectDir = this.projectDir.toPath(), 38 | delegate = when (shouldFail) { 39 | true -> buildAndFail() 40 | false -> build() 41 | }, 42 | ) 43 | 44 | class BuildResult( 45 | val projectDir: Path, 46 | private val delegate: BuildResultGradle, 47 | ) : BuildResultGradle { 48 | override fun getOutput(): String = delegate.output 49 | 50 | override fun getTasks(): MutableList = delegate.tasks 51 | 52 | override fun tasks(outcome: TaskOutcome?): MutableList = delegate.tasks(outcome) 53 | 54 | override fun taskPaths(outcome: TaskOutcome?): MutableList = delegate.taskPaths(outcome) 55 | 56 | override fun task(taskPath: String?): BuildTask? = delegate.task(taskPath) 57 | } 58 | 59 | fun BuildResult.assertResultAndGeneratedClass( 60 | taskName: String = COLON_TASK_NAME_FOR_COM, 61 | targetFolder: String = TARGET_FOLDER_DEFAULT, 62 | ): BuildResult { 63 | Assertions.assertEquals(TaskOutcome.SUCCESS, task(taskName)?.outcome, "task $taskName is successful") 64 | 65 | addressJavaExists(projectDir, targetFolder, taskToExecution[taskName]!!, taskToPackage[taskName]!!) 66 | 67 | return this 68 | } 69 | 70 | private val taskToExecution = mapOf( 71 | COLON_TASK_NAME_FOR_COM to EXECUTION_NAME_COM, 72 | COLON_TASK_NAME_FOR_ORG to EXECUTION_NAME_ORG, 73 | ) 74 | 75 | private val taskToPackage = mapOf( 76 | COLON_TASK_NAME_FOR_COM to PACKAGE_COM_EXAMPLE, 77 | COLON_TASK_NAME_FOR_ORG to PACKAGE_ORG_EXAMPLE, 78 | ) 79 | 80 | fun addressJavaExists(testProjectDir: Path, targetDirectoryPrefix: String, executionName: String, subfolder: String) { 81 | val js2pDir = testProjectDir.resolve(targetDirectoryPrefix).resolve(executionName).resolve(subfolder) 82 | assertTrue(js2pDir.toFile().exists()) 83 | assertTrue(js2pDir.resolve("Address.java").toFile().exists()) 84 | } 85 | -------------------------------------------------------------------------------- /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 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /demo/java/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 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/base/GitVersion.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.base 2 | 3 | import EXTRA_GIT_VERSION_ENABLE 4 | import EXTRA_GIT_VERSION_OVERRIDE 5 | import extraValue 6 | import isExtraEnabled 7 | import org.gradle.api.Project 8 | import java.io.IOException 9 | import java.nio.charset.StandardCharsets 10 | import java.time.LocalDateTime 11 | import java.time.format.DateTimeFormatter 12 | import java.util.Locale 13 | import java.util.concurrent.TimeUnit 14 | 15 | private val regex = Regex("""^v?([0-9.]*(?:-rc\d+)?)-(\d+)-g([0-9a-f]+)(-dirty)?$""") 16 | private const val DEFAULT_VERSION = "-.-.--0-g00000000-dirty" 17 | 18 | /** Obtain git versions or generate one. */ 19 | fun gitVersion(project: Project): String { 20 | val versionOverride = project.extraValue(EXTRA_GIT_VERSION_OVERRIDE) 21 | if (versionOverride != null) { 22 | return versionOverride 23 | } 24 | 25 | val commandVersion = when (project.isExtraEnabled(EXTRA_GIT_VERSION_ENABLE)) { 26 | true -> commandVersion(project) 27 | false -> null 28 | } 29 | return processVersionString(commandVersion ?: DEFAULT_VERSION) 30 | } 31 | 32 | /** 33 | * Process version string and return a valid version. 34 | * 35 | * If valid version can't be found, one will be generated. 36 | */ 37 | private fun processVersionString(value: String): String { 38 | val match = regex.find(value) 39 | if (match == null) { 40 | val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd.HH-mm-ss", Locale.US)) 41 | return "0.0.0-$now" 42 | } 43 | 44 | val (version, commitsAfterTag, revision, dirty) = match.destructured 45 | 46 | return when (commitsAfterTag) { 47 | "0" -> if (dirty.isEmpty()) { 48 | version 49 | } else { 50 | "$version$dirty" 51 | } 52 | 53 | else -> "$version-$commitsAfterTag-$revision$dirty" 54 | } 55 | } 56 | 57 | private const val ONE_MINUTE = 60L 58 | 59 | /** 60 | * Wait for `git` process for at most 1 minute to get a version by tag and state. 61 | * 62 | * Returns null if waited too long or execution wasn't successful 63 | */ 64 | private fun commandVersion(project: Project): String? { 65 | try { 66 | val process = ProcessBuilder() 67 | .command("git", "describe", "--tags", "--long", "--dirty") 68 | .redirectOutput(ProcessBuilder.Redirect.PIPE) 69 | .redirectError(ProcessBuilder.Redirect.PIPE) 70 | .start() 71 | process.waitFor(ONE_MINUTE, TimeUnit.SECONDS) 72 | return if (process.exitValue() == 0) { 73 | process 74 | .inputStream 75 | .bufferedReader(StandardCharsets.UTF_8) 76 | .readText() 77 | .trim() 78 | } else { 79 | val output = process 80 | .errorStream 81 | .bufferedReader(StandardCharsets.UTF_8) 82 | .readText() 83 | .trim() 84 | project.logger.error("Process exited with code ${process.exitValue()}: $output") 85 | null 86 | } 87 | } catch (e: UnsupportedOperationException) { 88 | project.logger.error("Can't execute git", e) 89 | } catch (e: IOException) { 90 | project.logger.error("Can't execute git", e) 91 | } catch (e: InterruptedException) { 92 | project.logger.error("process timed out", e) 93 | } 94 | return null 95 | } 96 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/main/kotlin/org/jsonschema2dataclass/Js2dPlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import org.gradle.kotlin.dsl.apply 7 | import org.jsonschema2dataclass.ext.Js2pExtension 8 | import org.jsonschema2dataclass.internal.GradlePluginRegistration 9 | import org.jsonschema2dataclass.internal.Js2dProcessor 10 | import org.jsonschema2dataclass.internal.compat.java.JavaPluginRegistration 11 | import org.jsonschema2dataclass.internal.defaultConfigurationSettings 12 | import org.jsonschema2dataclass.internal.js2p.Js2pProcessor 13 | import org.jsonschema2dataclass.internal.registrationTasksMachinery 14 | import org.jsonschema2dataclass.internal.task.DEFAULT_TARGET_FOLDER_BASE 15 | import org.jsonschema2dataclass.internal.task.JS2D_CONFIGURATION_NAME 16 | import org.jsonschema2dataclass.internal.task.JS2D_PLUGINS_CONFIGURATION_NAME 17 | import org.jsonschema2dataclass.internal.task.JS2P_EXTENSION_NAME 18 | import org.jsonschema2dataclass.internal.verifyExecutionNames 19 | import org.jsonschema2dataclass.internal.verifyExecutions 20 | import org.jsonschema2dataclass.internal.verifyGradleVersion 21 | 22 | private val processors: MutableList> = mutableListOf() 23 | 24 | @Suppress("unused") 25 | class Js2dPlugin : Plugin { 26 | private val javaPlugins = listOf("java", "java-library") 27 | 28 | override fun apply(project: Project) { 29 | verifyGradleVersion() 30 | 31 | val js2pExtension = project.extensions.create(JS2P_EXTENSION_NAME, Js2pExtension::class.java) 32 | js2pExtension.targetDirectoryPrefix.convention(project.layout.buildDirectory.dir(DEFAULT_TARGET_FOLDER_BASE)) 33 | 34 | val js2dConfiguration = createConfiguration(project, JS2D_CONFIGURATION_NAME) 35 | val js2dConfigurationPlugins = createConfiguration(project, JS2D_PLUGINS_CONFIGURATION_NAME) 36 | 37 | verifyExecutionNames(js2pExtension.executions) 38 | verifyExecutions(project, js2pExtension.executions) 39 | 40 | val processor = obtainProcessor() 41 | processors.add(processor) 42 | 43 | processor.toolingMinimalDependencies(project, js2dConfiguration) 44 | processor.toolingMinimalDependencies(project, js2dConfigurationPlugins) 45 | 46 | for (pluginId in javaPlugins) { 47 | project.plugins.withId(pluginId) { 48 | project.apply() 49 | } 50 | } 51 | } 52 | } 53 | 54 | internal class Js2pJavaPlugin : Plugin { 55 | override fun apply(project: Project) { 56 | applyPlugin(project, JavaPluginRegistration(), false) 57 | } 58 | } 59 | 60 | private fun applyPlugin(project: Project, registration: GradlePluginRegistration, disableGeneratedAnnotation: Boolean) { 61 | val js2pExtension = project.extensions.getByType(Js2pExtension::class.java) 62 | 63 | defaultConfigurationSettings( 64 | js2pExtension.executions, 65 | registration.defaultSchemaPath(project), 66 | disableGeneratedAnnotation, 67 | ) 68 | 69 | val js2pProcessor: Js2pProcessor = processors.first() as Js2pProcessor 70 | 71 | registrationTasksMachinery( 72 | project, 73 | registration, 74 | js2pExtension.targetDirectoryPrefix, 75 | js2pExtension.executions, 76 | js2pProcessor, 77 | ) 78 | } 79 | 80 | private fun createConfiguration(project: Project, name: String): Configuration = project.configurations 81 | .maybeCreate( 82 | name, 83 | ).apply { 84 | isCanBeConsumed = false 85 | isCanBeResolved = true 86 | isVisible = true 87 | } 88 | 89 | private fun obtainProcessor(): Js2dProcessor<*> = Js2pProcessor() 90 | -------------------------------------------------------------------------------- /docs/usage/basic.adoc: -------------------------------------------------------------------------------- 1 | :toc: 2 | :toc-placement: preamble 3 | :toclevels: 2 4 | :showtitle: 5 | 6 | = Basic plugin usage and support 7 | 8 | This page shows plugin basic usage and support. 9 | 10 | == Apply the plugin and basic settings 11 | 12 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 13 | 14 | Then it's required to specify execution and their settings in the extension. 15 | 16 | The minimal usage example looks like shown in the following table. 17 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration. 18 | 19 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work. 20 | 21 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen. 22 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly. 23 | Execution section might contain as many executions as project needs (at least 1). 24 | 25 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section. 26 | 27 | [options=header,cols="1,5"] 28 | |===== 29 | | DSL language | DSL 30 | // ------------------------------ 31 | | Groovy 32 | a| 33 | [source,gradle] 34 | ----- 35 | plugins { 36 | id "java" 37 | id "org.jsonschema2dataclass" version "x.y.z" 38 | } 39 | 40 | jsonSchema2Pojo { 41 | executions { 42 | main {} 43 | } 44 | } 45 | ----- 46 | // ------------------------------ 47 | | Kotlin 48 | a| 49 | [source,gradle] 50 | ----- 51 | plugins { 52 | `java` 53 | id("org.jsonschema2dataclass") version "x.y.z" 54 | } 55 | 56 | jsonSchema2Pojo { 57 | executions { 58 | create("main") { 59 | } 60 | } 61 | } 62 | ----- 63 | // ------------------------------ 64 | |===== 65 | 66 | == SDK and build tools support 67 | 68 | .Demos and statuses 69 | [options=header] 70 | |===== 71 | | SDK/Tool | Minimal Version | Maximum version | Notes 72 | // ------------------------------ 73 | | Java compiler 74 | | 8 75 | | 19 76 | | 77 | // ------------------------------ 78 | | Gradle 79 | | 6.0 80 | | 7.x 81 | | 8.0 support is beta till it will be released 82 | // ------------------------------ 83 | | Android Gradle Plugin 84 | | 3 85 | | 7 86 | | 87 | // ------------------------------ 88 | |===== 89 | 90 | == Demos and their statuses 91 | 92 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 93 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin. 94 | 95 | Also, there's also integration tests which are 96 | 97 | Any contributions are welcome. 98 | 99 | .Demos and statuses 100 | [options=header] 101 | |===== 102 | | Platform | Demo | Status | Notes 103 | // ------------------------------ 104 | .3+| JVM 105 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 106 | | Maintained and healthy 107 | | 108 | // ------------------------------ 109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 110 | | Maintained and healthy 111 | | 112 | // ------------------------------ 113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 114 | | Maintained and healthy 115 | | 116 | // ------------------------------ 117 | .4+| Android 118 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example 119 | | Maintained and healthy 120 | | 121 | // ------------------------------ 122 | | AGP 8 123 | | Waiting for releases from Google and Gradle 124 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation 125 | // ------------------------------ 126 | | AGP 4 127 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0 128 | | Was unmaintained for a while 129 | // ------------------------------ 130 | | AGP 3 131 | | ⚠️ Demo has been removed in 5.0 132 | | Was unmaintained for a while 133 | // ------------------------------ 134 | |===== 135 | 136 | For AGP 3 and AGP 4 I have no computer to build the demos. 137 | -------------------------------------------------------------------------------- /docs/usage/basic_5.adoc: -------------------------------------------------------------------------------- 1 | :plugin_major: 5 2 | :demo-agp4: was marked as unmaintained 3 | 4 | :toc: 5 | :toc-placement: preamble 6 | :toclevels: 2 7 | :showtitle: 8 | 9 | = Basic plugin usage and support 10 | 11 | This page shows plugin basic usage and support. 12 | 13 | == Apply the plugin and basic settings 14 | 15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 16 | 17 | Then it's required to specify execution and their settings in the extension. 18 | 19 | The minimal usage example looks like shown in the following table. 20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration. 21 | 22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work. 23 | Kotlin and Groovy automatically apply one of plugin mentioned before. 24 | 25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen. 26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly. 27 | Execution section might contain as many executions as project needs (at least 1). 28 | 29 | 30 | 31 | [options=header,cols="1,5"] 32 | |===== 33 | | DSL language | DSL 34 | // ------------------------------ 35 | | Groovy 36 | a| 37 | [source,gradle] 38 | ----- 39 | plugins { 40 | id "java" 41 | id "org.jsonschema2dataclass" version "x.y.z" 42 | } 43 | 44 | jsonSchema2Pojo { 45 | executions { 46 | main {} 47 | } 48 | } 49 | ----- 50 | // ------------------------------ 51 | | Kotlin 52 | a| 53 | [source,gradle] 54 | ----- 55 | plugins { 56 | `java` 57 | id("org.jsonschema2dataclass") version "x.y.z" 58 | } 59 | 60 | jsonSchema2Pojo { 61 | executions { 62 | create("main") { 63 | } 64 | } 65 | } 66 | ----- 67 | // ------------------------------ 68 | |===== 69 | 70 | == SDK and build tools support 71 | 72 | .Demos and statuses 73 | [options=header] 74 | |===== 75 | | SDK/Tool | Minimal Version | Maximum version | Notes 76 | // ------------------------------ 77 | | Java compiler 78 | | 8 79 | | 19 80 | | 81 | // ------------------------------ 82 | | Gradle 83 | | 6.0 84 | | 7.x 85 | | 8.0 support is beta till it will be released 86 | // ------------------------------ 87 | | Android Gradle Plugin 88 | | 3 89 | | 7 90 | | 91 | // ------------------------------ 92 | |===== 93 | 94 | == Demos and their statuses 95 | 96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin. 98 | 99 | Also, there's also integration tests which are 100 | 101 | Any contributions are welcome. 102 | 103 | .Demos and statuses 104 | [options=header] 105 | |===== 106 | | Platform | Demo | Status | Notes 107 | // ------------------------------ 108 | .3+| JVM 109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 110 | | Maintained and healthy 111 | | 112 | // ------------------------------ 113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 114 | | Maintained and healthy 115 | | 116 | // ------------------------------ 117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 118 | | Maintained and healthy 119 | | 120 | // ------------------------------ 121 | .4+| Android 122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example 123 | | Maintained and healthy 124 | | 125 | // ------------------------------ 126 | | AGP 8 127 | | Waiting for releases from Google and Gradle 128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation 129 | // ------------------------------ 130 | | AGP 4 131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0 132 | | Was unmaintained for a while 133 | // ------------------------------ 134 | | AGP 3 135 | | ⚠️ Demo has been removed in 5.0 136 | | Was unmaintained for a while 137 | // ------------------------------ 138 | |===== 139 | 140 | For AGP 3 and AGP 4 I have no computer to build the demos. 141 | -------------------------------------------------------------------------------- /docs/usage/basic_2.adoc: -------------------------------------------------------------------------------- 1 | :plugin_major: 5 2 | :demo-agp4: was marked as unmaintained 3 | 4 | :toc: 5 | :toc-placement: preamble 6 | :toclevels: 2 7 | :showtitle: 8 | 9 | = Basic plugin usage and support 10 | 11 | This page shows plugin basic usage and support. 12 | 13 | == Apply the plugin and basic settings 14 | 15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 16 | 17 | Then it's required to specify execution and their settings in the extension. 18 | 19 | The minimal usage example looks like shown in the following table. 20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration. 21 | 22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work. 23 | Kotlin and Groovy automatically apply one of plugin mentioned before. 24 | 25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen. 26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly. 27 | Execution section might contain as many executions as project needs (at least 1). 28 | 29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section. 30 | 31 | [options=header,cols="1,5"] 32 | |===== 33 | | DSL language | DSL 34 | // ------------------------------ 35 | | Groovy 36 | a| 37 | [source,gradle] 38 | ----- 39 | plugins { 40 | id "java" 41 | id "org.jsonschema2dataclass" version "x.y.z" 42 | } 43 | 44 | jsonSchema2Pojo { 45 | executions { 46 | main {} 47 | } 48 | } 49 | ----- 50 | // ------------------------------ 51 | | Kotlin 52 | a| 53 | [source,gradle] 54 | ----- 55 | plugins { 56 | `java` 57 | id("org.jsonschema2dataclass") version "x.y.z" 58 | } 59 | 60 | jsonSchema2Pojo { 61 | executions { 62 | create("main") { 63 | } 64 | } 65 | } 66 | ----- 67 | // ------------------------------ 68 | |===== 69 | 70 | == SDK and build tools support 71 | 72 | .Demos and statuses 73 | [options=header] 74 | |===== 75 | | SDK/Tool | Minimal Version | Maximum version | Notes 76 | // ------------------------------ 77 | | Java compiler 78 | | 8 79 | | 19 80 | | 81 | // ------------------------------ 82 | | Gradle 83 | | 6.0 84 | | 7.x 85 | | 8.0 support is beta till it will be released 86 | // ------------------------------ 87 | | Android Gradle Plugin 88 | | 3 89 | | 7 90 | | 91 | // ------------------------------ 92 | |===== 93 | 94 | == Demos and their statuses 95 | 96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin. 98 | 99 | Also, there's also integration tests which are 100 | 101 | Any contributions are welcome. 102 | 103 | .Demos and statuses 104 | [options=header] 105 | |===== 106 | | Platform | Demo | Status | Notes 107 | // ------------------------------ 108 | .3+| JVM 109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 110 | | Maintained and healthy 111 | | 112 | // ------------------------------ 113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 114 | | Maintained and healthy 115 | | 116 | // ------------------------------ 117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 118 | | Maintained and healthy 119 | | 120 | // ------------------------------ 121 | .4+| Android 122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example 123 | | Maintained and healthy 124 | | 125 | // ------------------------------ 126 | | AGP 8 127 | | Waiting for releases from Google and Gradle 128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation 129 | // ------------------------------ 130 | | AGP 4 131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0 132 | | Was unmaintained for a while 133 | // ------------------------------ 134 | | AGP 3 135 | | ⚠️ Demo has been removed in 5.0 136 | | Was unmaintained for a while 137 | // ------------------------------ 138 | |===== 139 | 140 | For AGP 3 and AGP 4 I have no computer to build the demos. 141 | -------------------------------------------------------------------------------- /docs/usage/basic_3.adoc: -------------------------------------------------------------------------------- 1 | :plugin_major: 5 2 | :demo-agp4: was marked as unmaintained 3 | 4 | :toc: 5 | :toc-placement: preamble 6 | :toclevels: 2 7 | :showtitle: 8 | 9 | = Basic plugin usage and support 10 | 11 | This page shows plugin basic usage and support. 12 | 13 | == Apply the plugin and basic settings 14 | 15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 16 | 17 | Then it's required to specify execution and their settings in the extension. 18 | 19 | The minimal usage example looks like shown in the following table. 20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration. 21 | 22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work. 23 | Kotlin and Groovy automatically apply one of plugin mentioned before. 24 | 25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen. 26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly. 27 | Execution section might contain as many executions as project needs (at least 1). 28 | 29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section. 30 | 31 | [options=header,cols="1,5"] 32 | |===== 33 | | DSL language | DSL 34 | // ------------------------------ 35 | | Groovy 36 | a| 37 | [source,gradle] 38 | ----- 39 | plugins { 40 | id "java" 41 | id "org.jsonschema2dataclass" version "x.y.z" 42 | } 43 | 44 | jsonSchema2Pojo { 45 | executions { 46 | main {} 47 | } 48 | } 49 | ----- 50 | // ------------------------------ 51 | | Kotlin 52 | a| 53 | [source,gradle] 54 | ----- 55 | plugins { 56 | `java` 57 | id("org.jsonschema2dataclass") version "x.y.z" 58 | } 59 | 60 | jsonSchema2Pojo { 61 | executions { 62 | create("main") { 63 | } 64 | } 65 | } 66 | ----- 67 | // ------------------------------ 68 | |===== 69 | 70 | == SDK and build tools support 71 | 72 | .Demos and statuses 73 | [options=header] 74 | |===== 75 | | SDK/Tool | Minimal Version | Maximum version | Notes 76 | // ------------------------------ 77 | | Java compiler 78 | | 8 79 | | 19 80 | | 81 | // ------------------------------ 82 | | Gradle 83 | | 6.0 84 | | 7.x 85 | | 8.0 support is beta till it will be released 86 | // ------------------------------ 87 | | Android Gradle Plugin 88 | | 3 89 | | 7 90 | | 91 | // ------------------------------ 92 | |===== 93 | 94 | == Demos and their statuses 95 | 96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin. 98 | 99 | Also, there's also integration tests which are 100 | 101 | Any contributions are welcome. 102 | 103 | .Demos and statuses 104 | [options=header] 105 | |===== 106 | | Platform | Demo | Status | Notes 107 | // ------------------------------ 108 | .3+| JVM 109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 110 | | Maintained and healthy 111 | | 112 | // ------------------------------ 113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 114 | | Maintained and healthy 115 | | 116 | // ------------------------------ 117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 118 | | Maintained and healthy 119 | | 120 | // ------------------------------ 121 | .4+| Android 122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example 123 | | Maintained and healthy 124 | | 125 | // ------------------------------ 126 | | AGP 8 127 | | Waiting for releases from Google and Gradle 128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation 129 | // ------------------------------ 130 | | AGP 4 131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0 132 | | Was unmaintained for a while 133 | // ------------------------------ 134 | | AGP 3 135 | | ⚠️ Demo has been removed in 5.0 136 | | Was unmaintained for a while 137 | // ------------------------------ 138 | |===== 139 | 140 | For AGP 3 and AGP 4 I have no computer to build the demos. 141 | -------------------------------------------------------------------------------- /docs/usage/basic_4.adoc: -------------------------------------------------------------------------------- 1 | :plugin_major: 5 2 | :demo-agp4: was marked as unmaintained 3 | 4 | :toc: 5 | :toc-placement: preamble 6 | :toclevels: 2 7 | :showtitle: 8 | 9 | = Basic plugin usage and support 10 | 11 | This page shows plugin basic usage and support. 12 | 13 | == Apply the plugin and basic settings 14 | 15 | A one should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 16 | 17 | Then it's required to specify execution and their settings in the extension. 18 | 19 | The minimal usage example looks like shown in the following table. 20 | Examples provided follow Gradle DSL to showcase `org.jsonschema2dataclass` plugin configuration. 21 | 22 | Plugin requires one of `java`, `java library`, `Android application` or `Android library` plugin applied to work. 23 | Kotlin and Groovy automatically apply one of plugin mentioned before. 24 | 25 | Execution name `main` as shown below is an arbitrary one and any other supported name can be chosen. 26 | Execution name must follow the regular expression `[a-z][A-Za-z0-9_]*` to generate task name properly. 27 | Execution section might contain as many executions as project needs (at least 1). 28 | 29 | Inside any execution a developer might override any parameter as per their needs as described in xref:parameters_{plugin_major}.adoc[parameters] section. 30 | 31 | [options=header,cols="1,5"] 32 | |===== 33 | | DSL language | DSL 34 | // ------------------------------ 35 | | Groovy 36 | a| 37 | [source,gradle] 38 | ----- 39 | plugins { 40 | id "java" 41 | id "org.jsonschema2dataclass" version "x.y.z" 42 | } 43 | 44 | jsonSchema2Pojo { 45 | executions { 46 | main {} 47 | } 48 | } 49 | ----- 50 | // ------------------------------ 51 | | Kotlin 52 | a| 53 | [source,gradle] 54 | ----- 55 | plugins { 56 | `java` 57 | id("org.jsonschema2dataclass") version "x.y.z" 58 | } 59 | 60 | jsonSchema2Pojo { 61 | executions { 62 | create("main") { 63 | } 64 | } 65 | } 66 | ----- 67 | // ------------------------------ 68 | |===== 69 | 70 | == SDK and build tools support 71 | 72 | .Demos and statuses 73 | [options=header] 74 | |===== 75 | | SDK/Tool | Minimal Version | Maximum version | Notes 76 | // ------------------------------ 77 | | Java compiler 78 | | 8 79 | | 19 80 | | 81 | // ------------------------------ 82 | | Gradle 83 | | 6.0 84 | | 7.x 85 | | 8.0 support is beta till it will be released 86 | // ------------------------------ 87 | | Android Gradle Plugin 88 | | 3 89 | | 7 90 | | 91 | // ------------------------------ 92 | |===== 93 | 94 | == Demos and their statuses 95 | 96 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 97 | These minimal applications aren't normal full-featured for a given platform, but can be used as a showcase for a plugin. 98 | 99 | Also, there's also integration tests which are 100 | 101 | Any contributions are welcome. 102 | 103 | .Demos and statuses 104 | [options=header] 105 | |===== 106 | | Platform | Demo | Status | Notes 107 | // ------------------------------ 108 | .3+| JVM 109 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 110 | | Maintained and healthy 111 | | 112 | // ------------------------------ 113 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 114 | | Maintained and healthy 115 | | 116 | // ------------------------------ 117 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 118 | | Maintained and healthy 119 | | 120 | // ------------------------------ 121 | .4+| Android 122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android/agp7[AGP 7] example 123 | | Maintained and healthy 124 | | 125 | // ------------------------------ 126 | | AGP 8 127 | | Waiting for releases from Google and Gradle 128 | | AGP 8 depends on Gradle 8.0 which is not released at the time of writing the documentation 129 | // ------------------------------ 130 | | AGP 4 131 | | ⚠️ Demo {demo-agp4} since {plugin_major}.0 132 | | Was unmaintained for a while 133 | // ------------------------------ 134 | | AGP 3 135 | | ⚠️ Demo has been removed in 5.0 136 | | Was unmaintained for a while 137 | // ------------------------------ 138 | |===== 139 | 140 | For AGP 3 and AGP 4 I have no computer to build the demos. 141 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/publishing/publishing.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.publishing 2 | 3 | import basePluginExtension 4 | import groovy.util.Node 5 | import groovy.util.NodeList 6 | import org.gradle.api.Project 7 | import org.gradle.api.publish.PublishingExtension 8 | import org.gradle.api.publish.maven.MavenPublication 9 | import org.gradle.kotlin.dsl.configure 10 | import org.gradle.kotlin.dsl.get 11 | import org.gradle.kotlin.dsl.getByName 12 | import org.gradle.kotlin.dsl.register 13 | import org.gradle.plugins.signing.SigningExtension 14 | 15 | fun applyPublishing(project: Project, signing: Boolean = false) { 16 | project.plugins.apply("maven-publish") 17 | 18 | project.configure { 19 | publications { 20 | register("release") release@{ 21 | if (signing) { 22 | project.configure { 23 | sign(this@release) 24 | } 25 | } 26 | setupModuleIdentity(project) 27 | from(project.components["java"]) 28 | setupLinks() 29 | } 30 | } 31 | } 32 | project.afterEvaluate { 33 | project.configure { 34 | publications { 35 | getByName("release") { 36 | reorderNodes(project) 37 | } 38 | } 39 | } 40 | } 41 | } 42 | 43 | private fun MavenPublication.setupModuleIdentity(project: Project) { 44 | project.afterEvaluate { 45 | artifactId = project.basePluginExtension.archivesName.get() 46 | version = project.version as String 47 | 48 | pom { 49 | val projectDescription = project.description?.takeIf { it.contains(": ") } 50 | ?: error("$project must have a description with format: \"Module Display Name: Module description.\"") 51 | name.set(projectDescription.substringBefore(": ").also { check(it.isNotBlank()) }) 52 | description.set(projectDescription.substringAfter(": ").also { check(it.isNotBlank()) }) 53 | } 54 | } 55 | } 56 | 57 | private fun MavenPublication.setupLinks() { 58 | pom { 59 | url.set("https://github.com/jsonschema2dataclass/js2d-gradle") 60 | scm { 61 | connection.set("scm:git:github.com/jsonschema2dataclass/js2d-gradle.git") 62 | developerConnection.set("scm:git:github.com/jsonschema2dataclass/js2d-gradle.git") 63 | url.set("https://github.com/jsonschema2dataclass/js2d-gradle/tree/master") 64 | } 65 | licenses { 66 | license { 67 | name.set("The Apache License, Version 2.0") 68 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") 69 | } 70 | } 71 | developers { 72 | developer { 73 | id.set("eirnym") 74 | name.set("Eir Nym") 75 | email.set("eirnym@gmail.com") 76 | } 77 | } 78 | } 79 | } 80 | 81 | private fun MavenPublication.reorderNodes(project: Project) { 82 | fun Node.getChildren(localName: String): NodeList = 83 | this.get(localName) as NodeList 84 | 85 | fun NodeList.nodes(): List = 86 | (this as Iterable<*>).filterIsInstance() 87 | 88 | fun Node.getChild(localName: String): Node? = 89 | this.getChildren(localName).nodes().singleOrNull() 90 | 91 | project.afterEvaluate { 92 | pom.withXml { 93 | asNode().apply { 94 | val lastNodes = sequenceOf( 95 | getChild("modelVersion"), 96 | getChild("groupId"), 97 | getChild("artifactId"), 98 | getChild("version"), 99 | getChild("name"), 100 | getChild("description"), 101 | getChild("url"), 102 | getChild("dependencies"), 103 | getChild("scm"), 104 | getChild("developers"), 105 | getChild("licenses"), 106 | ).filterNotNull() 107 | .toList() 108 | 109 | // lastNodes.forEach { println("found node ${it.name()}") } 110 | lastNodes.forEach { remove(it) } 111 | lastNodes.forEach { append(it) } 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/internal/NameGeneratorTest.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.js2p.internal 2 | 3 | import org.jsonschema2dataclass.internal.createTaskNameDescription 4 | import org.jsonschema2dataclass.internal.generatePart 5 | import org.junit.jupiter.api.Assertions.assertEquals 6 | import org.junit.jupiter.params.ParameterizedTest 7 | import org.junit.jupiter.params.provider.CsvSource 8 | 9 | private const val EXECUTION_NAME = "execution" 10 | 11 | class NameGeneratorTest { 12 | @ParameterizedTest 13 | @CsvSource( 14 | "variant,release,true,ForRelease,'for variant release'", 15 | "flavor,release,true,ForRelease,'for flavor release'", 16 | "variant,release,false,ForVariantRelease,'for variant release'", 17 | "flavor,release,false,ForFlavorRelease,'for flavor release'", 18 | ) 19 | fun generatePartTest( 20 | suffixName: String, 21 | suffixValue: String, 22 | compatible: Boolean, 23 | expectedName: String, 24 | expectedDescription: String, 25 | ) { 26 | val suffix = suffixName to suffixValue 27 | val actual = generatePart(suffix, compatible) 28 | assertEquals(expectedName to expectedDescription, actual) 29 | } 30 | 31 | @ParameterizedTest 32 | @CsvSource( 33 | "Js2p,'tool description',,,,,true," + 34 | "generateJsonSchema2DataClassConfigExecution," + 35 | "'tool description for configuration execution'", 36 | "Js2p,'tool description',,,,,false," + 37 | "generateJsonSchema2DataClassJs2pConfigExecution," + 38 | "'tool description for configuration execution'", 39 | "Js2p,'tool description',variant,release,,,true," + 40 | "generateJsonSchema2DataClassForReleaseConfigExecution," + 41 | "'tool description for variant release for configuration execution'", 42 | "Js2p,'tool description',variant,release,,,false," + 43 | "generateJsonSchema2DataClassJs2pForVariantReleaseConfigExecution," + 44 | "'tool description for variant release for configuration execution'", 45 | "Js2p,'tool description',variant,release,flavor,shop,true," + 46 | "generateJsonSchema2DataClassForVariantReleaseForFlavorShopConfigExecution," + 47 | "'tool description for variant release for flavor shop for configuration execution'", 48 | "Js2p,'tool description',variant,release,flavor,shop,false," + 49 | "generateJsonSchema2DataClassJs2pForVariantReleaseForFlavorShopConfigExecution," + 50 | "'tool description for variant release for flavor shop for configuration execution'", 51 | "Js2d,'tool description',,,,,true," + 52 | "generateJsonSchema2DataClassJs2dConfigExecution," + 53 | "'tool description for configuration execution'", 54 | "Js2d,'tool description',,,,,false," + 55 | "generateJsonSchema2DataClassJs2dConfigExecution," + 56 | "'tool description for configuration execution'", 57 | "Js2d,'tool description',variant,release,,,true," + 58 | "generateJsonSchema2DataClassJs2dForReleaseConfigExecution," + 59 | "'tool description for variant release for configuration execution'", 60 | "Js2d,'tool description',variant,release,,,false," + 61 | "generateJsonSchema2DataClassJs2dForVariantReleaseConfigExecution," + 62 | "'tool description for variant release for configuration execution'", 63 | "Js2d,'tool description',variant,release,flavor,shop,true," + 64 | "generateJsonSchema2DataClassJs2dForVariantReleaseForFlavorShopConfigExecution," + 65 | "'tool description for variant release for flavor shop for configuration execution'", 66 | "Js2d,'tool description',variant,release,flavor,shop,false," + 67 | "generateJsonSchema2DataClassJs2dForVariantReleaseForFlavorShopConfigExecution," + 68 | "'tool description for variant release for flavor shop for configuration execution'", 69 | ) 70 | fun generateSuffixesTest( 71 | toolName: String, 72 | toolDescription: String, 73 | suffix1Name: String?, 74 | suffix1Value: String?, 75 | suffix2Name: String?, 76 | suffix2Value: String?, 77 | compatible: Boolean, 78 | expectedName: String, 79 | expectedDescription: String, 80 | ) { 81 | val pairs = mutableListOf>() 82 | 83 | if (suffix1Name != null && suffix1Value != null) { 84 | pairs.add(suffix1Name to suffix1Value) 85 | } 86 | if (suffix2Name != null && suffix2Value != null) { 87 | pairs.add(suffix2Name to suffix2Value) 88 | } 89 | val suffixes = pairs.toMap() 90 | 91 | val tool = toolName to toolDescription 92 | 93 | val result = createTaskNameDescription( 94 | EXECUTION_NAME, 95 | suffixes, 96 | compatible, 97 | tool, 98 | ) 99 | val expected = expectedName to expectedDescription 100 | assertEquals(expected, result) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /docs/usage/basic_6.adoc: -------------------------------------------------------------------------------- 1 | :plugin_major: 6 2 | :demo-agp4: has been removed 3 | 4 | :toc: 5 | :toc-placement: preamble 6 | :toclevels: 2 7 | :showtitle: 8 | 9 | = Basic plugin usage and support 10 | 11 | This page shows plugin basic usage and support. 12 | 13 | == Plugin requirements and compatibility 14 | 15 | Plugin requires to work one of these plugins: `java`, `java library`, `Android application` or `Android library`. 16 | These plugins can be applied directly or indirectly. 17 | 18 | Additionally, plugin is compatible with `org.freefair.lombok`. 19 | 20 | == Apply the plugin and basic settings 21 | 22 | One should follow an https://plugins.gradle.org/plugin/org.jsonschema2dataclass[official Gradle guide] to apply the plugin. 23 | 24 | Examples are provided in a table below to showcase `org.jsonschema2dataclass` plugin minimal configuration. 25 | This way, extension `jsonSchema2Pojo` will be configured with an execution `example` in the `executions` container. 26 | 27 | More detailed usage is documented in xref:parameters_{plugin_major}.adoc[parameters] section. 28 | 29 | [options=header,cols="1,5"] 30 | |===== 31 | | DSL language | DSL example 32 | // ------------------------------ 33 | | Groovy 34 | a| 35 | [source,groovy] 36 | ----- 37 | plugins { 38 | id "java" 39 | id "org.jsonschema2dataclass" version "x.y.z" 40 | } 41 | 42 | jsonSchema2Pojo { 43 | executions { 44 | example {} 45 | } 46 | } 47 | ----- 48 | // ------------------------------ 49 | | Kotlin 50 | a| 51 | [source,kotlin] 52 | ----- 53 | plugins { 54 | java 55 | id("org.jsonschema2dataclass") version "x.y.z" 56 | } 57 | 58 | jsonSchema2Pojo { 59 | executions { 60 | create("example") { 61 | } 62 | } 63 | } 64 | ----- 65 | // ------------------------------ 66 | |===== 67 | 68 | == Processor dependencies 69 | 70 | In some cases it is required to specify dependencies for a processor to 71 | reference some JSON files via classpath or define plugin classes for a processor. 72 | 73 | To achieve this, it is required to add these dependencies to `jsonschema2dataclassPlugins` 74 | https://docs.gradle.org/current/userguide/dependency_management_terminology.html#sub:terminology_configuration[configuration]. 75 | 76 | NOTE: It's impossible to add a dependency from an output from an execution. 77 | 78 | == Hooks and task dependencies 79 | 80 | By default, plugin generates tasks to be run after process resources task, so the output from this task can be used. 81 | Additionally, plugin tasks are configured to run before execution of compilation 82 | and lombok (from `org.freefair.lombok`) processor. 83 | 84 | == SDK and build tools support 85 | 86 | .Demos and statuses 87 | [options=header] 88 | |===== 89 | | SDK/Tool | Minimal Version | Maximum version | Notes 90 | // ------------------------------ 91 | | Java compiler 92 | | 8 93 | | 19 94 | | 95 | // ------------------------------ 96 | | Gradle 97 | | 6.0 98 | | 7.x 99 | | 8.0 support is currently in beta. 100 | // ------------------------------ 101 | | Android Gradle Plugin 102 | | 3 103 | | 7 104 | | 105 | // ------------------------------ 106 | |===== 107 | 108 | == Demos and their statuses 109 | 110 | Project contains various minimal `org.jsonschema2dataclass` plugin usage https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo[demos]. 111 | These minimal applications doesn't represent a normal full-featured applications for a given platform. 112 | These application are included for a showcase plugin features and capabilities. 113 | 114 | NOTE: Any additional ideas and contributions are welcome. 115 | 116 | .Demos and statuses 117 | [options=header] 118 | |===== 119 | | Platform | Demo | Status | Notes 120 | // ------------------------------ 121 | .4+| JVM 122 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/groovy[Groovy DSL] example 123 | | Maintained and healthy 124 | | Demonstrates compatibility with Groovy DSL 125 | // ------------------------------ 126 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/kotlin[Kotlin DSL] example 127 | | Maintained and healthy 128 | | Demonstrates compatibility with Kotlin DSL and Kotlin language 129 | // ------------------------------ 130 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/model-publish[Model publishing] example 131 | | Maintained and healthy 132 | | Demonstrates a way to publish jars with sources and schemas along with classes 133 | // ------------------------------ 134 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/java/classpath[Plugin's processor classpath] examples 135 | | Maintained and healthy 136 | | Demonstrates usage for plugin's processor classpath manipulation to apply schemas and custom RuleFactory 137 | // ------------------------------ 138 | .4+| Android 139 | | https://github.com/jsonschema2dataclass/js2d-gradle/tree/main/demo/android-agp7[AGP 7] example 140 | | Maintained and healthy 141 | | Demonstrates usage in an android application 142 | // ------------------------------ 143 | | AGP 4 144 | | ⚠️ Demo has been removed since 6.0 145 | a| 146 | 147 | * AGP 4 API is used to bind to the Android project, so it's still technically supported. 148 | * PR and support for a demo is welcome 149 | 150 | // ------------------------------ 151 | |===== 152 | -------------------------------------------------------------------------------- /docs/migration/migration_5.adoc: -------------------------------------------------------------------------------- 1 | :toc: 2 | :toc-placement: preamble 3 | :toclevels: 2 4 | :showtitle: 5 | 6 | = Migration guide from 4.5.0 to 5.0 7 | 8 | This guide highlights major changes and shows how to change a project to use new plugin. 9 | 10 | == Default execution is deprecated and removed 11 | 12 | Previously, it was possible to define execution without an execution. 13 | Now it's important to define executions for every single project. 14 | 15 | Improperly upgraded projects using the old model will receive a warning 16 | during the build briefly explaining actions required. 17 | 18 | The reasons of deprecation and removal of this feature is: 19 | 20 | * There's no way to tell how and if extension has been applied. 21 | * Plugin features can't be extended as much as they planned. 22 | * Configuration refactoring can't be done as easy as it could be. 23 | * A lot of spaghetti, generated and copy-paste code in the plugin makes it hard to maintain and catch an error. 24 | 25 | Examples: 26 | 27 | .No Extension defined example 28 | [options=header,cols="1,5"] 29 | |===== 30 | | DSL language | DSL 31 | // ------------------------------ 32 | | Groovy 33 | 34 | Old version (prior 5.x), 35 | a| 36 | [source,gradle] 37 | ----- 38 | plugins { 39 | id "java" 40 | id "org.jsonschema2dataclass" version "x.y.z" 41 | } 42 | ----- 43 | // ------------------------------ 44 | | Groovy 45 | 46 | Recommended new version (5.x) 47 | a| 48 | [source,gradle] 49 | ----- 50 | plugins { 51 | id "java" 52 | id "org.jsonschema2dataclass" version "x.y.z" 53 | } 54 | 55 | jsonSchema2Pojo { 56 | executions { 57 | main {} 58 | } 59 | } 60 | ----- 61 | // ------------------------------ 62 | | Kotlin 63 | 64 | Old version (prior 5.x), 65 | a| 66 | [source,gradle] 67 | ----- 68 | plugins { 69 | `java` 70 | id("org.jsonschema2dataclass") version "x.y.z" 71 | } 72 | ----- 73 | // ------------------------------ 74 | | Kotlin 75 | 76 | Recommended new version (5.x) 77 | a| 78 | [source,gradle] 79 | ----- 80 | plugins { 81 | `java` 82 | id("org.jsonschema2dataclass") version "x.y.z" 83 | } 84 | 85 | jsonSchema2Pojo { 86 | executions { 87 | create("main") 88 | } 89 | } 90 | ----- 91 | // ------------------------------ 92 | |===== 93 | 94 | .No execution defined in extension 95 | [options=header,cols="1,5"] 96 | |===== 97 | | DSL language | DSL 98 | // ------------------------------ 99 | | Groovy 100 | 101 | Old version (prior 5.x), 102 | a| 103 | [source,gradle] 104 | ----- 105 | plugins { 106 | id "java" 107 | id "org.jsonschema2dataclass" version "x.y.z" 108 | } 109 | 110 | jsonSchema2Pojo { 111 | targetPackage = 'example' 112 | } 113 | ----- 114 | // ------------------------------ 115 | | Groovy 116 | 117 | Recommended new version (5.x) 118 | a| 119 | [source,gradle] 120 | ----- 121 | plugins { 122 | id "java" 123 | id "org.jsonschema2dataclass" version "x.y.z" 124 | } 125 | 126 | jsonSchema2Pojo { 127 | executions { 128 | main { 129 | targetPackage = 'example' 130 | } 131 | } 132 | } 133 | ----- 134 | // ------------------------------ 135 | | Kotlin 136 | 137 | Old version (prior 5.x), 138 | a| 139 | [source,gradle] 140 | ----- 141 | plugins { 142 | `java` 143 | id("org.jsonschema2dataclass") version "x.y.z" 144 | } 145 | jsonSchema2Pojo { 146 | targetPackage.set("example") 147 | } 148 | ----- 149 | // ------------------------------ 150 | | Kotlin 151 | 152 | Recommended new version (5.x) 153 | a| 154 | [source,gradle] 155 | ----- 156 | plugins { 157 | `java` 158 | id("org.jsonschema2dataclass") version "x.y.z" 159 | } 160 | 161 | jsonSchema2Pojo { 162 | executions { 163 | create("main") { 164 | targetPackage.set("example") 165 | } 166 | } 167 | } 168 | ----- 169 | // ------------------------------ 170 | |===== 171 | 172 | == Subtasks changed their names 173 | 174 | Version 5.0 renames sub-tasks to more readable values. Main tasks still have the same name as before. 175 | 176 | . Configuration name is used as part of task name instead of a sequence number. 177 | * Gradle API provides a set of configurations instead of list and never guarantees, which configuration will be first. 178 | * Using configuration names is more readable when a developer refers to it. 179 | . Android variant part is shifted toward beginning. 180 | * This way it's easier to read task list. 181 | 182 | [options=header] 183 | |===== 184 | | Old name | New name | Notes 185 | // ------------------------------ 186 | | generateJsonSchema2DataClass0 187 | | generateJsonSchema2DataClassConfigMain 188 | | Configuration name at the end 189 | // ------------------------------ 190 | | generateJsonSchema2DataClassForRelease 191 | | generateJsonSchema2DataClassForRelease 192 | | Common task with Android variant is the same 193 | // ------------------------------ 194 | | generateJsonSchema2DataClass0ForRelease 195 | | generateJsonSchema2DataClassForReleaseConfigMain 196 | | Android variant part shifted 197 | // ------------------------------ 198 | |===== 199 | 200 | == Ability to hook for any task in gradle scripts and other plugins 201 | 202 | From 5.x onwards the plugin applies itself and generate tasks as soon as possible. 203 | Thus, it's possible to directly hook the tasks if needed. 204 | 205 | Previously, it was possible create only indirect hooks for tasks (which is still the preferred way to hook): 206 | * generateJsonSchema2DataClass depends on resource processing tasks 207 | * compilation and Lombok plugin tasks depend on generateJsonSchema2DataClass 208 | 209 | == AGP 3 demo is removed, AGP 4 demo is unmaintained. 210 | 211 | I have no machine to build the demo. It requires build tools `30.0.3` at the most and can't use newer ones. 212 | Google provides binaries incompatible with my computer and CPU architecture. 213 | 214 | Additionally, I was unable to find live Android library or application projects on GitHub. 215 | 216 | This project is using and maintaining AGP3 API and will abandon it when Google decides to remove support of it. 217 | 218 | === AGP 3 demo is removed 219 | 220 | It doesn't build on CI for a little while and I can't build on my computer as well. 221 | 222 | === AGP 4 demo is unmaintained 223 | 224 | Mostly because of lack of build tools on my computer. 225 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/GradleVersions.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.js2p 2 | 3 | import org.gradle.api.JavaVersion 4 | import org.gradle.util.GradleVersion 5 | import org.junit.jupiter.params.provider.Arguments 6 | 7 | const val ENV_TEST_MIN = "TEST_GRADLE_VER_MIN" 8 | const val ENV_TEST_MAX = "TEST_GRADLE_VER_MAX" 9 | const val ENV_TEST_EXACT = "TEST_GRADLE_VER_EXACT" 10 | const val ENV_TEST_EXACT_CURRENT = "current" 11 | 12 | // Gradle releases can be found at https://gradle.org/releases/ 13 | // M.B. current (Running) release will always be tested even it's not listed here. 14 | private val gradleReleases8x = arrayOf( 15 | "8.8", 16 | "8.7", 17 | "8.6", 18 | "8.5", 19 | "8.4", 20 | "8.3", 21 | "8.2.1", 22 | "8.1.1", 23 | "8.0.2", 24 | ) 25 | private val gradleReleases7x = arrayOf( 26 | "7.6.4", 27 | "7.5.1", 28 | "7.4.2", 29 | "7.3.3", 30 | "7.2", 31 | "7.1.1", 32 | "7.0.2", 33 | ) 34 | private val gradleReleases6x = arrayOf( 35 | "6.9.1", 36 | "6.8.3", 37 | "6.7.1", 38 | "6.6.1", 39 | "6.5.1", 40 | "6.4.1", 41 | "6.3", 42 | "6.2.2", 43 | "6.2.1", 44 | "6.1.1", 45 | "6.0.1", 46 | ) 47 | 48 | private val gradleReleases = linkedSetOf( 49 | GradleVersion.current().version, 50 | *gradleReleases8x, 51 | *gradleReleases7x, 52 | *gradleReleases6x, 53 | ) 54 | 55 | private val compatibleVersions = filterCompatibleVersions("6.0") 56 | private val compatibleVersionsConfigurationCache = filterCompatibleVersions("6.6") 57 | 58 | /** 59 | * Supported gradle versions per java 60 | * 61 | * Information can be found here: https://docs.gradle.org/current/userguide/compatibility.html 62 | * N.B. "Support for running Gradle" is the only thing is important 63 | * 64 | * | Java version | Gradle version | 65 | * |--------------|----------------| 66 | * | 1.8 - 13 | >= 6.0 | 67 | * | 14 | >= 6.3 | 68 | * | 15 | >= 6.7 | 69 | * | 16 | >= 7.0 | 70 | * | 17 | >= 7.3 | 71 | * | 18 | >= 7.5 | 72 | * | 19 | >= 7.6 | 73 | * | 20 | >= 8.3 | 74 | * | 21 | >= 8.5 | 75 | * | 22 | >= 8.8 | 76 | * | 22 | >= ?.? | 77 | * | other | not supported | 78 | */ 79 | private fun gradleSupported(gradleVersion: ComparableGradleVersion): Boolean = 80 | when (JavaVersion.current()) { 81 | in JavaVersion.VERSION_1_8..JavaVersion.VERSION_13 -> gradleVersion >= 6 to 0 82 | JavaVersion.VERSION_14 -> gradleVersion >= 6 to 3 83 | JavaVersion.VERSION_15 -> gradleVersion >= 6 to 7 84 | JavaVersion.VERSION_16 -> gradleVersion >= 7 to 0 85 | JavaVersion.VERSION_17 -> gradleVersion >= 7 to 3 86 | JavaVersion.VERSION_18 -> gradleVersion >= 7 to 5 87 | JavaVersion.VERSION_19 -> gradleVersion >= 7 to 6 88 | JavaVersion.VERSION_20 -> gradleVersion >= 8 to 3 89 | JavaVersion.VERSION_21 -> gradleVersion >= 8 to 5 90 | JavaVersion.VERSION_22 -> gradleVersion >= 8 to 8 91 | else -> false // no official information on Gradle compatibility with further versions of Java 92 | } 93 | 94 | private fun filterCompatibleVersions(minimumInternalVersionString: String): List { 95 | val minimumInternalVersion = ComparableGradleVersion(minimumInternalVersionString) 96 | 97 | val minVersion = System.getenv()[ENV_TEST_MIN]?.let { ComparableGradleVersion(it) } 98 | val maxVersion = System.getenv()[ENV_TEST_MAX]?.let { ComparableGradleVersion(it) } 99 | val exactVersion = System.getenv()[ENV_TEST_EXACT]?.let { 100 | if (it == ENV_TEST_EXACT_CURRENT) { 101 | ComparableGradleVersion(GradleVersion.current().version) 102 | } else { 103 | ComparableGradleVersion(it) 104 | } 105 | } 106 | 107 | return gradleReleases 108 | .filter { v -> 109 | val version = ComparableGradleVersion(v) 110 | 111 | val supported = gradleSupported(version) 112 | val isAboveMinInternal = version >= minimumInternalVersion.gradleVersion 113 | 114 | val isAboveMin = minVersion?.let { version >= it.gradleVersion } ?: true 115 | val isBelowMax = maxVersion?.let { version <= it.gradleVersion } ?: true 116 | val isExact = exactVersion?.let { version.gradleVersion == it.gradleVersion } ?: true 117 | 118 | supported && isAboveMinInternal && isAboveMin && isBelowMax && isExact 119 | }.toList() 120 | } 121 | 122 | /** 123 | * Holder class for gradle releases version to test against current java 124 | * version 125 | */ 126 | @Suppress("unused") 127 | class GradleVersions private constructor() { 128 | companion object { 129 | @JvmStatic 130 | private fun argumentFilter(compatibleVersions: List): List = 131 | if (compatibleVersions.isNotEmpty()) { 132 | compatibleVersions.map { Arguments.of(*arrayOf(it)) } 133 | } else { 134 | listOf(Arguments.of(*arrayOf(null))) 135 | } 136 | 137 | @JvmStatic 138 | fun gradleReleasesForTests(): List = argumentFilter(compatibleVersions) 139 | 140 | @JvmStatic 141 | fun configurationCacheCompatibleGradleReleasesForTests(): List = 142 | argumentFilter(compatibleVersionsConfigurationCache) 143 | } 144 | } 145 | 146 | private class ComparableGradleVersion( 147 | gradleVersionString: String, 148 | ) : Comparable> { 149 | val gradleVersion: Pair 150 | 151 | init { 152 | val gradleVersionParts = gradleVersionString.split(".") 153 | gradleVersion = if (gradleVersionParts.size >= 2) { 154 | gradleVersionParts[0].toInt() to gradleVersionParts[1].toInt() 155 | } else { 156 | gradleVersionParts[0].toInt() to 0 157 | } 158 | } 159 | 160 | override fun compareTo(other: Pair): Int { 161 | val resultFirst = this.gradleVersion.first.compareTo(other.first) 162 | if (resultFirst == 0) { 163 | return this.gradleVersion.second.compareTo(other.second) 164 | } 165 | return resultFirst 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/TestCasesGenerator.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.js2p 2 | 3 | import org.jsonschema2dataclass.internal.task.DEFAULT_TARGET_FOLDER_BASE 4 | import org.jsonschema2dataclass.internal.task.PLUGIN_ID 5 | import java.io.File 6 | import java.nio.file.Files 7 | import java.nio.file.Path 8 | 9 | const val TARGET_FOLDER_BASE_CUSTOM = DEFAULT_TARGET_FOLDER_BASE + "s" 10 | val BUILD_FILE_HEADER = """ 11 | |plugins { 12 | | id "java-library" 13 | | id "$PLUGIN_ID" version "1.2.3" 14 | |} 15 | |repositories { 16 | | mavenCentral() 17 | |} 18 | |dependencies { 19 | | implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2" 20 | |} 21 | """.trimMargin() 22 | 23 | val BUILD_FILE_HEADER_PLUGIN_ONLY = """ 24 | |plugins { 25 | | id "$PLUGIN_ID" version "1.2.3" 26 | |} 27 | """.trimMargin() 28 | 29 | val BUILD_FILE_HEADER_LAZY = """ 30 | |plugins { 31 | | id "$PLUGIN_ID" version "1.2.3" 32 | |} 33 | | 34 | |// apply plugin: 'org.jsonschema2dataclass' 35 | |// Even though it is not recommended to use apply syntax, we use it here 36 | |// to ensure java-library plugin is applied after org.jsonschema2dataclass 37 | |apply plugin: 'java-library' 38 | | 39 | |repositories { 40 | | mavenCentral() 41 | |} 42 | |dependencies { 43 | | implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2" 44 | |} 45 | """.trimMargin() 46 | 47 | val ADDRESS_JSON = """ 48 | |{ 49 | | "description": "An Address following the convention of http://microformats.org/wiki/hcard", 50 | | "type": "object", 51 | | "properties": { 52 | | "post_office_box": { "type": "string" }, 53 | | "extended_address": { "type": "string" }, 54 | | "street_address": { "type": "string" }, 55 | | "locality":{ "type": "string", "required": true }, 56 | | "region": { "type": "string", "required": true }, 57 | | "postal_code": { "type": "string" }, 58 | | "country_name": { "type": "string", "required": true}, 59 | | "address": {"type": "array", "items": "string"} 60 | | }, 61 | | "dependencies": { 62 | | "post_office_box": "street_address", 63 | | "extended_address": "street_address" 64 | | } 65 | |} 66 | """.trimMargin() 67 | 68 | fun writeBuildFiles( 69 | testProjectDir: Path, 70 | shouldCopyAddressJSON: Boolean, 71 | suffix: String, 72 | buildFileHeader: String = BUILD_FILE_HEADER, 73 | ) { 74 | Files.write( 75 | testProjectDir.resolve("build.gradle"), 76 | (buildFileHeader + "\n" + suffix).trimIndent().toByteArray(), 77 | ) 78 | Files.write(testProjectDir.resolve("settings.gradle"), ByteArray(0)) 79 | if (shouldCopyAddressJSON) { 80 | copyAddressJSON(testProjectDir) 81 | } 82 | } 83 | 84 | fun createBuildFilesSingleSimple(testProjectDir: Path, shouldCopyAddressJSON: Boolean) { 85 | writeBuildFiles( 86 | testProjectDir, 87 | shouldCopyAddressJSON, 88 | """ 89 | |jsonSchema2Pojo{ 90 | | executions { 91 | | create("com") { 92 | | klass.targetPackage.set("com.example") 93 | | } 94 | | } 95 | |} 96 | """.trimMargin(), 97 | ) 98 | } 99 | 100 | fun createBuildFilesSingleNoExtension(testProjectDir: Path, shouldCopyAddressJSON: Boolean) { 101 | writeBuildFiles(testProjectDir, shouldCopyAddressJSON, "") 102 | } 103 | 104 | /** 105 | * Multiple executions 106 | */ 107 | fun createBuildFilesMultiple(testProjectDir: Path, shouldCopyAddressJSON: Boolean) { 108 | writeBuildFiles( 109 | testProjectDir, 110 | shouldCopyAddressJSON, 111 | """ 112 | |jsonSchema2Pojo{ 113 | | targetDirectoryPrefix = project.file("${'$'}{buildDir}/$TARGET_FOLDER_BASE_CUSTOM") 114 | | executions { 115 | | com{ 116 | | klass.targetPackage = "com.example" 117 | | } 118 | | org{ 119 | | klass.targetPackage = "org.example" 120 | | } 121 | | } 122 | |} 123 | """.trimMargin(), 124 | ) 125 | } 126 | 127 | /** 128 | * Single with execution 129 | */ 130 | fun createBuildFilesSingle(testProjectDir: Path, shouldCopyAddressJSON: Boolean) { 131 | writeBuildFiles( 132 | testProjectDir, 133 | shouldCopyAddressJSON, 134 | """ 135 | |jsonSchema2Pojo { 136 | | executions { 137 | | com { 138 | | klass.targetPackage = "com.example" 139 | | } 140 | | } 141 | |} 142 | """.trimMargin(), 143 | ) 144 | } 145 | 146 | /** 147 | * Single with execution, inherited 148 | */ 149 | fun createBuildFilesLazyInit(testProjectDir: Path, shouldCopyAddressJSON: Boolean) { 150 | writeBuildFiles( 151 | testProjectDir, 152 | shouldCopyAddressJSON, 153 | suffix = """ 154 | |jsonSchema2Pojo { 155 | | executions { 156 | | com { 157 | | klass.targetPackage = "com.example" 158 | | } 159 | | } 160 | |} 161 | """.trimMargin(), 162 | buildFileHeader = BUILD_FILE_HEADER_LAZY, 163 | ) 164 | Files.write(testProjectDir.resolve("settings.gradle"), ByteArray(0)) 165 | } 166 | 167 | internal fun copyAddressJSON(testProjectDir: Path) { 168 | val jsonDir = testProjectDir.resolve("src/main/resources/json") 169 | File(jsonDir.toString()).mkdirs() 170 | jsonDir.resolve("address.json").toFile().writeText(ADDRESS_JSON) 171 | } 172 | 173 | fun createBuildFilesWithSourcesJar(testProjectDir: Path) { 174 | writeBuildFiles( 175 | testProjectDir, 176 | true, 177 | """ 178 | |jsonSchema2Pojo{ 179 | | executions { 180 | | create("com") { 181 | | klass.targetPackage.set("com.example") 182 | | } 183 | | } 184 | |} 185 | | 186 | |java { 187 | | withSourcesJar() 188 | |} 189 | | 190 | |tasks.register("generateAndJarSources") { 191 | | dependsOn("generateJsonSchema2DataClass", "sourcesJar") 192 | |} 193 | """.trimMargin(), 194 | ) 195 | } 196 | -------------------------------------------------------------------------------- /internal/plugins/src/main/kotlin/org/jsonschema2dataclass/internal/plugin/lib/ProcessorVersionPlugin.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.plugin.lib 2 | 3 | import org.gradle.api.DefaultTask 4 | import org.gradle.api.GradleException 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | import org.gradle.api.file.DirectoryProperty 8 | import org.gradle.api.plugins.JavaPluginExtension 9 | import org.gradle.api.provider.Property 10 | import org.gradle.api.tasks.Input 11 | import org.gradle.api.tasks.Optional 12 | import org.gradle.api.tasks.OutputDirectory 13 | import org.gradle.api.tasks.SourceSet 14 | import org.gradle.api.tasks.SourceSetContainer 15 | import org.gradle.api.tasks.TaskAction 16 | import org.gradle.kotlin.dsl.apply 17 | import org.gradle.util.GradleVersion 18 | import versionCatalogs 19 | import java.io.File 20 | import java.util.Properties 21 | 22 | private const val PROCESSOR_VERSION_EXTENSION = "processorVersion" 23 | private const val PROCESSOR_VERSION_CATALOG = "processors" 24 | private const val DEFAULT_TARGET_FOLDER_BASE = "generated/sources/processorVersion" 25 | private const val DEFAULT_TARGET_FILENAME = "processor.properties" 26 | 27 | private val javaPlugins = listOf("java", "java-library") 28 | 29 | /** 30 | * Plugin to include processor path to metadata properties file. 31 | * 32 | * Used to put processor.properties into the output classpath of the library. 33 | * 34 | * This file is intended to be read by processor task impl to inject a runtime dependency to run processor. 35 | */ 36 | @Suppress("unused") 37 | class ProcessorVersionPlugin : Plugin { 38 | override fun apply(project: Project) { 39 | for (pluginId in javaPlugins) { 40 | project.plugins.withId(pluginId) { 41 | project.apply() 42 | } 43 | } 44 | } 45 | } 46 | 47 | class ProcessorVersionPluginImpl : Plugin { 48 | private fun mainSourceSet(project: Project): SourceSet = 49 | if (GradleVersion.current() < GradleVersion.version("7.1")) { 50 | obtainJavaSourceSetContainerV6(project) 51 | } else { 52 | obtainJavaSourceSetContainerV7(project) 53 | } 54 | 55 | override fun apply(project: Project) { 56 | val extension = project.extensions.create(PROCESSOR_VERSION_EXTENSION, ProcessorVersionPExtension::class.java) 57 | extension.fieldName.convention("processor") 58 | extension.outputFolder.convention(project.layout.buildDirectory.dir(DEFAULT_TARGET_FOLDER_BASE)) 59 | extension.filename.convention(DEFAULT_TARGET_FILENAME) 60 | 61 | val task = project.tasks.register("processorVersion", ProcessorVersionGeneratorTask::class.java) { 62 | this.library.set(extension.library) 63 | this.fieldName.set(extension.fieldName) 64 | this.filename.set(extension.filename) 65 | this.outputFolder.set(extension.outputFolder) 66 | 67 | this.resolvedIdentifier.set( 68 | extension.library.map { libraryName -> 69 | val dependency = project.versionCatalogs 70 | .named(PROCESSOR_VERSION_CATALOG) 71 | .findLibrary(libraryName) 72 | .orElseThrow { 73 | GradleException( 74 | "Unable resolve library for $libraryName in catalog $PROCESSOR_VERSION_CATALOG", 75 | ) 76 | }.get() 77 | 78 | "${dependency.module.group}:${dependency.module.name}:${dependency.versionConstraint.requiredVersion}" 79 | }, 80 | ) 81 | } 82 | 83 | project.tasks.named("processResources").configure { 84 | dependsOn(task) 85 | } 86 | project.tasks.named("compileKotlin").configure { 87 | dependsOn(task) 88 | } 89 | 90 | task.configure { 91 | val javaSourceSet = mainSourceSet(project).resources 92 | javaSourceSet.srcDirs(task) 93 | } 94 | } 95 | } 96 | 97 | abstract class ProcessorVersionPExtension { 98 | @get:Input 99 | abstract val library: Property 100 | 101 | @get:Input 102 | @get:Optional 103 | abstract val fieldName: Property 104 | 105 | @get:Input 106 | @get:Optional 107 | abstract val filename: Property 108 | 109 | @get:Optional 110 | abstract val outputFolder: DirectoryProperty 111 | } 112 | 113 | abstract class ProcessorVersionGeneratorTask : DefaultTask() { 114 | @get:Input 115 | abstract val library: Property 116 | 117 | @get:Input 118 | abstract val fieldName: Property 119 | 120 | @get:Input 121 | @get:Optional 122 | abstract val filename: Property 123 | 124 | @get:OutputDirectory 125 | abstract val outputFolder: DirectoryProperty 126 | 127 | @get:Input 128 | abstract val resolvedIdentifier: Property 129 | 130 | @TaskAction 131 | fun action() { 132 | if (filename.get().contains("..")) { 133 | throw GradleException("filename path must not contain `..`") 134 | } 135 | 136 | val identifier = resolvedIdentifier.get() 137 | 138 | val outputFile = this.outputFolder 139 | .get() 140 | .asFile 141 | .resolve(filename.get()) 142 | 143 | if (logger.isDebugEnabled) { 144 | logger.debug("Found library with identifier `$identifier`, writing to ${outputFile.absolutePath}") 145 | } 146 | outputFile.ensureParentDirsCreated() 147 | 148 | outputFile.writer().apply { 149 | val p = Properties() 150 | p[fieldName.get()] = identifier 151 | p.store(this, null) 152 | } 153 | } 154 | } 155 | 156 | /** 157 | * Obtain java source sets in Gradle 6.0 - 7.0.2 158 | */ 159 | @Suppress("DEPRECATION") 160 | private fun obtainJavaSourceSetContainerV6(project: Project): SourceSet = 161 | obtainSourceSetContainer(project.convention.plugins["java"]!!) 162 | .named("main") 163 | .get() 164 | 165 | private fun obtainSourceSetContainer(value: Any): SourceSetContainer { 166 | val method = value::class.java.getDeclaredMethod("getSourceSets") 167 | return method.invoke(value) as SourceSetContainer 168 | } 169 | 170 | /** 171 | * Obtain java source sets in Gradle 7.3+. 172 | */ 173 | private fun obtainJavaSourceSetContainerV7(project: Project): SourceSet = 174 | project 175 | .extensions 176 | .getByType(JavaPluginExtension::class.java) 177 | .sourceSets 178 | .named("main") 179 | .get() 180 | 181 | private fun File.ensureParentDirsCreated() { 182 | val parentFile = parentFile 183 | if (!parentFile.exists()) { 184 | check(parentFile.mkdirs()) { 185 | "Cannot create parent directories for $this" 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/test/kotlin/org/jsonschema2dataclass/js2p/JavaTaskFunctionalTest.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.js2p 2 | 3 | import org.gradle.testkit.runner.TaskOutcome 4 | import org.jsonschema2dataclass.internal.task.DEFAULT_TARGET_FOLDER_BASE 5 | import org.junit.jupiter.api.Assertions.assertEquals 6 | import org.junit.jupiter.api.Assertions.assertNull 7 | import org.junit.jupiter.api.Assumptions.assumeFalse 8 | import org.junit.jupiter.api.DisplayName 9 | import org.junit.jupiter.api.io.TempDir 10 | import org.junit.jupiter.params.ParameterizedTest 11 | import org.junit.jupiter.params.provider.MethodSource 12 | import java.nio.file.Path 13 | 14 | const val TARGET_FOLDER_CUSTOM = "build/$TARGET_FOLDER_BASE_CUSTOM" 15 | const val TARGET_FOLDER_DEFAULT = "build/$DEFAULT_TARGET_FOLDER_BASE" 16 | 17 | const val EXECUTION_NAME_COM = "com" 18 | const val PACKAGE_COM_EXAMPLE = "com/example" 19 | 20 | const val EXECUTION_NAME_ORG = "org" 21 | const val PACKAGE_ORG_EXAMPLE = "org/example" 22 | 23 | const val PARAM_SOURCE = "org.jsonschema2dataclass.js2p.GradleVersions#gradleReleasesForTests" 24 | const val PARAM_SOURCE_CONFIG = 25 | "org.jsonschema2dataclass.js2p.GradleVersions#configurationCacheCompatibleGradleReleasesForTests" 26 | 27 | class JavaTaskFunctionalTest { 28 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 29 | @MethodSource(PARAM_SOURCE) 30 | @DisplayName("single execution, no extension") 31 | fun withoutExtension(gradleVersion: String?, @TempDir testProjectDir: Path) { 32 | assumeFalse(gradleVersion == null) 33 | 34 | createBuildFilesSingleNoExtension(testProjectDir, true) 35 | 36 | val result = createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 37 | .execute(true) 38 | 39 | assertNull(result.task(COLON_TASK_NAME_FOR_COM)?.outcome) 40 | } 41 | 42 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 43 | @MethodSource(PARAM_SOURCE) 44 | @DisplayName("single execution") 45 | fun singleExtension(gradleVersion: String?, @TempDir testProjectDir: Path) { 46 | assumeFalse(gradleVersion == null) 47 | createBuildFilesSingle(testProjectDir, true) 48 | 49 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 50 | .execute() 51 | .assertResultAndGeneratedClass() 52 | } 53 | 54 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 55 | @MethodSource(PARAM_SOURCE) 56 | @DisplayName("single extension simple") 57 | fun singleExtensionSimple(gradleVersion: String?, @TempDir testProjectDir: Path) { 58 | assumeFalse(gradleVersion == null) 59 | createBuildFilesSingleSimple(testProjectDir, true) 60 | 61 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 62 | .execute() 63 | .assertResultAndGeneratedClass() 64 | } 65 | 66 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 67 | @MethodSource(PARAM_SOURCE) 68 | @DisplayName("multiple executions") 69 | fun multipleExecutions(gradleVersion: String?, @TempDir testProjectDir: Path) { 70 | assumeFalse(gradleVersion == null) 71 | createBuildFilesMultiple(testProjectDir, true) 72 | 73 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 74 | .execute() 75 | .assertResultAndGeneratedClass(taskName = COLON_TASK_NAME_FOR_COM, targetFolder = TARGET_FOLDER_CUSTOM) 76 | .assertResultAndGeneratedClass(taskName = COLON_TASK_NAME_FOR_ORG, targetFolder = TARGET_FOLDER_CUSTOM) 77 | } 78 | 79 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 80 | @MethodSource(PARAM_SOURCE) 81 | @DisplayName("compileJava task depends task even when project has no java code") 82 | fun noJavaCode(gradleVersion: String?, @TempDir testProjectDir: Path) { 83 | assumeFalse(gradleVersion == null) 84 | createBuildFilesSingle(testProjectDir, true) 85 | 86 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir, task = "compileJava") 87 | .execute() 88 | .assertResultAndGeneratedClass() 89 | } 90 | 91 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 92 | @MethodSource(PARAM_SOURCE) 93 | @DisplayName("task is cache-able") 94 | fun taskIsCacheable(gradleVersion: String?, @TempDir testProjectDir: Path) { 95 | assumeFalse(gradleVersion == null) 96 | createBuildFilesSingle(testProjectDir, true) 97 | 98 | val runner = createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 99 | runner.execute().assertResultAndGeneratedClass() 100 | 101 | // Run our task twice to be sure that results has been cached 102 | val execution2 = runner.execute() 103 | assertEquals(TaskOutcome.UP_TO_DATE, execution2.task(COLON_TASK_NAME_FOR_COM)?.outcome) 104 | } 105 | 106 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 107 | @MethodSource(PARAM_SOURCE) 108 | @DisplayName("task skips if no json file exists") 109 | fun noJsonFiles(gradleVersion: String?, @TempDir testProjectDir: Path) { 110 | assumeFalse(gradleVersion == null) 111 | createBuildFilesSingle(testProjectDir, false) 112 | 113 | val result = createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir).execute() 114 | assertEquals(TaskOutcome.NO_SOURCE, result.task(COLON_TASK_NAME_FOR_COM)?.outcome) 115 | } 116 | 117 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 118 | @MethodSource(PARAM_SOURCE) 119 | @DisplayName("java-library applied after org.jsonschema2dataclass") 120 | fun lazyWithoutExtension(gradleVersion: String?, @TempDir testProjectDir: Path) { 121 | assumeFalse(gradleVersion == null) 122 | createBuildFilesLazyInit(testProjectDir, true) 123 | 124 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir) 125 | .execute() 126 | .assertResultAndGeneratedClass() 127 | } 128 | 129 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 130 | @MethodSource(PARAM_SOURCE) 131 | @DisplayName("jarring sources does not fail after code generation") 132 | fun sourceJarCompatibility(gradleVersion: String?, @TempDir testProjectDir: Path) { 133 | assumeFalse(gradleVersion == null) 134 | createBuildFilesWithSourcesJar(testProjectDir) 135 | 136 | createRunner(gradleVersion = gradleVersion, testProjectDir = testProjectDir, task = "generateAndJarSources") 137 | .execute() 138 | .assertResultAndGeneratedClass() 139 | } 140 | 141 | @ParameterizedTest(name = "[{index}] {displayName} - {0}") 142 | @MethodSource(PARAM_SOURCE_CONFIG) 143 | @DisplayName("plugin is configuration cache compatible") 144 | fun configurationCacheCompatibility(gradleVersion: String?, @TempDir testProjectDir: Path) { 145 | assumeFalse(gradleVersion == null) 146 | createBuildFilesSingle(testProjectDir, true) 147 | 148 | createRunner( 149 | gradleVersion = gradleVersion, 150 | testProjectDir = testProjectDir, 151 | arguments = arrayOf("--configuration-cache"), 152 | ).execute() 153 | .assertResultAndGeneratedClass() 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /plugin-gradle/plugin/src/main/kotlin/org/jsonschema2dataclass/internal/TaskGeneration.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.Named 5 | import org.gradle.api.NamedDomainObjectCollection 6 | import org.gradle.api.Project 7 | import org.gradle.api.Task 8 | import org.gradle.api.UnknownTaskException 9 | import org.gradle.api.file.DirectoryProperty 10 | import org.gradle.api.file.FileCollection 11 | import org.gradle.api.tasks.TaskProvider 12 | import org.gradle.util.GradleVersion 13 | import org.jsonschema2dataclass.ext.Js2pConfiguration 14 | import org.jsonschema2dataclass.internal.compat.kotlin.capitalized 15 | import org.jsonschema2dataclass.internal.task.JS2D_TASK_NAME 16 | import org.jsonschema2dataclass.internal.task.JS2P_TOOL_NAME 17 | import java.nio.file.Path 18 | import java.util.UUID 19 | 20 | private const val BASE_TASK_DESCRIPTION = "Generates Java models from a schema" 21 | 22 | internal fun defaultConfigurationSettings( 23 | configurations: NamedDomainObjectCollection, 24 | defaultSourceFiles: Path, 25 | disableAnnotateGenerated: Boolean, 26 | ) { 27 | configurations.configureEach { 28 | if (io.source.isEmpty) { 29 | // registration.defaultSchemaPath(project) ?: project.files(DEFAULT_SCHEMA_PATH), 30 | io.source.setFrom(defaultSourceFiles) 31 | } 32 | if (disableAnnotateGenerated) { 33 | klass.annotateGenerated.set(false) 34 | } 35 | } 36 | } 37 | 38 | private typealias RegisterDependenciesCallback = ( 39 | taskProvider: TaskProvider, 40 | targetPath: Path?, 41 | dependsOn: Action, 42 | ) -> Unit 43 | 44 | internal fun registrationTasksMachinery( 45 | project: Project, 46 | registration: GradlePluginRegistration, 47 | targetDirectoryPrefix: DirectoryProperty, 48 | configurations: NamedDomainObjectCollection, 49 | processor: Js2dProcessor, 50 | ) { 51 | generateTasks( 52 | project, 53 | registration, 54 | configurations, 55 | ) { configuration, suffixes, callback -> 56 | // create a task for a configuration 57 | val (taskName, taskDescription) = createTaskNameDescription( 58 | configuration.name, 59 | suffixes, 60 | true, 61 | processor.toolNameForTask(), 62 | ) 63 | val task = project.tasks.register(taskName, processor.generatorTaskClass()) { 64 | description = taskDescription 65 | this.description = taskDescription 66 | this.group = "Build" 67 | this.configuration = configuration 68 | this.uuid = UUID.randomUUID() 69 | this.targetDirectory.set(targetDirectoryPrefix.dir(configuration.name)) 70 | 71 | // TODO: ask processor to extract source file collection from configuration 72 | val source = (configuration as Js2pConfiguration).io.source 73 | 74 | val newSource = source.filter { it.exists() && (!it.isDirectory || it.list()?.isNotEmpty() == true) } 75 | newSource.forEach { it.mkdirs() } 76 | skipInputWhenEmpty(this, newSource) 77 | } 78 | 79 | callback(task, targetDirectoryPrefix.asFile.get().toPath()) { 80 | dependsOn(project, task, this) 81 | } 82 | 83 | task 84 | } 85 | } 86 | 87 | @Suppress("SameParameterValue") 88 | private fun createPrimaryTask(taskName: String, taskDescription: String, project: Project): TaskProvider = 89 | project.tasks.register(taskName) { 90 | description = taskDescription 91 | group = "Build" 92 | } 93 | 94 | private typealias SubtaskGeneratorFunction = ( 95 | configuration: T, 96 | suffixes: Map, 97 | callback: RegisterDependenciesCallback, 98 | ) -> TaskProvider 99 | 100 | private fun generateTasks( 101 | project: Project, 102 | registration: GradlePluginRegistration, 103 | configurations: NamedDomainObjectCollection, 104 | createSubTask: SubtaskGeneratorFunction, 105 | ) { 106 | // create primary task first to declare task dependencies 107 | val primaryTask = createPrimaryTask(JS2D_TASK_NAME, BASE_TASK_DESCRIPTION, project) 108 | 109 | registration.registerPlugin(project) { suffixes: Map, callback: RegisterDependenciesCallback -> 110 | callback(primaryTask, null) { 111 | // register the main task 112 | dependsOn(project, primaryTask, this) 113 | } 114 | configurations.configureEach { 115 | val taskForConfiguration = createSubTask(this, suffixes, callback) 116 | primaryTask.configure { dependsOn(taskForConfiguration) } 117 | } 118 | } 119 | } 120 | 121 | private fun skipInputWhenEmpty(task: Task, sourceFiles: FileCollection) { 122 | val input = task.inputs 123 | .files(sourceFiles) 124 | .skipWhenEmpty() 125 | 126 | if (GradleVersion.current() >= GradleVersion.version("6.8")) { 127 | input.ignoreEmptyDirectories() 128 | } 129 | } 130 | 131 | internal fun createTaskNameDescription( 132 | executionName: String, 133 | suffixes: Map, 134 | taskNameCompatibleWith5: Boolean, 135 | processorName: Pair, 136 | ): Pair { 137 | val parts = generateSuffixes(processorName, executionName, suffixes, taskNameCompatibleWith5) 138 | 139 | val name = JS2D_TASK_NAME.plus(parts.joinToString("") { it.first }) 140 | val description = parts.joinToString(" ") { it.second } 141 | 142 | return name to description 143 | } 144 | 145 | private fun generateSuffixes( 146 | processorName: Pair, 147 | executionName: String, 148 | suffixes: Map, 149 | taskNameCompatibleWith5: Boolean, 150 | ) = sequence { 151 | val toolNameCompat5x = processorName.first == JS2P_TOOL_NAME && taskNameCompatibleWith5 152 | val toolNamePart = if (toolNameCompat5x) "" else processorName.first.capitalized() 153 | 154 | yield(toolNamePart to processorName.second) 155 | 156 | val partNameCompat5x = suffixes.size < 2 && taskNameCompatibleWith5 // maintain backward compatibility 157 | yieldAll(suffixes.asSequence().map { generatePart(it.toPair(), partNameCompat5x) }) 158 | yield("Config${executionName.capitalized()}" to "for configuration $executionName") 159 | } 160 | 161 | internal fun generatePart( 162 | // "variant" to "release" 163 | // "flavor" to "sweet" 164 | suffixes: Pair, 165 | taskNameCompatibleWith5: Boolean, 166 | ): Pair { 167 | val keyCapitalized = if (taskNameCompatibleWith5) { // maintain backward compatibility with 5.0.0 168 | "" 169 | } else { 170 | suffixes.first.capitalized() 171 | } 172 | val valueCapitalized = suffixes.second.capitalized() 173 | 174 | return "For$keyCapitalized$valueCapitalized" to "for ${suffixes.first} ${suffixes.second}" 175 | } 176 | 177 | private fun dependsOn(project: Project, task: TaskProvider, taskName: String) { 178 | try { 179 | project.tasks.named(taskName).configure { dependsOn(task) } 180 | } catch (_: UnknownTaskException) { 181 | project.tasks.whenObjectAdded { 182 | // add it later 183 | if (this.name == taskName) { 184 | this.dependsOn(task) 185 | } 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /docs/migration/migration_6.adoc: -------------------------------------------------------------------------------- 1 | :toc: 2 | :toc-placement: preamble 3 | :toclevels: 2 4 | :showtitle: 5 | 6 | = Migration guide from 5.0 to 6.0 7 | 8 | This guide highlights major changes and shows how to change a project to use new plugin. 9 | 10 | == Default options are removed from the extension 11 | 12 | Previously, it was possible to define default options for all executions. 13 | Now it's mandatory to define all options for every execution. 14 | 15 | == Configuration options for each execution were split into categories 16 | 17 | With plugin version 6.0 configuration options were moved into sub-categories. 18 | Additionally, some of them were renamed as category has context. 19 | Documentation and meaning for these configuration options is still the same. 20 | 21 | An execution configuration now contains following categories. 22 | 23 | .Execution configuration categories 24 | [options=header] 25 | |===== 26 | | Category name | Meaning 27 | // ------------------------------ 28 | | `io` 29 | | These options tell which files to read and what encoding to produce. 30 | // ------------------------------ 31 | | `klass` 32 | | General class generation options. 33 | // ------------------------------ 34 | | `constructors` 35 | | Options define how given class can be instantiated. 36 | // ------------------------------ 37 | | `methods` 38 | | Options to define which methods are created and which annotations are used. 39 | // ------------------------------ 40 | | `fields` 41 | | Options to define field type mapping (except date and time objects). 42 | // ------------------------------ 43 | | `dateTime` 44 | | Options to define date and time field generation and serialization. 45 | // ------------------------------ 46 | |===== 47 | 48 | === Option renames and placing into categories 49 | 50 | [options=header,cols="1,3,3"] 51 | |===== 52 | | Category | Original Source Option | New option name (if changed) 53 | // ------------------------------ 54 | .9+^.^| `io` 55 | | fileExtensions 56 | | 57 | // ------------------------------ 58 | | fileFilter 59 | | 60 | // ------------------------------ 61 | | propertyWordDelimiters 62 | | delimitersPropertyWord 63 | // ------------------------------ 64 | | outputEncoding 65 | | 66 | // ------------------------------ 67 | | source 68 | | 69 | // ------------------------------ 70 | | sourceType 71 | | 72 | // ------------------------------ 73 | | sourceSortOrder 74 | | 75 | // ------------------------------ 76 | | targetVersion 77 | | targetJavaVersion 78 | // ------------------------------ 79 | | refFragmentPathDelimiters 80 | | delimitersRefFragmentPath 81 | // ------------------------------ 82 | .12+^.^| `klass` 83 | | annotationStyle 84 | | 85 | // ------------------------------ 86 | | classNamePrefix 87 | | namePrefix 88 | // ------------------------------ 89 | | classNameSuffix 90 | | nameSuffix 91 | // ------------------------------ 92 | | customAnnotator 93 | | customAnnotatorClass 94 | // ------------------------------ 95 | | customRuleFactory 96 | | customRuleFactoryClass 97 | // ------------------------------ 98 | | includeGeneratedAnnotation 99 | | annotateGenerated 100 | // ------------------------------ 101 | | includeTypeInfo 102 | | jackson2IncludeTypeInfo 103 | // ------------------------------ 104 | | inclusionLevel 105 | | jackson2InclusionLevel 106 | // ------------------------------ 107 | | parcelable 108 | | androidParcelable 109 | // ------------------------------ 110 | | serializable 111 | | annotateSerializable 112 | // ------------------------------ 113 | | targetPackage 114 | | 115 | // ------------------------------ 116 | | useTitleAsClassname 117 | | nameUseTitle 118 | // ------------------------------ 119 | .4+^.^| `constructors` 120 | | includeAllPropertiesConstructor 121 | | allProperties 122 | // ------------------------------ 123 | | includeConstructorPropertiesAnnotation 124 | | annotateConstructorProperties 125 | // ------------------------------ 126 | | includeCopyConstructor 127 | | copyConstructor 128 | // ------------------------------ 129 | | includeRequiredPropertiesConstructor 130 | | requiredProperties 131 | // ------------------------------ 132 | .15+^.^| `methods` 133 | | generateBuilders 134 | | builders 135 | // ------------------------------ 136 | | includeAdditionalProperties 137 | | additionalProperties 138 | // ------------------------------ 139 | | includeDynamicBuilders 140 | | buildersDynamic 141 | // ------------------------------ 142 | | includeDynamicGetters 143 | | gettersDynamic 144 | // ------------------------------ 145 | | includeDynamicSetters 146 | | settersDynamic 147 | // ------------------------------ 148 | | includeGetters 149 | | getters 150 | // ------------------------------ 151 | | includeHashcodeAndEquals 152 | | hashcodeAndEquals 153 | // ------------------------------ 154 | | includeJsr303Annotations 155 | | annotateJsr303 156 | // ------------------------------ 157 | | includeJsr305Annotations 158 | | annotateJsr305 159 | // ------------------------------ 160 | | includeSetters 161 | | setters 162 | // ------------------------------ 163 | | includeToString 164 | | toStringMethod 165 | // ------------------------------ 166 | | toStringExcludes 167 | | 168 | // ------------------------------ 169 | | useInnerClassBuilders 170 | | buildersInnerClass 171 | // ------------------------------ 172 | | useJakartaValidation 173 | | annotateJsr303Jakarta 174 | // ------------------------------ 175 | | useOptionalForGetters 176 | | gettersUseOptional 177 | // ------------------------------ 178 | .7+^.^| `fields` 179 | | formatTypeMapping 180 | | formatToTypeMapping 181 | // ------------------------------ 182 | | initializeCollections 183 | | 184 | // ------------------------------ 185 | | useBigDecimals 186 | | floatUseBigDecimal 187 | // ------------------------------ 188 | | useBigIntegers 189 | | integerUseBigInteger 190 | // ------------------------------ 191 | | useDoubleNumbers 192 | | floatUseDouble 193 | // ------------------------------ 194 | | useLongIntegers 195 | | integerUseLong 196 | // ------------------------------ 197 | | usePrimitives 198 | | 199 | // ------------------------------ 200 | .12+^.^| `dateTime` 201 | | customDatePattern 202 | | datePattern 203 | // ------------------------------ 204 | | customDateTimePattern 205 | | dateTimePattern 206 | // ------------------------------ 207 | | customTimePattern 208 | | timePattern 209 | // ------------------------------ 210 | | dateTimeType 211 | | 212 | // ------------------------------ 213 | | dateType 214 | | 215 | // ------------------------------ 216 | | formatDateTimes 217 | | dateTimeFormat 218 | // ------------------------------ 219 | | formatDates 220 | | dateFormat 221 | // ------------------------------ 222 | | formatTimes 223 | | timeFormat 224 | // ------------------------------ 225 | | timeType 226 | | 227 | // ------------------------------ 228 | | useJodaDates 229 | | jodaDate 230 | // ------------------------------ 231 | | useJodaLocalDates 232 | | jodaLocalDate 233 | // ------------------------------ 234 | | useJodaLocalTimes 235 | | jodaLocalTime 236 | // ------------------------------ 237 | |===== 238 | === Options removed 239 | 240 | .Removed parameters and options 241 | [options=header,cols="1,4"] 242 | |==== 243 | | Name | Notes 244 | // ------------------------------ 245 | | removeOldOutput 246 | | Became uncontrollable by a user in favor for Gradle to handle generated files. 247 | // ------------------------------ 248 | | constructorsRequiredPropertiesOnly 249 | | Can be replaced with turning off generation of any constructors except `requiredProperties`. 250 | Was deprecated for a while in the underlying library. 251 | // ------------------------------ 252 | | includeConstructors 253 | | This option will be turned on if any constructor generation option is turned on. 254 | // ------------------------------ 255 | | includeDynamicAccessors 256 | | This option will be turned on if any dynamic accessor generation option is turned on. 257 | |==== 258 | 259 | == Additional configurations to setup processor dependencies 260 | 261 | To set up additional processor dependencies it's needed to add a dependency 262 | into `jsonschema2dataclassPlugins` configuration. 263 | 264 | This could be needed for the processor to resolve: 265 | 266 | * Resources referenced by classpath 267 | * Additional types not present in standard library and direct dependencies of the processor 268 | * Custom RuleFactory or an Annotator for the processor 269 | 270 | == Demos are using current version of plugin. 271 | 272 | Since version 6.0 all demos are using current version of plugin to build. 273 | They were made with a thought to be re-usable and show real-world scenarios of plugin usage. 274 | 275 | == AGP 4 demo is removed 276 | 277 | AGP 4 is a quite old technology, I can't find a living open-source Android application using AGP 4. 278 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/main/kotlin/org/jsonschema2dataclass/internal/js2p/Js2pWokerConfig.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.jsonschema2dataclass.ext.Js2pConfiguration 4 | import org.jsonschema2dataclass.ext.PluginConfigJs2pClass 5 | import org.jsonschema2dataclass.ext.PluginConfigJs2pConstructor 6 | import org.jsonschema2dataclass.ext.PluginConfigJs2pDateTime 7 | import org.jsonschema2dataclass.ext.PluginConfigJs2pField 8 | import org.jsonschema2dataclass.ext.PluginConfigJs2pIO 9 | import org.jsonschema2dataclass.ext.PluginConfigJs2pMethod 10 | import java.io.File 11 | import java.io.FileFilter 12 | import java.io.Serializable 13 | import java.net.URL 14 | import java.util.UUID 15 | 16 | internal class Js2pWorkerConfig( 17 | internal val uuid: UUID, 18 | internal val targetDirectory: File, 19 | internal val io: Js2pWorkerConfigIO, 20 | internal val klass: Js2pWorkerConfigClass, 21 | internal val constructors: Js2pWorkerConfigConstructor, 22 | internal val methods: Js2pWorkerConfigMethod, 23 | internal val fields: Js2pWorkerConfigFields, 24 | internal val dateTime: Js2pWorkerConfigDateTime, 25 | ) : Serializable { 26 | companion object { 27 | private const val serialVersionUID: Long = 123L 28 | 29 | fun fromConfig( 30 | uuid: UUID, 31 | targetDirectory: File, 32 | config: Js2pConfiguration, 33 | ): Js2pWorkerConfig = 34 | Js2pWorkerConfig( 35 | uuid, 36 | targetDirectory, 37 | workerConvert(config.io), 38 | workerConvert(config.klass), 39 | workerConvert(config.constructors), 40 | workerConvert(config.methods), 41 | workerConvert(config.fields), 42 | workerConvert(config.dateTime), 43 | ) 44 | } 45 | } 46 | 47 | internal class Js2pWorkerConfigIO( 48 | val sourceFiles: List, 49 | val delimitersPropertyWord: String?, 50 | val delimitersRefFragmentPath: String?, 51 | val fileExtensions: Set?, 52 | val fileFilter: FileFilter?, 53 | val outputEncoding: String?, 54 | val sourceSortOrder: String?, 55 | val sourceType: String?, 56 | val targetJavaVersion: String?, 57 | ) : Serializable { 58 | companion object { 59 | private const val serialVersionUID: Long = 123L 60 | } 61 | } 62 | 63 | internal class Js2pWorkerConfigClass( 64 | val androidParcelable: Boolean?, 65 | val annotateGenerated: Boolean?, 66 | val annotateSerializable: Boolean?, 67 | val annotationStyle: String?, 68 | val customAnnotatorClass: String?, 69 | val customRuleFactoryClass: String?, 70 | val jackson2IncludeTypeInfo: Boolean?, 71 | val jackson2InclusionLevel: String?, 72 | val namePrefix: String?, 73 | val nameSuffix: String?, 74 | val nameUseTitle: Boolean?, 75 | val targetPackage: String?, 76 | ) : Serializable { 77 | companion object { 78 | private const val serialVersionUID: Long = 123L 79 | } 80 | } 81 | 82 | internal class Js2pWorkerConfigConstructor( 83 | val allProperties: Boolean?, 84 | val annotateConstructorProperties: Boolean?, 85 | val copyConstructor: Boolean?, 86 | val requiredProperties: Boolean?, 87 | ) : Serializable { 88 | companion object { 89 | private const val serialVersionUID: Long = 123L 90 | } 91 | } 92 | 93 | internal class Js2pWorkerConfigMethod( 94 | val additionalProperties: Boolean?, 95 | val annotateJsr303Jakarta: Boolean?, 96 | val annotateJsr303: Boolean?, 97 | val annotateJsr305: Boolean?, 98 | val builders: Boolean?, 99 | val buildersDynamic: Boolean?, 100 | val buildersInnerClass: Boolean?, 101 | val getters: Boolean?, 102 | val gettersDynamic: Boolean?, 103 | val gettersUseOptional: Boolean?, 104 | val hashcodeAndEquals: Boolean?, 105 | val setters: Boolean?, 106 | val settersDynamic: Boolean?, 107 | val toStringExcludes: Set?, 108 | val toStringMethod: Boolean?, 109 | ) : Serializable { 110 | companion object { 111 | private const val serialVersionUID: Long = 123L 112 | } 113 | } 114 | 115 | internal class Js2pWorkerConfigFields( 116 | val floatUseBigDecimal: Boolean?, 117 | val floatUseDouble: Boolean?, 118 | val formatToTypeMapping: Map?, 119 | val initializeCollections: Boolean?, 120 | val integerUseBigInteger: Boolean?, 121 | val integerUseLong: Boolean?, 122 | val usePrimitives: Boolean?, 123 | ) : Serializable { 124 | companion object { 125 | private const val serialVersionUID: Long = 123L 126 | } 127 | } 128 | 129 | internal class Js2pWorkerConfigDateTime( 130 | val dateFormat: Boolean?, 131 | val datePattern: String?, 132 | val dateTimeFormat: Boolean?, 133 | val dateTimePattern: String?, 134 | val dateTimeType: String?, 135 | val dateType: String?, 136 | val jodaDate: Boolean?, 137 | val jodaLocalDate: Boolean?, 138 | val jodaLocalTime: Boolean?, 139 | val timeFormat: Boolean?, 140 | val timePattern: String?, 141 | val timeType: String?, 142 | ) : Serializable { 143 | companion object { 144 | private const val serialVersionUID: Long = 123L 145 | } 146 | } 147 | 148 | private fun workerConvert(io: PluginConfigJs2pIO): Js2pWorkerConfigIO = 149 | Js2pWorkerConfigIO( 150 | io.source.map { it.toURI().toURL() }, 151 | io.delimitersPropertyWord.orNull, 152 | io.delimitersRefFragmentPath.orNull, 153 | io.fileExtensions.orNull, 154 | io.fileFilter.orNull, 155 | io.outputEncoding.orNull, 156 | io.sourceSortOrder.orNull, 157 | io.sourceType.orNull, 158 | io.targetJavaVersion.orNull, 159 | ) 160 | 161 | private fun workerConvert(klass: PluginConfigJs2pClass): Js2pWorkerConfigClass = 162 | Js2pWorkerConfigClass( 163 | klass.androidParcelable.orNull, 164 | klass.annotateGenerated.orNull, 165 | klass.annotateSerializable.orNull, 166 | klass.annotationStyle.orNull, 167 | klass.customAnnotatorClass.orNull, 168 | klass.customRuleFactoryClass.orNull, 169 | klass.jackson2IncludeTypeInfo.orNull, 170 | klass.jackson2InclusionLevel.orNull, 171 | klass.namePrefix.orNull, 172 | klass.nameSuffix.orNull, 173 | klass.nameUseTitle.orNull, 174 | klass.targetPackage.orNull, 175 | ) 176 | 177 | private fun workerConvert(constructor: PluginConfigJs2pConstructor): Js2pWorkerConfigConstructor = 178 | Js2pWorkerConfigConstructor( 179 | constructor.allProperties.orNull, 180 | constructor.annotateConstructorProperties.orNull, 181 | constructor.copyConstructor.orNull, 182 | constructor.requiredProperties.orNull, 183 | ) 184 | 185 | private fun workerConvert(methods: PluginConfigJs2pMethod): Js2pWorkerConfigMethod = 186 | Js2pWorkerConfigMethod( 187 | methods.additionalProperties.orNull, 188 | methods.annotateJsr303Jakarta.orNull, 189 | methods.annotateJsr303.orNull, 190 | methods.annotateJsr305.orNull, 191 | methods.builders.orNull, 192 | methods.buildersDynamic.orNull, 193 | methods.buildersInnerClass.orNull, 194 | methods.getters.orNull, 195 | methods.gettersDynamic.orNull, 196 | methods.gettersUseOptional.orNull, 197 | methods.hashcodeAndEquals.orNull, 198 | methods.setters.orNull, 199 | methods.settersDynamic.orNull, 200 | methods.toStringExcludes.orNull, 201 | methods.toStringMethod.orNull, 202 | ) 203 | 204 | private fun workerConvert(fields: PluginConfigJs2pField): Js2pWorkerConfigFields = 205 | Js2pWorkerConfigFields( 206 | fields.floatUseBigDecimal.orNull, 207 | fields.floatUseDouble.orNull, 208 | fields.formatToTypeMapping.orNull, 209 | fields.initializeCollections.orNull, 210 | fields.integerUseBigInteger.orNull, 211 | fields.integerUseLong.orNull, 212 | fields.usePrimitives.orNull, 213 | ) 214 | 215 | private fun workerConvert(dateTime: PluginConfigJs2pDateTime): Js2pWorkerConfigDateTime = 216 | Js2pWorkerConfigDateTime( 217 | dateTime.dateFormat.orNull, 218 | dateTime.datePattern.orNull, 219 | dateTime.dateTimeFormat.orNull, 220 | dateTime.dateTimePattern.orNull, 221 | dateTime.dateTimeType.orNull, 222 | dateTime.dateType.orNull, 223 | dateTime.jodaDate.orNull, 224 | dateTime.jodaLocalDate.orNull, 225 | dateTime.jodaLocalTime.orNull, 226 | dateTime.timeFormat.orNull, 227 | dateTime.timePattern.orNull, 228 | dateTime.timeType.orNull, 229 | ) 230 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/js2p/Randomizer.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.jsonschema2dataclass.ext.Js2pConfiguration 4 | import org.jsonschema2dataclass.ext.PluginConfigJs2pClass 5 | import org.jsonschema2dataclass.ext.PluginConfigJs2pConstructor 6 | import org.jsonschema2dataclass.ext.PluginConfigJs2pDateTime 7 | import org.jsonschema2dataclass.ext.PluginConfigJs2pField 8 | import org.jsonschema2dataclass.ext.PluginConfigJs2pIO 9 | import org.jsonschema2dataclass.ext.PluginConfigJs2pMethod 10 | import org.jsonschema2dataclass.internal.nullable 11 | import org.jsonschema2dataclass.internal.randomBoolean 12 | import org.jsonschema2dataclass.internal.randomEnum 13 | import org.jsonschema2dataclass.internal.randomList 14 | import org.jsonschema2dataclass.internal.randomMap 15 | import org.jsonschema2dataclass.internal.randomSet 16 | import org.jsonschema2dataclass.internal.randomString 17 | import org.jsonschema2pojo.AnnotationStyle 18 | import org.jsonschema2pojo.Annotator 19 | import org.jsonschema2pojo.GenerationConfig 20 | import org.jsonschema2pojo.InclusionLevel 21 | import org.jsonschema2pojo.SourceSortOrder 22 | import org.jsonschema2pojo.SourceType 23 | import org.jsonschema2pojo.rules.RuleFactory 24 | import java.io.File 25 | 26 | /** 27 | * Randomize an plugin configuration 28 | */ 29 | internal fun randomize(configuration: Js2pConfiguration): Js2pConfiguration { 30 | randomize(configuration.io) 31 | randomize(configuration.klass) 32 | randomize(configuration.constructors) 33 | randomize(configuration.methods) 34 | randomize(configuration.fields) 35 | randomize(configuration.dateTime) 36 | return configuration 37 | } 38 | 39 | private fun randomize(value: PluginConfigJs2pIO) { 40 | value.source.setFrom("/${randomString()}") 41 | value.delimitersPropertyWord.set(nullable(randomString())) 42 | value.delimitersRefFragmentPath.set(nullable(randomString())) 43 | value.fileExtensions.set(nullable(randomSet())) 44 | value.outputEncoding.set(nullable(randomString())) 45 | value.sourceSortOrder.set(nullable(randomEnum().toString())) 46 | value.sourceType.set(nullable(randomEnum().toString())) 47 | value.targetJavaVersion.set(nullable(randomString())) 48 | } 49 | 50 | private fun randomize(value: PluginConfigJs2pClass) { 51 | value.androidParcelable.set(nullable(randomBoolean())) 52 | value.annotateGenerated.set(nullable(randomBoolean())) 53 | value.annotateSerializable.set(nullable(randomBoolean())) 54 | value.annotationStyle.set(nullable(randomEnum().toString())) 55 | value.customAnnotatorClass.set(Annotator::class.java.canonicalName) 56 | value.customRuleFactoryClass.set(RuleFactory::class.java.canonicalName) 57 | value.jackson2IncludeTypeInfo.set(nullable(randomBoolean())) 58 | value.jackson2InclusionLevel.set(nullable(randomEnum().toString())) 59 | value.namePrefix.set(nullable(randomString())) 60 | value.nameSuffix.set(nullable(randomString())) 61 | value.nameUseTitle.set(nullable(randomBoolean())) 62 | value.targetPackage.set(nullable(randomString())) 63 | } 64 | 65 | private fun randomize(value: PluginConfigJs2pConstructor) { 66 | value.allProperties.set(nullable(randomBoolean())) 67 | value.annotateConstructorProperties.set(nullable(randomBoolean())) 68 | value.copyConstructor.set(nullable(randomBoolean())) 69 | value.requiredProperties.set(nullable(randomBoolean())) 70 | } 71 | 72 | private fun randomize(value: PluginConfigJs2pMethod) { 73 | value.additionalProperties.set(nullable(randomBoolean())) 74 | value.annotateJsr303Jakarta.set(nullable(randomBoolean())) 75 | value.annotateJsr303.set(nullable(randomBoolean())) 76 | value.annotateJsr305.set(nullable(randomBoolean())) 77 | value.builders.set(nullable(randomBoolean())) 78 | value.buildersDynamic.set(nullable(randomBoolean())) 79 | value.buildersInnerClass.set(nullable(randomBoolean())) 80 | value.getters.set(nullable(randomBoolean())) 81 | value.gettersDynamic.set(nullable(randomBoolean())) 82 | value.gettersUseOptional.set(nullable(randomBoolean())) 83 | value.hashcodeAndEquals.set(nullable(randomBoolean())) 84 | value.setters.set(nullable(randomBoolean())) 85 | value.settersDynamic.set(nullable(randomBoolean())) 86 | value.toStringMethod.set(nullable(randomBoolean())) 87 | value.toStringExcludes.set(nullable(randomSet())) 88 | } 89 | 90 | private fun randomize(value: PluginConfigJs2pField) { 91 | value.floatUseBigDecimal.set(nullable(randomBoolean())) 92 | value.floatUseDouble.set(nullable(randomBoolean())) 93 | value.formatToTypeMapping.set(nullable(randomMap())) 94 | value.initializeCollections.set(nullable(randomBoolean())) 95 | value.integerUseBigInteger.set(nullable(randomBoolean())) 96 | value.integerUseLong.set(nullable(randomBoolean())) 97 | value.usePrimitives.set(nullable(randomBoolean())) 98 | } 99 | 100 | private fun randomize(value: PluginConfigJs2pDateTime) { 101 | value.dateFormat.set(nullable(randomBoolean())) 102 | value.datePattern.set(nullable(randomString())) 103 | value.dateTimeFormat.set(nullable(randomBoolean())) 104 | value.dateTimePattern.set(nullable(randomString())) 105 | value.dateTimeType.set(null) // TODO 106 | value.dateType.set(null) // TODO 107 | value.jodaDate.set(nullable(randomBoolean())) 108 | value.jodaLocalDate.set(nullable(randomBoolean())) 109 | value.jodaLocalTime.set(nullable(randomBoolean())) 110 | value.timeFormat.set(nullable(randomBoolean())) 111 | value.timePattern.set(nullable(randomString())) 112 | value.timeType.set(null) // TODO 113 | } 114 | 115 | /** 116 | * Randomize Generation config 117 | */ 118 | internal fun randomizeGenerationConfig(): GenerationConfig = SimpleGenerationConfig( 119 | constructorsRequiredPropertiesOnly = randomBoolean(), 120 | formatDateTimes = randomBoolean(), 121 | formatDates = randomBoolean(), 122 | formatTimes = randomBoolean(), 123 | generateBuilders = randomBoolean(), 124 | includeAdditionalProperties = randomBoolean(), 125 | includeAllPropertiesConstructor = randomBoolean(), 126 | includeConstructorPropertiesAnnotation = randomBoolean(), 127 | includeConstructors = randomBoolean(), 128 | includeCopyConstructor = randomBoolean(), 129 | includeDynamicAccessors = randomBoolean(), 130 | includeDynamicBuilders = randomBoolean(), 131 | includeDynamicGetters = randomBoolean(), 132 | includeDynamicSetters = randomBoolean(), 133 | includeGeneratedAnnotation = randomBoolean(), 134 | includeGetters = randomBoolean(), 135 | includeHashcodeAndEquals = randomBoolean(), 136 | includeJsr303Annotations = randomBoolean(), 137 | includeJsr305Annotations = randomBoolean(), 138 | includeRequiredPropertiesConstructor = randomBoolean(), 139 | includeSetters = randomBoolean(), 140 | includeToString = randomBoolean(), 141 | includeTypeInfo = randomBoolean(), 142 | initializeCollections = randomBoolean(), 143 | parcelable = randomBoolean(), 144 | removeOldOutput = randomBoolean(), 145 | serializable = randomBoolean(), 146 | useBigDecimals = randomBoolean(), 147 | useBigIntegers = randomBoolean(), 148 | useDoubleNumbers = randomBoolean(), 149 | useJakartaValidation = randomBoolean(), 150 | useJodaDates = randomBoolean(), 151 | useJodaLocalDates = randomBoolean(), 152 | useJodaLocalTimes = randomBoolean(), 153 | useLongIntegers = randomBoolean(), 154 | useOptionalForGetters = randomBoolean(), 155 | usePrimitives = randomBoolean(), 156 | useTitleAsClassname = randomBoolean(), 157 | annotationStyle = randomEnum(), 158 | classNamePrefix = randomString(), 159 | classNameSuffix = randomString(), 160 | customAnnotator = Annotator::class.java, 161 | customDatePattern = nullable(randomString()), 162 | customDateTimePattern = nullable(randomString()), 163 | customRuleFactory = RuleFactory::class.java, 164 | customTimePattern = nullable(randomString()), 165 | dateTimeType = nullable(randomString()), 166 | dateType = nullable(randomString()), 167 | fileExtensions = randomList(), 168 | fileFilter = null, 169 | formatTypeMapping = randomMap(), 170 | inclusionLevel = randomEnum(), 171 | outputEncoding = randomString(), 172 | propertyWordDelimiters = randomString(), 173 | refFragmentPathDelimiters = randomString(), 174 | source = null, 175 | sourceSortOrder = randomEnum(), 176 | sourceType = randomEnum(), 177 | targetDirectory = File("/"), 178 | targetPackage = randomString(), 179 | targetVersion = randomString(), 180 | timeType = nullable(randomString()), 181 | toStringExcludes = randomList(), 182 | ) 183 | -------------------------------------------------------------------------------- /plugin-gradle/processors/jsonschema2pojo/src/test/kotlin/org/jsonschema2dataclass/internal/js2p/SimpleGenerationConfig.kt: -------------------------------------------------------------------------------- 1 | package org.jsonschema2dataclass.internal.js2p 2 | 3 | import org.jsonschema2pojo.AnnotationStyle 4 | import org.jsonschema2pojo.Annotator 5 | import org.jsonschema2pojo.GenerationConfig 6 | import org.jsonschema2pojo.InclusionLevel 7 | import org.jsonschema2pojo.SourceSortOrder 8 | import org.jsonschema2pojo.SourceType 9 | import org.jsonschema2pojo.rules.RuleFactory 10 | import java.io.File 11 | import java.io.FileFilter 12 | import java.net.URL 13 | 14 | /** 15 | * Simple implementation of Json Schema 2 Pojo's Generation Config to test object conversion 16 | */ 17 | data class SimpleGenerationConfig( 18 | private val constructorsRequiredPropertiesOnly: Boolean, 19 | private val formatDateTimes: Boolean, 20 | private val formatDates: Boolean, 21 | private val formatTimes: Boolean, 22 | private val generateBuilders: Boolean, 23 | private val includeAdditionalProperties: Boolean, 24 | private val includeAllPropertiesConstructor: Boolean, 25 | private val includeConstructorPropertiesAnnotation: Boolean, 26 | private val includeConstructors: Boolean, 27 | private val includeCopyConstructor: Boolean, 28 | private val includeDynamicAccessors: Boolean, 29 | private val includeDynamicBuilders: Boolean, 30 | private val includeDynamicGetters: Boolean, 31 | private val includeDynamicSetters: Boolean, 32 | private val includeGeneratedAnnotation: Boolean, 33 | private val includeGetters: Boolean, 34 | private val includeHashcodeAndEquals: Boolean, 35 | private val includeJsr303Annotations: Boolean, 36 | private val includeJsr305Annotations: Boolean, 37 | private val includeRequiredPropertiesConstructor: Boolean, 38 | private val includeSetters: Boolean, 39 | private val includeToString: Boolean, 40 | private val includeTypeInfo: Boolean, 41 | private val initializeCollections: Boolean, 42 | private val parcelable: Boolean, 43 | private val removeOldOutput: Boolean, 44 | private val serializable: Boolean, 45 | private val useBigDecimals: Boolean, 46 | private val useBigIntegers: Boolean, 47 | private val useDoubleNumbers: Boolean, 48 | private val useJakartaValidation: Boolean, 49 | private val useJodaDates: Boolean, 50 | private val useJodaLocalDates: Boolean, 51 | private val useJodaLocalTimes: Boolean, 52 | private val useLongIntegers: Boolean, 53 | private val useOptionalForGetters: Boolean, 54 | private val usePrimitives: Boolean, 55 | private val useTitleAsClassname: Boolean, 56 | private val annotationStyle: AnnotationStyle, 57 | private val classNamePrefix: String, 58 | private val classNameSuffix: String, 59 | private val customAnnotator: Class, 60 | private val customDatePattern: String?, 61 | private val customDateTimePattern: String?, 62 | private val customRuleFactory: Class, 63 | private val customTimePattern: String?, 64 | private val dateTimeType: String?, 65 | private val dateType: String?, 66 | private val fileExtensions: List, 67 | private val fileFilter: FileFilter?, 68 | private val formatTypeMapping: Map, 69 | private val inclusionLevel: InclusionLevel, 70 | private val outputEncoding: String, 71 | private val propertyWordDelimiters: String, 72 | private val refFragmentPathDelimiters: String, 73 | private val source: Iterator?, 74 | private val sourceSortOrder: SourceSortOrder, 75 | private val sourceType: SourceType, 76 | private val targetDirectory: File, 77 | private val targetPackage: String, 78 | private val targetVersion: String, 79 | private val timeType: String?, 80 | private val toStringExcludes: List, 81 | ) : GenerationConfig { 82 | override fun getAnnotationStyle(): AnnotationStyle = annotationStyle 83 | 84 | override fun getClassNamePrefix(): String = classNamePrefix 85 | 86 | override fun getClassNameSuffix(): String = classNameSuffix 87 | 88 | override fun getCustomAnnotator(): Class = customAnnotator 89 | 90 | override fun getCustomDatePattern(): String? = customDatePattern 91 | 92 | override fun getCustomDateTimePattern(): String? = customDateTimePattern 93 | 94 | override fun getCustomRuleFactory(): Class = customRuleFactory 95 | 96 | override fun getCustomTimePattern(): String? = customTimePattern 97 | 98 | override fun getDateTimeType(): String? = dateTimeType 99 | 100 | override fun getDateType(): String? = dateType 101 | 102 | override fun getFileExtensions(): Array = fileExtensions.toTypedArray() 103 | 104 | override fun getFileFilter(): FileFilter? = fileFilter 105 | 106 | override fun getFormatTypeMapping(): Map = formatTypeMapping 107 | 108 | override fun getInclusionLevel(): InclusionLevel = inclusionLevel 109 | 110 | override fun getOutputEncoding(): String = outputEncoding 111 | 112 | override fun getPropertyWordDelimiters(): CharArray = propertyWordDelimiters.toCharArray() 113 | 114 | override fun getRefFragmentPathDelimiters(): String = refFragmentPathDelimiters 115 | 116 | override fun getSource(): Iterator? = source 117 | 118 | override fun getSourceSortOrder(): SourceSortOrder = sourceSortOrder 119 | 120 | override fun getSourceType(): SourceType = sourceType 121 | 122 | override fun getTargetDirectory(): File = targetDirectory 123 | 124 | override fun getTargetPackage(): String = targetPackage 125 | 126 | override fun getTargetVersion(): String = targetVersion 127 | 128 | override fun getTimeType(): String? = timeType 129 | 130 | override fun getToStringExcludes(): Array = toStringExcludes.toTypedArray() 131 | 132 | override fun isConstructorsRequiredPropertiesOnly(): Boolean = constructorsRequiredPropertiesOnly 133 | 134 | override fun isFormatDateTimes(): Boolean = formatDateTimes 135 | 136 | override fun isFormatDates(): Boolean = formatDates 137 | 138 | override fun isFormatTimes(): Boolean = formatTimes 139 | 140 | override fun isGenerateBuilders(): Boolean = generateBuilders 141 | 142 | override fun isIncludeAdditionalProperties(): Boolean = includeAdditionalProperties 143 | 144 | override fun isIncludeAllPropertiesConstructor(): Boolean = includeAllPropertiesConstructor 145 | 146 | override fun isIncludeConstructorPropertiesAnnotation(): Boolean = includeConstructorPropertiesAnnotation 147 | 148 | override fun isIncludeConstructors(): Boolean = includeConstructors 149 | 150 | override fun isIncludeCopyConstructor(): Boolean = includeCopyConstructor 151 | 152 | override fun isIncludeDynamicAccessors(): Boolean = includeDynamicAccessors 153 | 154 | override fun isIncludeDynamicBuilders(): Boolean = includeDynamicBuilders 155 | 156 | override fun isIncludeDynamicGetters(): Boolean = includeDynamicGetters 157 | 158 | override fun isIncludeDynamicSetters(): Boolean = includeDynamicSetters 159 | 160 | override fun isIncludeGeneratedAnnotation(): Boolean = includeGeneratedAnnotation 161 | 162 | override fun isIncludeGetters(): Boolean = includeGetters 163 | 164 | override fun isIncludeHashcodeAndEquals(): Boolean = includeHashcodeAndEquals 165 | 166 | override fun isIncludeJsr303Annotations(): Boolean = includeJsr303Annotations 167 | 168 | override fun isIncludeJsr305Annotations(): Boolean = includeJsr305Annotations 169 | 170 | override fun isIncludeRequiredPropertiesConstructor(): Boolean = includeRequiredPropertiesConstructor 171 | 172 | override fun isIncludeSetters(): Boolean = includeSetters 173 | 174 | override fun isIncludeToString(): Boolean = includeToString 175 | 176 | override fun isIncludeTypeInfo(): Boolean = includeTypeInfo 177 | 178 | override fun isInitializeCollections(): Boolean = initializeCollections 179 | 180 | override fun isParcelable(): Boolean = parcelable 181 | 182 | override fun isRemoveOldOutput(): Boolean = removeOldOutput 183 | 184 | override fun isSerializable(): Boolean = serializable 185 | 186 | override fun isUseBigDecimals(): Boolean = useBigDecimals 187 | 188 | override fun isUseBigIntegers(): Boolean = useBigIntegers 189 | 190 | override fun isUseDoubleNumbers(): Boolean = useDoubleNumbers 191 | 192 | override fun isUseJakartaValidation(): Boolean = useJakartaValidation 193 | 194 | override fun isUseJodaDates(): Boolean = useJodaDates 195 | 196 | override fun isUseJodaLocalDates(): Boolean = useJodaLocalDates 197 | 198 | override fun isUseJodaLocalTimes(): Boolean = useJodaLocalTimes 199 | 200 | override fun isUseLongIntegers(): Boolean = useLongIntegers 201 | 202 | override fun isUseOptionalForGetters(): Boolean = useOptionalForGetters 203 | 204 | override fun isUsePrimitives(): Boolean = usePrimitives 205 | 206 | override fun isUseTitleAsClassname(): Boolean = useTitleAsClassname 207 | } 208 | -------------------------------------------------------------------------------- /plugin-gradle/common/src/main/kotlin/org/jsonschema2dataclass/ext/Js2pExtension.kt: -------------------------------------------------------------------------------- 1 | /** JsonSchema 2 Pojo configuration extension */ 2 | package org.jsonschema2dataclass.ext 3 | 4 | import org.gradle.api.Action 5 | import org.gradle.api.Named 6 | import org.gradle.api.NamedDomainObjectContainer 7 | import org.gradle.api.file.ConfigurableFileCollection 8 | import org.gradle.api.file.DirectoryProperty 9 | import org.gradle.api.provider.MapProperty 10 | import org.gradle.api.provider.Property 11 | import org.gradle.api.provider.SetProperty 12 | import org.gradle.api.tasks.Input 13 | import org.gradle.api.tasks.InputFiles 14 | import org.gradle.api.tasks.Internal 15 | import org.gradle.api.tasks.Nested 16 | import org.gradle.api.tasks.Optional 17 | import org.gradle.api.tasks.PathSensitive 18 | import org.gradle.api.tasks.PathSensitivity 19 | import org.gradle.kotlin.dsl.invoke 20 | import java.io.FileFilter 21 | import javax.inject.Inject 22 | 23 | /** Jsonschema2pojo extension */ 24 | abstract class Js2pExtension { 25 | abstract val executions: NamedDomainObjectContainer 26 | 27 | @get:PathSensitive(PathSensitivity.RELATIVE) 28 | abstract val targetDirectoryPrefix: DirectoryProperty 29 | } 30 | 31 | /** Jsonschema2pojo single configuration */ 32 | abstract class Js2pConfiguration @Inject constructor( 33 | private val name: String, 34 | ) : Named { 35 | @Internal 36 | override fun getName(): String = name 37 | 38 | @get:Nested 39 | @get:Optional 40 | abstract val constructors: PluginConfigJs2pConstructor 41 | 42 | @get:Nested 43 | @get:Optional 44 | abstract val dateTime: PluginConfigJs2pDateTime 45 | 46 | @get:Nested 47 | @get:Optional 48 | abstract val fields: PluginConfigJs2pField 49 | 50 | @get:Nested 51 | @get:Optional 52 | abstract val io: PluginConfigJs2pIO 53 | 54 | @get:Nested 55 | @get:Optional 56 | abstract val klass: PluginConfigJs2pClass 57 | 58 | @get:Nested 59 | @get:Optional 60 | abstract val methods: PluginConfigJs2pMethod 61 | 62 | fun io(action: Action) { 63 | action(io) 64 | } 65 | 66 | fun klass(action: Action) { 67 | action(klass) 68 | } 69 | 70 | fun constructors(action: Action) { 71 | action(constructors) 72 | } 73 | 74 | fun methods(action: Action) { 75 | action(methods) 76 | } 77 | 78 | fun fields(action: Action) { 79 | action(fields) 80 | } 81 | 82 | fun dateTime(action: Action) { 83 | action(dateTime) 84 | } 85 | } 86 | 87 | /** Input-output parameters */ 88 | abstract class PluginConfigJs2pIO { 89 | @get:Input 90 | @get:Optional 91 | abstract val delimitersPropertyWord: Property 92 | 93 | @get:Input 94 | @get:Optional 95 | abstract val delimitersRefFragmentPath: Property 96 | 97 | @get:Input 98 | @get:Optional 99 | abstract val fileExtensions: SetProperty 100 | 101 | @get:Input 102 | @get:Optional 103 | abstract val fileFilter: Property 104 | 105 | @get:Input 106 | @get:Optional 107 | abstract val outputEncoding: Property 108 | 109 | @get:InputFiles 110 | @get:PathSensitive(PathSensitivity.RELATIVE) 111 | abstract val source: ConfigurableFileCollection 112 | 113 | @get:Input 114 | @get:Optional 115 | abstract val sourceSortOrder: Property 116 | 117 | @get:Input 118 | @get:Optional 119 | abstract val sourceType: Property 120 | 121 | @get:Input 122 | @get:Optional 123 | abstract val targetJavaVersion: Property 124 | } 125 | 126 | /** Class-level annotations and targeting */ 127 | abstract class PluginConfigJs2pClass { 128 | @get:Input 129 | @get:Optional 130 | abstract val androidParcelable: Property 131 | 132 | @get:Input 133 | @get:Optional 134 | abstract val annotateGenerated: Property 135 | 136 | @get:Input 137 | @get:Optional 138 | abstract val annotateSerializable: Property 139 | 140 | @get:Input 141 | @get:Optional 142 | abstract val annotationStyle: Property 143 | 144 | @get:Input 145 | @get:Optional 146 | abstract val customAnnotatorClass: Property 147 | 148 | @get:Input 149 | @get:Optional 150 | abstract val customRuleFactoryClass: Property 151 | 152 | @get:Input 153 | @get:Optional 154 | abstract val jackson2IncludeTypeInfo: Property 155 | 156 | @get:Input 157 | @get:Optional 158 | abstract val jackson2InclusionLevel: Property 159 | 160 | @get:Input 161 | @get:Optional 162 | abstract val namePrefix: Property 163 | 164 | @get:Input 165 | @get:Optional 166 | abstract val nameSuffix: Property 167 | 168 | @get:Input 169 | @get:Optional 170 | abstract val nameUseTitle: Property 171 | 172 | @get:Input 173 | @get:Optional 174 | abstract val targetPackage: Property 175 | } 176 | 177 | abstract class PluginConfigJs2pConstructor { 178 | @get:Input 179 | @get:Optional 180 | abstract val allProperties: Property 181 | 182 | @get:Input 183 | @get:Optional 184 | abstract val annotateConstructorProperties: Property 185 | 186 | @get:Input 187 | @get:Optional 188 | abstract val copyConstructor: Property 189 | 190 | @get:Input 191 | @get:Optional 192 | abstract val requiredProperties: Property 193 | } 194 | 195 | abstract class PluginConfigJs2pMethod { 196 | @get:Input 197 | @get:Optional 198 | abstract val additionalProperties: Property 199 | 200 | @get:Input 201 | @get:Optional 202 | abstract val annotateJsr303Jakarta: Property 203 | 204 | @get:Input 205 | @get:Optional 206 | abstract val annotateJsr303: Property 207 | 208 | @get:Input 209 | @get:Optional 210 | abstract val annotateJsr305: Property 211 | 212 | @get:Input 213 | @get:Optional 214 | abstract val builders: Property 215 | 216 | @get:Input 217 | @get:Optional 218 | abstract val buildersDynamic: Property 219 | 220 | @get:Input 221 | @get:Optional 222 | abstract val buildersInnerClass: Property 223 | 224 | @get:Input 225 | @get:Optional 226 | abstract val getters: Property 227 | 228 | @get:Input 229 | @get:Optional 230 | abstract val gettersDynamic: Property 231 | 232 | @get:Input 233 | @get:Optional 234 | abstract val gettersUseOptional: Property 235 | 236 | @get:Input 237 | @get:Optional 238 | abstract val hashcodeAndEquals: Property 239 | 240 | @get:Input 241 | @get:Optional 242 | abstract val setters: Property 243 | 244 | @get:Input 245 | @get:Optional 246 | abstract val settersDynamic: Property 247 | 248 | @get:Input 249 | @get:Optional 250 | abstract val toStringMethod: Property 251 | 252 | @get:Input 253 | @get:Optional 254 | abstract val toStringExcludes: SetProperty 255 | } 256 | 257 | abstract class PluginConfigJs2pField { 258 | @get:Input 259 | @get:Optional 260 | abstract val floatUseBigDecimal: Property 261 | 262 | @get:Input 263 | @get:Optional 264 | abstract val floatUseDouble: Property 265 | 266 | @get:Input 267 | @get:Optional 268 | abstract val formatToTypeMapping: MapProperty 269 | 270 | @get:Input 271 | @get:Optional 272 | abstract val initializeCollections: Property 273 | 274 | @get:Input 275 | @get:Optional 276 | abstract val integerUseBigInteger: Property 277 | 278 | @get:Input 279 | @get:Optional 280 | abstract val integerUseLong: Property 281 | 282 | @get:Input 283 | @get:Optional 284 | abstract val usePrimitives: Property 285 | } 286 | 287 | abstract class PluginConfigJs2pDateTime { 288 | @get:Input 289 | @get:Optional 290 | abstract val dateFormat: Property 291 | 292 | @get:Input 293 | @get:Optional 294 | abstract val datePattern: Property 295 | 296 | @get:Input 297 | @get:Optional 298 | abstract val dateTimeFormat: Property 299 | 300 | @get:Input 301 | @get:Optional 302 | abstract val dateTimePattern: Property 303 | 304 | @get:Input 305 | @get:Optional 306 | abstract val dateTimeType: Property 307 | 308 | @get:Input 309 | @get:Optional 310 | abstract val dateType: Property 311 | 312 | @get:Input 313 | @get:Optional 314 | abstract val jodaDate: Property 315 | 316 | @get:Input 317 | @get:Optional 318 | abstract val jodaLocalDate: Property 319 | 320 | @get:Input 321 | @get:Optional 322 | abstract val jodaLocalTime: Property 323 | 324 | @get:Input 325 | @get:Optional 326 | abstract val timeFormat: Property 327 | 328 | @get:Input 329 | @get:Optional 330 | abstract val timePattern: Property 331 | 332 | @get:Input 333 | @get:Optional 334 | abstract val timeType: Property 335 | } 336 | --------------------------------------------------------------------------------