diff --git a/build.gradle b/build.gradle deleted file mode 100644 index dc1b34d..0000000 --- a/build.gradle +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2014-2019 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id("com.netflix.nebula.plugin-plugin") version("25.+") -} - -compileGroovy.groovyOptions.configurationScript = file('src/groovyCompile/groovycConfig.groovy') - -description = 'Gradle plugin collect and provide information about the environment' - -contacts { - 'nebula-plugins-oss@netflix.com' { - moniker 'Nebula Plugins Maintainers' - github 'nebula-plugins' - } -} - -dependencies { - implementation gradleApi() - - // TODO, make these optional - implementation 'com.perforce:p4java:2015.2.1365273' - implementation 'com.netflix.nebula:nebula-gradle-interop:latest.release' - implementation 'com.netflix.nebula:gradle-contacts-plugin:latest.release' - implementation 'net.java.dev.jna:jna-platform:5.16.0' - testImplementation 'com.github.stefanbirkner:system-rules:1.19.0' - testImplementation ('org.ajoberstar.grgit:grgit-core:4.1.1') { - exclude group: 'org.codehaus.groovy', module: 'groovy' - } - testImplementation("org.spockframework:spock-junit4:2.4-groovy-4.0") - testImplementation("org.eclipse.jgit:org.eclipse.jgit:7.+") - testImplementation(libs.assertj) -} - -testing { - suites { - test { - useJUnitJupiter() - } - } -} - -test.exclude '**/*Local*' - -gradlePlugin { - plugins { - info { - id = 'com.netflix.nebula.info' - displayName = 'Gradle Info plugin' - description = project.description - implementationClass= 'nebula.plugin.info.InfoPlugin' - tags.set(['nebula', 'info']) - } - infoBasic { - id = 'com.netflix.nebula.info-basic' - displayName = 'Gradle Info Basic plugin' - description = project.description - implementationClass= 'nebula.plugin.info.basic.BasicInfoPlugin' - tags.set(['nebula', 'info']) - } - infoDependencies { - id = 'com.netflix.nebula.info-dependencies' - displayName = 'Gradle Info Dependencies plugin' - description = project.description - implementationClass= 'nebula.plugin.info.dependencies.DependenciesInfoPlugin' - tags.set(['nebula', 'info']) - } - infoBroker { - id = 'com.netflix.nebula.info-broker' - displayName = 'Gradle Info Broker plugin' - description = project.description - implementationClass= 'nebula.plugin.info.InfoBrokerPlugin' - tags.set(['nebula', 'info']) - } - infoCI { - id = 'com.netflix.nebula.info-ci' - displayName = 'Gradle Info CI plugin' - description = project.description - implementationClass= 'nebula.plugin.info.ci.ContinuousIntegrationInfoPlugin' - tags.set(['nebula', 'info']) - } - infoJAR { - id = 'com.netflix.nebula.info-jar' - displayName = 'Gradle Info JAR plugin' - description = project.description - implementationClass= 'nebula.plugin.info.reporting.InfoJarManifestPlugin' - tags.set(['nebula', 'info']) - } - infoJARProperties { - id = 'com.netflix.nebula.info-jar-properties' - displayName = 'Gradle Info JAR properties plugin' - description = project.description - implementationClass= 'nebula.plugin.info.reporting.InfoJarPropertiesFilePlugin' - tags.set(['nebula', 'info']) - } - infoJava { - id = 'com.netflix.nebula.info-java' - displayName = 'Gradle Info Java plugin' - description = project.description - implementationClass= 'nebula.plugin.info.java.InfoJavaPlugin' - tags.set(['nebula', 'info']) - } - infoOwners { - id = 'com.netflix.nebula.info-owners' - displayName = 'Gradle Info Owners plugin' - description = project.description - implementationClass= 'nebula.plugin.info.basic.ManifestOwnersPlugin' - tags.set(['nebula', 'info']) - } - infoProps { - id = 'com.netflix.nebula.info-props' - displayName = 'Gradle Info Properties plugin' - description = project.description - implementationClass= 'nebula.plugin.info.reporting.InfoPropertiesFilePlugin' - tags.set(['nebula', 'info']) - } - infoScm { - id = 'com.netflix.nebula.info-scm' - displayName = 'Gradle Info SCM plugin' - description = project.description - implementationClass= 'nebula.plugin.info.scm.ScmInfoPlugin' - tags.set(['nebula', 'info']) - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..2340386 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,138 @@ +/* + * Copyright 2014-2019 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + id("com.netflix.nebula.plugin-plugin") version ("25.+") + `kotlin-dsl` +} + +tasks.named("compileGroovy", GroovyCompile::class.java) { + groovyOptions.configurationScript = file("src/groovyCompile/groovycConfig.groovy") +} + +description = "Gradle plugin collect and provide information about the environment" + +contacts { + addPerson("nebula-plugins-oss@netflix.com") { + moniker = "Nebula Plugins Maintainers" + github = "nebula-plugins" + } +} + +dependencies { + // TODO, make these optional + implementation("com.perforce:p4java:2015.2.1365273") + implementation("com.netflix.nebula:nebula-gradle-interop:latest.release") + implementation("com.netflix.nebula:gradle-contacts-plugin:latest.release") + implementation("net.java.dev.jna:jna-platform:5.16.0") + testImplementation("com.github.stefanbirkner:system-rules:1.19.0") + testImplementation("org.ajoberstar.grgit:grgit-core:4.1.1") { + exclude(group = "org.codehaus.groovy", module = "groovy") + } + testImplementation("org.spockframework:spock-junit4:2.4-groovy-4.0") + testImplementation("org.eclipse.jgit:org.eclipse.jgit:7.+") + testImplementation(libs.assertj) +} + +testing { + suites { + named("test") { + useJUnitJupiter() + } + } +} + +gradlePlugin { + plugins { + create("info") { + id = "com.netflix.nebula.info" + displayName = "Gradle Info plugin" + description = project.description + implementationClass = "nebula.plugin.info.InfoPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoBasic") { + id = "com.netflix.nebula.info-basic" + displayName = "Gradle Info Basic plugin" + description = project.description + implementationClass = "nebula.plugin.info.basic.BasicInfoPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoDependencies") { + id = "com.netflix.nebula.info-dependencies" + displayName = "Gradle Info Dependencies plugin" + description = project.description + implementationClass = "nebula.plugin.info.dependencies.DependenciesInfoPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoBroker") { + id = "com.netflix.nebula.info-broker" + displayName = "Gradle Info Broker plugin" + description = project.description + implementationClass = "nebula.plugin.info.InfoBrokerPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoCI") { + id = "com.netflix.nebula.info-ci" + displayName = "Gradle Info CI plugin" + description = project.description + implementationClass = "nebula.plugin.info.ci.ContinuousIntegrationInfoPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoJAR") { + id = "com.netflix.nebula.info-jar" + displayName = "Gradle Info JAR plugin" + description = project.description + implementationClass = "nebula.plugin.info.reporting.InfoJarManifestPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoJARProperties") { + id = "com.netflix.nebula.info-jar-properties" + displayName = "Gradle Info JAR properties plugin" + description = project.description + implementationClass = "nebula.plugin.info.reporting.InfoJarPropertiesFilePlugin" + tags.set(listOf("nebula", "info")) + } + create("infoJava") { + id = "com.netflix.nebula.info-java" + displayName = "Gradle Info Java plugin" + description = project.description + implementationClass = "nebula.plugin.info.java.InfoJavaPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoOwners") { + id = "com.netflix.nebula.info-owners" + displayName = "Gradle Info Owners plugin" + description = project.description + implementationClass = "nebula.plugin.info.basic.ManifestOwnersPlugin" + tags.set(listOf("nebula", "info")) + } + create("infoProps") { + id = "com.netflix.nebula.info-props" + displayName = "Gradle Info Properties plugin" + description = project.description + implementationClass = "nebula.plugin.info.reporting.InfoPropertiesFilePlugin" + tags.set(listOf("nebula", "info")) + } + create("infoScm") { + id = "com.netflix.nebula.info-scm" + displayName = "Gradle Info SCM plugin" + description = project.description + implementationClass = "nebula.plugin.info.scm.ScmInfoPlugin" + tags.set(listOf("nebula", "info")) + } + } +} diff --git a/gradle.lockfile b/gradle.lockfile index 334afc1..0de7b26 100644 --- a/gradle.lockfile +++ b/gradle.lockfile @@ -1,44 +1,46 @@ # This is a Gradle generated file for dependency locking. # Manual edits can break the build and are not advised. # This file is expected to be part of source control. -cglib:cglib-nodep:3.2.2=integTestRuntimeClasspath,testRuntimeClasspath -com.github.stefanbirkner:system-rules:1.19.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.googlecode.javaewah:JavaEWAH:1.2.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.jcraft:jzlib:1.1.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.netflix.nebula:gradle-contacts-plugin:8.1.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.netflix.nebula:nebula-gradle-interop:3.1.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -com.netflix.nebula:nebula-test:11.11.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -com.perforce:p4java:2015.2.1365273=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -commons-codec:commons-codec:1.20.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -io.leangen.geantyref:geantyref:1.3.16=integTestRuntimeClasspath,testRuntimeClasspath -junit:junit-dep:4.11=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -junit:junit:4.13.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -net.bytebuddy:byte-buddy:1.17.7=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -net.java.dev.jna:jna-platform:5.16.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -net.java.dev.jna:jna:5.16.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.ajoberstar.grgit:grgit-core:4.1.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apache.groovy:groovy-bom:4.0.29=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apache.groovy:groovy:4.0.29=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.apiguardian:apiguardian-api:1.1.2=integTestCompileClasspath,testCompileClasspath -org.assertj:assertj-core:3.27.6=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.eclipse.jgit:org.eclipse.jgit:7.5.0.202512021534-r=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.hamcrest:hamcrest:3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains.kotlin:kotlin-stdlib:2.2.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath -org.jspecify:jspecify:1.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-api:5.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-engine:5.14.1=integTestRuntimeClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter-params:5.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.jupiter:junit-jupiter:5.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-commons:1.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-engine:1.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-launcher:1.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.junit:junit-bom:5.14.1=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath -org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.slf4j:slf4j-api:2.0.17=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.spockframework:spock-bom:2.4-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.spockframework:spock-core:2.4-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -org.spockframework:spock-junit4:2.4-groovy-4.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath -empty=annotationProcessor,integTestAnnotationProcessor,testAnnotationProcessor +cglib:cglib-nodep:3.2.2=testRuntimeClasspath +com.github.stefanbirkner:system-rules:1.19.0=testCompileClasspath,testRuntimeClasspath +com.googlecode.javaewah:JavaEWAH:1.2.3=testCompileClasspath,testRuntimeClasspath +com.jcraft:jzlib:1.1.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.netflix.nebula:gradle-contacts-plugin:8.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.netflix.nebula:nebula-gradle-interop:3.1.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +com.netflix.nebula:nebula-test:11.11.3=testCompileClasspath,testRuntimeClasspath +com.perforce:p4java:2015.2.1365273=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +commons-codec:commons-codec:1.20.0=testCompileClasspath,testRuntimeClasspath +io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath +junit:junit-dep:4.11=testCompileClasspath,testRuntimeClasspath +junit:junit:4.13.2=testCompileClasspath,testRuntimeClasspath +net.bytebuddy:byte-buddy:1.18.3=testCompileClasspath,testRuntimeClasspath +net.java.dev.jna:jna-platform:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +net.java.dev.jna:jna:5.16.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.ajoberstar.grgit:grgit-core:4.1.1=testCompileClasspath,testRuntimeClasspath +org.apache.groovy:groovy-bom:4.0.29=testCompileClasspath,testRuntimeClasspath +org.apache.groovy:groovy:4.0.29=testCompileClasspath,testRuntimeClasspath +org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath +org.assertj:assertj-core:3.27.7=testCompileClasspath,testRuntimeClasspath +org.eclipse.jgit:org.eclipse.jgit:7.5.0.202512021534-r=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath +org.hamcrest:hamcrest:3.0=testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-reflect:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:2.2.0=runtimeClasspath +org.jetbrains.kotlin:kotlin-stdlib:2.2.20=compileClasspath,embeddedKotlin,testCompileClasspath,testRuntimeClasspath +org.jetbrains:annotations:13.0=compileClasspath,embeddedKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.jspecify:jspecify:1.0.0=testCompileClasspath,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-api:5.14.1=testCompileClasspath,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-engine:5.14.1=testRuntimeClasspath +org.junit.jupiter:junit-jupiter-params:5.14.1=testCompileClasspath,testRuntimeClasspath +org.junit.jupiter:junit-jupiter:5.14.1=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-commons:1.14.1=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-engine:1.14.1=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-launcher:1.14.1=testCompileClasspath,testRuntimeClasspath +org.junit:junit-bom:5.14.1=testCompileClasspath,testRuntimeClasspath +org.objenesis:objenesis:2.4=testRuntimeClasspath +org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath +org.slf4j:slf4j-api:2.0.17=testCompileClasspath,testRuntimeClasspath +org.spockframework:spock-bom:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath +org.spockframework:spock-core:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath +org.spockframework:spock-junit4:2.4-groovy-4.0=testCompileClasspath,testRuntimeClasspath +empty=annotationProcessor,testAnnotationProcessor diff --git a/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy b/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy index 657de23..4a5f4b0 100644 --- a/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginSpec.groovy @@ -53,8 +53,6 @@ class ContinuousIntegrationInfoPluginSpec extends BaseIntegrationTestKitSpec { provider | envVariables || expectedBuildInfo 'Titus' | [TITUS_JOB_ID: 'cf12af48-e347-11ea-87d0-0242ac130003', TITUS_TASK_ID: 'dbac27de-e347-11ea-87d0-0242ac130003', NETFLIX_INSTANCE_ID: 'my-netflix-instance-id', NETFLIX_APP: 'my-netflix-app', 'Build-Job': 'my-netflix-app'] || ['Build-Job': 'my-netflix-app', 'Build-Number': 'cf12af48-e347-11ea-87d0-0242ac130003', 'Build-Id': 'cf12af48-e347-11ea-87d0-0242ac130003', 'Build-Url': 'my-netflix-instance-id/cf12af48-e347-11ea-87d0-0242ac130003'] 'Drone' | [DRONE: 'true', DRONE_REPO: 'org/my-repo', DRONE_BUILD_NUMBER: '1', 'Build-Job': 'org/my-repo'] || ['Build-Job': 'org/my-repo', 'Build-Number': '1', 'Build-Id': '1', 'Build-Url': "http://${AbstractContinuousIntegrationProvider.hostname()}/build/1"] - 'Jenkins' | [JOB_NAME: 'org/my-repo', BUILD_ID: '1', 'BUILD_NUMBER': '10', 'Build-Job': 'org/my-repo', 'BUILD_URL': 'http://localhost/org/my-repo/10'] || ['Build-Job': 'org/my-repo', 'Build-Number': '10', 'Build-Id': '1', 'Build-Url': 'http://localhost/org/my-repo/10'] - 'Github Actions' | [CI: 'true', GITHUB_ACTION: 'my-action', GITHUB_REPOSITORY: 'org/my-repo', GITHUB_RUN_NUMBER: '10', GITHUB_RUN_ID: '1', 'GITHUB_SERVER_URL': 'http://some-github'] || ['Build-Job': 'my-action', 'Build-Number': '10', 'Build-Id': '1', 'Build-Url': 'http://some-github/org/my-repo/actions/runs/1'] } private manifestKey(Attributes attributes, String key) { diff --git a/src/test/groovy/nebula/plugin/info/scm/PerforceScmProviderLocalSpec.groovy b/src/test/groovy/nebula/plugin/info/scm/PerforceScmProviderLocalSpec.groovy index bd6628c..7ae269d 100644 --- a/src/test/groovy/nebula/plugin/info/scm/PerforceScmProviderLocalSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/scm/PerforceScmProviderLocalSpec.groovy @@ -19,7 +19,9 @@ import com.perforce.p4java.client.IClient import com.perforce.p4java.impl.generic.client.ClientView import com.perforce.p4java.server.IServer import nebula.test.ProjectSpec +import spock.lang.Ignore +@Ignore class PerforceScmProviderLocalSpec extends ProjectSpec { def provider = new PerforceScmProvider() diff --git a/src/test/kotlin/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginTest.kt b/src/test/kotlin/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginTest.kt new file mode 100644 index 0000000..ff12a61 --- /dev/null +++ b/src/test/kotlin/nebula/plugin/info/ci/ContinuousIntegrationInfoPluginTest.kt @@ -0,0 +1,101 @@ +package nebula.plugin.info.ci + +import nebula.test.dsl.* +import nebula.test.dsl.TestKitAssertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir +import java.io.File +import java.util.jar.Attributes +import java.util.jar.JarFile + +internal class ContinuousIntegrationInfoPluginTest { + + @TempDir + lateinit var projectDir: File + + private fun TestProjectBuilder.exampleProject() { + properties { + buildCache(true) + configurationCache(true) + } + settings { + name("module") + } + rootProject { + plugins { + id("java-library") + id("com.netflix.nebula.info-broker") + id("com.netflix.nebula.info-ci") + id("com.netflix.nebula.info-jar") + } + } + } + + @Test + fun `test Github Actions`() { + val runner = testProject(projectDir) { + exampleProject() + } + val result = runner.run("jar", "-Pversion=1.0") { + withEnvironment( + mapOf( + "CI" to "true", + "GITHUB_ACTION" to "my-action", + "GITHUB_REPOSITORY" to "org/my-repo", + "GITHUB_RUN_NUMBER" to "10", + "GITHUB_RUN_ID" to "1", + "GITHUB_SERVER_URL" to "http://some-github" + ) + ) + } + + assertThat(result) + .hasNoDeprecationWarnings() + .hasNoMutableStateWarnings() + + val attributes = readJarAttributes() + assertThat(attributes.getKey("Build-Job")).isEqualTo("my-action") + assertThat(attributes.getKey("Build-Number")).isEqualTo("10") + assertThat(attributes.getKey("Build-Id")).isEqualTo("1") + assertThat(attributes.getKey("Build-Url")).isEqualTo("http://some-github/org/my-repo/actions/runs/1") + assertThat(attributes.getKey("Build-Host")).isEqualTo("http://some-github") + } + + @Test + fun `test Jenkins`() { + val runner = testProject(projectDir) { + exampleProject() + } + val result = runner.run("jar", "-Pversion=1.0") { + withEnvironment( + mapOf( + "JOB_NAME" to "org/my-repo", + "Build-Job" to "org/my-repo", + "BUILD_NUMBER" to "10", + "BUILD_ID" to "1", + "BUILD_URL" to "http://leeroy-jenkins/2", + "JENKINS_URL" to "http://leeroy-jenkins", + ) + ) + } + + assertThat(result) + .hasNoDeprecationWarnings() + .hasNoMutableStateWarnings() + + val attributes = readJarAttributes() + assertThat(attributes.getKey("Build-Job")).isEqualTo("org/my-repo") + assertThat(attributes.getKey("Build-Number")).isEqualTo("10") + assertThat(attributes.getKey("Build-Id")).isEqualTo("1") + assertThat(attributes.getKey("Build-Url")).isEqualTo("http://leeroy-jenkins/2") + assertThat(attributes.getKey("Build-Host")).isEqualTo("http://leeroy-jenkins") + } + + fun Attributes.getKey(key: String): Any? { + return get(Attributes.Name(key)) + } + + fun readJarAttributes(): Attributes { + return JarFile(projectDir.resolve("build/libs/module-1.0.jar")).manifest.mainAttributes + } +} \ No newline at end of file