Skip to content

Commit

Permalink
Make gradle cache work when used from different locations (open-telem…
Browse files Browse the repository at this point in the history
  • Loading branch information
iNikem authored and RashmiRam committed May 23, 2022
1 parent f99fe8a commit 04f444d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 26 deletions.
14 changes: 11 additions & 3 deletions conventions/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,9 @@ tasks.withType<Test>().configureEach {
jvmArgs("-Dotel.java.disabled.resource.providers=${resourceClassesCsv}")

val trustStore = project(":testing-common").file("src/misc/testing-keystore.p12")
inputs.file(trustStore)
// Work around payara not working when this is set for some reason.
if (project.name != "jaxrs-2.0-payara-testing") {
jvmArgs("-Djavax.net.ssl.trustStore=${trustStore.absolutePath}")
jvmArgs("-Djavax.net.ssl.trustStorePassword=testing")
jvmArgumentProviders.add(KeystoreArgumentsProvider(trustStore))
}

// All tests must complete within 15 minutes.
Expand All @@ -238,6 +236,16 @@ tasks.withType<Test>().configureEach {
}
}

class KeystoreArgumentsProvider(
@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
val trustStore: File
) : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> = listOf(
"-Djavax.net.ssl.trustStore=${trustStore.absolutePath}",
"-Djavax.net.ssl.trustStorePassword=testing")
}

afterEvaluate {
val testJavaVersion = gradle.startParameter.projectProperties["testJavaVersion"]?.let(JavaVersion::toVersion)
val useJ9 = gradle.startParameter.projectProperties["testJavaVM"]?.run { this == "openj9" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tasks {

fun createLanguageTask(
compileTaskProvider: TaskProvider<*>, name: String): TaskProvider<*> {
return tasks.register<ByteBuddySimpleTask>(name) {
return tasks.register<ByteBuddyTask>(name) {
setGroup("Byte Buddy")
outputs.cacheIf { true }
var transformationClassPath = inputClasspath
Expand All @@ -91,3 +91,12 @@ fun createTransformation(classPath: FileCollection, pluginClassName: String): Tr
plugin = ClasspathByteBuddyPlugin::class.java
}
}

//TODO remove when https://github.com/raphw/byte-buddy/issues/1169 is fixed
open class ByteBuddyTask : ByteBuddySimpleTask() {
@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
override fun getSource(): File? {
return super.getSource()
}
}
28 changes: 14 additions & 14 deletions instrumentation/gwt-2.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,38 @@ dependencies {
testImplementation("org.eclipse.jetty:jetty-webapp:9.4.35.v20201120")
}

val warDir = "$buildDir/testapp/war"
val warDir = file("$buildDir/testapp/war")

val launcher = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(8))
}

class CompilerArgumentsProvider : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> = listOf(
"test.gwt.Greeting", // gwt module
"-war", "$buildDir/testapp/war",
"-logLevel", "INFO",
"-localWorkers", "2",
"-compileReport",
"-extra", "$buildDir/testapp/extra",
"-draftCompile" // makes compile a bit faster
)
}

tasks {
val compileGwt by registering(JavaExec::class) {
dependsOn(classes)
// versions before 2.9 require java8
javaLauncher.set(launcher)

val extraDir = "$buildDir/testapp/extra"

outputs.cacheIf { true }

outputs.dir(extraDir)
outputs.dir(warDir)

mainClass.set("com.google.gwt.dev.Compiler")

classpath(sourceSets["testapp"].java.srcDirs, sourceSets["testapp"].compileClasspath)

args(
"test.gwt.Greeting", // gwt module
"-war", warDir,
"-logLevel", "INFO",
"-localWorkers", "2",
"-compileReport",
"-extra", extraDir,
"-draftCompile" // makes compile a bit faster
)
argumentProviders.add(CompilerArgumentsProvider())
}

val copyTestWebapp by registering(Copy::class) {
Expand Down
16 changes: 11 additions & 5 deletions javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,10 @@ tasks {

withType<Test>().configureEach {
dependsOn(shadowJar)
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().archiveFile.get().asFile}")
}
jvmArgumentProviders.add(JavaagentProvider(shadowJar.flatMap { it.archiveFile }))

testLogging {
events("started")
Expand Down Expand Up @@ -299,3 +295,13 @@ fun ShadowJar.excludeBootstrapJars() {
exclude(project(":javaagent-instrumentation-api"))
}
}

class JavaagentProvider(
@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
val agentJar: Provider<RegularFile>
) : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> = listOf(
"-javaagent:${file(agentJar).absolutePath}"
)
}
15 changes: 12 additions & 3 deletions testing/agent-for-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,20 @@ tasks {

afterEvaluate {
withType<Test>().configureEach {
dependsOn(jar)

jvmArgs("-Dotel.javaagent.debug=true")
jvmArgs("-javaagent:${jar.get().archiveFile.get().asFile.absolutePath}")
jvmArgs("-Dotel.metrics.exporter=otlp")

jvmArgumentProviders.add(JavaagentProvider(jar.flatMap { it.archiveFile }))
}
}
}

class JavaagentProvider(
@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
val agentJar: Provider<RegularFile>
) : CommandLineArgumentProvider {
override fun asArguments(): Iterable<String> = listOf(
"-javaagent:${file(agentJar).absolutePath}"
)
}

0 comments on commit 04f444d

Please sign in to comment.