|
| 1 | +import java.io.File |
| 2 | + |
| 3 | +plugins { |
| 4 | + id("com.netflix.nebula.integtest") version "10.0.1" |
| 5 | +} |
| 6 | + |
| 7 | +val integTestArtifacts by configurations.creating |
| 8 | +val integTestRuntime by configurations.creating { |
| 9 | + extendsFrom(configurations["integTestImplementation"]) |
| 10 | + isCanBeConsumed = true |
| 11 | + isCanBeResolved = true |
| 12 | +} |
| 13 | + |
| 14 | +dependencies { |
| 15 | + api(project(":rollbar-api")) |
| 16 | + api("org.slf4j:slf4j-api:1.7.25") |
| 17 | + |
| 18 | + compileOnly("com.google.code.findbugs:jsr305:3.0.2") |
| 19 | + |
| 20 | + testImplementation("com.google.code.gson:gson:2.8.6") |
| 21 | + |
| 22 | + "integTestImplementation"("com.github.tomakehurst:wiremock:2.27.0") |
| 23 | + "integTestImplementation"("com.google.code.gson:gson:2.8.2") |
| 24 | +} |
| 25 | + |
| 26 | +val versionName = project.version.toString().ifEmpty { "unspecified" } |
| 27 | + |
| 28 | +/** |
| 29 | + * This task will create a version property that is statically referenced when populating the |
| 30 | + * `notifier` section of the payload. It helps when users shade and / or relocate the |
| 31 | + * `rollbar-java` classes, since in those cases we no longer have access to our jar manifest. |
| 32 | + * The task creates a Java class instead of a text resource, since dynamically loaded resources |
| 33 | + * are not as reliable under relocation as a strongly typed bytecode reference to a compiled class. |
| 34 | + */ |
| 35 | +val createVersionClass by tasks.registering { |
| 36 | + val outputDir = layout.buildDirectory.dir("src/generated/main") |
| 37 | + outputs.dir(outputDir) |
| 38 | + |
| 39 | + doLast { |
| 40 | + val pkg = listOf("com", "rollbar", "notifier", "provider", "notifier") |
| 41 | + val pkgName = pkg.joinToString(".") |
| 42 | + val pkgPath = outputDir.get().asFile.resolve(pkg.joinToString(File.separator)) |
| 43 | + val escapedVersion = versionName.replace("\\", "\\\\").replace("\"", "\\\"") |
| 44 | + |
| 45 | + val classText = """ |
| 46 | + package $pkgName; |
| 47 | +
|
| 48 | + class VersionHelperResources { |
| 49 | + static String getVersion() { |
| 50 | + return "$escapedVersion"; |
| 51 | + } |
| 52 | + } |
| 53 | + """.trimIndent() |
| 54 | + |
| 55 | + pkgPath.mkdirs() |
| 56 | + pkgPath.resolve("VersionHelperResources.java").writeText(classText) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +sourceSets { |
| 61 | + named("main") { |
| 62 | + java.srcDir(createVersionClass.map { it.outputs.files.singleFile }) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +tasks.named("compileJava") { |
| 67 | + dependsOn(createVersionClass) |
| 68 | +} |
| 69 | + |
| 70 | +tasks.named("checkstyleMain") { |
| 71 | + dependsOn(createVersionClass) |
| 72 | +} |
| 73 | + |
| 74 | +//Ensure sourcesJar runs after version class is created |
| 75 | +tasks.withType<Jar>().configureEach { |
| 76 | + if (name == "sourcesJar") { |
| 77 | + dependsOn(createVersionClass) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +tasks.test { |
| 82 | + // This helps us test the VersionHelper class since there's no jar manifest available when |
| 83 | + // running tests. |
| 84 | + systemProperty("ROLLBAR_IMPLEMENTATION_VERSION", versionName) |
| 85 | +} |
| 86 | + |
| 87 | +// The 'java-test-fixtures' plugin is not getting along with 'nebula.integtest', so we'll use this instead |
| 88 | +val integTestJar by tasks.registering(Jar::class) { |
| 89 | + archiveClassifier.set("integtest") |
| 90 | + from(sourceSets["integTest"].output) |
| 91 | + dependsOn(tasks.named("integTestClasses")) |
| 92 | +} |
| 93 | + |
| 94 | +artifacts { |
| 95 | + add("integTestArtifacts", integTestJar) |
| 96 | +} |
0 commit comments