Skip to content

Commit

Permalink
Add a task to compare public APIs for every stable module. (#3183)
Browse files Browse the repository at this point in the history
* Add a task to compare public APIs for every stable module.

* add a few comments and make the build task depend on the japicmp task

* update the api diffs after rebasing.

* task must depend on jar

* a few script tweaks based on feedback

* small tweak to make it a little more kotlin-idiomatic

* refactoring to make the code more clear

* some more refactoring.

* make the latest released version a lazy val of the build script

* have the task depend on check, rather than build

* put all the API diffs into a central directory

* run at --info to diagnose CI issues

* try an older java 11 version

* try another combo

* remove the info logging
  • Loading branch information
jkwatson authored May 7, 2021
1 parent a8a85c6 commit bd6cfd8
Show file tree
Hide file tree
Showing 45 changed files with 216 additions and 1 deletion.
85 changes: 84 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import com.google.protobuf.gradle.*
import de.marcphilipp.gradle.nexus.NexusPublishExtension
import io.morethan.jmhreport.gradle.JmhReportExtension
import me.champeau.gradle.JMHPluginExtension
import me.champeau.gradle.japicmp.JapicmpTask
import nebula.plugin.release.git.opinion.Strategies
import net.ltgt.gradle.errorprone.ErrorProneOptions
import net.ltgt.gradle.errorprone.ErrorPronePlugin
Expand All @@ -24,6 +25,43 @@ plugins {
id("me.champeau.gradle.jmh") apply false
id("net.ltgt.errorprone") apply false
id("ru.vyarus.animalsniffer") apply false
id("me.champeau.gradle.japicmp") apply false
}


/**
* Locate the project's artifact of a particular version.
*/
fun Project.findArtifact(version: String) : File {
val existingGroup = this.group
try {
// Temporarily change the group name because we want to fetch an artifact with the same
// Maven coordinates as the project, which Gradle would not allow otherwise.
this.group = "virtual_group"
val depModule = "io.opentelemetry:${base.archivesBaseName}:$version@jar"
val depJar = "${base.archivesBaseName}-${version}.jar"
val configuration: Configuration = configurations.detachedConfiguration(
dependencies.create(depModule)
)
return files(configuration.files).filter {
it.name.equals(depJar)
}.singleFile
} finally {
this.group = existingGroup
}
}

/**
* The latest *released* version of the project. Evaluated lazily so the work is only done if necessary.
*/
val latestReleasedVersion : String by lazy {
// hack to find the current released version of the project
val temp: Configuration = project.configurations.create("tempConfig")
// pick the bom, since it's always there.
dependencies.add("tempConfig", "io.opentelemetry:opentelemetry-bom:latest.release")
val moduleVersion = project.configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion
project.configurations.remove(temp)
moduleVersion
}

if (!JavaVersion.current().isJava11Compatible()) {
Expand Down Expand Up @@ -422,9 +460,54 @@ subprojects {
}
}

plugins.withId("me.champeau.gradle.japicmp") {
afterEvaluate {
tasks {
val jApiCmp by registering(JapicmpTask::class) {
dependsOn("jar")
// the japicmp "old" version is either the user-specified one, or the latest release.
val userRequestedBase = project.properties["apiBaseVersion"] as String?
val baselineVersion: String = userRequestedBase ?: latestReleasedVersion
val baselineArtifact: File = project.findArtifact(baselineVersion)
oldClasspath = files(baselineArtifact)

// the japicmp "new" version is either the user-specified one, or the locally built jar.
val newVersion : String? = project.properties["apiNewVersion"] as String?
val newArtifact: File = if (newVersion == null) {
val jar = getByName("jar") as Jar
file(jar.archiveFile)
} else {
project.findArtifact(newVersion)
}
newClasspath = files(newArtifact)

//only output changes, not everything
isOnlyModified = true
//this is needed so that we only consider the current artifact, and not dependencies
isIgnoreMissingClasses = true
// double wildcards don't seem to work here (*.internal.*)
packageExcludes = listOf("*.internal", "io.opentelemetry.internal.shaded.jctools.*")
if (newVersion == null) {
val baseVersionString = if (userRequestedBase == null) "latest" else baselineVersion
txtOutputFile = file("$rootDir/docs/apidiffs/current_vs_${baseVersionString}/${project.base.archivesBaseName}.txt")
} else {
txtOutputFile = file("$rootDir/docs/apidiffs/${newVersion}_vs_${baselineVersion}/${project.base.archivesBaseName}.txt")
}
}
// have the check task depend on the api comparison task, to make it more likely it will get used.
named("check") {
dependsOn(jApiCmp)
}
}
}
}

plugins.withId("maven-publish") {
// generate the api diff report for any module that is stable and publishes a jar.
if (!project.hasProperty("otel.release") && !project.name.startsWith("bom")) {
plugins.apply("me.champeau.gradle.japicmp")
}
plugins.apply("signing")

plugins.apply("de.marcphilipp.nexus-publish")

configure<PublishingExtension> {
Expand Down
4 changes: 4 additions & 0 deletions context/src/main/java/io/opentelemetry/context/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ static Context root() {
* during an invocation to another thread. For example, you may use something like {@code Executor
* dbExecutor = Context.wrapTasks(threadPool)} to ensure calls like {@code dbExecutor.execute(()
* -> database.query())} have {@link Context} available on the thread executing database queries.
*
* @since 1.1.0
*/
static Executor taskWrapping(Executor executor) {
return command -> executor.execute(Context.current().wrap(command));
Expand All @@ -124,6 +126,8 @@ static Executor taskWrapping(Executor executor) {
* ExecutorService dbExecutor = Context.wrapTasks(threadPool)} to ensure calls like {@code
* dbExecutor.execute(() -> database.query())} have {@link Context} available on the thread
* executing database queries.
*
* @since 1.1.0
*/
static ExecutorService taskWrapping(ExecutorService executorService) {
return new CurrentContextExecutorService(executorService);
Expand Down
2 changes: 2 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
5 changes: 5 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-context.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Comparing source compatibility of against
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.context.Context (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) STATIC(+) java.util.concurrent.Executor taskWrapping(java.util.concurrent.Executor)
+++! NEW METHOD: PUBLIC(+) STATIC(+) java.util.concurrent.ExecutorService taskWrapping(java.util.concurrent.ExecutorService)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-exporter-otlp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporter (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW FIELD: PUBLIC(+) STATIC(+) FINAL(+) java.util.logging.Logger baseLogger
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-extension-aws.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
22 changes: 22 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-sdk-common.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC ABSTRACT io.opentelemetry.sdk.resources.Resource (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.resources.ResourceBuilder builder()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder toBuilder()
+++ NEW CLASS: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW CONSTRUCTOR: PUBLIC(+) ResourceBuilder()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.Resource build()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, java.lang.String)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, long)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, double)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, boolean)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, java.lang.String[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, long[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, double[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(java.lang.String, boolean[])
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(io.opentelemetry.api.common.AttributeKey, java.lang.Object)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder put(io.opentelemetry.api.common.AttributeKey, int)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder putAll(io.opentelemetry.api.common.Attributes)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.ResourceBuilder putAll(io.opentelemetry.sdk.resources.Resource)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-sdk-testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
4 changes: 4 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-sdk-trace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.trace.export.SimpleSpanProcessor (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.common.CompletableResultCode forceFlush()
2 changes: 2 additions & 0 deletions docs/apidiffs/1.1.0_vs_1.0.0/opentelemetry-sdk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
7 changes: 7 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Comparing source compatibility of against
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.trace.Span (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) io.opentelemetry.api.trace.Span setAllAttributes(io.opentelemetry.api.common.Attributes)
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.trace.SpanBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) io.opentelemetry.api.trace.SpanBuilder setAllAttributes(io.opentelemetry.api.common.Attributes)
2 changes: 2 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-context.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Comparing source compatibility of against
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setReadTimeout(long, java.util.concurrent.TimeUnit)
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.exporter.zipkin.ZipkinSpanExporterBuilder setReadTimeout(java.time.Duration)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk-common.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Comparing source compatibility of against
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.extension.resources.HostResource (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.resources.Resource get()
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.extension.resources.HostResourceProvider (not serializable)
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
+++ NEW SUPERCLASS: java.lang.Object
+++ NEW CONSTRUCTOR: PUBLIC(+) HostResourceProvider()
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.resources.Resource createResource(io.opentelemetry.sdk.autoconfigure.ConfigProperties)
2 changes: 2 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk-testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
2 changes: 2 additions & 0 deletions docs/apidiffs/current_vs_latest/opentelemetry-sdk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Comparing source compatibility of against
No changes.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pluginManagement {
id("org.jetbrains.kotlin.jvm") version "1.4.21"
id("org.unbroken-dome.test-sets") version "3.0.1"
id("ru.vyarus.animalsniffer") version "1.5.3"
id("me.champeau.gradle.japicmp") version "0.2.9"
}
}

Expand Down

0 comments on commit bd6cfd8

Please sign in to comment.