Permalink
Browse files

added @symbol annotation to simplify pipeline syntax

- 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 a106a4bde217c6b907bfee4ba14c6569ebf333ae
Showing with 537 additions and 161 deletions.
  1. +19 −4 pom.xml
  2. +3 −1 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisher.java
  3. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorPublisher.java
  4. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitPublisher.java
  5. +4 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogPublisher.java
  6. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFPublisher.java
  7. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/test/TestFolderBuilder.java
  8. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/test/TestPackageBuilder.java
  9. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/test/TestProjectBuilder.java
  10. +3 −1 src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartETBuilder.java
  11. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartTSBuilder.java
  12. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopETBuilder.java
  13. +2 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopTSBuilder.java
  14. +59 −0 src/test/java/de/tracetronic/jenkins/plugins/ecutest/SystemTestBase.java
  15. +50 −22 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisherST.java
  16. +49 −20 ...test/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorPublisherST.java
  17. +52 −24 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitPublisherST.java
  18. +48 −12 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogPublisherST.java
  19. +45 −12 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFPublisherST.java
  20. +28 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestFolderBuilderST.java
  21. +28 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestPackageBuilderST.java
  22. +28 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/test/TestProjectBuilderST.java
  23. +28 −11 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartETBuilderST.java
  24. +29 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StartTSBuilderST.java
  25. +23 −9 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopETBuilderST.java
  26. +23 −8 src/test/java/de/tracetronic/jenkins/plugins/ecutest/tool/StopTSBuilderST.java
23 pom.xml
@@ -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>
@@ -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 -->
@@ -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>
@@ -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>
@@ -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;
@@ -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));
@@ -357,6 +358,7 @@ public String getUrlName() {
* DescriptorImpl for {@link ATXPublisher}.
*/
@SuppressWarnings("rawtypes")
@Symbol("publishATX")
@Extension(ordinal = 1004)
public static class DescriptorImpl extends AbstractReportDescriptor {

@@ -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;

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

@@ -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;
@@ -367,6 +368,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link JUnitPublisher}.
*/
@Symbol("publishUNIT")
@Extension(ordinal = 1002)
public static final class DescriptorImpl extends AbstractReportDescriptor {

@@ -47,6 +47,7 @@

import jenkins.MasterToSlaveFileCallable;

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

@@ -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()) {
@@ -625,7 +626,7 @@ private void setBuildResult(final Run<?, ?> run, final TaskListener listener,

@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()) {
@@ -644,6 +645,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link ETLogPublisher}.
*/
@Symbol("publishETLogs")
@Extension(ordinal = 1000)
public static final class DescriptorImpl extends AbstractReportDescriptor {

@@ -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;
@@ -276,6 +277,7 @@ protected String getUrlName() {
/**
* DescriptorImpl for {@link TRFPublisher}.
*/
@Symbol("publishTRF")
@Extension(ordinal = 1003)
public static final class DescriptorImpl extends AbstractReportDescriptor {

@@ -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;
@@ -351,6 +352,7 @@ protected boolean runTest(final String testFolder, final TestConfig testConfig,
/**
* DescriptorImpl for {@link TestFolderBuilder}.
*/
@Symbol("testFolder")
@Extension(ordinal = 1000)
public static final class DescriptorImpl extends AbstractTestDescriptor {

@@ -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;
@@ -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 {

@@ -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;
@@ -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 {

@@ -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;
@@ -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()));
@@ -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 {

@@ -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;
@@ -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 {

@@ -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;
@@ -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 {

@@ -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;
@@ -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 {

@@ -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;
@@ -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)));
}
}
Oops, something went wrong.

0 comments on commit a106a4b

Please sign in to comment.