-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to semconv 1.22.0 * Restore and deprecated removed attributes * Add note about checing compatibility * Apply suggestions from code review Co-authored-by: Trask Stalnaker <[email protected]> * Fix grammar --------- Co-authored-by: Trask Stalnaker <[email protected]>
- Loading branch information
Showing
7 changed files
with
2,123 additions
and
1,203 deletions.
There are no files selected for viewing
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
126 changes: 126 additions & 0 deletions
126
buildSrc/src/main/kotlin/otel.japicmp-conventions.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,126 @@ | ||
import japicmp.model.JApiChangeStatus | ||
import japicmp.model.JApiClass | ||
import japicmp.model.JApiCompatibility | ||
import japicmp.model.JApiCompatibilityChange | ||
import japicmp.model.JApiMethod | ||
import me.champeau.gradle.japicmp.JapicmpTask | ||
import me.champeau.gradle.japicmp.report.Violation | ||
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers | ||
import me.champeau.gradle.japicmp.report.stdrules.BinaryIncompatibleRule | ||
import me.champeau.gradle.japicmp.report.stdrules.RecordSeenMembersSetup | ||
import me.champeau.gradle.japicmp.report.stdrules.SourceCompatibleRule | ||
import me.champeau.gradle.japicmp.report.stdrules.UnchangedMemberRule | ||
|
||
|
||
plugins { | ||
base | ||
|
||
id("me.champeau.gradle.japicmp") | ||
} | ||
|
||
/** | ||
* 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 = configurations.create("tempConfig") | ||
dependencies.add(temp.name, "io.opentelemetry.semconv:opentelemetry-semconv:latest.release") | ||
val moduleVersion = configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion | ||
configurations.remove(temp) | ||
logger.debug("Discovered latest release version: " + moduleVersion) | ||
moduleVersion | ||
} | ||
|
||
class SourceIncompatibleRule : AbstractRecordingSeenMembers() { | ||
override fun maybeAddViolation(member: JApiCompatibility): Violation? { | ||
if (!member.isSourceCompatible()) { | ||
return Violation.error(member, "Not source compatible") | ||
} | ||
return null | ||
} | ||
} | ||
|
||
/** | ||
* Locate the project's artifact of a particular version. | ||
*/ | ||
fun findArtifact(version: String): File { | ||
val existingGroup = 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. | ||
group = "virtual_group" | ||
val depModule = "io.opentelemetry.semconv:${base.archivesName.get()}:$version@jar" | ||
val depJar = "${base.archivesName.get()}-$version.jar" | ||
val configuration: Configuration = configurations.detachedConfiguration( | ||
dependencies.create(depModule), | ||
) | ||
return files(configuration.files).filter { | ||
it.name.equals(depJar) | ||
}.singleFile | ||
} finally { | ||
group = existingGroup | ||
} | ||
} | ||
|
||
// generate the api diff report for any module that is stable and publishes a jar. | ||
if (!project.hasProperty("otel.release")) { | ||
afterEvaluate { | ||
tasks { | ||
val jApiCmp by registering(JapicmpTask::class) { | ||
dependsOn("jar") | ||
|
||
// the japicmp "new" version is either the user-specified one, or the locally built jar. | ||
val apiNewVersion: String? by project | ||
val newArtifact = apiNewVersion?.let { findArtifact(it) } | ||
?: file(getByName<Jar>("jar").archiveFile) | ||
newClasspath.from(files(newArtifact)) | ||
|
||
// only output changes, not everything | ||
onlyModified.set(true) | ||
|
||
// the japicmp "old" version is either the user-specified one, or the latest release. | ||
val apiBaseVersion: String? by project | ||
val baselineVersion = apiBaseVersion ?: latestReleasedVersion | ||
oldClasspath.from( | ||
try { | ||
files(findArtifact(baselineVersion)) | ||
} catch (e: Exception) { | ||
// if we can't find the baseline artifact, this is probably one that's never been published before, | ||
// so publish the whole API. We do that by flipping this flag, and comparing the current against nothing. | ||
onlyModified.set(false) | ||
files() | ||
}, | ||
) | ||
|
||
// Reproduce defaults from https://github.com/melix/japicmp-gradle-plugin/blob/09f52739ef1fccda6b4310cf3f4b19dc97377024/src/main/java/me/champeau/gradle/japicmp/report/ViolationsGenerator.java#L130 | ||
// with some changes. | ||
val exclusions = mutableListOf<String>() | ||
// Allow new default methods on interfaces | ||
exclusions.add("METHOD_NEW_DEFAULT") | ||
// Allow adding default implementations for default methods | ||
exclusions.add("METHOD_ABSTRACT_NOW_DEFAULT") | ||
// Bug prevents recognizing default methods of superinterface. | ||
// Fixed in https://github.com/siom79/japicmp/pull/343 but not yet available in me.champeau.gradle.japicmp | ||
exclusions.add("METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE") | ||
compatibilityChangeExcludes.set(exclusions) | ||
richReport { | ||
addSetupRule(RecordSeenMembersSetup::class.java) | ||
addRule(JApiChangeStatus.NEW, SourceCompatibleRule::class.java) | ||
addRule(JApiChangeStatus.MODIFIED, SourceCompatibleRule::class.java) | ||
addRule(JApiChangeStatus.UNCHANGED, UnchangedMemberRule::class.java) | ||
addRule(BinaryIncompatibleRule::class.java) | ||
// Disallow source incompatible changes, which are allowed by default for some reason | ||
addRule(SourceIncompatibleRule::class.java) | ||
} | ||
|
||
// this is needed so that we only consider the current artifact, and not dependencies | ||
ignoreMissingClasses.set(true) | ||
packageExcludes.addAll("*.internal", "*.internal.*") | ||
} | ||
// have the check task depend on the api comparison task, to make it more likely it will get used. | ||
named("check") { | ||
dependsOn(jApiCmp) | ||
} | ||
} | ||
} | ||
} |
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.