Skip to content

Commit

Permalink
Merge pull request #736 from jglick/InternalCalls
Browse files Browse the repository at this point in the history
Implement `IgnoredInternalClasses`
  • Loading branch information
jglick authored Aug 28, 2024
2 parents 10edd34 + f9c2c77 commit bb34b2e
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pipeline-model-definition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>support-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ant</artifactId>
Expand Down Expand Up @@ -241,5 +245,6 @@

<properties>
<no-test-jar>false</no-test-jar>
<useBeta>true</useBeta>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -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.");
}

}
Original file line number Diff line number Diff line change
@@ -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.<init>"),
not(containsString("org.jenkinsci.plugins.pipeline.modeldefinition"))));
}

}
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.426.x</artifactId>
<version>2675.v1515e14da_7a_6</version>
<version>3023.v02a_987a_b_3ff9</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO until in BOM: -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>3953.v19f11da_8d2fa_</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness-tools</artifactId>
Expand Down Expand Up @@ -133,7 +139,7 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/pipeline-model-definition-plugin</gitHubRepo>
<jenkins.version>2.426.1</jenkins.version>
<jenkins.version>2.426.3</jenkins.version>
</properties>

<profiles>
Expand Down

0 comments on commit bb34b2e

Please sign in to comment.