Skip to content

Commit

Permalink
Update Publish Step to use 'Step' and 'SynchronousNonBlockingStepExec…
Browse files Browse the repository at this point in the history
…ution'

JENKINS-44427
  • Loading branch information
p4paul committed May 26, 2017
1 parent a0afc4a commit 0bbf1c5
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions src/main/java/org/jenkinsci/plugins/p4/workflow/P4PublishStep.java
@@ -1,29 +1,32 @@
package org.jenkinsci.plugins.p4.workflow;

import com.google.common.collect.ImmutableSet;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;

import javax.inject.Inject;

import org.jenkinsci.plugins.p4.credentials.P4CredentialsImpl;
import org.jenkinsci.plugins.p4.publish.PublishNotifierStep;
import org.jenkinsci.plugins.p4.publish.Publish;
import org.jenkinsci.plugins.p4.publish.PublishNotifierStep;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

public class P4PublishStep extends AbstractStepImpl {
import javax.annotation.Nonnull;
import java.util.Set;

public class P4PublishStep extends Step {

private final String credential;
private final Workspace workspace;
private final Publish publish;
Expand All @@ -47,12 +50,13 @@ public P4PublishStep(String credential, Workspace workspace, Publish publish) {
this.publish = publish;
}

@Extension(optional = true)
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
@Override
public StepExecution start(StepContext context) throws Exception {
return new P4PublishStepExecution(this, context);
}

public DescriptorImpl() {
super(P4PublishStepExecution.class);
}
@Extension(optional = true)
public static final class DescriptorImpl extends StepDescriptor {

@Override
public String getFunctionName() {
Expand All @@ -64,41 +68,36 @@ public String getDisplayName() {
return "P4 Publish";
}

@Override
public Set<? extends Class<?>> getRequiredContext() {
return ImmutableSet.of(Run.class, FilePath.class, Launcher.class, TaskListener.class);
}

public ListBoxModel doFillCredentialItems(@AncestorInPath Item project, @QueryParameter String credential) {
return P4CredentialsImpl.doFillCredentialItems(project, credential);
}

public FormValidation doCheckCredential(@AncestorInPath Item project, @QueryParameter String value) {
return P4CredentialsImpl.doCheckCredential(project, value);
}

}

public static class P4PublishStepExecution extends
AbstractSynchronousStepExecution<Void> {
public static class P4PublishStepExecution extends SynchronousNonBlockingStepExecution<Void> {

private static final long serialVersionUID = 1L;

@Inject
private transient P4PublishStep step;
@StepContextParameter
private transient Run<?, ?> run;
@StepContextParameter
private transient FilePath workspace;
@StepContextParameter
private transient TaskListener listener;
@StepContextParameter
private transient Launcher launcher;

protected P4PublishStepExecution(P4PublishStep step, @Nonnull StepContext context) {
super(context);
this.step = step;
}

@Override
protected Void run() throws Exception {
PublishNotifierStep notifier = new PublishNotifierStep(
step.getCredential(), step.getWorkspace(),
step.getPublish());
notifier.perform(run, workspace, launcher, listener);
PublishNotifierStep notifier = new PublishNotifierStep(step.getCredential(), step.getWorkspace(), step.getPublish());
notifier.perform(getContext().get(Run.class), getContext().get(FilePath.class), getContext().get(Launcher.class), getContext().get(TaskListener.class));
return null;
}

}

}

0 comments on commit 0bbf1c5

Please sign in to comment.