From 4ce9ff3a69c9969581ed4d72c6c9e675a9463ca9 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Wed, 30 Jun 2021 19:23:28 +0900 Subject: [PATCH] Migrate projects with isolateSpec to kotlin (#3447) * Migrate projects with isolateSpec to kotlin * Migrate --- javaagent/build.gradle | 159 --------------------- javaagent/build.gradle.kts | 157 ++++++++++++++++++++ settings.gradle | 1 + testing/agent-for-testing/build.gradle | 87 ----------- testing/agent-for-testing/build.gradle.kts | 83 +++++++++++ 5 files changed, 241 insertions(+), 246 deletions(-) delete mode 100644 javaagent/build.gradle create mode 100644 javaagent/build.gradle.kts delete mode 100644 testing/agent-for-testing/build.gradle create mode 100644 testing/agent-for-testing/build.gradle.kts diff --git a/javaagent/build.gradle b/javaagent/build.gradle deleted file mode 100644 index 4719c1c205..0000000000 --- a/javaagent/build.gradle +++ /dev/null @@ -1,159 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import com.github.jk1.license.filter.LicenseBundleNormalizer -import com.github.jk1.license.render.InventoryMarkdownReportRenderer - -plugins { - id "otel.shadow-conventions" - id "com.github.jk1.dependency-license-report" version "1.16" - - id("otel.java-conventions") - id("otel.publish-conventions") -} - -description = 'OpenTelemetry Javaagent' - -group = 'io.opentelemetry.javaagent' - -configurations { - shadowInclude { - canBeResolved = true - canBeConsumed = false - } -} - -processResources { - from(rootProject.file("licenses")) { - into("META-INF/licenses") - } -} - -jar { - manifest { - attributes( - "Main-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Agent-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Premain-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Can-Redefine-Classes": true, - "Can-Retransform-Classes": true, - ) - } -} - -CopySpec isolateSpec(Collection projectsWithShadowJar) { - return copySpec { - from({ projectsWithShadowJar.tasks.shadowJar.collect { zipTree(it.archiveFile) } }) { - // important to keep prefix 'inst' short, as it is prefixed to lots of strings in runtime mem - into 'inst' - rename '(^.*)\\.class$', '$1.classdata' - // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac) - rename '^LICENSE$', 'LICENSE.renamed' - } - } -} - -//Includes everything needed for OOTB experience -shadowJar { - archiveClassifier.set("all") - def projectsWithShadowJar = [project(':instrumentation'), project(":javaagent-exporters")] - projectsWithShadowJar.each { - dependsOn("${it.path}:shadowJar") - } - with isolateSpec(projectsWithShadowJar) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE -} - -//Includes instrumentations, but not exporters -task lightShadow(type: ShadowJar) { - archiveClassifier.set("") - dependsOn ':instrumentation:shadowJar' - def projectsWithShadowJar = [project(':instrumentation')] - with isolateSpec(projectsWithShadowJar) -} - -// lightShadow is the default classifier we publish so disable the default jar. -jar.enabled = false - -publishing { - publications { - maven(MavenPublication) { - artifact lightShadow - } - } -} - -tasks.withType(ShadowJar).configureEach { - configurations = [project.configurations.shadowInclude] - - manifest { - inheritFrom project.tasks.jar.manifest - } -} - -configurations { - licenseReportDependencies -} - -dependencies { - testCompileOnly project(':javaagent-bootstrap') - testCompileOnly project(':javaagent-api') - - testImplementation "com.google.guava:guava" - - testImplementation 'io.opentracing.contrib.dropwizard:dropwizard-opentracing:0.2.2' - - shadowInclude project(path: ':javaagent-bootstrap') - - // We only have compileOnly dependencies on these to make sure they don't leak into POMs. - licenseReportDependencies("com.github.ben-manes.caffeine:caffeine") { - transitive = false - } - licenseReportDependencies "com.blogspot.mydailyjava:weak-lock-free" - // TODO ideally this would be :instrumentation instead of :javaagent-tooling - // in case there are dependencies (accidentally) pulled in by instrumentation modules - // but I couldn't get that to work - licenseReportDependencies project(':javaagent-tooling') - licenseReportDependencies project(':javaagent-extension-api') - licenseReportDependencies project(':javaagent-bootstrap') -} - -tasks.withType(Test).configureEach { - inputs.file(shadowJar.archiveFile) - - jvmArgs "-Dotel.javaagent.debug=true" - - doFirst { - // Defining here to allow jacoco to be first on the command line. - jvmArgs "-javaagent:${shadowJar.archivePath}" - } - - testLogging { - events "started" - } - - dependsOn shadowJar -} -assemble.dependsOn lightShadow -assemble.dependsOn shadowJar - -licenseReport { - outputDir = rootProject.file("licenses") - - renderers = [new InventoryMarkdownReportRenderer()] - - configurations = ["licenseReportDependencies"] - - excludeGroups = [ - "io.opentelemetry.instrumentation", - "io.opentelemetry.javaagent" - ] - - filters = [new LicenseBundleNormalizer(bundlePath: "$projectDir/license-normalizer-bundle.json")] -} - -def cleanLicenses = tasks.register("cleanLicenses", Delete) { - delete(rootProject.file("licenses")) -} - -tasks.named("generateLicenseReport").configure { - dependsOn(cleanLicenses) -} diff --git a/javaagent/build.gradle.kts b/javaagent/build.gradle.kts new file mode 100644 index 0000000000..471fac2c0e --- /dev/null +++ b/javaagent/build.gradle.kts @@ -0,0 +1,157 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import com.github.jk1.license.filter.LicenseBundleNormalizer +import com.github.jk1.license.render.InventoryMarkdownReportRenderer + +plugins { + id("com.github.jk1.dependency-license-report") + + id("otel.java-conventions") + id("otel.publish-conventions") + id("otel.shadow-conventions") +} + +description = "OpenTelemetry Javaagent" + +group = "io.opentelemetry.javaagent" + +val shadowInclude by configurations.creating { + isCanBeResolved = true + isCanBeConsumed = false +} + +fun isolateSpec(projectsWithShadowJar: Collection): CopySpec = copySpec { + from(projectsWithShadowJar.map { zipTree(it.tasks.getByName("shadowJar").archiveFile) }) { + // important to keep prefix "inst" short, as it is prefixed to lots of strings in runtime mem + into("inst") + rename("""(^.*)\.class$""", "$1.classdata") + // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac) + rename("""^LICENSE$""", "LICENSE.renamed") + } +} + +tasks { + processResources.configure { + from(rootProject.file("licenses")) { + into("META-INF/licenses") + } + } + + //Includes everything needed for OOTB experience + val shadowJar by existing(ShadowJar::class) { + archiveClassifier.set("all") + val projectsWithShadowJar = listOf(project(":instrumentation"), project(":javaagent-exporters")) + projectsWithShadowJar.forEach { + dependsOn("${it.path}:shadowJar") + } + with(isolateSpec(projectsWithShadowJar)) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + //Includes instrumentations, but not exporters + val lightShadow by registering(ShadowJar::class) { + archiveClassifier.set("") + dependsOn(":instrumentation:shadowJar") + val projectsWithShadowJar = listOf(project(":instrumentation")) + with(isolateSpec(projectsWithShadowJar)) + } + + // lightShadow is the default classifier we publish so disable the default jar. + jar.configure { + enabled = false + + manifest { + attributes( + "Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Can-Redefine-Classes" to true, + "Can-Retransform-Classes" to true + ) + } + } + + withType().configureEach { + configurations = listOf(shadowInclude) + + manifest.inheritFrom(jar.get().manifest) + } + + withType().configureEach { + inputs.file(shadowJar.get().archiveFile) + + jvmArgs("-Dotel.javaagent.debug=true") + + doFirst { + // Defining here to allow jacoco to be first on the command line. + jvmArgs("-javaagent:${shadowJar.get().archivePath}") + } + + testLogging { + events("started") + } + + dependsOn(shadowJar) + } + + named("assemble") { + dependsOn(lightShadow) + dependsOn(shadowJar) + } + + val cleanLicenses by registering(Delete::class) { + delete(rootProject.file("licenses")) + } + + named("generateLicenseReport").configure { + dependsOn(cleanLicenses) + } + + publishing { + publications { + named("maven") { + artifact(lightShadow) + } + } + } +} + +val licenseReportDependencies by configurations.creating + +dependencies { + testCompileOnly(project(":javaagent-bootstrap")) + testCompileOnly(project(":javaagent-api")) + + testImplementation("com.google.guava:guava") + + testImplementation("io.opentracing.contrib.dropwizard:dropwizard-opentracing:0.2.2") + + shadowInclude(project(":javaagent-bootstrap")) + + // We only have compileOnly dependencies on these to make sure they don"t leak into POMs. + licenseReportDependencies("com.github.ben-manes.caffeine:caffeine") { + isTransitive = false + } + licenseReportDependencies("com.blogspot.mydailyjava:weak-lock-free") + // TODO ideally this would be :instrumentation instead of :javaagent-tooling + // in case there are dependencies (accidentally) pulled in by instrumentation modules + // but I couldn"t get that to work + licenseReportDependencies(project(":javaagent-tooling")) + licenseReportDependencies(project(":javaagent-extension-api")) + licenseReportDependencies(project(":javaagent-bootstrap")) +} + + +licenseReport { + outputDir = rootProject.file("licenses").absolutePath + + renderers = arrayOf(InventoryMarkdownReportRenderer()) + + configurations = arrayOf("licenseReportDependencies") + + excludeGroups = arrayOf( + "io.opentelemetry.instrumentation", + "io.opentelemetry.javaagent" + ) + + filters = arrayOf(LicenseBundleNormalizer("$projectDir/license-normalizer-bundle.json", true)) +} diff --git a/settings.gradle b/settings.gradle index f22e644543..d7d32c729d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,7 @@ pluginManagement { plugins { id 'com.github.ben-manes.versions' version '0.39.0' + id "com.github.jk1.dependency-license-report" version "1.16" id "io.github.gradle-nexus.publish-plugin" version "1.1.0" id "me.champeau.jmh" version "0.6.5" id "net.ltgt.nullaway" version "1.1.0" diff --git a/testing/agent-for-testing/build.gradle b/testing/agent-for-testing/build.gradle deleted file mode 100644 index b423239b0e..0000000000 --- a/testing/agent-for-testing/build.gradle +++ /dev/null @@ -1,87 +0,0 @@ -plugins { - id("otel.shadow-conventions") - - id("otel.java-conventions") - id("otel.publish-conventions") -} - -description = 'OpenTelemetry Javaagent for testing' -group = 'io.opentelemetry.javaagent' - -jar { - manifest { - attributes( - "Main-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Agent-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Premain-Class": "io.opentelemetry.javaagent.OpenTelemetryAgent", - "Can-Redefine-Classes": true, - "Can-Retransform-Classes": true, - ) - } -} - -CopySpec isolateSpec(Collection shadowJarTasks) { - return copySpec { - from({ shadowJarTasks.collect { zipTree(it.archiveFile) } }) { - // important to keep prefix 'inst' short, as it is prefixed to lots of strings in runtime mem - into 'inst' - rename '(^.*)\\.class$', '$1.classdata' - // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac) - rename '^LICENSE$', 'LICENSE.renamed' - } - } -} - -configurations { - shadowInclude { - canBeResolved = true - canBeConsumed = false - } -} - -evaluationDependsOn(":testing:agent-exporter") - -shadowJar { - configurations = [project.configurations.shadowInclude] - - archiveClassifier.set("") - - dependsOn ':testing:agent-exporter:shadowJar' - with isolateSpec([project(':testing:agent-exporter').tasks.shadowJar]) - - manifest { - inheritFrom project.tasks.jar.manifest - } -} - -jar { - enabled = false -} - -dependencies { - // Dependencies to include without obfuscation. - shadowInclude project(':javaagent-bootstrap') - - testImplementation project(':testing-common') - testImplementation "io.opentelemetry:opentelemetry-api" -} - -afterEvaluate { - tasks.withType(Test).configureEach { - inputs.file(shadowJar.archiveFile) - - jvmArgs "-Dotel.javaagent.debug=true" - jvmArgs "-javaagent:${shadowJar.archiveFile.get().asFile.absolutePath}" - - dependsOn shadowJar - } -} - -// Because shadow does not use default configurations -publishing { - publications { - maven { - project.shadow.component(it) - } - } -} diff --git a/testing/agent-for-testing/build.gradle.kts b/testing/agent-for-testing/build.gradle.kts new file mode 100644 index 0000000000..bb9b04e9ed --- /dev/null +++ b/testing/agent-for-testing/build.gradle.kts @@ -0,0 +1,83 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + id("otel.shadow-conventions") + + id("otel.java-conventions") + id("otel.publish-conventions") +} + +description = "OpenTelemetry Javaagent for testing" +group = "io.opentelemetry.javaagent" + +fun isolateSpec(shadowJarTasks: Collection): CopySpec = copySpec { + from(shadowJarTasks.map { zipTree(it.archiveFile) }) { + // important to keep prefix "inst" short, as it is prefixed to lots of strings in runtime mem + into("inst") + rename("""(^.*)\.class$""", "$1.classdata") + // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac) + rename("""^LICENSE$""", "LICENSE.renamed") + } +} + +val shadowInclude by configurations.creating { + isCanBeResolved = true + isCanBeConsumed = false +} + +evaluationDependsOn(":testing:agent-exporter") + +tasks { + jar.configure { + enabled = false + + manifest { + attributes( + "Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent", + "Can-Redefine-Classes" to true, + "Can-Retransform-Classes" to true + ) + } + } + + val shadowJar by existing(ShadowJar::class) { + configurations = listOf(shadowInclude) + + archiveClassifier.set("") + + dependsOn(":testing:agent-exporter:shadowJar") + with(isolateSpec(listOf(project(":testing:agent-exporter").tasks.getByName("shadowJar")))) + + manifest.inheritFrom(jar.get().manifest) + } + + afterEvaluate { + withType().configureEach { + inputs.file(shadowJar.get().archiveFile) + + jvmArgs("-Dotel.javaagent.debug=true") + jvmArgs("-javaagent:${shadowJar.get().archiveFile.get().asFile.absolutePath}") + + dependsOn(shadowJar) + } + } +} + +dependencies { + // Dependencies to include without obfuscation. + shadowInclude(project(":javaagent-bootstrap")) + + testImplementation(project(":testing-common")) + testImplementation("io.opentelemetry:opentelemetry-api") +} + +// Because shadow does not use default configurations +publishing { + publications { + named("maven") { + project.shadow.component(this) + } + } +}