Skip to content
Permalink
Browse files

[JENKINS-31999] added Pipeline compatibility for report publishers

- replaced AbstractBuild with Run
- replaced BuildListener with TaskListener
- added new DataBoundConstructor for mandatory parameters
- added DataBoundSetters for optional parameters with defaults
- implied project actions by implementing
SimpleBuildStep.LastBuildAction
  • Loading branch information...
cpoenisch committed May 23, 2016
1 parent c883004 commit 19baf576b578d65e18ff800ed45ef3f91ba61307
Showing with 579 additions and 416 deletions.
  1. +3 −3 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/AbstractArchiveFileReport.java
  2. +6 −6 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/AbstractReportAction.java
  3. +90 −54 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/AbstractReportPublisher.java
  4. +12 −10 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/AbstractRequestHandler.java
  5. +2 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/AbstractTestReport.java
  6. +12 −1 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXBuildAction.java
  7. +2 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXProjectAction.java
  8. +47 −37 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisher.java
  9. +2 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXReport.java
  10. +16 −17 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXReportGenerator.java
  11. +19 −20 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXReportUploader.java
  12. +4 −5 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/AbstractATXAction.java
  13. +4 −4 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/AbstractATXReportHandler.java
  14. +4 −5 ...n/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/AbstractReportGeneratorAction.java
  15. +4 −4 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGenerator.java
  16. +11 −1 ...main/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorBuildAction.java
  17. +2 −2 ...in/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorProjectAction.java
  18. +72 −43 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/generator/ReportGeneratorPublisher.java
  19. +64 −42 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitPublisher.java
  20. +19 −19 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitReportGenerator.java
  21. +11 −14 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitTestResultParser.java
  22. +4 −5 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/log/AbstractETLogAction.java
  23. +10 −1 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogBuildAction.java
  24. +2 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogProjectAction.java
  25. +92 −63 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/log/ETLogPublisher.java
  26. +4 −5 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/AbstractTRFAction.java
  27. +10 −1 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFBuildAction.java
  28. +2 −2 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFProjectAction.java
  29. +31 −29 src/main/java/de/tracetronic/jenkins/plugins/ecutest/report/trf/TRFPublisher.java
  30. +1 −0 src/main/java/de/tracetronic/jenkins/plugins/ecutest/test/TestFolderBuilder.java
  31. +1 −1 src/main/resources/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisher/config.jelly
  32. +1 −1 ...t/java/de/tracetronic/jenkins/plugins/ecutest/extension/jobdsl/ReportPublisherDslExtensionST.java
  33. +1 −1 ...acetronic/jenkins/plugins/ecutest/extension/jobdsl/ReportPublisherParamInstallDslExtensionST.java
  34. +1 −1 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/atx/ATXPublisherTest.java
  35. +13 −11 src/test/java/de/tracetronic/jenkins/plugins/ecutest/report/junit/JUnitTestResultParserST.java
@@ -29,7 +29,7 @@
*/
package de.tracetronic.jenkins.plugins.ecutest.report;

import hudson.model.AbstractBuild;
import hudson.model.Run;

import java.io.File;
import java.io.IOException;
@@ -117,7 +117,7 @@ protected VirtualFile getArchiveTargetDir(final File rootDir) {
* if serving the file failed
*/
public void doDynamic(final StaplerRequest req, final StaplerResponse rsp) throws IOException, ServletException {
final AbstractBuild<?, ?> build = getBuild(req);
final Run<?, ?> build = getBuild(req);
final AbstractReportAction action = getBuildAction(req);
if (build == null || action == null) {
LOGGER.warning(String.format("No build or related action found for url %s", req.getRequestURI()));
@@ -126,7 +126,7 @@ public void doDynamic(final StaplerRequest req, final StaplerResponse rsp) throw
}

final boolean isProjectLevel = action.isProjectLevel();
final File rootDir = isProjectLevel ? build.getProject().getRootDir() : build.getRootDir();
final File rootDir = isProjectLevel ? build.getParent().getRootDir() : build.getRootDir();
final File archiveFile = new File(new File(rootDir, getArchiveDir()), getFileName());
if (!archiveFile.exists()) {
LOGGER.warning(String.format("Archive file does not exists: %s for %s", getFileName(),
@@ -31,8 +31,8 @@

import hudson.PluginWrapper;
import hudson.model.Action;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;

import java.io.File;
import java.net.URISyntaxException;
@@ -82,13 +82,13 @@ public boolean isProjectLevel() {
}

@Override
public AbstractBuild<?, ?> getBuild(final StaplerRequest req) {
final AbstractBuild<?, ?> build = getAnchestorBuild(req);
public Run<?, ?> getBuild(final StaplerRequest req) {
final Run<?, ?> build = getAnchestorBuild(req);
if (build != null) {
return build;
}

final AbstractProject<?, ?> project = getAnchestorProject(req);
final Job<?, ?> project = getAnchestorProject(req);
if (project != null) {
return getLastReportBuild(project);
}
@@ -109,7 +109,7 @@ protected VirtualFile getArchiveTargetDir(final File rootDir) {
* @return the last build with report artifacts or {@code null} if no proper build exists
*/
@CheckForNull
protected abstract AbstractBuild<?, ?> getLastReportBuild(final AbstractProject<?, ?> project);
protected abstract Run<?, ?> getLastReportBuild(final Job<?, ?> project);

/**
* Gets the icon path inside of this plugin.
@@ -32,14 +32,9 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.Run;
@@ -50,15 +45,14 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.model.Jenkins;
import jenkins.tasks.SimpleBuildStep;

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

import de.tracetronic.jenkins.plugins.ecutest.env.TestEnvInvisibleAction;
import de.tracetronic.jenkins.plugins.ecutest.env.ToolEnvInvisibleAction;
@@ -75,24 +69,29 @@
* @author Christian Pönisch <christian.poenisch@tracetronic.de>
*/
@SuppressWarnings("unchecked")
public abstract class AbstractReportPublisher extends Recorder {
public abstract class AbstractReportPublisher extends Recorder implements SimpleBuildStep {

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

private final boolean allowMissing;
private final boolean runOnFailed;
private boolean allowMissing;
private boolean runOnFailed;
/**
* {@code Boolean} type is required to retain backward compatibility with default value {@code true}.
*
* @since 1.9
*/
private final Boolean archiving;
private Boolean archiving = true;
/**
* {@code Boolean} type is required to retain backward compatibility with default value {@code true}.
*
* @since 1.9
*/
private final Boolean keepAll;
private Boolean keepAll = true;

/**
* Instantiates a new {@link AbstractReportPublisher}.
*/
public AbstractReportPublisher() {
super();
}

/**
* Instantiates a new {@link AbstractReportPublisher}.
@@ -172,26 +171,63 @@ public boolean getKeepAll() {
return keepAll;
}

@Override
public abstract Action getProjectAction(final AbstractProject<?, ?> project);
/**
* @param allowMissing
* specifies whether missing reports are allowed
*/
@DataBoundSetter
public void setAllowMissing(final boolean allowMissing) {
this.allowMissing = allowMissing;
}

@Override
public Collection<? extends Action> getProjectActions(final AbstractProject<?, ?> project) {
final ArrayList<Action> actions = new ArrayList<Action>();
actions.add(getProjectAction(project));
if (project instanceof MatrixProject && ((MatrixProject) project).getActiveConfigurations() != null) {
for (final MatrixConfiguration mc : ((MatrixProject) project).getActiveConfigurations()) {
try {
mc.onLoad(mc.getParent(), mc.getName());
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, "Could not reload the matrix configuration");
}
}
}
/**
* @param runOnFailed
* specifies whether this publisher even runs on a failed build
*/
@DataBoundSetter
public void setRunOnFailed(final boolean runOnFailed) {
this.runOnFailed = runOnFailed;
}

return actions;
/**
* @param archiving
* specifies whether archiving artifacts is enabled
*/
@DataBoundSetter
public void setArchiving(final boolean archiving) {
this.archiving = archiving;
}

/**
* @param keepAll
* specifies whether artifacts are archived for all successful builds,
* otherwise only the most recent
*/
@DataBoundSetter
public void setKeepAll(final boolean keepAll) {
this.keepAll = keepAll;
}

// @Override
// public abstract Action getProjectAction(final AbstractProject<?, ?> project);
//
// @Override
// public Collection<? extends Action> getProjectActions(final AbstractProject<?, ?> project) {
// final ArrayList<Action> actions = new ArrayList<Action>();
// actions.add(getProjectAction(project));
// if (project instanceof MatrixProject && ((MatrixProject) project).getActiveConfigurations() != null) {
// for (final MatrixConfiguration mc : ((MatrixProject) project).getActiveConfigurations()) {
// try {
// mc.onLoad(mc.getParent(), mc.getName());
// } catch (final IOException e) {
// LOGGER.log(Level.SEVERE, "Could not reload the matrix configuration");
// }
// }
// }
//
// return actions;
// }

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
@@ -202,7 +238,7 @@ public BuildStepMonitor getRequiredMonitorService() {
* is set or if the build is not aborted or failed.
*
* @param result
* the build result
* the run result
* @return {@code true} if the build can continue
*/
protected boolean canContinue(final Result result) {
@@ -229,7 +265,7 @@ protected boolean canContinue(final Result result) {
* if the build gets interrupted
*/
protected AbstractToolInstallation configureToolInstallation(final String toolName,
final BuildListener listener, final EnvVars envVars) throws IOException, InterruptedException {
final TaskListener listener, final EnvVars envVars) throws IOException, InterruptedException {
AbstractToolInstallation installation = getToolInstallation(toolName, envVars);

if (installation != null) {
@@ -269,13 +305,13 @@ public ETInstallation getToolInstallation(final String toolName, final EnvVars e
/**
* Gets the workspace directory, either previous ECU-TEST workspace or default one.
*
* @param build
* the build
* @param run
* the run
* @return the workspace directory
*/
protected String getWorkspaceDir(final AbstractBuild<?, ?> build) {
protected String getWorkspaceDir(final Run<?, ?> run) {
String workspaceDir = "";
final ToolEnvInvisibleAction toolEnvAction = build.getAction(ToolEnvInvisibleAction.class);
final ToolEnvInvisibleAction toolEnvAction = run.getAction(ToolEnvInvisibleAction.class);
if (toolEnvAction != null) {
workspaceDir = toolEnvAction.getToolWorkspace();
}
@@ -285,13 +321,13 @@ protected String getWorkspaceDir(final AbstractBuild<?, ?> build) {
/**
* Gets the settings directory, either previous ECU-TEST settings or default one.
*
* @param build
* the build
* @param run
* the run
* @return the settings directory
*/
protected String getSettingsDir(final AbstractBuild<?, ?> build) {
protected String getSettingsDir(final Run<?, ?> run) {
String settingsDir = "";
final ToolEnvInvisibleAction toolEnvAction = build.getAction(ToolEnvInvisibleAction.class);
final ToolEnvInvisibleAction toolEnvAction = run.getAction(ToolEnvInvisibleAction.class);
if (toolEnvAction != null) {
settingsDir = toolEnvAction.getToolSettings();
}
@@ -301,12 +337,12 @@ protected String getSettingsDir(final AbstractBuild<?, ?> build) {
/**
* Gets the archive target.
*
* @param build
* the build
* @param run
* the run
* @return the archive target
*/
protected FilePath getArchiveTarget(final AbstractBuild<?, ?> build) {
return new FilePath(isKeepAll() ? getBuildArchiveDir(build) : getProjectArchiveDir(build.getParent()));
protected FilePath getArchiveTarget(final Run<?, ?> run) {
return new FilePath(isKeepAll() ? getBuildArchiveDir(run) : getProjectArchiveDir(run.getParent()));
}

/**
@@ -342,8 +378,8 @@ private File getBuildArchiveDir(final Run<?, ?> run) {
* Builds a list of report files for report generation.
* Includes the report files generated during separate sub-project execution.
*
* @param build
* the build
* @param run
* the run
* @param launcher
* the launcher
* @return the list of report files
@@ -352,10 +388,10 @@ private File getBuildArchiveDir(final Run<?, ?> run) {
* @throws InterruptedException
* if the build gets interrupted
*/
protected List<FilePath> getReportFiles(final AbstractBuild<?, ?> build, final Launcher launcher)
protected List<FilePath> getReportFiles(final Run<?, ?> run, final Launcher launcher)
throws IOException, InterruptedException {
final List<FilePath> reportFiles = new ArrayList<FilePath>();
final List<TestEnvInvisibleAction> testEnvActions = build.getActions(TestEnvInvisibleAction.class);
final List<TestEnvInvisibleAction> testEnvActions = run.getActions(TestEnvInvisibleAction.class);
for (final TestEnvInvisibleAction testEnvAction : testEnvActions) {
final FilePath testReportDir = new FilePath(launcher.getChannel(), testEnvAction.getTestReportDir());
if (testReportDir.exists()) {
@@ -369,17 +405,17 @@ private File getBuildArchiveDir(final Run<?, ?> run) {
/**
* Removes the report actions from all previous builds which published at project level.
*
* @param build
* the build
* @param run
* the run
* @param clazz
* the report action class to remove
* @throws IOException
* signals that an I/O exception has occurred
*/
@SuppressWarnings("deprecation")
public static void removePreviousReports(final AbstractBuild<?, ?> build,
public static void removePreviousReports(final Run<?, ?> run,
final Class<? extends AbstractReportAction> clazz) throws IOException {
AbstractBuild<?, ?> prevBuild = build.getPreviousBuild();
Run<?, ?> prevBuild = run.getPreviousBuild();
while (prevBuild != null) {
final AbstractReportAction buildAction = prevBuild.getAction(clazz);
if (buildAction != null && buildAction.isProjectLevel()) {

0 comments on commit 19baf57

Please sign in to comment.
You can’t perform that action at this time.