├── exhaustive-gradle ├── src │ ├── test │ │ ├── fixture │ │ │ ├── js │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── main │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── jvm │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── main │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── mpp │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── commonMain │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── .gitignore │ │ │ ├── android │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── main │ │ │ │ │ │ ├── AndroidManifest.xml │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── js-test │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── test │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── jvm-test │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── test │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── mpp-test │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ └── commonTest │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ ├── android-unit-test │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ │ ├── main │ │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ │ └── test │ │ │ │ │ │ └── kotlin │ │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ │ └── android-instrumentation-test │ │ │ │ ├── settings.gradle │ │ │ │ ├── src │ │ │ │ ├── main │ │ │ │ │ └── AndroidManifest.xml │ │ │ │ └── androidTest │ │ │ │ │ └── kotlin │ │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── Example.kt │ │ │ │ └── build.gradle │ │ └── kotlin │ │ │ └── app │ │ │ └── cash │ │ │ └── exhaustive │ │ │ └── gradle │ │ │ └── ExhaustivePluginTest.kt │ └── main │ │ └── kotlin │ │ └── app │ │ └── cash │ │ └── exhaustive │ │ └── gradle │ │ └── ExhaustivePlugin.kt ├── gradle.properties └── build.gradle ├── .gitattributes ├── .gitignore ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── publish.gradle └── dependencies.gradle ├── settings.gradle ├── exhaustive-compiler ├── gradle.properties ├── build.gradle └── src │ ├── main │ └── kotlin │ │ └── app │ │ └── cash │ │ └── exhaustive │ │ └── compiler │ │ ├── ExhaustiveComponentRegistrar.kt │ │ ├── ExhaustiveErrors.kt │ │ └── ExhaustiveDeclarationChecker.kt │ └── test │ └── kotlin │ └── app │ └── cash │ └── exhaustive │ └── compiler │ └── ExhaustiveCompilerTest.kt ├── exhaustive-annotation ├── gradle.properties ├── build.gradle └── src │ └── commonMain │ └── kotlin │ └── app │ └── cash │ └── exhaustive │ └── Exhaustive.kt ├── .editorconfig ├── gradle.properties ├── CHANGELOG.md ├── RELEASING.md ├── .github └── workflows │ ├── build.yaml │ └── release.yaml ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE.txt /exhaustive-gradle/src/test/fixture/js/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.bat text eol=crlf 4 | *.jar binary -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | gradle 3 | .gradle 4 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/js-test/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm-test/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp-test/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-unit-test/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-instrumentation-test/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ IDEA 2 | /.idea 3 | *.iml 4 | 5 | # Gradle 6 | /.gradle 7 | build 8 | /reports 9 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-unit-test/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cashapp/exhaustive/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-instrumentation-test/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'exhaustive' 2 | 3 | include ':exhaustive-annotation' 4 | include ':exhaustive-compiler' 5 | include ':exhaustive-gradle' 6 | -------------------------------------------------------------------------------- /exhaustive-compiler/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=exhaustive-compiler 2 | POM_NAME=Exhaustive compiler 3 | POM_DESCRIPTION=Annotation for enforcing exhaustive when in statement form 4 | -------------------------------------------------------------------------------- /exhaustive-gradle/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=exhaustive-gradle 2 | POM_NAME=Exhaustive Gradle plugin 3 | POM_DESCRIPTION=Annotation for enforcing exhaustive when in statement form 4 | -------------------------------------------------------------------------------- /exhaustive-annotation/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=exhaustive-annotation 2 | POM_NAME=Exhastive Annotation 3 | POM_DESCRIPTION=Annotation for enforcing exhaustive when in statement form 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_size = 2 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | 9 | [*.{kt,kts}] 10 | kotlin_imports_layout = ascii 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/js/src/main/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm/src/main/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android/src/main/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/js-test/src/test/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm-test/src/test/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp/src/commonMain/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-unit-test/src/test/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp-test/src/commonTest/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-annotation/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'org.jetbrains.kotlin.multiplatform' 2 | apply from: "$rootDir/gradle/publish.gradle" 3 | 4 | kotlin { 5 | js { 6 | nodejs() 7 | } 8 | 9 | jvm() 10 | 11 | iosArm32() 12 | iosArm64() 13 | iosX64() 14 | linuxX64() 15 | macosX64() 16 | mingwX64() 17 | tvosArm64() 18 | tvosX64() 19 | watchosArm32() 20 | watchosArm64() 21 | watchosX86() 22 | } 23 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-instrumentation-test/src/androidTest/kotlin/com/example/Example.kt: -------------------------------------------------------------------------------- 1 | package com.example 2 | 3 | import app.cash.exhaustive.Exhaustive 4 | 5 | enum class RouletteColor { Red, Black, Green } 6 | 7 | fun subject(value: RouletteColor) { 8 | @Exhaustive 9 | when (value) { 10 | RouletteColor.Red -> println("red") 11 | RouletteColor.Black -> println("black") 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /exhaustive-compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'org.jetbrains.kotlin.jvm' 2 | apply plugin: 'org.jetbrains.kotlin.kapt' 3 | apply from: "$rootDir/gradle/publish.gradle" 4 | 5 | dependencies { 6 | compileOnly deps.kotlin.embeddableCompiler 7 | testImplementation deps.kotlin.embeddableCompiler 8 | 9 | kapt deps.autoService.compiler 10 | compileOnly deps.autoService.annotations 11 | 12 | testImplementation deps.junit 13 | testImplementation deps.truth 14 | testImplementation deps.kotlinCompileTesting 15 | testImplementation project(':exhaustive-annotation') 16 | } 17 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.vanniktech.maven.publish" 2 | 3 | mavenPublish { 4 | targets { 5 | installArchives { 6 | def url = file("${rootProject.buildDir}/localMaven").toURI().toString() 7 | releaseRepositoryUrl = url 8 | snapshotRepositoryUrl = url 9 | } 10 | } 11 | } 12 | 13 | signing { 14 | def signingKey = findProperty('signingKey') 15 | def signingPassword = '' 16 | useInMemoryPgpKeys(signingKey, signingPassword) 17 | } 18 | 19 | if (project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) { 20 | apply plugin: 'org.jetbrains.dokka' 21 | 22 | dokkaHtml { 23 | outputDirectory = new File("$buildDir/dokka") 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.jvm' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | repositories { 20 | maven { 21 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 22 | } 23 | mavenCentral() 24 | } 25 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/jvm-test/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.jvm' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | repositories { 20 | maven { 21 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 22 | } 23 | mavenCentral() 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | GROUP=app.cash.exhaustive 2 | VERSION_NAME=0.3.0-SNAPSHOT 3 | 4 | POM_URL=https://github.com/cashapp/exhasutive/ 5 | POM_SCM_URL=https://github.com/cashapp/exhasutive/ 6 | POM_SCM_CONNECTION=scm:git:git://github.com/cashapp/exhasutive.git 7 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/cashapp/exhasutive.git 8 | 9 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 11 | POM_LICENCE_DIST=repo 12 | 13 | POM_DEVELOPER_ID=cashapp 14 | POM_DEVELOPER_NAME=CashApp 15 | POM_DEVELOPER_URL=https://github.com/cashapp/ 16 | 17 | kotlin.mpp.stability.nowarn=true 18 | kotlin.js.compiler=both 19 | 20 | systemProp.org.gradle.internal.http.socketTimeout=120000 21 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [Unreleased] 4 | 5 | 6 | 7 | ## [0.2.0] 8 | 9 | Fixes: 10 | 11 | * Support for Kotlin 1.5.20 12 | 13 | 14 | ## [0.2.0-M1] 15 | 16 | Fixes: 17 | 18 | * Support for Kotlin 1.5.20-M1 19 | 20 | 21 | ## [0.1.1] 22 | 23 | Fixes: 24 | 25 | * Lower Java requirement from Java 14 to Java 8 26 | 27 | 28 | ## [0.1.0] 29 | 30 | Initial release. 31 | 32 | 33 | [Unreleased]: https://github.com/cashapp/exhaustive/compare/0.2.0...HEAD 34 | [0.2.0]: https://github.com/cashapp/exhaustive/releases/tag/0.2.0 35 | [0.2.0-M1]: https://github.com/cashapp/exhaustive/releases/tag/0.2.0-M1 36 | [0.1.1]: https://github.com/cashapp/exhaustive/releases/tag/0.1.1 37 | [0.1.0]: https://github.com/cashapp/exhaustive/releases/tag/0.1.0 38 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.multiplatform' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | repositories { 20 | maven { 21 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 22 | } 23 | mavenCentral() 24 | } 25 | 26 | kotlin { 27 | jvm() 28 | } 29 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/mpp-test/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.multiplatform' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | repositories { 20 | maven { 21 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 22 | } 23 | mavenCentral() 24 | } 25 | 26 | kotlin { 27 | jvm() 28 | } 29 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/js/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.js' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | kotlin { 20 | js { 21 | nodejs() 22 | } 23 | } 24 | 25 | repositories { 26 | maven { 27 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 28 | } 29 | mavenCentral() 30 | } 31 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/js-test/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 7 | } 8 | repositories { 9 | maven { 10 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 11 | } 12 | mavenCentral() 13 | } 14 | } 15 | 16 | apply plugin: 'org.jetbrains.kotlin.js' 17 | apply plugin: 'app.cash.exhaustive' 18 | 19 | kotlin { 20 | js { 21 | nodejs() 22 | } 23 | } 24 | 25 | repositories { 26 | maven { 27 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 28 | } 29 | mavenCentral() 30 | } 31 | -------------------------------------------------------------------------------- /gradle/dependencies.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.versions = [ 3 | 'kotlin': '1.5.31', 4 | 'autoService': '1.0', 5 | ] 6 | 7 | ext.deps = [ 8 | 'kotlin': [ 9 | 'embeddableCompiler': "org.jetbrains.kotlin:kotlin-compiler-embeddable:${versions.kotlin}", 10 | 'gradlePlugin' : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}", 11 | 'gradlePluginApi': "org.jetbrains.kotlin:kotlin-gradle-plugin-api:${versions.kotlin}", 12 | ], 13 | 'autoService': [ 14 | 'annotations': "com.google.auto.service:auto-service-annotations:${versions.autoService}", 15 | 'compiler': "com.google.auto.service:auto-service:${versions.autoService}", 16 | ], 17 | 'kotlinCompileTesting': 'com.github.tschuchortdev:kotlin-compile-testing:1.4.4', 18 | 'junit': 'junit:junit:4.13.2', 19 | 'truth': 'com.google.truth:truth:1.1.3', 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath 'com.android.tools.build:gradle:4.1.0' 7 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 8 | } 9 | repositories { 10 | maven { 11 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 12 | } 13 | mavenCentral() 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | apply plugin: 'com.android.library' 20 | apply plugin: 'org.jetbrains.kotlin.android' 21 | apply plugin: 'app.cash.exhaustive' 22 | 23 | android { 24 | compileSdkVersion 30 25 | } 26 | 27 | repositories { 28 | maven { 29 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 30 | } 31 | mavenCentral() 32 | google() 33 | jcenter() 34 | } 35 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-unit-test/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath 'com.android.tools.build:gradle:4.1.0' 7 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 8 | } 9 | repositories { 10 | maven { 11 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 12 | } 13 | mavenCentral() 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | apply plugin: 'com.android.library' 20 | apply plugin: 'org.jetbrains.kotlin.android' 21 | apply plugin: 'app.cash.exhaustive' 22 | 23 | android { 24 | compileSdkVersion 30 25 | } 26 | 27 | repositories { 28 | maven { 29 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 30 | } 31 | mavenCentral() 32 | google() 33 | jcenter() 34 | } 35 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/fixture/android-instrumentation-test/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply from: '../../../../../gradle/dependencies.gradle' 3 | 4 | dependencies { 5 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" 6 | classpath 'com.android.tools.build:gradle:4.1.0' 7 | classpath "app.cash.exhaustive:exhaustive-gradle:${exhaustiveVersion}" 8 | } 9 | repositories { 10 | maven { 11 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 12 | } 13 | mavenCentral() 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | apply plugin: 'com.android.library' 20 | apply plugin: 'org.jetbrains.kotlin.android' 21 | apply plugin: 'app.cash.exhaustive' 22 | 23 | android { 24 | compileSdkVersion 30 25 | } 26 | 27 | repositories { 28 | maven { 29 | url "file://${projectDir.absolutePath}/../../../../../build/localMaven" 30 | } 31 | mavenCentral() 32 | google() 33 | jcenter() 34 | } 35 | -------------------------------------------------------------------------------- /exhaustive-annotation/src/commonMain/kotlin/app/cash/exhaustive/Exhaustive.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive 2 | 3 | import kotlin.annotation.AnnotationRetention.SOURCE 4 | 5 | /** 6 | * Denote a `when` statement which is required to exhaustively cover all cases. 7 | * 8 | * The Kotlin compiler will only enforce exhaustiveness for a `when` used as an expression. This 9 | * annotation extends that same enforcement to statement `when`s. Additionally, these `when`s are 10 | * forbidden from having an `else` branch since it is mutually exclusive with exhaustiveness. 11 | * 12 | * ```kotlin 13 | * enum class RouletteColor { Red, Black, Green } 14 | * 15 | * fun printColor(color: RouletteColor) { 16 | * @Exhaustive 17 | * when (subject) { 18 | * Red -> println("red") 19 | * Black -> println("black") 20 | * } 21 | * } 22 | * ``` 23 | * Compilation of the above will fail with: 24 | * ``` 25 | * e: Example.kt:5: @Exhaustive when is not exhaustive! 26 | * 27 | * Missing branches: 28 | * - RouletteColor.Green 29 | * ``` 30 | */ 31 | @Retention(SOURCE) 32 | annotation class Exhaustive 33 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/main/kotlin/app/cash/exhaustive/gradle/ExhaustivePlugin.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.gradle 2 | 3 | import org.gradle.api.provider.Provider 4 | import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation 5 | import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin 6 | import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact 7 | import org.jetbrains.kotlin.gradle.plugin.SubpluginOption 8 | 9 | class ExhaustivePlugin : KotlinCompilerPluginSupportPlugin { 10 | override fun getCompilerPluginId() = "app.cash.exhaustive" 11 | 12 | override fun getPluginArtifact() = SubpluginArtifact( 13 | "app.cash.exhaustive", 14 | "exhaustive-compiler", 15 | exhaustiveVersion 16 | ) 17 | 18 | override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean { 19 | return kotlinCompilation.target.project.plugins.hasPlugin(ExhaustivePlugin::class.java) 20 | } 21 | 22 | override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider> { 23 | kotlinCompilation.dependencies { 24 | compileOnly("app.cash.exhaustive:exhaustive-annotation:$exhaustiveVersion") 25 | } 26 | return kotlinCompilation.target.project.provider { emptyList() } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | # Releasing 2 | 3 | 1. Update the `VERSION_NAME` in `gradle.properties` to the release version. 4 | 5 | 2. Update the `CHANGELOG.md`: 6 | 1. Change the `Unreleased` header to the release version. 7 | 2. Add a link URL to ensure the header link works. 8 | 3. Add a new `Unreleased` section to the top. 9 | 10 | 3. Update the `README.md`: 11 | 1. Change the "Download" section to reflect the new release version. 12 | 2. Change the snapshot section to reflect the next "SNAPSHOT" version, if it is changing. 13 | 3. Update the Kotlin version compatibility table 14 | 15 | 4. Commit 16 | 17 | ``` 18 | $ git commit -am "Prepare version X.Y.X" 19 | ``` 20 | 21 | 5. Tag 22 | 23 | ``` 24 | $ git tag -am "Version X.Y.Z" X.Y.Z 25 | ``` 26 | 27 | 6. Update the `VERSION_NAME` in `gradle.properties` to the next "SNAPSHOT" version. 28 | 29 | 7. Commit 30 | 31 | ``` 32 | $ git commit -am "Prepare next development version" 33 | ``` 34 | 35 | 8. Push! 36 | 37 | ``` 38 | $ git push && git push --tags 39 | ``` 40 | 41 | This will trigger a GitHub Action workflow which will create a GitHub release and upload the 42 | release artifacts to Sonatype Nexus. 43 | 44 | 9. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. 45 | -------------------------------------------------------------------------------- /exhaustive-compiler/src/main/kotlin/app/cash/exhaustive/compiler/ExhaustiveComponentRegistrar.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.compiler 2 | 3 | import com.google.auto.service.AutoService 4 | import org.jetbrains.kotlin.com.intellij.mock.MockProject 5 | import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar 6 | import org.jetbrains.kotlin.config.CompilerConfiguration 7 | import org.jetbrains.kotlin.container.StorageComponentContainer 8 | import org.jetbrains.kotlin.container.useInstance 9 | import org.jetbrains.kotlin.descriptors.ModuleDescriptor 10 | import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor 11 | import org.jetbrains.kotlin.platform.TargetPlatform 12 | 13 | @AutoService(ComponentRegistrar::class) 14 | class ExhaustiveComponentRegistrar : ComponentRegistrar { 15 | override fun registerProjectComponents( 16 | project: MockProject, 17 | configuration: CompilerConfiguration, 18 | ) { 19 | StorageComponentContainerContributor.registerExtension( 20 | project, 21 | ExhaustiveStorageComponentContainerContributor, 22 | ) 23 | } 24 | } 25 | 26 | private object ExhaustiveStorageComponentContainerContributor : StorageComponentContainerContributor { 27 | override fun registerModuleComponents( 28 | container: StorageComponentContainer, 29 | platform: TargetPlatform, 30 | moduleDescriptor: ModuleDescriptor, 31 | ) { 32 | container.useInstance(ExhaustiveDeclarationChecker) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | pull_request: {} 5 | push: 6 | branches: 7 | - '*' 8 | tags-ignore: 9 | - '*' 10 | 11 | env: 12 | GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false" 13 | 14 | jobs: 15 | build: 16 | strategy: 17 | matrix: 18 | os: [macOS-latest, windows-latest] 19 | 20 | runs-on: ${{matrix.os}} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | - uses: gradle/wrapper-validation-action@v1 25 | - uses: actions/setup-java@v2 26 | with: 27 | distribution: 'zulu' 28 | java-version: 14 29 | 30 | - run: ./gradlew build 31 | 32 | - run: ./gradlew publish 33 | if: ${{ github.ref == 'refs/heads/trunk' && github.repository == 'cashapp/exhaustive' }} 34 | env: 35 | ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 36 | ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 37 | 38 | - run: ./gradlew publishMingwX64PublicationToMavenRepository 39 | if: ${{ github.ref == 'refs/heads/trunk' && github.repository == 'cashapp/exhaustive' && matrix.os == 'windows-latest' }} 40 | env: 41 | ORG_GRADLE_PROJECT_SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 42 | ORG_GRADLE_PROJECT_SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 43 | -------------------------------------------------------------------------------- /exhaustive-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'org.jetbrains.kotlin.jvm' 2 | apply plugin: 'java-gradle-plugin' 3 | apply from: "$rootDir/gradle/publish.gradle" 4 | 5 | dependencies { 6 | compileOnly gradleApi() 7 | compileOnly deps.kotlin.gradlePlugin 8 | 9 | testImplementation deps.junit 10 | testImplementation deps.truth 11 | testImplementation gradleTestKit() 12 | } 13 | 14 | gradlePlugin { 15 | plugins { 16 | exhaustive { 17 | id = "app.cash.exhaustive" 18 | displayName = "Exhaustive When" 19 | description = "Annotation for enforcing exhaustive when in statement form" 20 | implementationClass = "app.cash.exhaustive.gradle.ExhaustivePlugin" 21 | } 22 | } 23 | } 24 | 25 | test { 26 | dependsOn(':exhaustive-annotation:installArchives') 27 | dependsOn(':exhaustive-compiler:installArchives') 28 | dependsOn(':exhaustive-gradle:installArchives') 29 | } 30 | 31 | def versionDirectory = "$buildDir/generated/version/" 32 | 33 | sourceSets { 34 | main.java.srcDir versionDirectory 35 | } 36 | 37 | task pluginVersion { 38 | def outputDir = file(versionDirectory) 39 | 40 | inputs.property 'version', project.version 41 | outputs.dir outputDir 42 | 43 | doLast { 44 | def versionFile = file("$outputDir/app/cash/exhaustive/gradle/version.kt") 45 | versionFile.parentFile.mkdirs() 46 | versionFile.text = """// Generated file. Do not edit! 47 | package app.cash.exhaustive.gradle 48 | 49 | internal const val exhaustiveVersion = "${project.version}" 50 | """ 51 | } 52 | } 53 | 54 | tasks.getByName('compileKotlin').dependsOn('pluginVersion') 55 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | env: 9 | GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false" 10 | 11 | jobs: 12 | publish: 13 | strategy: 14 | matrix: 15 | os: [macOS-latest, windows-latest] 16 | 17 | runs-on: ${{matrix.os}} 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | - uses: gradle/wrapper-validation-action@v1 22 | - uses: actions/setup-java@v2 23 | with: 24 | distribution: 'zulu' 25 | java-version: 14 26 | 27 | - name: Build and publish artifacts 28 | env: 29 | SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 30 | SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 31 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }} 32 | run: ./gradlew build publish 33 | 34 | - name: Build and publish artifacts 35 | env: 36 | SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} 37 | SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} 38 | ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ARTIFACT_SIGNING_PRIVATE_KEY }} 39 | run: ./gradlew build publishMingwX64PublicationToMavenRepository 40 | if: matrix.os == 'windows-latest' 41 | 42 | github_release: 43 | runs-on: ubuntu-latest 44 | 45 | needs: 46 | - publish 47 | 48 | steps: 49 | - uses: actions/checkout@v2 50 | 51 | - name: Extract release notes 52 | id: release_notes 53 | uses: ffurrer2/extract-release-notes@v1 54 | 55 | - name: Create release 56 | uses: softprops/action-gh-release@v1 57 | with: 58 | body: ${{ steps.release_notes.outputs.release_notes }} 59 | env: 60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 61 | -------------------------------------------------------------------------------- /exhaustive-gradle/src/test/kotlin/app/cash/exhaustive/gradle/ExhaustivePluginTest.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.gradle 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import java.io.File 5 | import org.gradle.testkit.runner.GradleRunner 6 | import org.junit.Assume.assumeTrue 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.junit.runners.Parameterized 10 | import org.junit.runners.Parameterized.Parameters 11 | 12 | @RunWith(Parameterized::class) 13 | class ExhaustivePluginTest( 14 | private val fixtureName: String, 15 | ) { 16 | companion object { 17 | @JvmStatic 18 | @Parameters(name = "{0}") 19 | fun parameters() = listOf( 20 | arrayOf("android"), 21 | arrayOf("android-unit-test"), 22 | arrayOf("android-instrumentation-test"), 23 | arrayOf("js"), 24 | arrayOf("js-test"), 25 | arrayOf("jvm"), 26 | arrayOf("jvm-test"), 27 | arrayOf("mpp"), 28 | arrayOf("mpp-test"), 29 | ) 30 | } 31 | 32 | private val fixturesDir = File("src/test/fixture") 33 | 34 | private fun versionProperty() = "-PexhaustiveVersion=$exhaustiveVersion" 35 | 36 | @Test fun build() { 37 | // KotlinCompilerPluginSupportPlugin does not work with instrumentation compilations yet. 38 | assumeTrue(fixtureName != "android-instrumentation-test") 39 | 40 | val fixtureDir = File(fixturesDir, fixtureName) 41 | val gradleRoot = File(fixtureDir, "gradle").also { it.mkdir() } 42 | File("../gradle/wrapper").copyRecursively(File(gradleRoot, "wrapper"), true) 43 | 44 | val result = GradleRunner.create() 45 | .withProjectDir(fixtureDir) 46 | .withArguments("clean", "build", "--stacktrace", versionProperty()) 47 | .buildAndFail() 48 | assertThat(result.output).contains("BUILD FAILED") 49 | assertThat(result.output).contains( 50 | """ 51 | |Example.kt: (9, 3): @Exhaustive when is not exhaustive! 52 | | 53 | |Missing branches: 54 | |- com.example.RouletteColor.Green 55 | """.trimMargin() 56 | ) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /exhaustive-compiler/src/main/kotlin/app/cash/exhaustive/compiler/ExhaustiveErrors.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.compiler 2 | 3 | import app.cash.exhaustive.compiler.ExhaustiveErrors.INVALID_ELSE_BRANCH 4 | import app.cash.exhaustive.compiler.ExhaustiveErrors.NOT_EXHAUSTIVE 5 | import app.cash.exhaustive.compiler.ExhaustiveErrors.WHEN_SUBJECT_REQUIRED 6 | import org.jetbrains.kotlin.com.intellij.psi.PsiElement 7 | import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0 8 | import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1 9 | import org.jetbrains.kotlin.diagnostics.Errors 10 | import org.jetbrains.kotlin.diagnostics.Severity.ERROR 11 | import org.jetbrains.kotlin.diagnostics.WhenMissingCase 12 | import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages 13 | import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap 14 | import org.jetbrains.kotlin.diagnostics.rendering.MultiRenderer 15 | 16 | internal object ExhaustiveErrors { 17 | @JvmField 18 | val INVALID_ELSE_BRANCH = DiagnosticFactory0.create(ERROR) 19 | @JvmField 20 | val NOT_EXHAUSTIVE = DiagnosticFactory1.create>(ERROR) 21 | @JvmField 22 | val WHEN_SUBJECT_REQUIRED = DiagnosticFactory0.create(ERROR) 23 | 24 | init { 25 | Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( 26 | ExhaustiveErrors::class.java, 27 | DefaultErrorMessagesExhaustive, 28 | ) 29 | } 30 | } 31 | 32 | private object DefaultErrorMessagesExhaustive : DefaultErrorMessages.Extension { 33 | private val map = DiagnosticFactoryToRendererMap("Exhaustive").apply { 34 | put(INVALID_ELSE_BRANCH, "@Exhaustive when must not contain an 'else' branch") 35 | put(WHEN_SUBJECT_REQUIRED, "@Exhaustive when must have a subject expression") 36 | 37 | put( 38 | NOT_EXHAUSTIVE, 39 | "@Exhaustive when is not exhaustive!\n\nMissing branches:\n{0}", 40 | object : MultiRenderer> { 41 | override fun render(a: List): Array { 42 | return arrayOf( 43 | a.joinToString(prefix = "- ", separator = "\n- ") { it.branchConditionText }, 44 | ) 45 | } 46 | }, 47 | ) 48 | } 49 | 50 | override fun getMap() = map 51 | } 52 | -------------------------------------------------------------------------------- /exhaustive-compiler/src/main/kotlin/app/cash/exhaustive/compiler/ExhaustiveDeclarationChecker.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.compiler 2 | 3 | import app.cash.exhaustive.compiler.ExhaustiveErrors.INVALID_ELSE_BRANCH 4 | import app.cash.exhaustive.compiler.ExhaustiveErrors.NOT_EXHAUSTIVE 5 | import app.cash.exhaustive.compiler.ExhaustiveErrors.WHEN_SUBJECT_REQUIRED 6 | import org.jetbrains.kotlin.cfg.WhenChecker 7 | import org.jetbrains.kotlin.descriptors.DeclarationDescriptor 8 | import org.jetbrains.kotlin.name.FqName 9 | import org.jetbrains.kotlin.psi.KtAnnotatedExpression 10 | import org.jetbrains.kotlin.psi.KtDeclaration 11 | import org.jetbrains.kotlin.psi.KtTreeVisitorVoid 12 | import org.jetbrains.kotlin.psi.KtWhenExpression 13 | import org.jetbrains.kotlin.resolve.BindingContext.ANNOTATION 14 | import org.jetbrains.kotlin.resolve.BindingTrace 15 | import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker 16 | import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext 17 | 18 | internal object ExhaustiveDeclarationChecker : DeclarationChecker { 19 | private val exhaustiveAnnotation = FqName("app.cash.exhaustive.Exhaustive") 20 | 21 | override fun check( 22 | declaration: KtDeclaration, 23 | descriptor: DeclarationDescriptor, 24 | context: DeclarationCheckerContext, 25 | ) { 26 | val bindingContext = context.trace.bindingContext 27 | 28 | declaration.accept(object : KtTreeVisitorVoid() { 29 | override fun visitAnnotatedExpression(expression: KtAnnotatedExpression) { 30 | val whenExpression = expression.baseExpression 31 | if (whenExpression is KtWhenExpression) { 32 | val wantsExhaustive = expression.annotationEntries 33 | .any { exhaustiveAnnotation == bindingContext.get(ANNOTATION, it)?.fqName } 34 | if (wantsExhaustive) { 35 | validateExhaustiveWhen(whenExpression, context.trace) 36 | } 37 | } 38 | 39 | super.visitAnnotatedExpression(expression) 40 | } 41 | }) 42 | } 43 | 44 | private fun validateExhaustiveWhen( 45 | whenExpression: KtWhenExpression, 46 | trace: BindingTrace, 47 | ) { 48 | whenExpression.elseExpression?.let { elseExpression -> 49 | trace.report(INVALID_ELSE_BRANCH.on(elseExpression)) 50 | return 51 | } 52 | 53 | if (whenExpression.subjectExpression == null) { 54 | trace.report(WHEN_SUBJECT_REQUIRED.on(whenExpression)) 55 | return 56 | } 57 | 58 | val missingCases = WhenChecker.getMissingCases(whenExpression, trace.bindingContext) 59 | if (missingCases.isNotEmpty()) { 60 | trace.report(NOT_EXHAUSTIVE.on(whenExpression, missingCases)) 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /exhaustive-compiler/src/test/kotlin/app/cash/exhaustive/compiler/ExhaustiveCompilerTest.kt: -------------------------------------------------------------------------------- 1 | package app.cash.exhaustive.compiler 2 | 3 | import com.google.common.truth.Truth.assertThat 4 | import com.tschuchort.compiletesting.KotlinCompilation 5 | import com.tschuchort.compiletesting.KotlinCompilation.ExitCode.COMPILATION_ERROR 6 | import com.tschuchort.compiletesting.KotlinCompilation.ExitCode.OK 7 | import com.tschuchort.compiletesting.KotlinCompilation.Result 8 | import com.tschuchort.compiletesting.SourceFile 9 | import org.intellij.lang.annotations.Language 10 | import org.junit.Test 11 | 12 | class ExhaustiveCompilerTest { 13 | @Test fun booleanExhaustiveCompiles() { 14 | val result = compile( 15 | """ 16 | import app.cash.exhaustive.Exhaustive 17 | 18 | fun subject(value: Boolean) { 19 | @Exhaustive 20 | when (value) { 21 | true -> println("yep") 22 | false -> println("nope") 23 | } 24 | } 25 | """.trimIndent() 26 | ) 27 | 28 | assertThat(result.exitCode).isEqualTo(OK) 29 | } 30 | 31 | @Test fun booleanNonExhaustiveFailsToCompile() { 32 | val result = compile( 33 | """ 34 | import app.cash.exhaustive.Exhaustive 35 | 36 | fun subject(value: Boolean) { 37 | @Exhaustive 38 | when (value) { 39 | true -> println("yep") 40 | } 41 | } 42 | """.trimIndent() 43 | ) 44 | 45 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 46 | assertThat(result.messages).contains( 47 | """ 48 | |@Exhaustive when is not exhaustive! 49 | | 50 | |Missing branches: 51 | |- false 52 | """.trimMargin() 53 | ) 54 | } 55 | 56 | @Test fun booleanElseFailsToCompile() { 57 | val result = compile( 58 | """ 59 | import app.cash.exhaustive.Exhaustive 60 | 61 | fun subject(value: Boolean) { 62 | @Exhaustive 63 | when (value) { 64 | true -> println("yep") 65 | else -> println("nope") 66 | } 67 | } 68 | """.trimIndent() 69 | ) 70 | 71 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 72 | assertThat(result.messages).contains("@Exhaustive when must not contain an 'else' branch") 73 | } 74 | 75 | @Test fun enumExhaustiveCompiles() { 76 | val result = compile( 77 | """ 78 | import app.cash.exhaustive.Exhaustive 79 | 80 | enum class RouletteColor { Red, Black, Green } 81 | 82 | fun subject(value: RouletteColor) { 83 | @Exhaustive 84 | when (value) { 85 | RouletteColor.Red -> println("red") 86 | RouletteColor.Black -> println("black") 87 | RouletteColor.Green -> println("green") 88 | } 89 | } 90 | """.trimIndent() 91 | ) 92 | 93 | assertThat(result.exitCode).isEqualTo(OK) 94 | } 95 | 96 | @Test fun enumNonExhaustiveFailsToCompile() { 97 | val result = compile( 98 | """ 99 | import app.cash.exhaustive.Exhaustive 100 | 101 | enum class RouletteColor { Red, Black, Green } 102 | 103 | fun subject(value: RouletteColor) { 104 | @Exhaustive 105 | when (value) { 106 | RouletteColor.Red -> println("red") 107 | RouletteColor.Black -> println("black") 108 | } 109 | } 110 | """.trimIndent() 111 | ) 112 | 113 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 114 | assertThat(result.messages).contains( 115 | """ 116 | |@Exhaustive when is not exhaustive! 117 | | 118 | |Missing branches: 119 | |- RouletteColor.Green 120 | """.trimMargin() 121 | ) 122 | } 123 | 124 | @Test fun enumElseFailsToCompile() { 125 | val result = compile( 126 | """ 127 | import app.cash.exhaustive.Exhaustive 128 | 129 | enum class RouletteColor { Red, Black, Green } 130 | 131 | fun subject(value: RouletteColor) { 132 | @Exhaustive 133 | when (value) { 134 | RouletteColor.Red -> println("red") 135 | RouletteColor.Black -> println("black") 136 | else -> println("green") 137 | } 138 | } 139 | """.trimIndent() 140 | ) 141 | 142 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 143 | assertThat(result.messages).contains("@Exhaustive when must not contain an 'else' branch") 144 | } 145 | 146 | @Test fun sealedClassExhaustiveCompiles() { 147 | val result = compile( 148 | """ 149 | import app.cash.exhaustive.Exhaustive 150 | 151 | sealed class RouletteColor { 152 | object Red : RouletteColor() 153 | object Black : RouletteColor() 154 | object Green : RouletteColor() 155 | } 156 | 157 | fun subject(value: RouletteColor) { 158 | @Exhaustive 159 | when (value) { 160 | RouletteColor.Red -> println("red") 161 | RouletteColor.Black -> println("black") 162 | RouletteColor.Green -> println("green") 163 | } 164 | } 165 | """.trimIndent() 166 | ) 167 | 168 | assertThat(result.exitCode).isEqualTo(OK) 169 | } 170 | 171 | @Test fun sealedClassNonExhaustiveFailsToCompile() { 172 | val result = compile( 173 | """ 174 | import app.cash.exhaustive.Exhaustive 175 | 176 | sealed class RouletteColor { 177 | object Red : RouletteColor() 178 | object Black : RouletteColor() 179 | object Green : RouletteColor() 180 | } 181 | 182 | fun subject(value: RouletteColor) { 183 | @Exhaustive 184 | when (value) { 185 | RouletteColor.Red -> println("red") 186 | RouletteColor.Black -> println("black") 187 | } 188 | } 189 | """.trimIndent() 190 | ) 191 | 192 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 193 | assertThat(result.messages).contains( 194 | """ 195 | |@Exhaustive when is not exhaustive! 196 | | 197 | |Missing branches: 198 | |- RouletteColor.Green 199 | """.trimMargin() 200 | ) 201 | } 202 | 203 | @Test fun sealedClassElseFailsToCompile() { 204 | val result = compile( 205 | """ 206 | import app.cash.exhaustive.Exhaustive 207 | 208 | sealed class RouletteColor { 209 | object Red : RouletteColor() 210 | object Black : RouletteColor() 211 | object Green : RouletteColor() 212 | } 213 | 214 | fun subject(value: RouletteColor) { 215 | @Exhaustive 216 | when (value) { 217 | RouletteColor.Red -> println("red") 218 | RouletteColor.Black -> println("black") 219 | else -> println("green") 220 | } 221 | } 222 | """.trimIndent() 223 | ) 224 | 225 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 226 | assertThat(result.messages).contains("@Exhaustive when must not contain an 'else' branch") 227 | } 228 | 229 | @Test fun noSubjectFailsToCompile() { 230 | val result = compile( 231 | """ 232 | import app.cash.exhaustive.Exhaustive 233 | 234 | fun subject() { 235 | @Exhaustive 236 | when { 237 | true -> println("sup") 238 | } 239 | } 240 | """.trimIndent() 241 | ) 242 | 243 | assertThat(result.exitCode).isEqualTo(COMPILATION_ERROR) 244 | assertThat(result.messages).contains("@Exhaustive when must have a subject expression") 245 | } 246 | 247 | private fun compile(@Language("kotlin") source: String): Result { 248 | return KotlinCompilation().apply { 249 | sources = listOf(SourceFile.kotlin("main.kt", source)) 250 | messageOutputStream = System.out 251 | compilerPlugins = listOf(ExhaustiveComponentRegistrar()) 252 | inheritClassPath = true 253 | }.compile() 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Exhaustive 2 | 3 | **WARNING:** This plugin is deprecated! 4 | 5 | Kotlin 1.7 [made](https://youtrack.jetbrains.com/issue/KT-47709) all `when` statements exhaustive by default and this plugin is no longer required. 6 | 7 | --- 8 | 9 | An annotation and Kotlin compiler plugin for enforcing a `when` statement is exhaustive. 10 | 11 | 12 | ```kotlin 13 | enum class RouletteColor { Red, Black, Green } 14 | 15 | fun printColor(color: RouletteColor) { 16 | @Exhaustive 17 | when (color) { 18 | Red -> println("red") 19 | Black -> println("black") 20 | } 21 | } 22 | ``` 23 | ``` 24 | e: Example.kt:5: @Exhaustive when is not exhaustive! 25 | 26 | Missing branches: 27 | - RouletteColor.Green 28 | ``` 29 | 30 | No more assigning to dummy local properties or referencing pointless functions or properties to 31 | force the `when` to be an expression for exhaustiveness checking. The plugin reuses the same check 32 | that is used for a `when` expression. 33 | 34 | In addition to being forced to be exhaustive, an annotated `when` statement is forbidden from using 35 | an `else` branch. 36 | 37 | ```kotlin 38 | fun printColor(color: RouletteColor) { 39 | @Exhaustive 40 | when (color) { 41 | Red -> println("red") 42 | Black -> println("black") 43 | else -> println("green") 44 | } 45 | } 46 | ``` 47 | ``` 48 | e: Example.kt:5: @Exhaustive when must not contain an 'else' branch 49 | ``` 50 | 51 | The presence of an `else` block indicates support for a default action. The exhaustive check would 52 | otherwise always pass with this branch which is why it is disallowed. 53 | 54 | Sealed classes are also supported. 55 | 56 | ```kotlin 57 | sealed class RouletteColor { 58 | object Red : RouletteColor() 59 | object Black : RouletteColor() 60 | object Green : RouletteColor() 61 | } 62 | 63 | fun printColor(color: RouletteColor) { 64 | @Exhaustive 65 | when (color) { 66 | RouletteColor.Red -> println("red") 67 | RouletteColor.Black -> println("black") 68 | } 69 | } 70 | ``` 71 | ``` 72 | e: Example.kt:9: @Exhaustive when is not exhaustive! 73 | 74 | Missing branches: 75 | - RouletteColor.Green 76 | ``` 77 | 78 | 79 | ## Usage 80 | 81 | ```groovy 82 | buildscript { 83 | dependencies { 84 | classpath 'app.cash.exhaustive:exhaustive-gradle:0.2.0' 85 | } 86 | repositories { 87 | mavenCentral() 88 | } 89 | } 90 | 91 | apply plugin: 'org.jetbrains.kotlin.jvm' // or .android or .multiplatform or .js 92 | apply plugin: 'app.cash.exhaustive' 93 | ``` 94 | 95 | The `@Exhaustive` annotation will be made available in your main and test source sets but will not 96 | be shipped as a dependency of the module. 97 | 98 | Since Kotlin compiler plugins are an unstable API, certain versions of Exhaustive only work with 99 | certain versions of Kotlin. 100 | 101 | | Kotlin | Exhaustive | 102 | |-----------------|------------| 103 | | 1.4.10 - 1.5.10 | 0.1.1 | 104 | | 1.5.20 - 1.5.31 | 0.2.0 | 105 | 106 | Versions of Kotlin older than 1.4.10 are not supported. 107 | Versions newer than those listed may be supported but are untested. 108 | 109 |
110 | Snapshots of the development version are available in Sonatype's snapshots repository. 111 |

112 | 113 | ```groovy 114 | buildscript { 115 | dependencies { 116 | classpath 'app.cash.exhaustive:exhaustive-gradle:0.3.0-SNAPSHOT' 117 | } 118 | repositories { 119 | maven { 120 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 121 | } 122 | } 123 | } 124 | 125 | // 'apply' same as above 126 | ``` 127 | 128 |

129 |
130 | 131 | 132 | ## Alternatives Considered 133 | 134 | In the weeks prior to building this project a set of alternatives were explored and rejected 135 | for various reasons. They are listed below. If you evaluate their merits differently, you are 136 | welcome to use them instead. The solution provided by this plugin is not perfect either. 137 | 138 | ### Unused local and warning suppression 139 | 140 | ```kotlin 141 | fun printColor(color: RouletteColor) { 142 | @Suppress("UNUSED_VARIABLE") 143 | val exhaustive = when (color) { 144 | RouletteColor.Red -> println("red") 145 | RouletteColor.Black -> println("black") 146 | } 147 | } 148 | ``` 149 | 150 | Pros: 151 | - Works everywhere without library or plugin 152 | - No overhead or impact on compiled code 153 | 154 | Neutral: 155 | - Somewhat self-describing as to the intent, assuming good local property names 156 | - Good locality as the exhaustiveness forcing is very close to the `when` keyword, although 157 | somewhat overshadowed by the warning suppression 158 | 159 | Cons: 160 | - Requires suppression of warning which need to be put into a shared template or 161 | requires alt+enter,enter-ing to create the final form 162 | - Requires the use of _unique_ local property names (`_` is not allowed here) 163 | 164 | ### Built-in trailing property or function call 165 | 166 | ```kotlin 167 | fun printColor(color: RouletteColor) { 168 | when (color) { 169 | RouletteColor.Red -> println("red") 170 | RouletteColor.Black -> println("black") 171 | }.javaClass // or .hashCode() or anything else... 172 | } 173 | ``` 174 | 175 | Pros: 176 | - Works everywhere without library or plugin 177 | 178 | Cons: 179 | - Not self-describing as to the effect on the `when` and the developer intent behind adding it 180 | - Poor locality as the property is far away from the `when` keyword it modifies 181 | - Impact on compiled code in the form of a property call, function call, and/or additional 182 | instructions at the call-site 183 | 184 | ### Library trailing property 185 | 186 | ```kotlin 187 | @Suppress("unused") // Receiver reference forces when into expression form. 188 | inline val Any?.exhaustive get() = Unit 189 | 190 | fun printColor(color: RouletteColor) { 191 | when (color) { 192 | RouletteColor.Red -> println("red") 193 | RouletteColor.Black -> println("black") 194 | }.exhaustive 195 | } 196 | ``` 197 | 198 | Pros: 199 | - Self-describing effect on the `when` 200 | - No impact on compiled code 201 | 202 | Cons: 203 | - Requires a library 204 | - Poor locality as the property is far away from the `when` keyword it modifies 205 | - Pollutes the extension namespace by showing up for everything, not just `when` 206 | 207 | ### Library leading expression 208 | 209 | ```kotlin 210 | @Suppress("NOTHING_TO_INLINE", "ClassName", "UNUSED_PARAMETER") // Faking a soft keyword. 211 | object exhaustive { 212 | inline operator fun minus(other: Any?) = Unit 213 | } 214 | 215 | fun printColor(color: RouletteColor) { 216 | exhaustive-when (color) { 217 | RouletteColor.Red -> println("red") 218 | RouletteColor.Black -> println("black") 219 | } 220 | } 221 | ``` 222 | 223 | Pro: 224 | - Great locality as the syntactical trick appears almost like a soft keyword modifying the `when` 225 | 226 | Neutral: 227 | - Slight impact on compiled code (which could be mitigated on Android with an embedded R8 rule) 228 | 229 | Cons: 230 | - Requires a library 231 | - Feels too clever 232 | - Code formatting will insert a space before and after the minus sign breaking the effect 233 | 234 | ### Use soft keyword in compiler 235 | 236 | ```kotlin 237 | fun printColor(color: RouletteColor) { 238 | sealed when (color) { 239 | RouletteColor.Red -> println("red") 240 | RouletteColor.Black -> println("black") 241 | } 242 | } 243 | ``` 244 | 245 | Pros: 246 | - Great locality as a soft keyword directly modifying the `when` 247 | - No impact on compiled code 248 | - Part of the actual language 249 | 250 | Cons: 251 | - Requires forking the compiler and IDE plugin which is an overwhelming long-term commitment!!! 252 | 253 | 254 | # License 255 | 256 | Copyright 2020 Square, Inc. 257 | 258 | Licensed under the Apache License, Version 2.0 (the "License"); 259 | you may not use this file except in compliance with the License. 260 | You may obtain a copy of the License at 261 | 262 | http://www.apache.org/licenses/LICENSE-2.0 263 | 264 | Unless required by applicable law or agreed to in writing, software 265 | distributed under the License is distributed on an "AS IS" BASIS, 266 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 267 | See the License for the specific language governing permissions and 268 | limitations under the License. 269 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------