Skip to content
Permalink
Browse files

Merge pull request #2 from oleg-nenashev/JENKINS-49237-jep-200

[JENKINS-49237/JENKINS-21511] -Facelift the code and make it compatible with Jenkins 2.102+
  • Loading branch information...
oleg-nenashev committed Feb 3, 2018
2 parents de836b1 + b7d5dd2 commit 6f6123807b2a54c607d0c77fa4279d870d105703
Showing with 460 additions and 90 deletions.
  1. +2 −0 Jenkinsfile
  2. +13 −7 pom.xml
  3. +6 −6 src/main/java/hudson/plugins/cppncss/AbstractBuildReport.java
  4. +6 −2 src/main/java/hudson/plugins/cppncss/AbstractProjectReport.java
  5. +6 −0 src/main/java/hudson/plugins/cppncss/CppNCSSGhostwriter.java
  6. +13 −11 src/main/java/hudson/plugins/cppncss/CppNCSSHealthMetrics.java
  7. +4 −2 src/main/java/hudson/plugins/cppncss/CppNCSSPublisher.java
  8. +4 −4 src/main/java/hudson/plugins/cppncss/PluginImpl.java
  9. +99 −0 src/main/java/hudson/plugins/cppncss/parser/FormattedStatisticSummary.java
  10. +47 −24 src/main/java/hudson/plugins/cppncss/parser/Statistic.java
  11. +43 −0 src/main/java/hudson/plugins/cppncss/parser/StatisticSummary.java
  12. +15 −2 src/main/java/hudson/plugins/cppncss/parser/StatisticsResult.java
  13. +24 −1 src/main/java/hudson/plugins/cppncss/parser/StatisticsTotalResult.java
  14. +51 −0 src/main/java/hudson/plugins/cppncss/parser/StringStatisticSummary.java
  15. +41 −4 src/main/java/hudson/plugins/helpers/AbstractBuildAction.java
  16. +15 −7 src/main/java/hudson/plugins/helpers/BuildProxy.java
  17. +3 −3 src/main/java/hudson/plugins/helpers/BuildProxyCallableHelper.java
  18. +24 −15 src/main/java/hudson/plugins/helpers/GraphHelper.java
  19. +0 −1 src/main/java/hudson/plugins/helpers/health/HealthTarget.java
  20. +11 −0 src/main/resources/META-INF/hudson.remoting.ClassFilter
  21. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractBuildReport/largeGraph.jelly
  22. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractBuildReport/normalGraph.jelly
  23. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractBuildReport/reportDetail.jelly
  24. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractProjectReport/largeGraph.jelly
  25. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractProjectReport/normalGraph.jelly
  26. +1 −0 src/main/resources/hudson/plugins/cppncss/AbstractProjectReport/reportDetail.jelly
  27. +1 −0 src/main/resources/hudson/plugins/cppncss/CppNCSSPublisher/config.jelly
  28. +5 −0 src/main/resources/hudson/plugins/cppncss/parser/FormattedStatisticSummary/summary.jelly
  29. +5 −0 src/main/resources/hudson/plugins/cppncss/parser/StringStatisticSummary/summary.jelly
  30. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/enlargedGraph.jelly
  31. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/floatingBox.jelly
  32. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/index.jelly
  33. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/largeGraph.jelly
  34. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/normalGraph.jelly
  35. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/reportDetail.jelly
  36. +2 −1 src/main/resources/hudson/plugins/helpers/AbstractBuildAction/summary.jelly
  37. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/enlargedGraph.jelly
  38. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/floatingBox.jelly
  39. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/index.jelly
  40. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/largeGraph.jelly
  41. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/normalGraph.jelly
  42. +1 −0 src/main/resources/hudson/plugins/helpers/AbstractProjectAction/reportDetail.jelly
  43. +1 −0 src/main/resources/index.jelly
  44. +1 −0 src/main/resources/lib/health/row.jelly
@@ -0,0 +1,2 @@
// Build the plugin using https://github.com/jenkins-infra/pipeline-library
buildPlugin(jenkinsVersions: [null, '2.104'])
20 pom.xml
@@ -2,17 +2,22 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.358</version>
<relativePath>../pom.xml</relativePath>
<version>3.3</version>
</parent>

<artifactId>cppncss</artifactId>
<packaging>hpi</packaging>
<version>1.2-SNAPSHOT</version>
<name>Jenkins CppNCSS plugin</name>
<url>http://wiki.jenkins-ci.org/display/JENKINS/CPPNCSS+Plugin</url>
<url>https://wiki.jenkins.io/display/JENKINS/CPPNCSS+Plugin</url>

<properties>
<jenkins.version>1.651.3</jenkins.version>
<java.level>7</java.level>
</properties>

<build>
<plugins>
<plugin>
@@ -32,8 +37,9 @@
</build>
<dependencies>
<dependency>
<groupId>org.jvnet.hudson.main</groupId>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
<developers>
@@ -47,14 +53,14 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>
@@ -2,6 +2,7 @@

import hudson.model.AbstractBuild;
import hudson.model.HealthReportingAction;
import hudson.plugins.cppncss.parser.StatisticSummary;
import hudson.plugins.cppncss.parser.StatisticsResult;
import hudson.plugins.cppncss.parser.StatisticsTotalResult;
import hudson.plugins.helpers.AbstractBuildAction;
@@ -52,21 +53,20 @@ public Integer getFunctionNcssViolationThreshold(){
return functionNcssViolationThreshold;
}

/**
/**
* The summary of this build report for display on the build index page.
*
* @return
*/
public String getSummary() {
@Override
public StatisticSummary getStatisticSummary() {
AbstractBuild<?, ?> prevBuild = getBuild().getPreviousBuild();
while (prevBuild != null && prevBuild.getAction(getClass()) == null) {
prevBuild = prevBuild.getPreviousBuild();
}
if (prevBuild == null) {
return totals.toSummary();
return totals.getStatisticSummary();
} else {
AbstractBuildReport action = prevBuild.getAction(getClass());
return totals.toSummary(action.getTotals());
return totals.getStatisticSummary(action.getTotals());
}
}

@@ -92,13 +92,17 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
return;
}

Calendar t = getProject().getLastBuild().getTimestamp();
final AbstractBuild<?, ?> lastBuild = getProject().getLastBuild();
if (lastBuild == null) { // No sense to build graph if there is no builds, right?
return;
}

Calendar t = lastBuild.getTimestamp();
if (req.checkIfModified(t, rsp)) {
return; // up to date
}

ChartUtil.generateGraph(req, rsp, GraphHelper.buildChart(getProject().getLastBuild(), getFunctionCcnViolationThreshold(), getFunctionNcssViolationThreshold()), getGraphWidth(),
ChartUtil.generateGraph(req, rsp, GraphHelper.buildChart(lastBuild, getFunctionCcnViolationThreshold(), getFunctionNcssViolationThreshold()), getGraphWidth(),
getGraphHeight());
}

@@ -1,5 +1,6 @@
package hudson.plugins.cppncss;

import hudson.AbortException;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Action;
@@ -50,6 +51,11 @@ public boolean performFromMaster(AbstractBuild<?, ?> build, FilePath executionRo
if (targets != null && targets.length > 0) {
List<Action> actions = build.getActions();
Result buildResult = build.getResult();
if (buildResult == null) {
// The entire method need to be modified to support Pipeline
throw new AbortException("Cannot perform publisher for a running job. The plugin needs to be updated to support plugins like Any Build Step. File a JIRA ticket if you need that");
}

for (Action action : actions) {
if(action instanceof CppNCSSBuildIndividualReport) {
CppNCSSBuildIndividualReport cppncssAction = (CppNCSSBuildIndividualReport)action;
@@ -8,6 +8,9 @@

import org.apache.commons.beanutils.Converter;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* Created by IntelliJ IDEA. User: stephen Date: 18-Mar-2008 Time: 06:04:17 To change this template use File | Settings
* | File Templates.
@@ -135,18 +138,17 @@ static float measureNew(CppNCSSHealthMetrics metrics, CppNCSSBuildIndividualRepo
return newValue;

};

private static CppNCSSBuildIndividualReport getPreviousCppNCSSReport(AbstractBuild<?, ?> build){

@CheckForNull
private static CppNCSSBuildIndividualReport getPreviousCppNCSSReport(@Nonnull AbstractBuild<?, ?> build){
AbstractBuild<?, ?> previousBuild = build.getPreviousBuild();
CppNCSSBuildIndividualReport resultReport = null;
while(previousBuild != null && resultReport == null){
CppNCSSBuildIndividualReport action = (CppNCSSBuildIndividualReport)previousBuild.getAction(AbstractBuildReport.class);
previousBuild = previousBuild.getPreviousBuild();
if(action != null){
resultReport = action;
break;
}
while(previousBuild != null){
AbstractBuildReport report = previousBuild.getAction(AbstractBuildReport.class);
if (report instanceof CppNCSSBuildIndividualReport) {
return (CppNCSSBuildIndividualReport)report;
}
previousBuild = previousBuild.getPreviousBuild();
}
return resultReport;
return null;
}
}
@@ -1,5 +1,6 @@
package hudson.plugins.cppncss;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Action;
@@ -51,6 +52,8 @@ public Integer getFunctionNcssViolationThreshold() {
return functionNcssViolationThreshold;
}

// TODO: replace by lists
@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Legacy code, suppressed due to the performance reasons")
public CppNCSSHealthTarget[] getTargets() {
return targets;
}
@@ -87,9 +90,8 @@ public String getDisplayName() {
return "Publish " + PluginImpl.DISPLAY_NAME;
}

public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
static {
ConvertUtils.register(CppNCSSHealthMetrics.CONVERTER, CppNCSSHealthMetrics.class);
return req.bindJSON(CppNCSSPublisher.class, formData);
}

public boolean isApplicable(Class<? extends AbstractProject> aClass) {
@@ -6,8 +6,8 @@
* @author Shaohua Wen
*/
public class PluginImpl {
public static String DISPLAY_NAME = "Cpp NCSS Report";
public static String GRAPH_NAME = "Cpp NCSS Trend";
public static String URL = "cppncss";
public static String ICON_FILE_NAME = "graph.gif";
public final static String DISPLAY_NAME = "Cpp NCSS Report";
public final static String GRAPH_NAME = "Cpp NCSS Trend";
public final static String URL = "cppncss";
public final static String ICON_FILE_NAME = "graph.gif";
}
@@ -0,0 +1,99 @@
/*
* The MIT License
*
* Copyright (c) 2018 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.plugins.cppncss.parser;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import javax.annotation.Nonnull;

/**
* @author Oleg Nenashev
*/
@Restricted(NoExternalUse.class)
public final class FormattedStatisticSummary extends StatisticSummary {

private final long wasFunctions;
private final long wasNcss;
private final long wasCcn;
private final long functions;
private final long ncss;
private final long ccn;

public FormattedStatisticSummary(long wasCcn, long wasFunctions, long wasNcss, long ccn, long functions, long ncss) {
this.wasFunctions = wasFunctions;
this.wasNcss = wasNcss;
this.wasCcn = wasCcn;
this.functions = functions;
this.ncss = ncss;
this.ccn = ccn;
}

public FormattedStatisticSummary(long ccn, long functions, long ncss) {
this(0,0,0, ccn, functions, ncss);
}

public FormattedStatisticSummary(@Nonnull Statistic was, @Nonnull Statistic now) {
this(was.getCcn(), was.getFunctions(), was.getNcss(), now.getCcn(), now.getFunctions(), now.getNcss());
}

public long getCcn() {
return ccn;
}

public long getFunctions() {
return functions;
}

public long getNcss() {
return ncss;
}

private static String diff(long a, long b, String name) {
if (a == b) {
return "";
} else if (a < b) {
return "<li>" + name + " (+" + (b - a) + ")</li>";
} else { // if (a < b)
return "<li>" + name + " (-" + (a - b) + ")</li>";
}
}

/**
* Converts object to the HTML string
*/
@Override
public String getHtmlSummary() {
return "<ul>"
+ diff(wasCcn, ccn, "ccn")
+ diff(wasFunctions, functions, "functions")
+ diff(wasCcn, ncss, "ncss")
+ "</ul>";
}

@Override
public String toString() {
return String.format("cnn: %s, functions: %s, ncss: %s. Was: %s/%s/%s", ccn, functions, ncss, wasCcn, wasFunctions, wasNcss);
}
}

0 comments on commit 6f61238

Please sign in to comment.
You can’t perform that action at this time.