Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-40906] Address code review comments
  • Loading branch information
stephenc committed Jan 21, 2017
1 parent 76f9cfa commit cf5969d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 58 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Expand Up @@ -68,6 +68,16 @@ THE SOFTWARE.
<no-test-jar>false</no-test-jar>
<workflow-step-api.version>2.7</workflow-step-api.version>
</properties>
<dependencyManagement>
<!-- TODO figure out why the version is being forced down to 2.5 without this -->
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow-step-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Expand Up @@ -55,6 +55,7 @@
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.SynchronousStepExecution;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -164,12 +165,6 @@ public String toString() {
@Extension
public static class DescriptorImpl extends StepDescriptor {

/**
* Default constructor.
*/
public DescriptorImpl() {
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -203,6 +198,7 @@ public Step newInstance(@CheckForNull StaplerRequest req, @NonNull JSONObject fo
src.put("id", "_");
SCMSource source = req.bindJSON(SCMSource.class, src);
List<String> targets = new ArrayList<>();
// TODO JENKINS-27901 use standard control when available
Object t = formData.get("targets");
if (t instanceof JSONObject) {
JSONObject o = (JSONObject) t;
Expand Down Expand Up @@ -232,24 +228,18 @@ public FormValidation doCheckTarget(@QueryParameter String value) {
/**
* Our {@link StepExecution}.
*/
@SuppressFBWarnings("SE_BAD_FIELD") // SCMSource being non-serializable is not an issue as we are a sync step.
public static class Execution extends StepExecution {
public static class Execution extends SynchronousStepExecution<SCM> {

/**
* Ensure consistent serialization.
*/
private static final long serialVersionUID = 1L;

/**
* The current
*/
private transient volatile Thread executing;

/**
* The {@link SCMSource}
*/
@NonNull
private final SCMSource source;
private transient final SCMSource source;

/**
* The {@link SCMSource}
Expand Down Expand Up @@ -297,34 +287,6 @@ protected SCM run() throws Exception {
return source.build(fetch.getHead(), fetch);
}

/** {@inheritDoc} */
@Override
public final boolean start() throws Exception {
executing = Thread.currentThread();
try {
getContext().onSuccess(run());
} catch (Throwable t) {
getContext().onFailure(t);
} finally {
executing = null;
}
return true;
}

/**
* If the computation is going synchronously, try to cancel that.
*/
@Override
public void stop(Throwable cause) throws Exception {
Thread e = executing; // capture
if (e != null) {
if (e instanceof Executor) {
((Executor) e).interrupt(ABORTED, new ExceptionCause(cause));
} else {
e.interrupt();
}
}
}
}

/**
Expand Down Expand Up @@ -385,19 +347,4 @@ public boolean isObserving() {
}

}

static class ExceptionCause extends CauseOfInterruption implements Serializable {
private final Throwable t;

public ExceptionCause(Throwable t) {
this.t = t;
}

@Override
public String getShortDescription() {
return "Exception: " + t.getMessage();
}

private static final long serialVersionUID = 1L;
}
}
Expand Up @@ -39,7 +39,7 @@
// this will check if there is a branch with the same name as the current branch in
// https://example.com/example.git and use that for the checkout, but if there is no
// branch with the same name it will fall back to the master branch
checkout resolveScm(source: git('https://example.com/example.git'), targets: [env.BRANCH_NAME,'master']
checkout resolveScm(source: git('https://example.com/example.git'), targets: [BRANCH_NAME,'master']
}
// rest of pipeline
</pre>
Expand Down

0 comments on commit cf5969d

Please sign in to comment.