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

Moved PushdStep to workflow-durable-task-step #258

Merged
merged 2 commits into from
Feb 16, 2023
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>1227.vdc0a_d1fd4338</version> <!-- TODO until in BOM -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -124,6 +129,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<scope>runtime</scope> <!-- TODO switch to test once 1227.vdc0a_d1fd4338 or later is widely adopted -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,84 +24,22 @@

package org.jenkinsci.plugins.workflow.steps;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.FilePath;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.workflow.support.steps.FilePathDynamicContext;
import org.kohsuke.stapler.DataBoundConstructor;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
* Temporarily changes the working directory.
* @deprecated Only exists as a placeholder for old running builds; now {@code org.jenkinsci.plugins.workflow.support.steps.PushdStep}.
*/
public class PushdStep extends Step {

private final String path;

@DataBoundConstructor public PushdStep(String path) {
this.path = path;
}

public String getPath() {
return path;
}

@Override public StepExecution start(StepContext context) throws Exception {
return new Execution(path, context);
}

@Extension public static final class DescriptorImpl extends StepDescriptor {

@Override public String getFunctionName() {
return "dir";
}

@NonNull
@Override public String getDisplayName() {
return "Change current directory";
}
@Deprecated
public class PushdStep {

@Override public boolean takesImplicitBlockArgument() {
return true;
}

@Override public Set<? extends Class<?>> getRequiredContext() {
Set<Class<?>> context = new HashSet<>();
Collections.addAll(context, TaskListener.class, FilePath.class);
return Collections.unmodifiableSet(context);
}

@Override public Set<? extends Class<?>> getProvidedContext() {
return Collections.singleton(FilePath.class);
}

}
private PushdStep() {}

public static class Execution extends AbstractStepExecutionImpl {

@SuppressFBWarnings(value="SE_TRANSIENT_FIELD_NOT_RESTORED", justification="Only used when starting.")
private transient final String path;

Execution(String path, StepContext context) {
super(context);
this.path = path;
private Execution() {
throw new AssertionError("only deserialized");
}

@Override public boolean start() throws Exception {
FilePath dir = getContext().get(FilePath.class).child(path);
getContext().get(TaskListener.class).getLogger().println("Running in " + dir);
getContext().newBodyInvoker()
// TODO perhaps should just be moved into workflow-durable-task-step?
.withContext(FilePathDynamicContext.createContextualObject(dir))
// Could use a dedicated BodyExecutionCallback here if we wished to print a message at the end ("Returning to ${cwd}"):
.withCallback(BodyExecutionCallback.wrap(getContext()))
.start();
return false;
throw new AssertionError("only deserialized");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test deserialization of the old execution with this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see testing notes in upstream.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great; It looks like I was reviewing the upstream PR at the same time you were adding the testing notes, so I did not see them before.

}

@Override public void onResume() {}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.