Skip to content

Commit

Permalink
Merge pull request #32 from mixalturek/master
Browse files Browse the repository at this point in the history
[JENKINS-21552] Configureable Graph
  • Loading branch information
mixalturek committed Jan 29, 2014
2 parents 07e91e8 + 25d14a0 commit 1119334
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 29 deletions.
37 changes: 25 additions & 12 deletions src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java
Expand Up @@ -32,13 +32,13 @@ public class SloccountChartBuilder implements Serializable {
private SloccountChartBuilder(){
}

public static JFreeChart buildChart(SloccountBuildAction action){

public static JFreeChart buildChart(SloccountBuildAction action,
int numBuildsInGraph){
String strLines = Messages.Sloccount_Trend_Lines();

JFreeChart chart = ChartFactory.createStackedAreaChart(null, null,
strLines, buildDataset(action), PlotOrientation.VERTICAL,
true, false, true);
strLines, buildDataset(action, numBuildsInGraph),
PlotOrientation.VERTICAL, true, false, true);

chart.setBackgroundPaint(Color.white);

Expand Down Expand Up @@ -68,12 +68,16 @@ strLines, buildDataset(action), PlotOrientation.VERTICAL,
return chart;
}

private static CategoryDataset buildDataset(SloccountBuildAction lastAction){
private static CategoryDataset buildDataset(SloccountBuildAction lastAction,
int numBuildsInGraph){
DataSetBuilder<String, NumberOnlyBuildLabel> builder = new DataSetBuilder<String, NumberOnlyBuildLabel>();
Set<String> allLanguages = new HashSet<String>();

SloccountBuildAction action = lastAction;
while(action != null){
int numBuilds = 0;

// numBuildsInGraph <= 1 means unlimited
while(action != null && (numBuildsInGraph <= 1 || numBuilds < numBuildsInGraph)){
SloccountResult result = action.getResult();
if(result != null){
NumberOnlyBuildLabel buildLabel = new NumberOnlyBuildLabel(action.getBuild());
Expand All @@ -90,6 +94,8 @@ private static CategoryDataset buildDataset(SloccountBuildAction lastAction){
// Language disappeared
builder.add(0, language, buildLabel);
}

++numBuilds;
}

action = action.getPreviousAction();
Expand All @@ -98,14 +104,15 @@ private static CategoryDataset buildDataset(SloccountBuildAction lastAction){
return builder.build();
}

public static JFreeChart buildChartDelta(SloccountBuildAction action){

public static JFreeChart buildChartDelta(SloccountBuildAction action,
int numBuildsInGraph){

String strLinesDelta = Messages.Sloccount_Trend_Lines()
+ " " + Messages.Sloccount_Trend_Delta();

JFreeChart chart = ChartFactory.createStackedAreaChart(null, null,
strLinesDelta, buildDatasetDelta(action), PlotOrientation.VERTICAL,
true, false, true);
strLinesDelta, buildDatasetDelta(action, numBuildsInGraph),
PlotOrientation.VERTICAL, true, false, true);

chart.setBackgroundPaint(Color.white);

Expand Down Expand Up @@ -135,7 +142,8 @@ strLinesDelta, buildDatasetDelta(action), PlotOrientation.VERTICAL,
return chart;
}

private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction){
private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction,
int numBuildsInGraph){
DataSetBuilder<String, NumberOnlyBuildLabel> builder = new DataSetBuilder<String, NumberOnlyBuildLabel>();
Set<String> allLanguages = new HashSet<String>();
SloccountBuildAction action = lastAction;
Expand All @@ -145,7 +153,10 @@ private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction
allLanguages.addAll(action.getResult().getStatistics().getAllLanguages());
}

while(action != null){
int numBuilds = 0;

// numBuildsInGraph <= 1 means unlimited
while(action != null && (numBuildsInGraph <= 1 || numBuilds < numBuildsInGraph)){
SloccountBuildAction previousAction = action.getPreviousAction();
SloccountResult result = action.getResult();
SloccountReportStatistics previousStatistics = null;
Expand Down Expand Up @@ -179,6 +190,8 @@ private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction
// Language disappeared (current - previous = 0 - previous)
builder.add(-previous.getLineCount(), language, buildLabel);
}

++numBuilds;
}

action = previousAction;
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/hudson/plugins/sloccount/SloccountProjectAction.java
Expand Up @@ -24,8 +24,16 @@ public class SloccountProjectAction implements Action, Serializable {

public AbstractProject<?,?> project;

public SloccountProjectAction(final AbstractProject<?, ?> project) {
/**
* Maximal number of last successful builds displayed in the trend graphs.
* One or less means unlimited.
*/
private final int numBuildsInGraph;

public SloccountProjectAction(final AbstractProject<?, ?> project,
int numBuildsInGraph) {
this.project = project;
this.numBuildsInGraph = numBuildsInGraph;
}

public String getIconFileName() {
Expand Down Expand Up @@ -118,7 +126,7 @@ public void doTrendMap(final StaplerRequest request, final StaplerResponse respo
ChartUtil.generateClickableMap(
request,
response,
SloccountChartBuilder.buildChart(lastAction),
SloccountChartBuilder.buildChart(lastAction, numBuildsInGraph),
CHART_WIDTH,
CHART_HEIGHT);
}
Expand All @@ -140,7 +148,7 @@ public void doTrend(final StaplerRequest request, final StaplerResponse response
ChartUtil.generateGraph(
request,
response,
SloccountChartBuilder.buildChart(lastAction),
SloccountChartBuilder.buildChart(lastAction, numBuildsInGraph),
CHART_WIDTH,
CHART_HEIGHT);
}
Expand All @@ -162,7 +170,7 @@ public void doTrendDeltaMap(final StaplerRequest request, final StaplerResponse
ChartUtil.generateClickableMap(
request,
response,
SloccountChartBuilder.buildChartDelta(lastAction),
SloccountChartBuilder.buildChartDelta(lastAction, numBuildsInGraph),
CHART_WIDTH,
CHART_HEIGHT);
}
Expand All @@ -184,7 +192,7 @@ public void doTrendDelta(final StaplerRequest request, final StaplerResponse res
ChartUtil.generateGraph(
request,
response,
SloccountChartBuilder.buildChartDelta(lastAction),
SloccountChartBuilder.buildChartDelta(lastAction, numBuildsInGraph),
CHART_WIDTH,
CHART_HEIGHT);
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/hudson/plugins/sloccount/SloccountPublisher.java
Expand Up @@ -39,19 +39,25 @@ public class SloccountPublisher extends Recorder implements Serializable {

private final String pattern;
private final String encoding;

@DataBoundConstructor
public SloccountPublisher(String pattern, String encoding){


/**
* Maximal number of last successful builds displayed in the trend graphs.
* One or less means unlimited.
*/
private final int numBuildsInGraph;

@DataBoundConstructor
public SloccountPublisher(String pattern, String encoding,
int numBuildsInGraph){
super();

this.pattern = pattern;
this.encoding = encoding;
this.numBuildsInGraph = numBuildsInGraph;
}

@Override
public Action getProjectAction(AbstractProject<?,?> project){
return new SloccountProjectAction(project);
return new SloccountProjectAction(project, numBuildsInGraph);
}

protected boolean canContinue(final Result result) {
Expand Down Expand Up @@ -170,4 +176,8 @@ public String getPattern() {
public String getEncoding() {
return encoding;
}

public int getNumBuildsInGraph() {
return numBuildsInGraph;
}
}
Expand Up @@ -6,4 +6,4 @@ Sloccount.Trend.Name=SLOCCount Trend
Sloccount.Trend.Lines=lines
Sloccount.Trend.Delta=(delta)

Sloccount.Portlet.Name=SLOCCount
Sloccount.Portlet.Name=SLOCCount Statistics
Expand Up @@ -6,7 +6,11 @@
</f:entry>
<f:advanced>
<f:entry title="${%Report charset}" description="${%description.encoding}">
<f:textbox name="encoding" value="${instance.encoding}"/>
<f:textbox name="encoding" value="${instance.encoding}"/>
</f:entry>

<f:entry title="${%Builds in graph}" description="${%description.numBuildsInGraph}">
<f:textbox name="numBuildsInGraph" value="${instance.numBuildsInGraph}"/>
</f:entry>
</f:advanced>
</j:jelly>
@@ -1,9 +1,13 @@
description.pattern=<a href="{0}">Fileset 'includes'</a> \
setting that specifies the generated raw SLOCCount report files, such as '**/sloccount.sc'. \
Basedir of the fileset is <a href="ws/">the workspace root</a>. \
If no value is set, then the default '**/sloccount.sc' is used. Be sure not to include any \
non-report files into this pattern. The report files must have been generated by sloccount \
setting that specifies the generated raw SLOCCount report files, such as '**/sloccount.sc'. \
Basedir of the fileset is <a href="ws/">the workspace root</a>. \
If no value is set, then the default '**/sloccount.sc' is used. Be sure not to include any \
non-report files into this pattern. The report files must have been generated by sloccount \
using the "--wide --details" options.

description.encoding=The character encoding to be used to read the SLOCCount result files. If no value is set, \
then the default 'UTF-8' is used.

description.numBuildsInGraph=Maximal number of last successful builds, that \
are displayed in the trend graphs. Use one or less \
for unlimited.

0 comments on commit 1119334

Please sign in to comment.