Skip to content

Commit

Permalink
added @symbol annotation to simplify pipeline syntax
Browse files Browse the repository at this point in the history
- regarding to
https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md#defining-symbols
- can be first used starting with workflow-cps 2.10 and structs 1.3
(JENKINS-29922)
- identically named like the Job DSL extensions
  • Loading branch information
cpoenisch committed Sep 29, 2016
1 parent 369d9cd commit a106a4b
Show file tree
Hide file tree
Showing 26 changed files with 537 additions and 161 deletions.
23 changes: 19 additions & 4 deletions pom.xml
Expand Up @@ -86,6 +86,7 @@
<matrix-project.version>1.4</matrix-project.version>
<junit.version>1.3</junit.version>
<job-dsl.version>1.37</job-dsl.version>
<structs.version>1.5</structs.version>

<!-- Static code analysis -->
<maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
Expand All @@ -94,8 +95,11 @@
<!-- Test scope -->
<equalsverifier.version>2.1.5</equalsverifier.version>
<mockito-core.version>1.10.19</mockito-core.version>
<workflow.version>1.4.2</workflow.version>
<jacoco.version>0.7.7.201606060606</jacoco.version>
<workflow-aggregator.version>1.4.3</workflow-aggregator.version>
<workflow-basic-steps.version>1.4.3</workflow-basic-steps.version>
<workflow-cps.version>1.4.3</workflow-cps.version>
<workflow-step-api.version>1.4.3</workflow-step-api.version>
<concurrency>2</concurrency>

<!-- JACOB -->
Expand Down Expand Up @@ -172,6 +176,11 @@
<artifactId>xstream</artifactId>
<version>1.4.7-jenkins-1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>${structs.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -193,19 +202,25 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<version>${workflow-aggregator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>${workflow-basic-steps.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow.version}</version>
<version>${workflow-cps.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<version>${workflow-step-api.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
Expand Up @@ -59,6 +59,7 @@
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -236,7 +237,7 @@ public void performReport(final Run<?, ?> run, final FilePath workspace, final L
*/
private boolean publishReports(final ATXInstallation installation, final Run<?, ?> run,
final Launcher launcher, final TaskListener listener)
throws IOException, InterruptedException {
throws IOException, InterruptedException {
final TTConsoleLogger logger = new TTConsoleLogger(listener);
final boolean isUploadEnabled = isUploadEnabled(installation);
final boolean isServerReachable = isServerReachable(installation, launcher, run.getEnvironment(listener));
Expand Down Expand Up @@ -357,6 +358,7 @@ public String getUrlName() {
* DescriptorImpl for {@link ATXPublisher}.
*/
@SuppressWarnings("rawtypes")
@Symbol("publishATX")
@Extension(ordinal = 1004)
public static class DescriptorImpl extends AbstractReportDescriptor {

Expand Down
Expand Up @@ -46,6 +46,7 @@
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

Expand Down Expand Up @@ -409,6 +410,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link ReportGeneratorPublisher}.
*/
@Symbol("publishGenerators")
@Extension(ordinal = 1001)
public static class DescriptorImpl extends AbstractReportDescriptor {

Expand Down
Expand Up @@ -54,6 +54,7 @@

import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -367,6 +368,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link JUnitPublisher}.
*/
@Symbol("publishUNIT")
@Extension(ordinal = 1002)
public static final class DescriptorImpl extends AbstractReportDescriptor {

Expand Down
Expand Up @@ -47,6 +47,7 @@

import jenkins.MasterToSlaveFileCallable;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

Expand Down Expand Up @@ -432,7 +433,7 @@ private int traverseReports(final List<ETLogReport> logReports, final FilePath a
*/
private int traverseSubReports(final ETLogReport logReport, final FilePath testReportDir,
final FilePath subTestReportDir, int id)
throws IOException, InterruptedException {
throws IOException, InterruptedException {
for (final FilePath subDir : subTestReportDir.listDirectories()) {
FilePath logFile = subDir.child(ERROR_LOG_NAME);
if (logFile.exists()) {
Expand Down Expand Up @@ -625,7 +626,7 @@ private static final class ListFilesCallable extends MasterToSlaveFileCallable<L

@Override
public List<String> invoke(final File baseDir, final VirtualChannel channel) throws IOException,
InterruptedException {
InterruptedException {
final List<String> files = new ArrayList<String>();
for (final String includedFile : Util.createFileSet(baseDir, includes, excludes)
.getDirectoryScanner().getIncludedFiles()) {
Expand All @@ -644,6 +645,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link ETLogPublisher}.
*/
@Symbol("publishETLogs")
@Extension(ordinal = 1000)
public static final class DescriptorImpl extends AbstractReportDescriptor {

Expand Down
Expand Up @@ -41,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import de.tracetronic.jenkins.plugins.ecutest.env.TestEnvInvisibleAction;
Expand Down Expand Up @@ -276,6 +277,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link TRFPublisher}.
*/
@Symbol("publishTRF")
@Extension(ordinal = 1003)
public static final class DescriptorImpl extends AbstractReportDescriptor {

Expand Down
Expand Up @@ -46,6 +46,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -351,6 +352,7 @@ private List<String> scanProjects(final String testFolder, final Launcher launch
/**
* DescriptorImpl for {@link TestFolderBuilder}.
*/
@Symbol("testFolder")
@Extension(ordinal = 1000)
public static final class DescriptorImpl extends AbstractTestDescriptor {

Expand Down
Expand Up @@ -42,6 +42,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -142,6 +143,7 @@ protected boolean runTest(final String testFile, final TestConfig testConfig,
/**
* DescriptorImpl for {@link TestPackageBuilder}.
*/
@Symbol("testPackage")
@Extension(ordinal = 1002)
public static final class DescriptorImpl extends AbstractTestDescriptor {

Expand Down
Expand Up @@ -42,6 +42,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -142,6 +143,7 @@ protected boolean runTest(final String testFile, final TestConfig testConfig,
/**
* DescriptorImpl for {@link TestProjectBuilder}.
*/
@Symbol("testProject")
@Extension(ordinal = 1001)
public static final class DescriptorImpl extends AbstractTestDescriptor {

Expand Down
Expand Up @@ -45,6 +45,7 @@
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -262,7 +263,7 @@ public void performTool(final Run<?, ?> run, final FilePath workspace, final Lau
* in case of an invalid workspace
*/
private void checkWorkspace(final FilePath workspacePath, final FilePath settingsPath) throws IOException,
InterruptedException, ETPluginException {
InterruptedException, ETPluginException {
if (!workspacePath.exists()) {
throw new ETPluginException(String.format("ECU-TEST workspace at %s does not exist!",
workspacePath.getRemote()));
Expand All @@ -278,6 +279,7 @@ private void checkWorkspace(final FilePath workspacePath, final FilePath setting
/**
* DescriptorImpl for {@link StartETBuilder}.
*/
@Symbol("startET")
@Extension(ordinal = 1006)
public static final class DescriptorImpl extends AbstractToolDescriptor {

Expand Down
Expand Up @@ -44,6 +44,7 @@
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -191,6 +192,7 @@ public void performTool(final Run<?, ?> run, final FilePath workspace, final Lau
/**
* DescriptorImpl for {@link StartTSBuilder}.
*/
@Symbol("startTS")
@Extension(ordinal = 1004)
public static final class DescriptorImpl extends AbstractToolDescriptor {

Expand Down
Expand Up @@ -41,6 +41,7 @@
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import de.tracetronic.jenkins.plugins.ecutest.ETPluginException;
Expand Down Expand Up @@ -114,6 +115,7 @@ public void performTool(final Run<?, ?> run, final FilePath workspace, final Lau
/**
* DescriptorImpl for {@link StopETBuilder}.
*/
@Symbol("stopET")
@Extension(ordinal = 1005)
public static final class DescriptorImpl extends AbstractToolDescriptor {

Expand Down
Expand Up @@ -41,6 +41,7 @@
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import de.tracetronic.jenkins.plugins.ecutest.ETPluginException;
Expand Down Expand Up @@ -109,6 +110,7 @@ public void performTool(final Run<?, ?> run, final FilePath workspace, final Lau
/**
* DescriptorImpl for {@link StopTSBuilder}.
*/
@Symbol("stopTS")
@Extension(ordinal = 1003)
public static final class DescriptorImpl extends AbstractToolDescriptor {

Expand Down
Expand Up @@ -29,11 +29,23 @@
*/
package de.tracetronic.jenkins.plugins.ecutest;

import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeThat;
import hudson.Functions;
import hudson.model.Label;
import hudson.slaves.DumbSlave;
import hudson.slaves.SlaveComputer;
import hudson.util.VersionNumber;

import java.io.File;
import java.net.URLConnection;

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

import org.junit.Before;
import org.junit.Rule;
import org.jvnet.hudson.test.JenkinsRule;
Expand Down Expand Up @@ -95,4 +107,51 @@ protected WebClient getWebClient() {
webClient.setCssErrorHandler(new QuietCssErrorHandler());
return webClient;
}

/**
* Creates a dumb slave and assumes that it runs on a Windows machine.
*
* @return the dumb slave
* @throws Exception
* signals that an exception has occurred
*/
protected DumbSlave assumeWindowsSlave() throws Exception {
// Windows only
final DumbSlave slave = jenkins.createOnlineSlave(Label.get("slaves"));
final SlaveComputer computer = slave.getComputer();
assumeFalse("Test is Windows only!", computer.isUnix());
return slave;
}

/**
* To use the @Symbol annotation in tests, minimum workflow-cps version 2.10 is required.
* This dependency comes with other dependency version requirements, as stated by this method.
* To run tests restricted by this method, type
*
* <pre>
* mvn clean install -Djenkins.version=1.642.1 -Djava.level=7 -Dworkflow-aggregator.version=2.3 -Dworkflow-basic-steps.version=2.1 -Dworkflow-cps.version=2.10 -Dworkflow-step-api.version=2.3
* </pre>
*/
protected static void assumeSymbolDependencies() {
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("jenkins.version"), "1.642.1");
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("java.level"), "7");
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("workflow-aggregator.version"), "2.3");
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("workflow-basic-steps.version"), "2.1");
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("workflow-cps.version"), "2.10");
assumePropertyIsGreaterThanOrEqualTo(System.getProperty("workflow-step-api.version"), "2.3");
}

/**
* Checks if the given property is not null, and if it's greater than or equal to the given version.
*
* @param property
* the property to be checked
* @param version
* the version on which the property is checked against
*/
private static void assumePropertyIsGreaterThanOrEqualTo(@CheckForNull final String property,
@Nonnull final String version) {
assertNotNull("Property should exist", property);
assumeThat(new VersionNumber(property).compareTo(new VersionNumber(version)), is(greaterThanOrEqualTo(0)));
}
}

0 comments on commit a106a4b

Please sign in to comment.