Skip to content

Commit

Permalink
[JENKINS-31999] added Pipeline compatibility for tool-related build s…
Browse files Browse the repository at this point in the history
…teps

- replaced AbstractBuild with Run
- replaced BuildListener with TaskListener
- added new DataBoundConstructor for mandatory parameters
- added DataBoundSetters for optional parameters with defaults
- made custom console logger compatible
  • Loading branch information
cpoenisch committed May 19, 2016
1 parent 68e246d commit 6ef4aa7
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 132 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -94,6 +94,7 @@
<!-- Test scope -->
<equalsverifier.version>1.7.8</equalsverifier.version>
<mockito-core.version>1.10.19</mockito-core.version>
<workflow-aggregator.version>1.4.2</workflow-aggregator.version>
<concurrency>2</concurrency>

<!-- JACOB -->
Expand Down Expand Up @@ -183,6 +184,12 @@
<version>${equalsverifier.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow-aggregator.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 TraceTronic GmbH
* Copyright (c) 2015-2016 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -34,7 +34,7 @@
import hudson.model.InvisibleAction;
import hudson.model.ParameterValue;
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.StringParameterValue;
import hudson.model.listeners.RunListener;

Expand All @@ -57,20 +57,20 @@ public class ToolEnvActionView extends InvisibleAction {

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

private final AbstractBuild<?, ?> build;
private final Run<?, ?> build;
private final transient TaskListener listener;

/**
* Instantiates a new {@link ToolEnvActionView}.
*
* @param build
* @param run
* the build
* @param listener
* the listener
*/
public ToolEnvActionView(final AbstractBuild<?, ?> build, final TaskListener listener) {
public ToolEnvActionView(final Run<?, ?> run, final TaskListener listener) {
super();
this.build = build;
build = run;
this.listener = listener;
}

Expand Down Expand Up @@ -107,10 +107,10 @@ public Set<ParameterValue> getEnvVariables() {
* Listener notifying the build on completion and adding this {@link ToolEnvInvisibleAction} as a new build action.
*/
@Extension
public static final class RunListenerImpl extends RunListener<AbstractBuild<?, ?>> {
public static final class RunListenerImpl extends RunListener<Run<?, ?>> {

@Override
public void onCompleted(final AbstractBuild<?, ?> run, final TaskListener listener) {
public void onCompleted(final Run<?, ?> run, final TaskListener listener) {
if (run.getAction(ToolEnvInvisibleAction.class) != null) {
run.addAction(new ToolEnvActionView(run, listener));
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 TraceTronic GmbH
* Copyright (c) 2015-2016 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -29,7 +29,7 @@
*/
package de.tracetronic.jenkins.plugins.ecutest.log;

import hudson.model.BuildListener;
import hudson.model.TaskListener;

import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -43,7 +43,7 @@
*/
public class TTConsoleLogger {

private final BuildListener listener;
private final TaskListener listener;
private final TTConsoleAnnotator annotator;

/**
Expand All @@ -52,7 +52,7 @@ public class TTConsoleLogger {
* @param listener
* the listener
*/
public TTConsoleLogger(final BuildListener listener) {
public TTConsoleLogger(final TaskListener listener) {
this.listener = listener;
annotator = new TTConsoleAnnotator(this.listener.getLogger());
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 TraceTronic GmbH
* Copyright (c) 2015-2016 TraceTronic GmbH
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -34,7 +34,6 @@
import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleNote;
import hudson.model.Run;

import java.util.Arrays;

Expand All @@ -44,13 +43,12 @@
*
* @author Christian Pönisch <christian.poenisch@tracetronic.de>
*/
public class TTConsoleNote extends ConsoleNote<Run<?, ?>> {
public class TTConsoleNote extends ConsoleNote<Object> {

private static final long serialVersionUID = 1L;

@Override
public ConsoleAnnotator<Run<?, ?>> annotate(final Run<?, ?> context, final MarkupText text,
final int charPos) {
public ConsoleAnnotator<Object> annotate(final Object context, final MarkupText text, final int charPos) {
final String plainText = text.getText();
if (plainText.contains("ERROR:")) {
text.addMarkup(0, text.length(), "<span style=\"font-weight: bold; color:#FF0000\">", "</span>");
Expand Down
Expand Up @@ -30,18 +30,23 @@
package de.tracetronic.jenkins.plugins.ecutest.tool;

import hudson.EnvVars;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.Run;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Builder;

import java.io.IOException;
import java.util.List;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import jenkins.tasks.SimpleBuildStep;

import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundSetter;

import de.tracetronic.jenkins.plugins.ecutest.env.ToolEnvInvisibleAction;
import de.tracetronic.jenkins.plugins.ecutest.tool.installation.AbstractToolInstallation;
Expand All @@ -51,10 +56,23 @@
*
* @author Christian Pönisch <christian.poenisch@tracetronic.de>
*/
public abstract class AbstractToolBuilder extends Builder {
public abstract class AbstractToolBuilder extends Builder implements SimpleBuildStep {

@Nonnull
private final String toolName;
private final String timeout;
@Nonnull
private String timeout = String.valueOf(getDescriptor().getDefaultTimeout());

/**
* Instantiates a {@link AbstractToolBuilder}.
*
* @param toolName
* the tool name
*/
public AbstractToolBuilder(@Nonnull final String toolName) {
super();
this.toolName = toolName;
}

/**
* Instantiates a {@link AbstractToolBuilder}.
Expand All @@ -63,7 +81,9 @@ public abstract class AbstractToolBuilder extends Builder {
* the tool name
* @param timeout
* the timeout
* @deprecated since 1.11 use {@link #AbstractToolBuilder(String)}
*/
@Deprecated
public AbstractToolBuilder(final String toolName, final String timeout) {
super();
this.toolName = toolName;
Expand All @@ -73,26 +93,37 @@ public AbstractToolBuilder(final String toolName, final String timeout) {
/**
* @return the tool name
*/
@Nonnull
public String getToolName() {
return toolName;
}

/**
* @return the timeout
*/
@Nonnull
public String getTimeout() {
return timeout;
}

/**
* @param timeout
* the timeout
*/
@DataBoundSetter
public void setTimeout(@Nonnull final String timeout) {
this.timeout = timeout;
}

/**
* Gets the test identifier by the size of {@link ToolEnvInvisibleAction}s already added to the build.
*
* @param build
* the build
* @param run
* the run
* @return the tool id
*/
protected int getToolId(final AbstractBuild<?, ?> build) {
final List<ToolEnvInvisibleAction> toolEnvActions = build.getActions(ToolEnvInvisibleAction.class);
protected int getToolId(final Run<?, ?> run) {
final List<ToolEnvInvisibleAction> toolEnvActions = run.getActions(ToolEnvInvisibleAction.class);
return toolEnvActions.size();
}

Expand All @@ -110,7 +141,7 @@ protected int getToolId(final AbstractBuild<?, ?> build) {
* if the build gets interrupted
*/
@CheckForNull
protected AbstractToolInstallation configureToolInstallation(final BuildListener listener,
protected AbstractToolInstallation configureToolInstallation(final TaskListener listener,
final EnvVars envVars) throws IOException, InterruptedException {
AbstractToolInstallation installation = getToolInstallation(envVars);
if (installation != null) {
Expand All @@ -132,7 +163,7 @@ protected AbstractToolInstallation configureToolInstallation(final BuildListener
*/
@CheckForNull
public AbstractToolInstallation getToolInstallation(final EnvVars envVars) {
final String expToolName = envVars.expand(toolName);
final String expToolName = envVars.expand(getToolName());
for (final AbstractToolInstallation installation : getDescriptor().getInstallations()) {
if (StringUtils.equals(expToolName, installation.getName())) {
return installation;
Expand All @@ -141,6 +172,11 @@ public AbstractToolInstallation getToolInstallation(final EnvVars envVars) {
return null;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

@Override
public AbstractToolDescriptor getDescriptor() {
return (AbstractToolDescriptor) super.getDescriptor();
Expand Down

0 comments on commit 6ef4aa7

Please sign in to comment.