Skip to content
Permalink
Browse files

Merge pull request #47 from jglick/WorkflowJob.disabled+core-JENKINS-…

…27299

[JENKINS-27299] WorkflowJob.disabled on new core
  • Loading branch information
jglick committed May 17, 2017
2 parents 5a6f277 + be04421 commit 8da02e98393c64ebe0f3500e20462adff50c6e67
@@ -97,12 +97,9 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.interceptor.RequirePOST;

@SuppressWarnings({"unchecked", "rawtypes"})
public final class WorkflowJob extends Job<WorkflowJob,WorkflowRun> implements LazyBuildMixIn.LazyLoadingJob<WorkflowJob,WorkflowRun>, ParameterizedJobMixIn.ParameterizedJob<WorkflowJob, WorkflowRun>, TopLevelItem, Queue.FlyweightTask, SCMTriggerItem {
@@ -209,8 +206,7 @@ public void setDefinition(FlowDefinition definition) {
}
}
}
// TODO https://github.com/jenkinsci/jenkins/pull/2866: return ParameterizedJobMixIn.ParameterizedJob.super.isBuildable();
return !isDisabled() && !isHoldOffBuildUntilSave();
return ParameterizedJobMixIn.ParameterizedJob.super.isBuildable();
}

@Override protected RunMap<WorkflowRun> _getRuns() {
@@ -253,14 +249,6 @@ public void setDefinition(FlowDefinition definition) {
return buildMixIn.createHistoryWidget();
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
@Override public WorkflowRun createExecutable() throws IOException {
if (isDisabled()) {
return null;
}
return buildMixIn.newBuild();
}

@Override public @CheckForNull QueueTaskFuture<WorkflowRun> scheduleBuild2(int quietPeriod, Action... actions) {
return ParameterizedJobMixIn.ParameterizedJob.super.scheduleBuild2(quietPeriod, actions);
}
@@ -269,24 +257,20 @@ public void setDefinition(FlowDefinition definition) {
return getParameterizedJobMixIn().extendSearchIndex(super.makeSearchIndex());
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override
public boolean isDisabled() {
@Override public boolean isDisabled() {
return disabled;
}

@Restricted(DoNotUse.class)
// TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override
public void setDisabled(boolean disabled) {
@Override public void setDisabled(boolean disabled) {
this.disabled = disabled;
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override
public boolean supportsMakeDisabled() {
@Override public boolean supportsMakeDisabled() {
return true;
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
public void makeDisabled(boolean b) throws IOException {
@Override public void makeDisabled(boolean b) throws IOException {
if (isDisabled() == b) {
return; // noop
}
@@ -301,22 +285,6 @@ public void makeDisabled(boolean b) throws IOException {
ItemListener.fireOnUpdated(this);
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
@RequirePOST
public HttpResponse doDisable() throws IOException, ServletException {
checkPermission(CONFIGURE);
makeDisabled(true);
return new HttpRedirect(".");
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
@RequirePOST
public HttpResponse doEnable() throws IOException, ServletException {
checkPermission(CONFIGURE);
makeDisabled(false);
return new HttpRedirect(".");
}

@Override public BallColor getIconColor() {
if (isDisabled()) {
return isBuilding() ? BallColor.DISABLED_ANIME : BallColor.DISABLED;
@@ -591,27 +559,6 @@ public void replaceAction(Action a) {
return typical;
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
public boolean schedulePolling() {
if (isDisabled()) {
return false;
}
SCMTrigger scmt = getSCMTrigger();
if (scmt == null) {
return false;
}
scmt.run();
return true;
}

// TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override
@SuppressWarnings("deprecation")
public void doPolling(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
hudson.model.BuildAuthorizationToken.checkPermission((Job) this, getAuthToken(), req, rsp);
schedulePolling();
rsp.sendRedirect(".");
}

@SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull")
@Override public PollingResult poll(TaskListener listener) {
if (!isBuildable()) {
@@ -24,31 +24,8 @@
~ THE SOFTWARE.
-->

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:p="/lib/hudson/project" xmlns:t="/lib/hudson" xmlns:l="/lib/layout" xmlns:f="/lib/form">
<j:choose> <!-- TODO https://github.com/jenkinsci/jenkins/pull/2866 <p:makeDisabled/> -->
<j:when test="${!it.supportsMakeDisabled()}">
<!-- for now, quietly omit the option -->
</j:when>
<j:when test="${it.disabled}">
<div class="warning">
<form method="post" id='enable-project' action="enable">
${%This project is currently disabled}
<l:hasPermission permission="${it.CONFIGURE}">
<f:submit value="${%Enable}" />
</l:hasPermission>
</form>
</div>
</j:when>
<j:otherwise>
<div align="right">
<form method="post" id="disable-project" action="disable">
<l:hasPermission permission="${it.CONFIGURE}">
<f:submit value="${%Disable Project}" />
</l:hasPermission>
</form>
</div>
</j:otherwise>
</j:choose>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:p="/lib/hudson/project" xmlns:t="/lib/hudson">
<p:makeDisabled/>
<p:projectActionFloatingBox/>
<table style="margin-top: 1em; margin-left:1em;">
<!-- TODO display prominentActions -->
@@ -4,6 +4,7 @@
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import hudson.cli.CLICommandInvoker;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import hudson.security.WhoAmI;
@@ -94,7 +95,8 @@ public void addAction() throws Exception {
wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST));
assertTrue(p.isDisabled());
assertNull(p.scheduleBuild2(0));
// TODO https://github.com/jenkinsci/jenkins/pull/2866 reënable by CLI
assertThat(new CLICommandInvoker(j, "enable-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
assertFalse(p.isDisabled());
}

}

0 comments on commit 8da02e9

Please sign in to comment.
You can’t perform that action at this time.