diff --git a/pipeline-model-definition/pom.xml b/pipeline-model-definition/pom.xml index 1ed740ba7..f7a8a5f9d 100644 --- a/pipeline-model-definition/pom.xml +++ b/pipeline-model-definition/pom.xml @@ -201,7 +201,11 @@ junit test - + + org.jenkins-ci.plugins + support-core + test + org.jenkins-ci.plugins ant @@ -241,5 +245,6 @@ false + true diff --git a/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCalls.java b/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCalls.java new file mode 100644 index 000000000..e0d17e0a2 --- /dev/null +++ b/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCalls.java @@ -0,0 +1,40 @@ +/* + * The MIT License + * + * Copyright 2024 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.jenkinsci.plugins.pipeline.modeldefinition.parser; + +import hudson.Extension; +import org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler; +import org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescribable; +import org.jenkinsci.plugins.workflow.cps.IgnoredInternalClasses; + +@Extension public final class InternalCalls implements IgnoredInternalClasses { + + @Override public boolean ignore(Class clazz) { + return WithScriptDescribable.class.isAssignableFrom(clazz) || + CredentialsBindingHandler.class.isAssignableFrom(clazz) || + clazz.getName().startsWith("org.jenkinsci.plugins.pipeline.modeldefinition."); + } + +} diff --git a/pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCallsTest.java b/pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCallsTest.java new file mode 100644 index 000000000..1fdaaf1ce --- /dev/null +++ b/pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/InternalCallsTest.java @@ -0,0 +1,68 @@ +/* + * The MIT License + * + * Copyright 2024 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.jenkinsci.plugins.pipeline.modeldefinition.parser; + +import com.cloudbees.jenkins.support.api.Container; +import com.cloudbees.jenkins.support.api.Content; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.cps.CpsFlowExecution; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.BuildWatcher; +import org.jvnet.hudson.test.JenkinsRule; + +public final class InternalCallsTest { + + @Rule public final JenkinsRule r = new JenkinsRule(); + @ClassRule public static final BuildWatcher bw = new BuildWatcher(); + + @Test public void declarative() throws Throwable { + var p = r.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition("pipeline {options {quietPeriod 0}; agent any; stages {stage('x') {steps {echo(/constructing ${new hudson.EnvVars()}/)}}}}", true)); + r.assertLogContains("constructing [:]", r.buildAndAssertSuccess(p)); + var baos = new ByteArrayOutputStream(); + new CpsFlowExecution.PipelineInternalCalls().addContents(new Container() { + @Override public void add(Content content) { + try { + content.writeTo(baos); + } catch (IOException x) { + assert false : x; + } + } + }); + assertThat(baos.toString(), allOf( + containsString("hudson.EnvVars."), + not(containsString("org.jenkinsci.plugins.pipeline.modeldefinition")))); + } + +} diff --git a/pom.xml b/pom.xml index 254f43331..95451c8cf 100644 --- a/pom.xml +++ b/pom.xml @@ -75,10 +75,16 @@ io.jenkins.tools.bom bom-2.426.x - 2675.v1515e14da_7a_6 + 3023.v02a_987a_b_3ff9 import pom + + + org.jenkins-ci.plugins.workflow + workflow-cps + 3953.v19f11da_8d2fa_ + org.jenkins-ci.main jenkins-test-harness-tools @@ -133,7 +139,7 @@ 999999-SNAPSHOT jenkinsci/pipeline-model-definition-plugin - 2.426.1 + 2.426.3