Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed JENKINS-9726
  • Loading branch information
gboissinot committed Jun 14, 2011
1 parent 84bf363 commit 931af5b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.398</version>
<version>1.407</version>
</parent>

<groupId>com.thalesgroup.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -29,8 +29,10 @@
import hudson.Util;
import hudson.model.BuildListener;
import hudson.remoting.VirtualChannel;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.selectors.FileSelector;

import java.io.File;
import java.io.IOException;
Expand All @@ -43,9 +45,11 @@ public class CppcheckParserResult implements FilePath.FileCallable<CppcheckRepor

private final String cppcheckReportPattern;

private final boolean ignoreBlankFiles;

public static final String DELAULT_REPORT_MAVEN = "**/cppcheck-result.xml";

public CppcheckParserResult(final BuildListener listener, String cppcheckReportPattern) {
public CppcheckParserResult(final BuildListener listener, String cppcheckReportPattern, boolean ignoreBlankFiles) {

if (cppcheckReportPattern == null) {
cppcheckReportPattern = DELAULT_REPORT_MAVEN;
Expand All @@ -57,6 +61,7 @@ public CppcheckParserResult(final BuildListener listener, String cppcheckReportP

this.listener = listener;
this.cppcheckReportPattern = cppcheckReportPattern;
this.ignoreBlankFiles = ignoreBlankFiles;
}

public CppcheckReport invoke(java.io.File basedir, VirtualChannel channel) throws IOException {
Expand Down Expand Up @@ -98,13 +103,20 @@ private static void mergeReport(CppcheckReport cppcheckReportResult, CppcheckRep
}

/**
* Return all cppechk report files
* Return all cppcheck report files
*
* @param parentPath parent
* @return an array of strings
*/
private String[] findCppcheckReports(File parentPath) {
FileSet fs = Util.createFileSet(parentPath, this.cppcheckReportPattern);
if (this.ignoreBlankFiles) {
fs.add(new FileSelector() {
public boolean isSelected(File basedir, String filename, File file) throws BuildException {
return file != null && file.length() != 0;
}
});
}
DirectoryScanner ds = fs.getDirectoryScanner();
return ds.getIncludedFiles();
}
Expand Down
Expand Up @@ -75,11 +75,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
if (this.canContinue(build.getResult())) {
CppcheckLogger.log(listener, "Starting the cppcheck analysis.");

// final FilePath[] moduleRoots = build.getModuleRoots();
// final boolean multipleModuleRoots = moduleRoots != null && moduleRoots.length > 1;
// final FilePath moduleRoot = multipleModuleRoots ? build.getWorkspace() : build.getModuleRoot();

CppcheckParserResult parser = new CppcheckParserResult(listener, cppcheckConfig.getCppcheckReportPattern());
CppcheckParserResult parser = new CppcheckParserResult(listener, cppcheckConfig.getCppcheckReportPattern(), cppcheckConfig.isIgnoreBlankFiles());
CppcheckReport cppcheckReport;
try {
cppcheckReport = build.getWorkspace().act(parser);
Expand Down Expand Up @@ -166,7 +162,6 @@ private void copyFilesFromSlaveToMaster(final File rootDir,
*/
public static final class CppcheckDescriptor extends BuildStepDescriptor<Publisher> {


public CppcheckDescriptor() {
super(CppcheckPublisher.class);
load();
Expand Down Expand Up @@ -225,5 +220,4 @@ public void setCppcheckConfig(CppcheckConfig cppcheckConfig) {
this.cppcheckConfig = cppcheckConfig;
}


}
Expand Up @@ -33,6 +33,8 @@ public class CppcheckConfig implements Serializable {

private String cppcheckReportPattern;

private boolean ignoreBlankFiles;

private CppcheckConfigSeverityEvaluation configSeverityEvaluation = new CppcheckConfigSeverityEvaluation();

private CppcheckConfigGraph configGraph = new CppcheckConfigGraph();
Expand All @@ -41,7 +43,9 @@ public CppcheckConfig() {
}

@DataBoundConstructor
public CppcheckConfig(String cppcheckReportPattern, String threshold,
@SuppressWarnings("unused")
public CppcheckConfig(String cppcheckReportPattern,
boolean ignoreBlankFiles, String threshold,
String newThreshold, String failureThreshold,
String newFailureThreshold, String healthy, String unHealthy,
boolean severityError, boolean severityPossibleError,
Expand All @@ -50,7 +54,7 @@ public CppcheckConfig(String cppcheckReportPattern, String threshold,
boolean displaySeverityStyle, boolean displaySeverityPossibleStyle) {

this.cppcheckReportPattern = cppcheckReportPattern;

this.ignoreBlankFiles = ignoreBlankFiles;
this.configSeverityEvaluation = new CppcheckConfigSeverityEvaluation(
threshold, newThreshold, failureThreshold, newFailureThreshold, healthy,
unHealthy, severityError, severityPossibleError, severityStyle, severityPossibleStyle);
Expand Down Expand Up @@ -104,26 +108,18 @@ public String getCppcheckReportPattern() {
return cppcheckReportPattern;
}

public void setCppcheckReportPattern(String cppcheckReportPattern) {
this.cppcheckReportPattern = cppcheckReportPattern;
public boolean isIgnoreBlankFiles() {
return ignoreBlankFiles;
}

public CppcheckConfigSeverityEvaluation getConfigSeverityEvaluation() {
return configSeverityEvaluation;
}

public void setConfigSeverityEvaluation(
CppcheckConfigSeverityEvaluation configSeverityEvaluation) {
this.configSeverityEvaluation = configSeverityEvaluation;
}

public CppcheckConfigGraph getConfigGraph() {
return configGraph;
}

public void setConfigGraph(CppcheckConfigGraph configGraph) {
this.configGraph = configGraph;
}

// Backward compatibility. Do not remove.
// CPPCHECK:OFF
Expand Down
Expand Up @@ -33,10 +33,15 @@
<f:entry title="${%Cppcheck report XMLs}"
description="${%description.pattern('http://ant.apache.org/manual/Types/fileset.html')}">
<f:textbox name="cppcheckReportPattern" value="${config.cppcheckReportPattern}"/>
</f:entry>
</f:entry>

<f:advanced>
<f:entry>
<f:checkbox name="ignoreBlankFiles" value="${config.ignoreBlankFiles}"/>
<label>Ignore blank files</label>
</f:entry>

<f:advanced>
<u:thresholds id="cppcheck"/>
</f:advanced>
</f:advanced>

</j:jelly>
Expand Up @@ -23,19 +23,18 @@

package com.thalesgroup.hudson.plugins.cppcheck;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import hudson.model.BuildListener;
import hudson.remoting.VirtualChannel;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CppcheckParserResultTest extends AbstractWorkspaceTest {

Expand All @@ -52,19 +51,19 @@ public void setUp() throws Exception {

@Test
public void testNullPattern() {
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null);
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null, false);
Assert.assertEquals("With none pattern, the default pattern must be " + CppcheckParserResult.DELAULT_REPORT_MAVEN, CppcheckParserResult.DELAULT_REPORT_MAVEN, cppcheckParserResult.getCppcheckReportPattern());
}

@Test
public void testEmptyPattern() {
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null);
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null, false);
Assert.assertEquals("With empty pattern, the default pattern must be " + CppcheckParserResult.DELAULT_REPORT_MAVEN, CppcheckParserResult.DELAULT_REPORT_MAVEN, cppcheckParserResult.getCppcheckReportPattern());
}

@Test
public void testNoMatch() throws Exception {
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, "*.xml");
CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, "*.xml", false);
CppcheckReport report = cppcheckParserResult.invoke(new File(workspace.toURI()), channel);
Assert.assertEquals("A pattern with no match files is not allowed.", null, report);
}
Expand Down

0 comments on commit 931af5b

Please sign in to comment.