diff --git a/src/main/java/hudson/plugins/sloccount/ReportSummary.java b/src/main/java/hudson/plugins/sloccount/ReportSummary.java index 07e3814..dabed23 100644 --- a/src/main/java/hudson/plugins/sloccount/ReportSummary.java +++ b/src/main/java/hudson/plugins/sloccount/ReportSummary.java @@ -17,7 +17,7 @@ private ReportSummary(){ } public static String createReportSummary(List current, - List previous){ + List previous){ StringBuilder builder = new StringBuilder(); if(current != null){ @@ -55,7 +55,7 @@ public static String createReportSummary(List curre } public static String createReportSummaryDetails(List current, - List previous){ + List previous){ StringBuilder builder = new StringBuilder(); @@ -63,7 +63,7 @@ public static String createReportSummaryDetails(List statistics) lineCount += it.getLineCount(); } - return lineCount; + return lineCount; } private static int getFileCount(List statistics) @@ -147,7 +147,7 @@ private static int getFileCount(List statistics) fileCount += it.getFileCount(); } - return fileCount; + return fileCount; } private static int getLanguageCount(List statistics) @@ -155,14 +155,14 @@ private static int getLanguageCount(List statistics return statistics.size(); } - private static SloccountLanguageStatistics getLanguage(List statistics, String name) + static SloccountLanguageStatistics getLanguage(List statistics, String name) { - for(SloccountLanguageStatistics it : statistics) { + for(SloccountLanguageStatistics it : statistics) { if(it.getName().equals(name)) { - return it; + return it; } } - - return new SloccountLanguageStatistics(name, 0, 0); + + return new SloccountLanguageStatistics(name, 0, 0); } } diff --git a/src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java b/src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java index 5d4d196..a5780ff 100644 --- a/src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java +++ b/src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java @@ -1,14 +1,13 @@ package hudson.plugins.sloccount; -import hudson.plugins.sloccount.model.Language; import hudson.plugins.sloccount.model.SloccountLanguageStatistics; -import hudson.plugins.sloccount.model.SloccountReport; import hudson.util.ChartUtil.NumberOnlyBuildLabel; import hudson.util.DataSetBuilder; import hudson.util.ShiftedCategoryAxis; import java.awt.Color; import java.io.Serializable; +import java.util.List; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; @@ -33,7 +32,9 @@ public static JFreeChart buildChart(SloccountBuildAction action){ String strLines = Messages.Sloccount_ReportSummary_Lines(); - JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strLines, buildDataset(action), PlotOrientation.VERTICAL, true, false, true); + JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, + strLines, buildDataset(action), PlotOrientation.VERTICAL, + true, false, true); chart.setBackgroundPaint(Color.white); @@ -82,4 +83,75 @@ private static CategoryDataset buildDataset(SloccountBuildAction lastAction){ return builder.build(); } + + public static JFreeChart buildChartDelta(SloccountBuildAction action){ + + String strLinesDelta = Messages.Sloccount_ReportSummary_Lines() + + " " + Messages.Sloccount_Trend_Delta(); + + JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, + strLinesDelta, buildDatasetDelta(action), PlotOrientation.VERTICAL, + true, false, true); + + chart.setBackgroundPaint(Color.white); + + CategoryPlot plot = chart.getCategoryPlot(); + plot.setBackgroundPaint(Color.WHITE); + plot.setOutlinePaint(null); + plot.setForegroundAlpha(0.8f); + 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); + + NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); + rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); + + // crop extra space around the graph + plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); + + SloccountAreaRenderer renderer = new SloccountAreaRenderer(action.getUrlName()); + plot.setRenderer(renderer); + + return chart; + } + + private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction){ + DataSetBuilder builder = new DataSetBuilder(); + + SloccountBuildAction action = lastAction; + + while(action != null){ + SloccountBuildAction previousAction = action.getPreviousAction(); + SloccountResult result = action.getResult(); + List previousStatistics = null; + + if(result != null){ + NumberOnlyBuildLabel buildLabel = new NumberOnlyBuildLabel(action.getBuild()); + + if(previousAction != null && previousAction.getResult() != null){ + previousStatistics = previousAction.getResult().getStatistics(); + } else { + // This will produce zero delta for the first build + previousStatistics = result.getStatistics(); + } + + for(SloccountLanguageStatistics current : result.getStatistics()){ + SloccountLanguageStatistics previous = ReportSummary.getLanguage(previousStatistics, current.getName()); + + builder.add(current.getLineCount() - previous.getLineCount(), + current.getName(), buildLabel); + } + } + + action = previousAction; + }; + + return builder.build(); + } } diff --git a/src/main/java/hudson/plugins/sloccount/SloccountProjectAction.java b/src/main/java/hudson/plugins/sloccount/SloccountProjectAction.java index 15146e9..13131d5 100644 --- a/src/main/java/hudson/plugins/sloccount/SloccountProjectAction.java +++ b/src/main/java/hudson/plugins/sloccount/SloccountProjectAction.java @@ -54,8 +54,8 @@ public void doIndex(final StaplerRequest request, final StaplerResponse response if (build != null) { response.sendRedirect2(String.format("../%d/%s", build.getNumber(), SloccountBuildAction.URL_NAME)); }else{ - // Click to the link in menu on the job page before the first build - response.sendRedirect2(".."); + // Click to the link in menu on the job page before the first build + response.sendRedirect2(".."); } } @@ -154,4 +154,51 @@ public void doTrend(final StaplerRequest request, final StaplerResponse response CHART_WIDTH, CHART_HEIGHT); } + + /** + * Display the trend delta map. Delegates to the the associated + * {@link ResultAction}. + * + * @param request + * Stapler request + * @param response + * Stapler response + * @throws IOException + * in case of an error + */ + public void doTrendDeltaMap(final StaplerRequest request, final StaplerResponse response) throws IOException { + AbstractBuild lastBuild = this.getLastFinishedBuild(); + SloccountBuildAction lastAction = lastBuild.getAction(SloccountBuildAction.class); + + ChartUtil.generateClickableMap( + request, + response, + SloccountChartBuilder.buildChartDelta(lastAction), + CHART_WIDTH, + CHART_HEIGHT); + } + + /** + * Display the trend delta graph. Delegates to the the associated + * {@link ResultAction}. + * + * @param request + * Stapler request + * @param response + * Stapler response + * @throws IOException + * in case of an error in + * {@link ResultAction#doGraph(StaplerRequest, StaplerResponse, int)} + */ + public void doTrendDelta(final StaplerRequest request, final StaplerResponse response) throws IOException { + AbstractBuild lastBuild = this.getLastFinishedBuild(); + SloccountBuildAction lastAction = lastBuild.getAction(SloccountBuildAction.class); + + ChartUtil.generateGraph( + request, + response, + SloccountChartBuilder.buildChartDelta(lastAction), + CHART_WIDTH, + CHART_HEIGHT); + } } diff --git a/src/main/resources/hudson/plugins/sloccount/Messages.properties b/src/main/resources/hudson/plugins/sloccount/Messages.properties index 612bca4..4af06d2 100644 --- a/src/main/resources/hudson/plugins/sloccount/Messages.properties +++ b/src/main/resources/hudson/plugins/sloccount/Messages.properties @@ -8,4 +8,6 @@ Sloccount.ReportSummary.Lines=lines of code Sloccount.ReportSummary.Files=files Sloccount.ReportSummary.and=and Sloccount.ReportSummary.in=in -Sloccount.ReportSummary.Languages=languages \ No newline at end of file +Sloccount.ReportSummary.Languages=languages + +Sloccount.Trend.Delta=(delta) diff --git a/src/main/resources/hudson/plugins/sloccount/SloccountProjectAction/floatingBox.jelly b/src/main/resources/hudson/plugins/sloccount/SloccountProjectAction/floatingBox.jelly index 0442d19..4665260 100644 --- a/src/main/resources/hudson/plugins/sloccount/SloccountProjectAction/floatingBox.jelly +++ b/src/main/resources/hudson/plugins/sloccount/SloccountProjectAction/floatingBox.jelly @@ -8,6 +8,9 @@
+
+ +
\ No newline at end of file