diff --git a/pom.xml b/pom.xml index df9d632..37a55c1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 1.532.3 + 1.580 rubyMetrics @@ -62,8 +62,8 @@ scm:git:git://github.com/jenkinsci/rubymetrics-plugin.git scm:git:git@github.com:jenkinsci/rubymetrics-plugin.git https://github.com/jenkins/rubymetrics-plugin - HEAD - + HEAD + diff --git a/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsBuildAction.java b/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsBuildAction.java index e75db13..f877f84 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsBuildAction.java +++ b/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsBuildAction.java @@ -1,9 +1,6 @@ package hudson.plugins.rubyMetrics; -import hudson.model.AbstractBuild; -import hudson.model.HealthReport; -import hudson.model.HealthReportingAction; -import hudson.model.Result; +import hudson.model.*; import hudson.util.ChartUtil; import hudson.util.ColorPalette; import hudson.util.DataSetBuilder; @@ -30,14 +27,14 @@ @SuppressWarnings("unchecked") public abstract class AbstractRubyMetricsBuildAction implements HealthReportingAction { - protected final AbstractBuild owner; + protected final Run owner; - protected AbstractRubyMetricsBuildAction(AbstractBuild owner) { + protected AbstractRubyMetricsBuildAction(Run owner) { this.owner = owner; } public T getPreviousResult() { - AbstractBuild b = owner; + Run b = owner; while (true) { b = b.getPreviousBuild(); if (b == null) @@ -126,7 +123,7 @@ private JFreeChart createChart(CategoryDataset dataset, String rangeAxisLabel) { return chart; } - public AbstractBuild getOwner() { + public Run getOwner() { return owner; } diff --git a/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsPublisher.java b/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsPublisher.java index 6e4cf3c..6773cd3 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsPublisher.java +++ b/src/main/java/hudson/plugins/rubyMetrics/AbstractRubyMetricsPublisher.java @@ -1,16 +1,14 @@ package hudson.plugins.rubyMetrics; -import hudson.model.AbstractBuild; -import hudson.model.BuildListener; -import hudson.model.Result; +import hudson.model.*; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Recorder; public abstract class AbstractRubyMetricsPublisher extends Recorder { - protected boolean fail(AbstractBuild build, BuildListener listener, String message) { + protected boolean fail(Run run, TaskListener listener, String message) { listener.getLogger().println(message); - build.setResult(Result.FAILURE); + run.setResult(Result.FAILURE); return true; } diff --git a/src/main/java/hudson/plugins/rubyMetrics/HtmlParser.java b/src/main/java/hudson/plugins/rubyMetrics/HtmlParser.java index 4521a2d..8ef1741 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/HtmlParser.java +++ b/src/main/java/hudson/plugins/rubyMetrics/HtmlParser.java @@ -1,6 +1,7 @@ package hudson.plugins.rubyMetrics; import hudson.model.BuildListener; +import hudson.model.TaskListener; import org.htmlparser.Node; import org.htmlparser.Parser; import org.htmlparser.Text; @@ -19,7 +20,7 @@ public abstract class HtmlParser { protected static final String CLASS_ATTR_NAME = "class"; protected final File rootFilePath; - protected BuildListener listener; + protected TaskListener listener; public HtmlParser(File rootFilePath) { this.rootFilePath = rootFilePath; diff --git a/src/main/java/hudson/plugins/rubyMetrics/HtmlPublisher.java b/src/main/java/hudson/plugins/rubyMetrics/HtmlPublisher.java index 2366dad..eb6d826 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/HtmlPublisher.java +++ b/src/main/java/hudson/plugins/rubyMetrics/HtmlPublisher.java @@ -1,9 +1,7 @@ package hudson.plugins.rubyMetrics; import hudson.FilePath; -import hudson.model.AbstractBuild; -import hudson.model.BuildListener; -import hudson.model.Result; +import hudson.model.*; import java.io.File; import java.io.FilenameFilter; @@ -18,31 +16,29 @@ public String getReportDir() { return reportDir; } - protected boolean prepareMetricsReportBeforeParse(AbstractBuild build, BuildListener listener, + protected boolean prepareMetricsReportBeforeParse(Run run, FilePath workspace, TaskListener listener, FilenameFilter indexFilter, String toolShortName) throws InterruptedException { - if (build.getResult() == Result.FAILURE) { + if (run.getResult() == Result.FAILURE) { listener.getLogger().println("Build failed, skipping " + toolShortName + " coverage report"); return true; } listener.getLogger().println("Publishing " + toolShortName + " report..."); - final FilePath workspace = build.getModuleRoot(); - - boolean copied = moveReportsToBuildRootDir(workspace, build.getRootDir(), listener, reportDir, "**/*"); + boolean copied = moveReportsToBuildRootDir(workspace, run.getRootDir(), listener, reportDir, "**/*"); if (!copied) { - build.setResult(Result.FAILURE); - return fail(build, listener, toolShortName + " report directory wasn't found using the pattern '" + reportDir + "'."); + run.setResult(Result.FAILURE); + return fail(run, listener, toolShortName + " report directory wasn't found using the pattern '" + reportDir + "'."); } - File[] coverageFiles = build.getRootDir().listFiles(indexFilter); + File[] coverageFiles = run.getRootDir().listFiles(indexFilter); if (coverageFiles == null || coverageFiles.length == 0) { - return fail(build, listener, toolShortName + " report index file wasn't found"); + return fail(run, listener, toolShortName + " report index file wasn't found"); } return true; } - protected File[] getCoverageFiles(AbstractBuild build, FilenameFilter indexFilter) { - return build.getRootDir().listFiles(indexFilter); + protected File[] getCoverageFiles(Run run, FilenameFilter indexFilter) { + return run.getRootDir().listFiles(indexFilter); } } diff --git a/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovBuildAction.java b/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovBuildAction.java index 546febb..939ff5b 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovBuildAction.java +++ b/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovBuildAction.java @@ -2,6 +2,7 @@ import hudson.model.AbstractBuild; import hudson.model.HealthReport; +import hudson.model.Run; import hudson.plugins.rubyMetrics.AbstractRubyMetricsBuildAction; import hudson.plugins.rubyMetrics.rcov.model.*; import hudson.util.ChartUtil; @@ -17,7 +18,7 @@ public class RcovBuildAction extends AbstractRubyMetricsBuildAction { private final RcovResult results; private final List targets; - public RcovBuildAction(AbstractBuild owner, RcovResult results, List targets) { + public RcovBuildAction(Run owner, RcovResult results, List targets) { super(owner); this.results = results; this.targets = targets; diff --git a/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovPublisher.java b/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovPublisher.java index b39bf71..e2a4218 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovPublisher.java +++ b/src/main/java/hudson/plugins/rubyMetrics/rcov/RcovPublisher.java @@ -1,6 +1,7 @@ package hudson.plugins.rubyMetrics.rcov; import hudson.Extension; +import hudson.FilePath; import hudson.Launcher; import hudson.model.*; import hudson.plugins.rubyMetrics.HtmlPublisher; @@ -9,11 +10,14 @@ import hudson.plugins.rubyMetrics.rcov.model.Targets; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Publisher; +import jenkins.tasks.SimpleBuildStep; import net.sf.json.JSONObject; import org.apache.commons.beanutils.ConvertUtils; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.StaplerRequest; +import javax.annotation.Nonnull; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -27,9 +31,12 @@ * */ @SuppressWarnings({"unchecked", "serial"}) -public class RcovPublisher extends HtmlPublisher { +public class RcovPublisher extends HtmlPublisher implements SimpleBuildStep { - private List targets; + private List targets = new ArrayList(){{ + add(new MetricTarget(Targets.TOTAL_COVERAGE, 80, null, null)); + add(new MetricTarget(Targets.CODE_COVERAGE, 80, null, null)); + }}; @DataBoundConstructor public RcovPublisher(String reportDir) { @@ -40,27 +47,26 @@ public RcovPublisher(String reportDir) { * {@inheritDoc} */ @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + public void perform(@Nonnull Run run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, + @Nonnull TaskListener listener) throws InterruptedException, IOException { final RcovFilenameFilter indexFilter = new RcovFilenameFilter(); - prepareMetricsReportBeforeParse(build, listener, indexFilter, DESCRIPTOR.getToolShortName()); - if (build.getResult() == Result.FAILURE) { - return false; + prepareMetricsReportBeforeParse(run, workspace, listener, indexFilter, DESCRIPTOR.getToolShortName()); + if (run.getResult() == Result.FAILURE) { + return; } - RcovParser parser = new RcovParser(build.getRootDir()); - RcovResult results = parser.parse(getCoverageFiles(build, indexFilter)[0]); + RcovParser parser = new RcovParser(run.getRootDir()); + RcovResult results = parser.parse(getCoverageFiles(run, indexFilter)[0]); - RcovBuildAction action = new RcovBuildAction(build, results, targets); - build.getActions().add(action); + RcovBuildAction action = new RcovBuildAction(run, results, targets); + run.getActions().add(action); if (failMetrics(results, listener)) { - build.setResult(Result.UNSTABLE); + run.setResult(Result.UNSTABLE); } - - return true; } - private boolean failMetrics(RcovResult results, BuildListener listener) { + private boolean failMetrics(RcovResult results, TaskListener listener) { float initRatio = 0; float resultRatio = 0; for (MetricTarget target : targets) { diff --git a/src/main/java/hudson/plugins/rubyMetrics/rcov/model/RcovFileDetail.java b/src/main/java/hudson/plugins/rubyMetrics/rcov/model/RcovFileDetail.java index 2e8717c..ad148d3 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/rcov/model/RcovFileDetail.java +++ b/src/main/java/hudson/plugins/rubyMetrics/rcov/model/RcovFileDetail.java @@ -2,6 +2,7 @@ import hudson.model.AbstractBuild; import hudson.model.ModelObject; +import hudson.model.Run; import hudson.plugins.rubyMetrics.rcov.RcovParser; import org.htmlparser.util.ParserException; @@ -17,10 +18,10 @@ public class RcovFileDetail implements ModelObject, Serializable { private static final Logger LOGGER = Logger.getLogger(RcovFileDetail.class.getName()); - private final AbstractBuild owner; + private final Run owner; private final RcovFileResult result; - public RcovFileDetail(final AbstractBuild owner, final RcovFileResult result) { + public RcovFileDetail(final Run owner, final RcovFileResult result) { this.owner = owner; this.result = result; } @@ -29,7 +30,7 @@ public static long getSerialVersionUID() { return serialVersionUID; } - public AbstractBuild getOwner() { + public Run getOwner() { return owner; } diff --git a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroBuildAction.java b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroBuildAction.java index b2d8e2c..4df9ff3 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroBuildAction.java +++ b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroBuildAction.java @@ -1,6 +1,7 @@ package hudson.plugins.rubyMetrics.saikuro; import hudson.model.AbstractBuild; +import hudson.model.Run; import hudson.plugins.rubyMetrics.AbstractRubyMetricsBuildAction; import hudson.plugins.rubyMetrics.saikuro.model.SaikuroFileDetail; import hudson.plugins.rubyMetrics.saikuro.model.SaikuroFileResult; @@ -15,7 +16,7 @@ public class SaikuroBuildAction extends AbstractRubyMetricsBuildAction{ private SaikuroResult results; - public SaikuroBuildAction(AbstractBuild owner, SaikuroResult results) { + public SaikuroBuildAction(Run owner, SaikuroResult results) { super(owner); this.results = results; } diff --git a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroParser.java b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroParser.java index abd1420..8c0c084 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroParser.java +++ b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroParser.java @@ -1,6 +1,7 @@ package hudson.plugins.rubyMetrics.saikuro; import hudson.model.BuildListener; +import hudson.model.TaskListener; import hudson.plugins.rubyMetrics.HtmlParser; import hudson.plugins.rubyMetrics.saikuro.model.SaikuroFileResult; import hudson.plugins.rubyMetrics.saikuro.model.SaikuroResult; @@ -20,7 +21,7 @@ public class SaikuroParser extends HtmlParser { - public SaikuroParser(File rootFilePath, BuildListener listener) { + public SaikuroParser(File rootFilePath, TaskListener listener) { super(rootFilePath); this.listener = listener; } diff --git a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroPublisher.java b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroPublisher.java index 01741bc..ac8da5e 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroPublisher.java +++ b/src/main/java/hudson/plugins/rubyMetrics/saikuro/SaikuroPublisher.java @@ -1,20 +1,23 @@ package hudson.plugins.rubyMetrics.saikuro; +import hudson.FilePath; import hudson.Launcher; import hudson.model.*; import hudson.plugins.rubyMetrics.HtmlPublisher; import hudson.plugins.rubyMetrics.saikuro.model.SaikuroResult; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Publisher; +import jenkins.tasks.SimpleBuildStep; import net.sf.json.JSONObject; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.StaplerRequest; +import javax.annotation.Nonnull; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -public class SaikuroPublisher extends HtmlPublisher { +public class SaikuroPublisher extends HtmlPublisher implements SimpleBuildStep { @DataBoundConstructor public SaikuroPublisher(String reportDir) { @@ -25,20 +28,19 @@ public SaikuroPublisher(String reportDir) { * {@inheritDoc} */ @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + public void perform(@Nonnull Run run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, + @Nonnull TaskListener listener) throws InterruptedException, IOException { final SaikuroFilenameFilter indexFilter = new SaikuroFilenameFilter(); - prepareMetricsReportBeforeParse(build, listener, indexFilter, DESCRIPTOR.getToolShortName()); - if (build.getResult() == Result.FAILURE) { - return false; + prepareMetricsReportBeforeParse(run, workspace, listener, indexFilter, DESCRIPTOR.getToolShortName()); + if (run.getResult() == Result.FAILURE) { + return; } - SaikuroParser parser = new SaikuroParser(build.getRootDir(), listener); - SaikuroResult results = parser.parse(getCoverageFiles(build, indexFilter)[0]); + SaikuroParser parser = new SaikuroParser(run.getRootDir(), listener); + SaikuroResult results = parser.parse(getCoverageFiles(run, indexFilter)[0]); - SaikuroBuildAction action = new SaikuroBuildAction(build, results); - build.getActions().add(action); - - return true; + SaikuroBuildAction action = new SaikuroBuildAction(run, results); + run.getActions().add(action); } private static class SaikuroFilenameFilter implements FilenameFilter { diff --git a/src/main/java/hudson/plugins/rubyMetrics/saikuro/model/SaikuroFileDetail.java b/src/main/java/hudson/plugins/rubyMetrics/saikuro/model/SaikuroFileDetail.java index fee45ad..f9b9b57 100644 --- a/src/main/java/hudson/plugins/rubyMetrics/saikuro/model/SaikuroFileDetail.java +++ b/src/main/java/hudson/plugins/rubyMetrics/saikuro/model/SaikuroFileDetail.java @@ -2,20 +2,21 @@ import hudson.model.AbstractBuild; import hudson.model.ModelObject; +import hudson.model.Run; import java.io.Serializable; public class SaikuroFileDetail implements ModelObject, Serializable { - private final AbstractBuild owner; + private final Run owner; private final SaikuroFileResult result; - public SaikuroFileDetail(final AbstractBuild owner, final SaikuroFileResult result) { + public SaikuroFileDetail(final Run owner, final SaikuroFileResult result) { this.owner = owner; this.result = result; } - public AbstractBuild getOwner() { + public Run getOwner() { return owner; }