Navigation Menu

Skip to content

Commit

Permalink
Fix JENKINS-9727
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Jun 17, 2011
1 parent bdc2467 commit 31a2a1d
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 18 deletions.
19 changes: 17 additions & 2 deletions pom.xml
Expand Up @@ -44,7 +44,7 @@
<java2html.version>5.0</java2html.version>
<junit.version>4.8.2</junit.version>
<mockito.version>1.8.5</mockito.version>
<ivy.plugin.version>1.15</ivy.plugin.version>
<ivy.plugin.version>1.19</ivy.plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -89,7 +89,7 @@
</dependency>

<dependency>
<groupId>org.jvnet.hudson.plugins</groupId>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ivy</artifactId>
<version>${ivy.plugin.version}</version>
<optional>true</optional>
Expand Down Expand Up @@ -119,6 +119,21 @@
<goal>xjc</goal>
</goals>
</execution>
<execution>
<id>generatedCppcheck2</id>
<configuration>
<packageName>org.jenkinsci.plugins.cppcheck.model</packageName>
<schemaDirectory>${basedir}/src/main/resources/org/jenkinsci/plugins/cppcheck
</schemaDirectory>
<schemaFiles>cppcheck-2.0.xsd</schemaFiles>
<staleFile>${project.build.directory}/generated-sources/jaxb/cppcheck2/.staleFlag.
</staleFile>
<clearOutputDir>false</clearOutputDir>
</configuration>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Expand Up @@ -109,7 +109,6 @@ public Object getDynamic(final String link, final StaplerRequest request, final
return null;
}


Map<Integer, CppcheckWorkspaceFile> agregateMap = cppcheckSourceContainer.getInternalMap();
if (agregateMap != null) {
CppcheckWorkspaceFile vCppcheckWorkspaceFile = agregateMap.get(Integer.parseInt(StringUtils.substringAfter(link, "source.")));
Expand Down
Expand Up @@ -24,9 +24,9 @@
package com.thalesgroup.hudson.plugins.cppcheck.parser;

import com.thalesgroup.hudson.plugins.cppcheck.CppcheckReport;
import com.thalesgroup.hudson.plugins.cppcheck.exception.CppcheckException;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile;
import com.thalesgroup.jenkinsci.plugins.cppcheck.model.*;
import org.jenkinsci.plugins.cppcheck.model.Errors;
import org.jenkinsci.plugins.cppcheck.model.Results;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
Expand All @@ -53,6 +53,36 @@ public CppcheckReport parse(final File file) throws IOException {
}


CppcheckReport report;
AtomicReference<JAXBContext> jc = new AtomicReference<JAXBContext>();
try {
jc.set(JAXBContext.newInstance(
org.jenkinsci.plugins.cppcheck.model.Error.class,
org.jenkinsci.plugins.cppcheck.model.Errors.class,
org.jenkinsci.plugins.cppcheck.model.Cppcheck.class,
org.jenkinsci.plugins.cppcheck.model.Results.class));
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
org.jenkinsci.plugins.cppcheck.model.Results results = (org.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
if (results.getCppcheck() == null) {
throw new JAXBException("Test with versio 1");
}
report = getReportVersion2(results);
} catch (JAXBException jxe) {
try {
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results.class));
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results = (com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results) unmarshaller.unmarshal(file);
report = getReportVersion1(results);
} catch (JAXBException jxe1) {
throw new IOException(jxe1);
}

}
return report;
}

private CppcheckReport getReportVersion1(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Results results) {

CppcheckReport cppCheckReport = new CppcheckReport();
List<CppcheckFile> everyErrors = new ArrayList<CppcheckFile>();
List<CppcheckFile> styleSeverities = new ArrayList<CppcheckFile>();
Expand All @@ -61,16 +91,64 @@ public CppcheckReport parse(final File file) throws IOException {
List<CppcheckFile> possibleErrorSeverities = new ArrayList<CppcheckFile>();
List<CppcheckFile> noCategorySeverities = new ArrayList<CppcheckFile>();

try {
AtomicReference<JAXBContext> jc;
jc = new AtomicReference<JAXBContext>();
jc.set(JAXBContext.newInstance(com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error.class, Results.class));
Unmarshaller unmarshaller = jc.get().createUnmarshaller();
Results results = (Results) unmarshaller.unmarshal(file);
CppcheckFile cppcheckFile;
for (int i = 0; i < results.getError().size(); i++) {
com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error error = results.getError().get(i);
cppcheckFile = new CppcheckFile();

cppcheckFile.setFileName(error.getFile());

//line can be optional
String lineAtr;
if ((lineAtr = error.getLine()) != null) {
cppcheckFile.setLineNumber(Integer.parseInt(lineAtr));
}

cppcheckFile.setCppCheckId(error.getId());
cppcheckFile.setSeverity(error.getSeverity());
cppcheckFile.setMessage(error.getMsg());

if ("possible error".equals(cppcheckFile.getSeverity())) {
possibleErrorSeverities.add(cppcheckFile);
} else if ("style".equals(cppcheckFile.getSeverity())) {
styleSeverities.add(cppcheckFile);
} else if ("possible style".equals(cppcheckFile.getSeverity())) {
possibleStyleSeverities.add(cppcheckFile);
} else if ("error".equals(cppcheckFile.getSeverity())) {
errorSeverities.add(cppcheckFile);
} else {
noCategorySeverities.add(cppcheckFile);
}
everyErrors.add(cppcheckFile);
}

cppCheckReport.setEverySeverities(everyErrors);
cppCheckReport.setPossibleErrorSeverities(possibleErrorSeverities);
cppCheckReport.setStyleSeverities(styleSeverities);
cppCheckReport.setPossibleStyleSeverities(possibleStyleSeverities);
cppCheckReport.setErrorSeverities(errorSeverities);
cppCheckReport.setNoCategorySeverities(noCategorySeverities);

return cppCheckReport;
}

CppcheckFile cppcheckFile;
for (int i = 0; i < results.getError().size(); i++) {
com.thalesgroup.jenkinsci.plugins.cppcheck.model.Error error = results.getError().get(i);
private CppcheckReport getReportVersion2(Results results) {

CppcheckReport cppCheckReport = new CppcheckReport();
List<CppcheckFile> everyErrors = new ArrayList<CppcheckFile>();
List<CppcheckFile> styleSeverities = new ArrayList<CppcheckFile>();
List<CppcheckFile> possibleStyleSeverities = new ArrayList<CppcheckFile>();
List<CppcheckFile> errorSeverities = new ArrayList<CppcheckFile>();
List<CppcheckFile> possibleErrorSeverities = new ArrayList<CppcheckFile>();
List<CppcheckFile> noCategorySeverities = new ArrayList<CppcheckFile>();

CppcheckFile cppcheckFile;

Errors errors = results.getErrors();

if (errors != null) {
for (int i = 0; i < errors.getError().size(); i++) {
org.jenkinsci.plugins.cppcheck.model.Error error = errors.getError().get(i);
cppcheckFile = new CppcheckFile();

cppcheckFile.setFileName(error.getFile());
Expand Down Expand Up @@ -98,9 +176,6 @@ public CppcheckReport parse(final File file) throws IOException {
}
everyErrors.add(cppcheckFile);
}

} catch (JAXBException jaxbe) {
throw new CppcheckException("Can't parse cppcheck result file " + file.getPath(), jaxbe);
}

cppCheckReport.setEverySeverities(everyErrors);
Expand All @@ -111,6 +186,7 @@ public CppcheckReport parse(final File file) throws IOException {
cppCheckReport.setNoCategorySeverities(noCategorySeverities);

return cppCheckReport;

}


}
51 changes: 51 additions & 0 deletions src/main/resources/org/jenkinsci/plugins/cppcheck/cppcheck-2.0.xsd
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
/*******************************************************************************
* Author : Gregory Boissinot *
******************************************************************************/
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="error">
<xs:complexType>
<xs:sequence>
<xs:element name="location">
<xs:complexType>
<xs:attribute name="file"/>
<xs:attribute name="line"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="file" type="xs:string" use="required"/>
<xs:attribute name="line" type="xs:string" use="optional"/>
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="severity" type="xs:string" use="required"/>
<xs:attribute name="msg" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>

<xs:element name="cppcheck">
<xs:complexType>
<xs:attribute name="version"/>
</xs:complexType>
</xs:element>

<xs:element name="errors">
<xs:complexType>
<xs:sequence>
<xs:element ref="error" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>


<xs:element name="results">
<xs:complexType>
<xs:sequence>
<xs:element ref="cppcheck" minOccurs="1" maxOccurs="1"/>
<xs:element ref="errors" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
@@ -0,0 +1,66 @@
package org.jenkinsci.plugins.cppcheck;

import com.thalesgroup.hudson.plugins.cppcheck.CppcheckReport;
import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile;
import com.thalesgroup.hudson.plugins.cppcheck.parser.CppcheckParser;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.List;

/**
* @author Gregory Boissinot
*/
public class CppcheckParserTest {


CppcheckParser cppcheckParser;

@Before
public void setUp() throws Exception {
cppcheckParser = new CppcheckParser();
}

@Test
public void testcppcheck1Version2() throws Exception {
processCppcheck("version2/testCppcheck.xml", 16, 0, 0, 0, 2, 14);
}

private void processCppcheck(String filename,
int nbErrors,
int nbSeveritiesPossibleError,
int nbSeveritiesPossibleStyle,
int nbStyleErrors,
int nbSeveritiesError,
int nbSeveritiesNoCategory) throws Exception {

CppcheckReport cppcheckReport = cppcheckParser.parse(new File(this.getClass().getResource(filename).toURI()));

List<CppcheckFile> everyErrors = cppcheckReport.getEverySeverities();
List<CppcheckFile> possibileErrorSeverities = cppcheckReport.getPossibleErrorSeverities();
List<CppcheckFile> styleErrors = cppcheckReport.getStyleSeverities();
List<CppcheckFile> possibleStyleSeverities = cppcheckReport.getPossibleStyleSeverities();
List<CppcheckFile> errorSeverities = cppcheckReport.getErrorSeverities();
List<CppcheckFile> noCategorySeverities = cppcheckReport.getNoCategorySeverities();

assert possibileErrorSeverities != null;
assert possibleStyleSeverities != null;
assert errorSeverities != null;
assert everyErrors != null;
assert styleErrors != null;
assert noCategorySeverities != null;

Assert.assertEquals("Wrong computing of list of errors", everyErrors.size(),
noCategorySeverities.size() + possibleStyleSeverities.size() + errorSeverities.size() + possibileErrorSeverities.size() + styleErrors.size());

Assert.assertEquals("Wrong total number of errors", nbErrors, everyErrors.size());
Assert.assertEquals("Wrong total number of errors for the severity 'possible error'", nbSeveritiesPossibleError, possibileErrorSeverities.size());
Assert.assertEquals("Wrong total number of errors for the severity 'possible style'", nbSeveritiesPossibleStyle, possibleStyleSeverities.size());
Assert.assertEquals("Wrong total number of errors for the severity 'style'", nbStyleErrors, styleErrors.size());
Assert.assertEquals("Wrong total number of errors for the severity 'error'", nbSeveritiesError, errorSeverities.size());
Assert.assertEquals("Wrong total number of errors with no category", nbSeveritiesNoCategory, noCategorySeverities.size());
}

}
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.48"/>
<errors>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Display/TestGenericDisplay.h&quot; not found." verbose="Include file: &quot;Test/Display/TestGenericDisplay.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="21"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Server/SuperFly.h&quot; not found." verbose="Include file: &quot;Test/Server/SuperFly.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="22"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Graphics/DispColors.h&quot; not found." verbose="Include file: &quot;Graphics/DispColors.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="23"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Graphics/TextureData.h&quot; not found." verbose="Include file: &quot;Graphics/TextureData.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="24"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Graphics/Decals.h&quot; not found." verbose="Include file: &quot;Graphics/Decals.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="25"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;InterfaceTest/InterfaceTest.hpp&quot; not found." verbose="Include file: &quot;InterfaceTest/InterfaceTest.hpp&quot; not found.">
<location file="TestGenericDisplay.cpp" line="26"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Utility/Assert.h&quot; not found." verbose="Include file: &quot;Utility/Assert.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="27"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Utility/FormatCharTesters.h&quot; not found." verbose="Include file: &quot;Utility/FormatCharTesters.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="28"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Utility/Units.h&quot; not found." verbose="Include file: &quot;Utility/Units.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="29"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Display/TestRegion.h&quot; not found." verbose="Include file: &quot;Test/Display/TestRegion.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="31"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;DisplayExec/DisplayModel.h&quot; not found." verbose="Include file: &quot;DisplayExec/DisplayModel.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="32"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Display/TestIndicatorFactory.h&quot; not found." verbose="Include file: &quot;Test/Display/TestIndicatorFactory.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="33"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Display/TestDataMonitor.h&quot; not found." verbose="Include file: &quot;Test/Display/TestDataMonitor.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="35"/>
</error>
<error id="missingInclude" severity="information" msg="Include file: &quot;Test/Display/TestStatusBlock.h&quot; not found." verbose="Include file: &quot;Test/Display/TestStatusBlock.h&quot; not found.">
<location file="TestGenericDisplay.cpp" line="38"/>
</error>
<error id="syntaxError" severity="error" msg="Invalid number of charTestter ({) when these macros are defined: 'TEST;TEST_VM2;TODO_TESTS_REFACTOR'." verbose="Invalid number of charTestter ({) when these macros are defined: 'TEST;TEST_VM2;TODO_TESTS_REFACTOR'.">
<location file="TestGenericDisplay.cpp" line="1600"/>
</error>
<error id="syntaxError" severity="error" msg="Invalid number of charTestter ({) when these macros are defined: 'TODO_TESTS_REFACTOR'." verbose="Invalid number of charTestter ({) when these macros are defined: 'TODO_TESTS_REFACTOR'.">
<location file="TestGenericDisplay.cpp" line="1600"/>
</error>
</errors>
</results>

0 comments on commit 31a2a1d

Please sign in to comment.