diff --git a/build.gradle.kts b/build.gradle.kts index 7864c55b..f74bb2a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -127,6 +127,7 @@ dependencies { testImplementation("org.jenkins-ci.main:jenkins-test-harness:2225.v04fa_3929c9b_5") testImplementation("org.jenkins-ci.main:jenkins-test-harness-tools:2.2") testImplementation("io.jenkins:configuration-as-code:1.4") + testImplementation("io.jenkins.configuration-as-code:test-harness:1.4") testImplementation("org.jenkins-ci.plugins:timestamper") testImplementation("org.jenkins-ci.plugins:pipeline-stage-step") testImplementation("org.jenkins-ci.plugins:pipeline-maven:3.10.0") diff --git a/src/main/java/hudson/plugins/gradle/injection/InjectionConfig.java b/src/main/java/hudson/plugins/gradle/injection/InjectionConfig.java index 0fee937f..f00592cf 100644 --- a/src/main/java/hudson/plugins/gradle/injection/InjectionConfig.java +++ b/src/main/java/hudson/plugins/gradle/injection/InjectionConfig.java @@ -102,6 +102,9 @@ public class InjectionConfig extends GlobalConfiguration { // Legacy property that is not used anymore private transient String injectionVcsRepositoryPatterns; private VcsRepositoryFilter parsedVcsRepositoryFilter = VcsRepositoryFilter.EMPTY; + // Legacy properties, kept for reading old configurations + private transient boolean injectMavenExtension; + private transient boolean injectCcudExtension; public InjectionConfig() { load(); @@ -367,6 +370,24 @@ public void setCheckForBuildAgentErrors(boolean checkForBuildAgentErrors) { this.checkForBuildAgentErrors = checkForBuildAgentErrors; } + public boolean isInjectCcudExtension() { + return injectCcudExtension; + } + + @DataBoundSetter + public void setInjectCcudExtension(boolean injectCcudExtension) { + this.injectCcudExtension = injectCcudExtension; + } + + public boolean isInjectMavenExtension() { + return injectMavenExtension; + } + + @DataBoundSetter + public void setInjectMavenExtension(boolean injectMavenExtension) { + this.injectMavenExtension = injectMavenExtension; + } + /** * Required to display filter in the UI. */ diff --git a/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigWithCasCTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigWithCasCTest.groovy new file mode 100644 index 00000000..69853418 --- /dev/null +++ b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigWithCasCTest.groovy @@ -0,0 +1,47 @@ +package hudson.plugins.gradle.injection + + +import hudson.plugins.gradle.AbstractIntegrationTest +import io.jenkins.plugins.casc.misc.ConfiguredWithCode +import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule +import org.junit.Rule +import org.junit.rules.RuleChain +import spock.lang.Subject +import spock.lang.Unroll + +@Unroll +@Subject(InjectionConfig.class) +class InjectionConfigWithCasCTest extends AbstractIntegrationTest { + @Rule + public final RuleChain rules = RuleChain.outerRule(noSpaceInTmpDirs).around(new JenkinsConfiguredWithCodeRule()) + + @ConfiguredWithCode("injection-config.yml") + def 'current configuration is readable with JCasC'() { + expect: + with(InjectionConfig.get()) { + it.allowUntrusted == true + it.ccudExtensionCustomCoordinates == "mycustom-ccud:ext" + it.ccudExtensionVersion == "2.0.1" + it.ccudPluginVersion == "2.0.2" + it.checkForBuildAgentErrors == true + it.enabled == true + it.enforceUrl == true + it.gradleCaptureTaskInputFiles == true + it.gradleInjectionDisabledNodes*.label == ["non-gradle-node"] + it.gradleInjectionEnabledNodes*.label == ["gradle-node"] + it.gradlePluginRepositoryUrl == "https://plugins.gradle.org" + it.gradlePluginVersion == "3.18.1" + it.injectMavenExtension == true + it.injectCcudExtension == true + it.mavenCaptureGoalInputFiles == true + it.mavenExtensionCustomCoordinates == "mycustom:ext" + it.mavenExtensionRepositoryUrl == "https://repo1.maven.org/maven2" + it.mavenExtensionVersion == "1.22.1" + it.mavenInjectionDisabledNodes*.label == ["non-maven-node"] + it.mavenInjectionEnabledNodes*.label == ["maven-node"] + it.server == "http://localhost:5086" + it.shortLivedTokenExpiry == 24 + it.vcsRepositoryFilter == "+:myrepo" + } + } +} diff --git a/src/test/resources/injection-config.yml b/src/test/resources/injection-config.yml new file mode 100644 index 00000000..ebe8ae1c --- /dev/null +++ b/src/test/resources/injection-config.yml @@ -0,0 +1,30 @@ +jenkins: +unclassified: + injectionConfig: + allowUntrusted: true + ccudExtensionCustomCoordinates: "mycustom-ccud:ext" + ccudExtensionVersion: "2.0.1" + ccudPluginVersion: "2.0.2" + checkForBuildAgentErrors: true + enabled: true + enforceUrl: true + gradleCaptureTaskInputFiles: true + gradleInjectionDisabledNodes: + - label: "non-gradle-node" + gradleInjectionEnabledNodes: + - label: "gradle-node" + gradlePluginRepositoryUrl: "https://plugins.gradle.org" + gradlePluginVersion: "3.18.1" + injectMavenExtension: true + injectCcudExtension: true + mavenCaptureGoalInputFiles: true + mavenExtensionCustomCoordinates: "mycustom:ext" + mavenExtensionRepositoryUrl: "https://repo1.maven.org/maven2" + mavenExtensionVersion: "1.22.1" + mavenInjectionDisabledNodes: + - label: "non-maven-node" + mavenInjectionEnabledNodes: + - label: "maven-node" + server: "http://localhost:5086" + shortLivedTokenExpiry: 24 + vcsRepositoryFilter: "+:myrepo"