Skip to content

Commit

Permalink
FIx JENKINS-10369 and JENKINS-9727
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Jul 31, 2011
1 parent 3c1140b commit e41b580
Show file tree
Hide file tree
Showing 46 changed files with 3,554 additions and 1,639 deletions.
Expand Up @@ -23,9 +23,8 @@

package com.thalesgroup.hudson.plugins.cppcheck;

import hudson.util.StackedAreaRenderer2;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;

import hudson.util.StackedAreaRenderer2;
import org.jfree.data.category.CategoryDataset;

/**
Expand Down
Expand Up @@ -23,24 +23,24 @@

package com.thalesgroup.hudson.plugins.cppcheck;

import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig;
import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfigGraph;
import com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile;
import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckBuildAction;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckBuildHealthEvaluator;
import hudson.model.AbstractBuild;
import hudson.model.HealthReport;
import hudson.util.ChartUtil;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;
import hudson.util.DataSetBuilder;
import hudson.util.Graph;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;

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

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig;
import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfigGraph;
import com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph;
import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckBuildAction;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckBuildHealthEvaluator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;


public class CppcheckBuildAction extends AbstractCppcheckBuildAction {
Expand Down Expand Up @@ -87,8 +87,7 @@ public Object getTarget() {
public HealthReport getBuildHealth() {
try {
return new CppcheckBuildHealthEvaluator().evaluatBuildHealth(cppcheckConfig, result.getNumberErrorsAccordingConfiguration(cppcheckConfig, false));
}
catch (IOException ioe) {
} catch (IOException ioe) {
return new HealthReport();
}
}
Expand Down Expand Up @@ -145,11 +144,54 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException
*
* @return the created object
*/
@SuppressWarnings({"unused", "deprecation"})
private Object readResolve() {
if (build != null) {
this.owner = build;
}
return this;

//Report
CppcheckReport report = result.getReport();
org.jenkinsci.plugins.cppcheck.CppcheckReport newReport = new org.jenkinsci.plugins.cppcheck.CppcheckReport();
if (report != null) {
newReport.setAllErrors(report.getEverySeverities());
newReport.setErrorSeverityList(report.getErrorSeverities());
newReport.setWarningSeverityList(report.getPossibleErrorSeverities());
newReport.setStyleSeverityList(report.getStyleSeverities());
newReport.setPerformanceSeverityList(report.getPossibleStyleSeverities());
newReport.setInformationSeverityList(report.getNoCategorySeverities());
newReport.setNoCategorySeverityList(new ArrayList<CppcheckFile>());
}

//Result
org.jenkinsci.plugins.cppcheck.CppcheckResult newResult = new org.jenkinsci.plugins.cppcheck.CppcheckResult(newReport, result.getCppcheckSourceContainer(), getOwner());

//Config
org.jenkinsci.plugins.cppcheck.config.CppcheckConfig newConfig = new org.jenkinsci.plugins.cppcheck.config.CppcheckConfig(
cppcheckConfig.getCppcheckReportPattern(),
cppcheckConfig.isIgnoreBlankFiles(),
cppcheckConfig.getConfigSeverityEvaluation().getThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getNewThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getFailureThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getNewFailureThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getHealthy(),
cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityError(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle(),
true,
cppcheckConfig.getConfigGraph().getXSize(),
cppcheckConfig.getConfigGraph().getYSize(),
cppcheckConfig.getConfigGraph().isDiplayAllError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityStyle(),
cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleStyle(),
true);

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

}


Expand Down
@@ -1,71 +1,68 @@
package com.thalesgroup.hudson.plugins.cppcheck;

import org.apache.commons.lang.StringUtils;

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

public class CppcheckMetricUtil {

public static int convert(String threshold) {
if (isValid(threshold)) {
if (StringUtils.isNotBlank(threshold)) {
try {
return Integer.valueOf(threshold);
}
catch (NumberFormatException exception) {
// not valid
}
}
}
throw new IllegalArgumentException("Not a parsable integer value >= 0: " + threshold);
}

public static boolean isValid(final String threshold) {
if (StringUtils.isNotBlank(threshold)) {
try {
return Integer.valueOf(threshold) >= 0;
}
catch (NumberFormatException exception) {
// not valid
}
}
return false;
}

public static String getMessageSelectedSeverties(CppcheckConfig cppcheckConfig) {
StringBuffer sb = new StringBuffer();

if (cppcheckConfig.getConfigSeverityEvaluation().isAllSeverities()) {
sb.append("with all severities");
return sb.toString();
}

if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityError()) {
sb.append(" and ");
sb.append("severity 'error'");
}

if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError()) {
sb.append(" and ");
sb.append("severity 'possible error'");
}


if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle()) {
sb.append(" and ");
sb.append("severity 'possible style'");
}


if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle()) {
sb.append(" and ");
sb.append("severity 'style'");
}

if (sb.length() != 0)
sb.delete(0, 5);

return sb.toString();
}

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

import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig;
import org.apache.commons.lang.StringUtils;

public class CppcheckMetricUtil {

public static int convert(String threshold) {
if (isValid(threshold)) {
if (StringUtils.isNotBlank(threshold)) {
try {
return Integer.valueOf(threshold);
} catch (NumberFormatException exception) {
// not valid
}
}
}
throw new IllegalArgumentException("Not a parsable integer value >= 0: " + threshold);
}

public static boolean isValid(final String threshold) {
if (StringUtils.isNotBlank(threshold)) {
try {
return Integer.valueOf(threshold) >= 0;
} catch (NumberFormatException exception) {
// not valid
}
}
return false;
}

public static String getMessageSelectedSeverties(CppcheckConfig cppcheckConfig) {
StringBuffer sb = new StringBuffer();

if (cppcheckConfig.getConfigSeverityEvaluation().isAllSeverities()) {
sb.append("with all severities");
return sb.toString();
}

if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityError()) {
sb.append(" and ");
sb.append("severity 'error'");
}

if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError()) {
sb.append(" and ");
sb.append("severity 'possible error'");
}


if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle()) {
sb.append(" and ");
sb.append("severity 'possible style'");
}


if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle()) {
sb.append(" and ");
sb.append("severity 'style'");
}

if (sb.length() != 0)
sb.delete(0, 5);

return sb.toString();
}

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

package com.thalesgroup.hudson.plugins.cppcheck;

import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckProjectAction;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Result;

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


public class CppcheckProjectAction extends AbstractCppcheckProjectAction {

Expand All @@ -41,7 +40,7 @@ public CppcheckProjectAction(final AbstractProject<?, ?> project) {
}

public AbstractBuild<?, ?> getLastFinishedBuild() {
AbstractBuild<?, ?> lastBuild = (AbstractBuild<?, ?>) project.getLastBuild();
AbstractBuild<?, ?> lastBuild = project.getLastBuild();
while (lastBuild != null && (lastBuild.isBuilding() || lastBuild.getAction(CppcheckBuildAction.class) == null)) {
lastBuild = lastBuild.getPreviousBuild();
}
Expand All @@ -52,7 +51,7 @@ public CppcheckProjectAction(final AbstractProject<?, ?> project) {
public final boolean isDisplayGraph() {
//Latest
AbstractBuild<?, ?> b = getLastFinishedBuild();
if (b == null){
if (b == null) {
return false;
}

Expand Down
Expand Up @@ -28,7 +28,6 @@
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckBuildResultEvaluator;
import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckLogger;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixProject;
Expand All @@ -47,6 +46,7 @@
import java.io.IOException;
import java.util.Collection;

@Deprecated
public class CppcheckPublisher extends Recorder {

private CppcheckConfig cppcheckConfig;
Expand Down Expand Up @@ -154,14 +154,15 @@ private void copyFilesFromSlaveToMaster(final File rootDir,
}
}

@Extension

public static final CppcheckDescriptor DESCRIPTOR = new CppcheckDescriptor();

/**
* The Cppcheck Descriptor
*/
public static final class CppcheckDescriptor extends BuildStepDescriptor<Publisher> {

@SuppressWarnings("deprecation")
public CppcheckDescriptor() {
super(CppcheckPublisher.class);
load();
Expand Down Expand Up @@ -200,12 +201,10 @@ public CppcheckConfig getConfig() {
@Override
public Publisher newInstance(StaplerRequest req, JSONObject formData)
throws hudson.model.Descriptor.FormException {

@SuppressWarnings("deprecation")
CppcheckPublisher pub = new CppcheckPublisher();

CppcheckConfig cppcheckConfig = req.bindJSON(CppcheckConfig.class, formData);
pub.setCppcheckConfig(cppcheckConfig);

return pub;
}
}
Expand All @@ -220,4 +219,36 @@ public void setCppcheckConfig(CppcheckConfig cppcheckConfig) {
this.cppcheckConfig = cppcheckConfig;
}

@SuppressWarnings("unused")
private Object readResolve() {
org.jenkinsci.plugins.cppcheck.config.CppcheckConfig newConfig = new org.jenkinsci.plugins.cppcheck.config.CppcheckConfig(
cppcheckConfig.getCppcheckReportPattern(),
cppcheckConfig.isIgnoreBlankFiles(),
cppcheckConfig.getConfigSeverityEvaluation().getThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getNewThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getFailureThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getNewFailureThreshold(),
cppcheckConfig.getConfigSeverityEvaluation().getHealthy(),
cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityError(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle(),
cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle(),
true,
cppcheckConfig.getConfigGraph().getXSize(),
cppcheckConfig.getConfigGraph().getYSize(),
cppcheckConfig.getConfigGraph().isDiplayAllError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleError(),
cppcheckConfig.getConfigGraph().isDisplaySeverityStyle(),
cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleStyle(),
true);


org.jenkinsci.plugins.cppcheck.CppcheckPublisher cppcheckPublisher = new org.jenkinsci.plugins.cppcheck.CppcheckPublisher();
cppcheckPublisher.setCppcheckConfig(newConfig);
return cppcheckPublisher;
}


}

0 comments on commit e41b580

Please sign in to comment.