Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-22073] ProjectAction should render graph, optimize build.xml…
… size

- Issue: The trend graph is part of project/job page and should be created in CppcheckProjectAction instead of in CppcheckBuildAction.
- Issue: Every build.xml file contains full plugin configuration, this is not needed.
- Creating of the graph moved from CppcheckBuildAction to proper CppcheckProjectAction.
- CppcheckBuildAction now stores no configuration which results in smaller build.xml.
- Various methods updated to receive only CppcheckConfigSeverityEvaluation in their parameters.
- Weather column in the jobs table (mouse over tool tip) updated to contain only a constant label with a percentage, use of a deprecated API removed. It isn't neccessary to dynamically show a configuration here. This allows to replace whole <configSeverityEvaluation> part of build.xml by one integer.
- Several @SuppressWarnings("unused") that are causing compiler warnings removed.
- Code updated to be better readable.
  • Loading branch information
mixalturek committed Mar 8, 2014
1 parent 2bb2ba0 commit 87b1634
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 229 deletions.
Expand Up @@ -146,7 +146,7 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
*
* @return the created object
*/
@SuppressWarnings({"unused", "deprecation"})
@SuppressWarnings("deprecation")
private Object readResolve() {
if (build != null) {
this.owner = build;
Expand Down Expand Up @@ -201,9 +201,8 @@ private Object readResolve() {
newConfig.setConfigGraph(configGraph);


return new org.jenkinsci.plugins.cppcheck.CppcheckBuildAction(owner, newResult, newConfig);

return new org.jenkinsci.plugins.cppcheck.CppcheckBuildAction(owner, newResult,
org.jenkinsci.plugins.cppcheck.CppcheckBuildAction.computeHealthReportPercentage(
newResult, configSeverityEvaluation));
}


}
Expand Up @@ -24,14 +24,8 @@

import hudson.model.*;
import org.kohsuke.stapler.StaplerProxy;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;

public abstract class AbstractCppcheckBuildAction extends Actionable implements Action, HealthReportingAction, StaplerProxy {


protected AbstractBuild<?, ?> owner;

protected AbstractCppcheckBuildAction(AbstractBuild<?, ?> owner) {
Expand All @@ -55,7 +49,4 @@ public <T extends AbstractCppcheckBuildAction> T getPreviousResult() {
public AbstractBuild<?, ?> getOwner() {
return owner;
}

public abstract void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException;

}
Expand Up @@ -23,8 +23,11 @@

package com.thalesgroup.hudson.plugins.cppcheck.util;

import org.jenkinsci.plugins.cppcheck.Messages;

import com.thalesgroup.hudson.plugins.cppcheck.CppcheckMetricUtil;
import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig;

import hudson.model.HealthReport;

public class CppcheckBuildHealthEvaluator {
Expand All @@ -48,7 +51,7 @@ public HealthReport evaluatBuildHealth(CppcheckConfig cppcheckConfig, int nbErro
/ (CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy()) - CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getHealthy())));
}

return new HealthReport(percentage, Messages._CppcheckBuildHealthEvaluator_Description(CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig)));
return new HealthReport(percentage, Messages.cppcheck_BuildHealthEvaluatorDescription(CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig)));
}
return null;
}
Expand Down
124 changes: 39 additions & 85 deletions src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckBuildAction.java
@@ -1,21 +1,16 @@
package org.jenkinsci.plugins.cppcheck;


import com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph;
import java.io.IOException;

import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckBuildAction;

import hudson.model.AbstractBuild;
import hudson.model.HealthReport;
import hudson.util.ChartUtil;
import hudson.util.DataSetBuilder;
import hudson.util.Graph;

import org.jenkinsci.plugins.cppcheck.config.CppcheckConfig;
import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigGraph;
import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation;
import org.jenkinsci.plugins.cppcheck.util.CppcheckBuildHealthEvaluator;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import java.io.IOException;
import java.util.Calendar;

/**
* @author Gregory Boissinot
Expand All @@ -25,12 +20,19 @@ public class CppcheckBuildAction extends AbstractCppcheckBuildAction {
public static final String URL_NAME = "cppcheckResult";

private CppcheckResult result;
private CppcheckConfig cppcheckConfig;

public CppcheckBuildAction(AbstractBuild<?, ?> owner, CppcheckResult result, CppcheckConfig cppcheckConfig) {
/**
* The health report percentage.
*
* @since 1.15
*/
private int healthReportPercentage;

public CppcheckBuildAction(AbstractBuild<?, ?> owner, CppcheckResult result,
int healthReportPercentage) {
super(owner);
this.result = result;
this.cppcheckConfig = cppcheckConfig;
this.healthReportPercentage = healthReportPercentage;
}

public String getIconFileName() {
Expand Down Expand Up @@ -62,88 +64,33 @@ public Object getTarget() {
}

public HealthReport getBuildHealth() {
try {
return new CppcheckBuildHealthEvaluator().evaluatBuildHealth(cppcheckConfig,
result.getNumberErrorsAccordingConfiguration(cppcheckConfig, false));
} catch (IOException ioe) {
return new HealthReport();
if(healthReportPercentage >= 0 && healthReportPercentage <= 100) {
return new HealthReport(healthReportPercentage,
Messages._cppcheck_BuildStability());
} else {
return null;
}
}

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

for (CppcheckBuildAction a = this; a != null; a = a.getPreviousResult()) {
ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(a.owner);
CppcheckStatistics statistics = a.getResult().getStatistics();
CppcheckConfigGraph configGraph = cppcheckConfig.getConfigGraph();

// error
if (configGraph.isDisplayErrorSeverity())
dsb.add(statistics.getNumberErrorSeverity(),
Messages.cppcheck_Error(), label);

//warning
if (configGraph.isDisplayWarningSeverity())
dsb.add(statistics.getNumberWarningSeverity(),
Messages.cppcheck_Warning(), label);

//style
if (configGraph.isDisplayStyleSeverity())
dsb.add(statistics.getNumberStyleSeverity(),
Messages.cppcheck_Style(), label);

//performance
if (configGraph.isDisplayPerformanceSeverity())
dsb.add(statistics.getNumberPerformanceSeverity(),
Messages.cppcheck_Performance(), label);

//information
if (configGraph.isDisplayInformationSeverity())
dsb.add(statistics.getNumberInformationSeverity(),
Messages.cppcheck_Information(), label);

//no category
if (configGraph.isDisplayNoCategorySeverity())
dsb.add(statistics.getNumberNoCategorySeverity(),
Messages.cppcheck_NoCategory(), label);

//portability
if (configGraph.isDisplayPortabilitySeverity())
dsb.add(statistics.getNumberPortabilitySeverity(),
Messages.cppcheck_Portability(), label);

// all errors
if (configGraph.isDisplayAllErrors())
dsb.add(statistics.getNumberTotal(),
Messages.cppcheck_AllErrors(), label);
}
return dsb;
}

public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if (ChartUtil.awtProblemCause != null) {
rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
return;
}

Calendar timestamp = getBuild().getTimestamp();
if (req.checkIfModified(timestamp, rsp)) {
return;
public static int computeHealthReportPercentage(CppcheckResult result,
CppcheckConfigSeverityEvaluation severityEvaluation) {
try {
return new CppcheckBuildHealthEvaluator().evaluatBuildHealth(severityEvaluation,
result.getNumberErrorsAccordingConfiguration(severityEvaluation,
false));
} catch (IOException e) {
return -1;
}

Graph g = new CppcheckGraph(getOwner(), getDataSetBuilder().build(),
Messages.cppcheck_NumberOfErrors(),
cppcheckConfig.getConfigGraph().getXSize(),
cppcheckConfig.getConfigGraph().getYSize());
g.doPng(req, rsp);
}

// Backward compatibility
@Deprecated
private transient AbstractBuild<?, ?> build;

/** Backward compatibility with version 1.14 and less. */
@Deprecated
private transient CppcheckConfig cppcheckConfig;

/**
* Initializes members that were not present in previous versions of this plug-in.
*
Expand All @@ -153,6 +100,13 @@ private Object readResolve() {
if (build != null) {
this.owner = build;
}

// Backward compatibility with version 1.14 and less
if (cppcheckConfig != null) {
healthReportPercentage = computeHealthReportPercentage(result,
cppcheckConfig.getConfigSeverityEvaluation());
}

return this;
}
}
@@ -1,21 +1,37 @@
package org.jenkinsci.plugins.cppcheck;

import java.io.IOException;
import java.util.Calendar;

import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Result;
import hudson.util.ChartUtil;
import hudson.util.DataSetBuilder;
import hudson.util.Graph;

import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigGraph;
import org.jenkinsci.plugins.cppcheck.util.AbstractCppcheckProjectAction;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph;

/**
* @author Gregory Boissinot
*/
public class CppcheckProjectAction extends AbstractCppcheckProjectAction {
/** Cppcheck graph configuration. */
private final CppcheckConfigGraph configGraph;

public String getSearchUrl() {
return getUrlName();
}

public CppcheckProjectAction(final AbstractProject<?, ?> project) {
public CppcheckProjectAction(final AbstractProject<?, ?> project,
CppcheckConfigGraph configGraph) {
super(project);
this.configGraph = configGraph;
}

public AbstractBuild<?, ?> getLastFinishedBuild() {
Expand Down Expand Up @@ -73,4 +89,78 @@ public String getDisplayName() {
public String getUrlName() {
return CppcheckBuildAction.URL_NAME;
}

public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
if (ChartUtil.awtProblemCause != null) {
rsp.sendRedirect2(req.getContextPath() + "/images/headless.png");
return;
}

AbstractBuild<?, ?> lastBuild = getLastFinishedBuild();
Calendar timestamp = lastBuild.getTimestamp();

if (req.checkIfModified(timestamp, rsp)) {
return;
}

Graph g = new CppcheckGraph(lastBuild, getDataSetBuilder().build(),
Messages.cppcheck_NumberOfErrors(),
configGraph.getXSize(),
configGraph.getYSize());
g.doPng(req, rsp);
}

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

AbstractBuild<?,?> lastBuild = getLastFinishedBuild();
CppcheckBuildAction lastAction = lastBuild.getAction(CppcheckBuildAction.class);

for (CppcheckBuildAction a = lastAction; a != null; a = a.getPreviousResult()) {
ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel(a.getOwner());
CppcheckStatistics statistics = a.getResult().getStatistics();

// error
if (configGraph.isDisplayErrorSeverity())
dsb.add(statistics.getNumberErrorSeverity(),
Messages.cppcheck_Error(), label);

//warning
if (configGraph.isDisplayWarningSeverity())
dsb.add(statistics.getNumberWarningSeverity(),
Messages.cppcheck_Warning(), label);

//style
if (configGraph.isDisplayStyleSeverity())
dsb.add(statistics.getNumberStyleSeverity(),
Messages.cppcheck_Style(), label);

//performance
if (configGraph.isDisplayPerformanceSeverity())
dsb.add(statistics.getNumberPerformanceSeverity(),
Messages.cppcheck_Performance(), label);

//information
if (configGraph.isDisplayInformationSeverity())
dsb.add(statistics.getNumberInformationSeverity(),
Messages.cppcheck_Information(), label);

//no category
if (configGraph.isDisplayNoCategorySeverity())
dsb.add(statistics.getNumberNoCategorySeverity(),
Messages.cppcheck_NoCategory(), label);

//portability
if (configGraph.isDisplayPortabilitySeverity())
dsb.add(statistics.getNumberPortabilitySeverity(),
Messages.cppcheck_Portability(), label);

// all errors
if (configGraph.isDisplayAllErrors())
dsb.add(statistics.getNumberTotal(),
Messages.cppcheck_AllErrors(), label);
}
return dsb;
}
}
Expand Up @@ -102,7 +102,7 @@ public CppcheckConfig getCppcheckConfig() {

@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
return new CppcheckProjectAction(project);
return new CppcheckProjectAction(project, cppcheckConfig.getConfigGraph());
}

protected boolean canContinue(final Result result) {
Expand Down Expand Up @@ -146,17 +146,21 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
build.getModuleRoot(), cppcheckReport.getAllErrors());

CppcheckResult result = new CppcheckResult(cppcheckReport.getStatistics(), build);
CppcheckConfigSeverityEvaluation severityEvaluation
= cppcheckConfig.getConfigSeverityEvaluation();

Result buildResult = new CppcheckBuildResultEvaluator().evaluateBuildResult(
listener, result.getNumberErrorsAccordingConfiguration(cppcheckConfig, false),
result.getNumberErrorsAccordingConfiguration(cppcheckConfig, true),
cppcheckConfig);
listener, result.getNumberErrorsAccordingConfiguration(severityEvaluation, false),
result.getNumberErrorsAccordingConfiguration(severityEvaluation, true),
severityEvaluation);

if (buildResult != Result.SUCCESS) {
build.setResult(buildResult);
}

CppcheckBuildAction buildAction = new CppcheckBuildAction(build, result, cppcheckConfig);
CppcheckBuildAction buildAction = new CppcheckBuildAction(build, result,
CppcheckBuildAction.computeHealthReportPercentage(result, severityEvaluation));

build.addAction(buildAction);

XmlFile xmlSourceContainer = new XmlFile(new File(build.getRootDir(),
Expand Down

0 comments on commit 87b1634

Please sign in to comment.