Permalink
Browse files

[FIXED JENKINS-16038] Crop unusaged whitespace in coverage graph

  • Loading branch information...
ssogabe committed Dec 13, 2012
1 parent 6f6003e commit bbef9a1d62b2592537272a5019e344850f1d924b
@@ -3,5 +3,6 @@
.settings
build
target
temp
work
*.iml
@@ -0,0 +1,17 @@
package hudson.plugins.cobertura;

import hudson.model.AbstractBuild;
import hudson.plugins.cobertura.targets.CoverageMetric;

import java.util.Map;

public interface Chartable
{

Chartable getPreviousResult();

Map<CoverageMetric, Ratio> getResults();

AbstractBuild< ? , ? > getOwner();

}
@@ -1,35 +1,15 @@
package hudson.plugins.cobertura;

import hudson.model.AbstractBuild;
import hudson.model.HealthReport;
import hudson.model.HealthReportingAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.plugins.cobertura.targets.CoverageMetric;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.plugins.cobertura.targets.CoverageTarget;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.util.ChartUtil;
import hudson.util.ColorPalette;
import hudson.util.DataSetBuilder;
import hudson.util.DescribableList;
import hudson.util.ShiftedCategoryAxis;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleEdge;
import org.jfree.ui.RectangleInsets;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
@@ -39,13 +19,19 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jfree.chart.JFreeChart;
import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

/**
* Created by IntelliJ IDEA.
*
* @author connollys
* @since 03-Jul-2007 08:43:08
*/
public class CoberturaBuildAction implements HealthReportingAction, StaplerProxy {
public class CoberturaBuildAction implements HealthReportingAction, StaplerProxy, Chartable {
private final AbstractBuild<?, ?> owner;
private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
@@ -150,6 +136,14 @@ public Object getTarget() {
return getResult(); //To change body of implemented methods use File | Settings | File Templates.
}

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

public Map<CoverageMetric, Ratio> getResults() {
return result;
}

/**
* Getter for property 'previousResult'.
*
@@ -251,65 +245,9 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
if (req.checkIfModified(t, rsp))
return; // up to date

DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dsb = new DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel>();

for (CoberturaBuildAction a = this; a != null; a = a.getPreviousResult()) {
ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(a.owner);
for (Map.Entry<CoverageMetric, Ratio> value : a.result.entrySet()) {
dsb.add(value.getValue().getPercentageFloat(), value.getKey().getName(), label);
}
}

ChartUtil.generateGraph(req, rsp, createChart(dsb.build()), 500, 200);
JFreeChart chart = new CoverageChart( this ).createChart();
ChartUtil.generateGraph(req, rsp, chart, 500, 200);
}

private JFreeChart createChart(CategoryDataset dataset) {

final JFreeChart chart = ChartFactory.createLineChart(
null, // chart title
null, // unused
"%", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = chart.getCategoryPlot();

// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);

CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);

final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setUpperBound(100);
rangeAxis.setLowerBound(0);

final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseStroke(new BasicStroke(2.0f));
ColorPalette.apply(renderer);

// crop extra space around the graph
plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

return chart;
}
}
@@ -16,21 +16,17 @@
import hudson.plugins.cobertura.renderers.SourceCodePainter;
import hudson.plugins.cobertura.renderers.SourceEncoding;
import hudson.plugins.cobertura.targets.CoverageMetric;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.plugins.cobertura.targets.CoverageTarget;
import hudson.plugins.cobertura.targets.CoverageResult;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -39,19 +35,18 @@
import java.util.Set;
import java.util.TreeMap;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.ConvertUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

import net.sf.json.JSONObject;

import org.apache.commons.beanutils.ConvertUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
* Cobertura {@link Publisher}.
*
@@ -65,6 +60,7 @@
private final boolean failUnstable;
private final boolean autoUpdateHealth;
private final boolean autoUpdateStability;
private final boolean zoomCoverageChart;

private CoverageTarget healthyTarget;
private CoverageTarget unhealthyTarget;
@@ -77,13 +73,14 @@
* @stapler-constructor
*/
@DataBoundConstructor
public CoberturaPublisher(String coberturaReportFile, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability, SourceEncoding sourceEncoding) {
public CoberturaPublisher(String coberturaReportFile, boolean onlyStable, boolean failUnhealthy, boolean failUnstable, boolean autoUpdateHealth, boolean autoUpdateStability, boolean zoomCoverageChart, SourceEncoding sourceEncoding) {
this.coberturaReportFile = coberturaReportFile;
this.onlyStable = onlyStable;
this.failUnhealthy = failUnhealthy;
this.failUnstable = failUnstable;
this.autoUpdateHealth = autoUpdateHealth;
this.autoUpdateStability = autoUpdateStability;
this.zoomCoverageChart = zoomCoverageChart;
this.sourceEncoding = sourceEncoding;
this.healthyTarget = new CoverageTarget();
this.unhealthyTarget = new CoverageTarget();
@@ -226,6 +223,10 @@ public boolean getAutoUpdateStability() {
return autoUpdateStability;
}

public boolean getZoomCoverageChart() {
return zoomCoverageChart;
}

/**
* Getter for property 'healthyTarget'.
*
Oops, something went wrong.

0 comments on commit bbef9a1

Please sign in to comment.