Skip to content

Commit

Permalink
Merge branch 'master' into eager-load-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
svanoort committed Nov 11, 2016
2 parents f25a451 + e05ab12 commit 532d76d
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 70 deletions.
29 changes: 14 additions & 15 deletions pom.xml
Expand Up @@ -28,12 +28,12 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.11</version>
<version>2.17</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Pipeline: Supporting APIs</name>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Supporting+APIs+Plugin</url>
Expand Down Expand Up @@ -63,18 +63,17 @@
</pluginRepositories>
<properties>
<jenkins.version>1.642.3</jenkins.version>
<jenkins-test-harness.version>2.11</jenkins-test-harness.version>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.2</version>
<version>2.4</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.4</version>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -84,12 +83,12 @@
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<version>1.4.9.Final</version>
<version>1.4.9.Final</version> <!-- TODO JENKINS-32986 need 1.4.12.Final when released to pick up JBMAR-189 https://github.com/jboss-remoting/jboss-marshalling/pull/48 -->
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.2</version>
<version>2.4</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand All @@ -108,13 +107,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.1</version>
<version>1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.9</version>
<version>2.20</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -126,19 +125,19 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.3</version>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>1.15</version>
<version>2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>1.15</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -149,7 +149,12 @@ public AnnotatedLargeText<? extends FlowNode> getLogText() {
*/
private static boolean isRunning(FlowNode node) {
if (node instanceof BlockStartNode) {
return new LinearBlockHoppingScanner().findFirstMatch(node.getExecution().getCurrentHeads(), Predicates.equalTo(node)) != null;
for (FlowNode head : node.getExecution().getCurrentHeads()) {
if (new LinearBlockHoppingScanner().findFirstMatch(head, Predicates.equalTo(node)) != null) {
return true;
}
}
return false;
} else {
return node.isRunning();
}
Expand Down
Expand Up @@ -25,6 +25,7 @@

import hudson.model.Action;
import hudson.model.InvisibleAction;
import org.jenkinsci.plugins.workflow.actions.PersistentAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;

import java.io.IOException;
Expand All @@ -41,7 +42,7 @@
*
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class PauseAction extends InvisibleAction {
public class PauseAction extends InvisibleAction implements PersistentAction {

private static final Logger LOGGER = Logger.getLogger(PauseAction.class.getName());

Expand Down
@@ -0,0 +1,120 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.workflow.support.actions;

import com.google.inject.Inject;
import hudson.EnvVars;
import hudson.model.TaskListener;
import java.util.LinkedList;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.Rule;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

public class LogActionImplTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();

@Test public void logsAndBlocks() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition("parallel a: {chatty('LBBL') {echo(/atom step in A with $remaining commands to go/)}}, b: {chatty('BL') {echo(/atom step in B with $remaining commands to go/)}}", true));
WorkflowRun b = r.buildAndAssertSuccess(p);
r.assertLogContains("logging from LBBL with 3 commands to go", b);
r.assertLogContains("atom step in A with 2 commands to go", b);
r.assertLogContains("atom step in A with 1 commands to go", b);
r.assertLogContains("logging from LBBL with 0 commands to go", b);
r.assertLogContains("atom step in B with 1 commands to go", b);
/* TODO misuse of FlowNode.isRunning in WorkflowRun.copyLogs prevents this from appearing unless we access TaskListener from start(); should be fixed by JENKINS-38381:
r.assertLogContains("logging from BL with 0 commands to go", b);
*/
}
public static class ChattyStep extends AbstractStepImpl {
public final String pattern;
@DataBoundConstructor public ChattyStep(String pattern) {this.pattern = pattern;}
@TestExtension("logsAndBlocks") public static class DescriptorImpl extends AbstractStepDescriptorImpl {
public DescriptorImpl() {
super(Execution.class);
}
@Override public String getFunctionName() {return "chatty";}
@Override public boolean takesImplicitBlockArgument() {return true;}
}
public static class Execution extends AbstractStepExecutionImpl {
@Inject(optional=true) transient ChattyStep step;
String pattern;
LinkedList<Boolean> commands; // L ~ false to log, B ~ true to run block
@Override public boolean start() throws Exception {
commands = new LinkedList<>();
pattern = step.pattern;
for (char c : pattern.toCharArray()) {
if (c == 'L') {
commands.add(false);
} else {
assert c == 'B';
commands.add(true);
}
}
run();
return false;
}
private void run() throws Exception {
StepContext context = getContext();
if (commands.isEmpty()) {
context.onSuccess(null);
} else if (commands.pop()) {
context.newBodyInvoker().withCallback(new Callback()).withContext(new EnvVars("remaining", Integer.toString(commands.size()))).start();
} else {
context.get(TaskListener.class).getLogger().println("logging from " + pattern + " with " + commands.size() + " commands to go");
run();
}
}
@Override public void stop(Throwable cause) throws Exception {}
private final class Callback extends BodyExecutionCallback {
@Override public void onSuccess(StepContext context, Object result) {
try {
run();
} catch (Exception x) {
context.onFailure(x);
}
}
@Override public void onFailure(StepContext context, Throwable t) {
context.onFailure(t);
}
}
}
}

}

This file was deleted.

0 comments on commit 532d76d

Please sign in to comment.