Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate need for reflection when calling getChangeSets #41

Merged
merged 2 commits into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
buildPlugin(jenkinsVersions: [null, '2.32.2'])
buildPlugin()
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.30</version>
<version>2.33</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -40,7 +40,7 @@
<licenses>
<license>
<name>MIT License</name>
<url>http://opensource.org/licenses/MIT</url>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
Expand All @@ -62,7 +62,7 @@
</pluginRepository>
</pluginRepositories>
<properties>
<jenkins.version>1.642.3</jenkins.version>
<jenkins.version>2.60.2</jenkins.version>
<no-test-jar>false</no-test-jar>
<git-plugin.version>3.0.5</git-plugin.version>
<workflow-scm-step-plugin.version>2.4</workflow-scm-step-plugin.version>
Expand Down Expand Up @@ -147,7 +147,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.10</version>
<version>2.12.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -161,6 +161,12 @@
<artifactId>git</artifactId>
<version>${git-plugin.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@
import hudson.model.Run;
import hudson.scm.ChangeLogSet;
import hudson.security.ACL;
import hudson.security.ACLContext;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import jenkins.scm.RunWithSCM;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction;

Expand Down Expand Up @@ -89,11 +88,8 @@ public void setDescription(String d) throws IOException {
throw new SecurityException("can only set the description property on the current build");
}
// Even if the build is carrying a specific authentication, we want it to be allowed to update itself:
SecurityContext orig = ACL.impersonate(ACL.SYSTEM);
try {
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
build().setDescription(d);
} finally {
SecurityContextHolder.setContext(orig);
}
}

Expand All @@ -102,11 +98,8 @@ public void setDisplayName(String n) throws IOException {
if (!currentBuild) {
throw new SecurityException("can only set the displayName property on the current build");
}
SecurityContext orig = ACL.impersonate(ACL.SYSTEM);
try {
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
build().setDisplayName(n);
} finally {
SecurityContextHolder.setContext(orig);
}
}

Expand Down Expand Up @@ -233,10 +226,14 @@ public String getId() throws AbortException {
@Whitelisted
public List<ChangeLogSet<? extends ChangeLogSet.Entry>> getChangeSets() throws Exception {
Run<?,?> build = build();
try { // TODO JENKINS-24141 should not need to use reflection here
return (List) build.getClass().getMethod("getChangeSets").invoke(build);
} catch (NoSuchMethodException x) {
return Collections.emptyList();
if (build instanceof RunWithSCM) { // typical cases
return ((RunWithSCM<?, ?>) build).getChangeSets();
} else {
try { // to support WorkflowRun prior to workflow-job 2.12
return (List) build.getClass().getMethod("getChangeSets").invoke(build);
} catch (NoSuchMethodException x) { // something weird like ExternalRun
return Collections.emptyList();
}
}
}

Expand Down