forked from Kotlin/binary-compatibility-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for explicit public API markers (Kotlin#116)
* Add support for defining public declarations explicitly If the added properties are used, all unmatched declarations will be excluded from the API check. If properties for both ignored and explicit markers are set, filtering of ignored declarations will happen after filtering of declarations not explicitly marked as public. * Support validation of non-main source sets for kotlin-jvm projects
- Loading branch information
1 parent
c595e65
commit 5d08f51
Showing
13 changed files
with
357 additions
and
38 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/functionalTest/kotlin/kotlinx/validation/test/MixedMarkersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.test | ||
|
||
import kotlinx.validation.api.* | ||
import kotlinx.validation.api.buildGradleKts | ||
import kotlinx.validation.api.kotlin | ||
import kotlinx.validation.api.resolve | ||
import kotlinx.validation.api.test | ||
import org.junit.Test | ||
|
||
class MixedMarkersTest : BaseKotlinGradleTest() { | ||
|
||
@Test | ||
fun testMixedMarkers() { | ||
val runner = test { | ||
buildGradleKts { | ||
resolve("examples/gradle/base/withPlugin.gradle.kts") | ||
resolve("examples/gradle/configuration/publicMarkers/mixedMarkers.gradle.kts") | ||
} | ||
|
||
kotlin("MixedAnnotations.kt") { | ||
resolve("examples/classes/MixedAnnotations.kt") | ||
} | ||
|
||
apiFile(projectName = rootProjectDir.name) { | ||
resolve("examples/classes/MixedAnnotations.dump") | ||
} | ||
|
||
runner { | ||
arguments.add(":apiCheck") | ||
} | ||
} | ||
|
||
runner.withDebug(true).build().apply { | ||
assertTaskSuccess(":apiCheck") | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/functionalTest/kotlin/kotlinx/validation/test/PublicMarkersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package kotlinx.validation.test | ||
|
||
import kotlinx.validation.api.* | ||
import kotlinx.validation.api.buildGradleKts | ||
import kotlinx.validation.api.kotlin | ||
import kotlinx.validation.api.resolve | ||
import kotlinx.validation.api.test | ||
import org.junit.Test | ||
|
||
class PublicMarkersTest : BaseKotlinGradleTest() { | ||
|
||
@Test | ||
fun testPublicMarkers() { | ||
val runner = test { | ||
buildGradleKts { | ||
resolve("examples/gradle/base/withPlugin.gradle.kts") | ||
resolve("examples/gradle/configuration/publicMarkers/markers.gradle.kts") | ||
} | ||
|
||
kotlin("ClassWithPublicMarkers.kt") { | ||
resolve("examples/classes/ClassWithPublicMarkers.kt") | ||
} | ||
|
||
kotlin("ClassInPublicPackage.kt") { | ||
resolve("examples/classes/ClassInPublicPackage.kt") | ||
} | ||
|
||
apiFile(projectName = rootProjectDir.name) { | ||
resolve("examples/classes/ClassWithPublicMarkers.dump") | ||
} | ||
|
||
runner { | ||
arguments.add(":apiCheck") | ||
} | ||
} | ||
|
||
runner.withDebug(true).build().apply { | ||
assertTaskSuccess(":apiCheck") | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/functionalTest/resources/examples/classes/ClassInPublicPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package foo.api | ||
|
||
class ClassInPublicPackage { | ||
class Inner | ||
} |
23 changes: 23 additions & 0 deletions
23
src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public final class foo/ClassWithPublicMarkers { | ||
public final fun getBar1 ()I | ||
public final fun getBar2 ()I | ||
public final fun setBar1 (I)V | ||
public final fun setBar2 (I)V | ||
} | ||
|
||
public final class foo/ClassWithPublicMarkers$MarkedClass { | ||
public fun <init> ()V | ||
public final fun getBar1 ()I | ||
} | ||
|
||
public abstract interface annotation class foo/PublicClass : java/lang/annotation/Annotation { | ||
} | ||
|
||
public final class foo/api/ClassInPublicPackage { | ||
public fun <init> ()V | ||
} | ||
|
||
public final class foo/api/ClassInPublicPackage$Inner { | ||
public fun <init> ()V | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
src/functionalTest/resources/examples/classes/ClassWithPublicMarkers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package foo | ||
|
||
@Target(AnnotationTarget.CLASS) | ||
annotation class PublicClass | ||
|
||
@Target(AnnotationTarget.FIELD) | ||
annotation class PublicField | ||
|
||
@Target(AnnotationTarget.PROPERTY) | ||
annotation class PublicProperty | ||
|
||
public class ClassWithPublicMarkers { | ||
@PublicField | ||
var bar1 = 42 | ||
|
||
@PublicProperty | ||
var bar2 = 42 | ||
|
||
@PublicClass | ||
class MarkedClass { | ||
val bar1 = 41 | ||
} | ||
|
||
var notMarkedPublic = 42 | ||
|
||
class NotMarkedClass | ||
} |
5 changes: 5 additions & 0 deletions
5
src/functionalTest/resources/examples/classes/MixedAnnotations.dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public final class mixed/MarkedPublicWithPrivateMembers { | ||
public fun <init> ()V | ||
public final fun otherFun ()V | ||
} | ||
|
49 changes: 49 additions & 0 deletions
49
src/functionalTest/resources/examples/classes/MixedAnnotations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
package mixed | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.FUNCTION) | ||
annotation class PublicApi | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.FUNCTION) | ||
annotation class PrivateApi | ||
|
||
@PublicApi | ||
class MarkedPublicWithPrivateMembers { | ||
@PrivateApi | ||
var private1 = 42 | ||
|
||
@field:PrivateApi | ||
var private2 = 15 | ||
|
||
@PrivateApi | ||
fun privateFun() = Unit | ||
|
||
@PublicApi | ||
@PrivateApi | ||
fun privateFun2() = Unit | ||
|
||
fun otherFun() = Unit | ||
} | ||
|
||
// Member annotations should be ignored in explicitly private classes | ||
@PrivateApi | ||
class MarkedPrivateWithPublicMembers { | ||
@PublicApi | ||
var public1 = 42 | ||
|
||
@field:PublicApi | ||
var public2 = 15 | ||
|
||
@PublicApi | ||
fun publicFun() = Unit | ||
|
||
fun otherFun() = Unit | ||
} | ||
|
||
@PrivateApi | ||
@PublicApi | ||
class PublicAndPrivateFilteredOut |
13 changes: 13 additions & 0 deletions
13
src/functionalTest/resources/examples/gradle/configuration/publicMarkers/markers.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
configure<kotlinx.validation.ApiValidationExtension> { | ||
publicMarkers.add("foo.PublicClass") | ||
publicMarkers.add("foo.PublicField") | ||
publicMarkers.add("foo.PublicProperty") | ||
|
||
publicPackages.add("foo.api") | ||
publicClasses.add("foo.PublicClass") | ||
} |
9 changes: 9 additions & 0 deletions
9
...ctionalTest/resources/examples/gradle/configuration/publicMarkers/mixedMarkers.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2016-2022 JetBrains s.r.o. | ||
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
configure<kotlinx.validation.ApiValidationExtension> { | ||
nonPublicMarkers.add("mixed.PrivateApi") | ||
publicMarkers.add("mixed.PublicApi") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.