Skip to content

Commit

Permalink
try to make pipeline working
Browse files Browse the repository at this point in the history
it somehow works now (doesn't crash anymore), but doesn't display
anything ... so this would need more work

also tests seems to be broken
  • Loading branch information
SuperTux88 committed Jul 23, 2016
1 parent b577805 commit 61f5f2a
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 65 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.532.3</version>
<version>1.580</version>
</parent>

<artifactId>rubyMetrics</artifactId>
Expand Down Expand Up @@ -62,8 +62,8 @@
<connection>scm:git:git://github.com/jenkinsci/rubymetrics-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/rubymetrics-plugin.git</developerConnection>
<url>https://github.com/jenkins/rubymetrics-plugin</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 extends AbstractRubyMetricsBuildAction> T getPreviousResult() {
AbstractBuild<?, ?> b = owner;
Run<?, ?> b = owner;
while (true) {
b = b.getPreviousBuild();
if (b == null)
Expand Down Expand Up @@ -126,7 +123,7 @@ private JFreeChart createChart(CategoryDataset dataset, String rangeAxisLabel) {
return chart;
}

public AbstractBuild<?, ?> getOwner() {
public Run<?, ?> getOwner() {
return owner;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/rubyMetrics/HtmlParser.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/hudson/plugins/rubyMetrics/HtmlPublisher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +18,7 @@ public class RcovBuildAction extends AbstractRubyMetricsBuildAction {
private final RcovResult results;
private final List<MetricTarget> targets;

public RcovBuildAction(AbstractBuild<?, ?> owner, RcovResult results, List<MetricTarget> targets) {
public RcovBuildAction(Run<?, ?> owner, RcovResult results, List<MetricTarget> targets) {
super(owner);
this.results = results;
this.targets = targets;
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/hudson/plugins/rubyMetrics/rcov/RcovPublisher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -27,9 +31,12 @@
*
*/
@SuppressWarnings({"unchecked", "serial"})
public class RcovPublisher extends HtmlPublisher {
public class RcovPublisher extends HtmlPublisher implements SimpleBuildStep {

private List<MetricTarget> targets;
private List<MetricTarget> targets = new ArrayList<MetricTarget>(){{
add(new MetricTarget(Targets.TOTAL_COVERAGE, 80, null, null));
add(new MetricTarget(Targets.CODE_COVERAGE, 80, null, null));
}};

@DataBoundConstructor
public RcovPublisher(String reportDir) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -29,7 +30,7 @@ public static long getSerialVersionUID() {
return serialVersionUID;
}

public AbstractBuild<?, ?> getOwner() {
public Run<?, ?> getOwner() {
return owner;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 61f5f2a

Please sign in to comment.