├── .github ├── CODEOWNERS ├── dependabot.yml ├── release-drafter.yml └── workflows │ ├── jenkins-security-scan.yml │ └── release-drafter.yml ├── .gitignore ├── .mvn ├── extensions.xml └── maven.config ├── CHANGELOG.md ├── Jenkinsfile ├── README.md ├── docs └── images │ └── 1.15_config.png ├── pom.xml └── src ├── it ├── java │ └── com │ │ └── thalesgroup │ │ └── hudson │ │ └── plugins │ │ └── cppcheck │ │ ├── CppcheckPublisherTest.java │ │ └── MultiFileSCM.java └── resources │ └── com │ └── thalesgroup │ └── hudson │ └── plugins │ └── cppcheck │ ├── testcppcheck1.xml │ └── testcppcheck2.xml ├── main ├── java │ ├── com │ │ └── thalesgroup │ │ │ └── hudson │ │ │ └── plugins │ │ │ └── cppcheck │ │ │ ├── CppcheckAreaRenderer.java │ │ │ ├── CppcheckBuildAction.java │ │ │ ├── CppcheckHealthReportThresholds.java │ │ │ ├── CppcheckMetricUtil.java │ │ │ ├── CppcheckParserResult.java │ │ │ ├── CppcheckProjectAction.java │ │ │ ├── CppcheckPublisher.java │ │ │ ├── CppcheckReport.java │ │ │ ├── CppcheckResult.java │ │ │ ├── CppcheckSource.java │ │ │ ├── CppcheckSummary.java │ │ │ ├── config │ │ │ ├── CppcheckConfig.java │ │ │ ├── CppcheckConfigGraph.java │ │ │ └── CppcheckConfigSeverityEvaluation.java │ │ │ ├── exception │ │ │ └── CppcheckException.java │ │ │ ├── graph │ │ │ └── CppcheckGraph.java │ │ │ ├── model │ │ │ ├── CppcheckFile.java │ │ │ ├── CppcheckSourceContainer.java │ │ │ └── CppcheckWorkspaceFile.java │ │ │ ├── parser │ │ │ └── CppcheckParser.java │ │ │ └── util │ │ │ ├── AbstractCppcheckBuildAction.java │ │ │ ├── AbstractCppcheckProjectAction.java │ │ │ ├── CppcheckBuildHealthEvaluator.java │ │ │ ├── CppcheckBuildResultEvaluator.java │ │ │ ├── CppcheckLogger.java │ │ │ └── CppcheckUtil.java │ └── org │ │ └── jenkinsci │ │ └── plugins │ │ └── cppcheck │ │ ├── CppcheckBuildAction.java │ │ ├── CppcheckDiffState.java │ │ ├── CppcheckParserResult.java │ │ ├── CppcheckProjectAction.java │ │ ├── CppcheckPublisher.java │ │ ├── CppcheckReport.java │ │ ├── CppcheckResult.java │ │ ├── CppcheckSourceAll.java │ │ ├── CppcheckSourceContainer.java │ │ ├── CppcheckStatistics.java │ │ ├── CppcheckTablePortlet.java │ │ ├── config │ │ ├── CppcheckConfig.java │ │ ├── CppcheckConfigGraph.java │ │ └── CppcheckConfigSeverityEvaluation.java │ │ ├── parser │ │ └── CppcheckParser.java │ │ └── util │ │ ├── AbstractCppcheckProjectAction.java │ │ ├── CppcheckBuildHealthEvaluator.java │ │ ├── CppcheckBuildResultEvaluator.java │ │ ├── CppcheckLogger.java │ │ └── CppcheckMetricUtil.java ├── resources │ ├── com │ │ └── thalesgroup │ │ │ └── hudson │ │ │ └── plugins │ │ │ └── cppcheck │ │ │ ├── CppcheckBuildAction │ │ │ └── summary.jelly │ │ │ ├── CppcheckProjectAction │ │ │ ├── floatingBox.jelly │ │ │ └── nodata.jelly │ │ │ ├── CppcheckPublisher │ │ │ ├── config.jelly │ │ │ └── config.properties │ │ │ ├── CppcheckResult │ │ │ ├── index.jelly │ │ │ ├── nosourcepermission.jelly │ │ │ └── summary.jelly │ │ │ ├── CppcheckSource │ │ │ ├── index.jelly │ │ │ └── index.properties │ │ │ ├── Messages.properties │ │ │ └── cppcheck-1.0.xsd │ ├── index.jelly │ ├── jelly │ │ └── cppcheck │ │ │ ├── format.jelly │ │ │ └── taglib │ ├── org │ │ └── jenkinsci │ │ │ └── plugins │ │ │ └── cppcheck │ │ │ ├── CppcheckBuildAction │ │ │ ├── statistics.jelly │ │ │ └── summary.jelly │ │ │ ├── CppcheckProjectAction │ │ │ ├── floatingBox.jelly │ │ │ ├── jobMain.jelly │ │ │ └── nodata.jelly │ │ │ ├── CppcheckPublisher │ │ │ ├── config.jelly │ │ │ ├── help-pattern.html │ │ │ ├── help-severity.html │ │ │ └── help-thresholds.html │ │ │ ├── CppcheckResult │ │ │ ├── details.jelly │ │ │ ├── index.jelly │ │ │ └── nosourcepermission.jelly │ │ │ ├── CppcheckSourceAll │ │ │ └── index.jelly │ │ │ ├── CppcheckTablePortlet │ │ │ ├── portlet.jelly │ │ │ └── table.jelly │ │ │ ├── Messages.properties │ │ │ └── cppcheck-2.0.xsd │ └── util │ │ ├── taglib │ │ ├── thresholds.jelly │ │ └── thresholds.properties └── webapp │ ├── help.html │ └── icons │ ├── cppcheck-24.png │ ├── cppcheck-32.png │ └── cppcheck-48.png └── test ├── java ├── com │ └── thalesgroup │ │ └── hudson │ │ └── plugins │ │ └── cppcheck │ │ ├── AbstractWorkspaceTest.java │ │ ├── CppcheckBuildHealthEvaluatorTest.java │ │ ├── CppcheckBuildResultEvaluatorTest.java │ │ ├── CppcheckParserResultTest.java │ │ ├── CppcheckParserTest.java │ │ ├── CppcheckResultTest.java │ │ └── CppcheckSummaryTest.java └── org │ └── jenkinsci │ └── plugins │ └── cppcheck │ └── CppcheckParserTest.java └── resources ├── com └── thalesgroup │ └── hudson │ └── plugins │ └── cppcheck │ ├── testcppcheck-part1.xml │ ├── testcppcheck-part2.xml │ ├── testcppcheck.cpp │ ├── testcppcheck1.xml │ └── testcppcheck2.xml └── org └── jenkinsci └── plugins └── cppcheck └── version2 └── testCppcheck.xml /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jenkinsci/cppcheck-plugin-developers 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 2 | 3 | version: 2 4 | updates: 5 | - package-ecosystem: "maven" 6 | directory: "/" 7 | schedule: 8 | interval: "weekly" 9 | - package-ecosystem: "github-actions" 10 | directory: "/" 11 | schedule: 12 | interval: "weekly" 13 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc 2 | _extends: .github 3 | tag-template: cppcheck-$NEXT_MINOR_VERSION 4 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | # Jenkins Security Scan 2 | # For more information, see: https://www.jenkins.io/doc/developer/security/scan/ 3 | 4 | name: Jenkins Security Scan 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | pull_request: 11 | types: [opened, synchronize, reopened] 12 | workflow_dispatch: 13 | 14 | permissions: 15 | security-events: write 16 | contents: read 17 | actions: read 18 | 19 | jobs: 20 | security-scan: 21 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 22 | with: 23 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 24 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 25 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | # Automates creation of Release Drafts using Release Drafter 2 | # More Info: https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc 3 | 4 | on: 5 | push: 6 | branches: 7 | - master 8 | 9 | jobs: 10 | update_release_draft: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # Drafts your next Release notes as Pull Requests are merged into "master" 14 | - uses: release-drafter/release-drafter@v5 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | 3 | # mvn hpi:run 4 | work 5 | 6 | # IntelliJ IDEA project files 7 | *.iml 8 | *.iws 9 | *.ipr 10 | .idea 11 | 12 | # Eclipse project files 13 | .settings 14 | .classpath 15 | .project 16 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.3 6 | 7 | 8 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | buildPlugin(useContainerAgent: true, configurations: [ 2 | [ platform: 'linux', jdk: '8' ], 3 | [ platform: 'linux', jdk: '11' ], 4 | [ platform: 'windows', jdk: '11' ], 5 | ]) 6 | -------------------------------------------------------------------------------- /docs/images/1.15_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/docs/images/1.15_config.png -------------------------------------------------------------------------------- /src/it/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckPublisherTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import hudson.model.FreeStyleBuild; 27 | import hudson.model.FreeStyleProject; 28 | import hudson.model.Label; 29 | import hudson.slaves.DumbSlave; 30 | import org.jvnet.hudson.test.HudsonTestCase; 31 | import org.jvnet.hudson.test.SingleFileSCM; 32 | 33 | import java.util.ArrayList; 34 | import java.util.List; 35 | 36 | public class CppcheckPublisherTest extends HudsonTestCase { 37 | 38 | 39 | /** 40 | * Verify that it works on a master. 41 | */ 42 | public void testOnMaster() throws Exception { 43 | FreeStyleProject project = createFreeStyleProject(); 44 | 45 | List files = new ArrayList(2); 46 | 47 | files.add(new SingleFileSCM("cppcheckresult/testcppcheck1.xml", 48 | getClass().getResource("testcppcheck1.xml"))); 49 | 50 | 51 | project.setScm(new MultiFileSCM(files)); 52 | 53 | project.getPublishersList().add(new CppcheckPublisher("cppcheckresult/testcppcheck1.xml", null, null, null, null, null, null, null)); 54 | FreeStyleBuild build1 = project.scheduleBuild2(0).get(); 55 | 56 | //FreeStyleBuild build2 = project.scheduleBuild2(0).get(); 57 | System.out.println(build1.getLog()); 58 | assertBuildStatusSuccess(build1); 59 | 60 | } 61 | 62 | /** 63 | * Verify that it works on a slave. 64 | */ 65 | public void oldtestOnSlave() throws Exception { 66 | FreeStyleProject project = createFreeStyleProject(); 67 | DumbSlave slave = createSlave(new Label("cppcheck-test-slave")); 68 | 69 | project.setAssignedLabel(slave.getSelfLabel()); 70 | List files = new ArrayList(2); 71 | files.add(new SingleFileSCM("cppcheckresult/testcppcheck1.xml", 72 | getClass().getResource("testcppcheck1.xml"))); 73 | project.setScm(new MultiFileSCM(files)); 74 | 75 | project.getPublishersList().add(new CppcheckPublisher("cppcheckresult/testcppcheck1.xml", null, null, null, null, null, null, null)); 76 | FreeStyleBuild build1 = project.scheduleBuild2(0).get(); 77 | assertBuildStatusSuccess(build1); 78 | } 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/it/java/com/thalesgroup/hudson/plugins/cppcheck/MultiFileSCM.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import hudson.FilePath; 27 | import hudson.Launcher; 28 | import hudson.model.AbstractBuild; 29 | import hudson.model.BuildListener; 30 | import hudson.scm.NullSCM; 31 | import org.jvnet.hudson.test.SingleFileSCM; 32 | 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.util.ArrayList; 36 | import java.util.List; 37 | 38 | 39 | public class MultiFileSCM extends NullSCM { 40 | private List files = new ArrayList(); 41 | 42 | public MultiFileSCM(List files) { 43 | this.files = files; 44 | } 45 | 46 | @SuppressWarnings("unchecked") 47 | @Override 48 | public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { 49 | for (SingleFileSCM file : this.files) { 50 | file.checkout(build, launcher, workspace, listener, changeLogFile); 51 | } 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/it/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | 12 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/it/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Checking /tmp/cppcheck/testcppcheck.cpp... 4 | 6 | 8 | 10 | 12 | 14 | 16 | 17 | 18 | 19 | 1/2 files checked 50% done 20 | Checking /tmp/cppcheck/testcppcheck2.cpp... 21 | 23 | 25 | 27 | 29 | 31 | 33 | 34 | 35 | 36 | 2/2 files checked 100% done 37 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckAreaRenderer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import hudson.util.ChartUtil.NumberOnlyBuildLabel; 27 | import hudson.util.StackedAreaRenderer2; 28 | 29 | import org.jfree.data.category.CategoryDataset; 30 | 31 | /** 32 | * Renderer that provides direct access to the individual results of a build via 33 | * links. This renderer does not render tooltips, these need to be defined in 34 | * sub-classes. 35 | */ 36 | public class CppcheckAreaRenderer extends StackedAreaRenderer2 { 37 | /** 38 | * Unique identifier of this class. 39 | */ 40 | private static final long serialVersionUID = 1440842055316682192L; 41 | /** 42 | * Base URL of the graph links. 43 | */ 44 | private final String url; 45 | 46 | 47 | public CppcheckAreaRenderer(final String url) { 48 | super(); 49 | this.url = "/" + url + "/"; 50 | } 51 | 52 | /** 53 | * {@inheritDoc} 54 | */ 55 | @Override 56 | public final String generateURL(final CategoryDataset dataset, final int row, final int column) { 57 | return getLabel(dataset, column).build.getNumber() + url; 58 | } 59 | 60 | /** 61 | * Returns the Jenkins build label at the specified column. 62 | * 63 | * @param dataset data set of values 64 | * @param column the column 65 | * @return the label of the column 66 | */ 67 | private NumberOnlyBuildLabel getLabel(final CategoryDataset dataset, final int column) { 68 | return (NumberOnlyBuildLabel) dataset.getColumnKey(column); 69 | } 70 | 71 | /** 72 | * Checks this instance for equality with an arbitrary object. 73 | * 74 | * @param obj the object (null not permitted). 75 | * 76 | * @return A boolean. 77 | */ 78 | public boolean equals(Object obj) { 79 | if (obj == this) { 80 | return true; 81 | } 82 | if (!(obj instanceof CppcheckAreaRenderer)) { 83 | return false; 84 | } 85 | CppcheckAreaRenderer that = (CppcheckAreaRenderer) obj; 86 | 87 | if (this.url != that.url) { 88 | return false; 89 | } 90 | return super.equals(obj); 91 | } 92 | 93 | 94 | public int hashCode() { 95 | return this.url.hashCode(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckHealthReportThresholds.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | 25 | package com.thalesgroup.hudson.plugins.cppcheck; 26 | 27 | import java.io.Serializable; 28 | 29 | 30 | public class CppcheckHealthReportThresholds implements Serializable { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | private final String threshold; 35 | 36 | private final String newThreshold; 37 | 38 | private final String failureThreshold; 39 | 40 | private final String newFailureThreshold; 41 | 42 | private final String healthy; 43 | 44 | private final String unHealthy; 45 | 46 | private final String thresholdLimit; 47 | 48 | 49 | public CppcheckHealthReportThresholds(String threshold, String newThreshold, String failureThreshold, String newFailureThreshold, String healthy, String unHealthy, String thresholdLimit) { 50 | this.threshold = threshold; 51 | this.newThreshold = newThreshold; 52 | this.failureThreshold = failureThreshold; 53 | this.newFailureThreshold = newFailureThreshold; 54 | this.healthy = healthy; 55 | this.unHealthy = unHealthy; 56 | this.thresholdLimit = thresholdLimit; 57 | } 58 | 59 | public String getThreshold() { 60 | return threshold; 61 | } 62 | 63 | public String getNewThreshold() { 64 | return newThreshold; 65 | } 66 | 67 | public String getFailureThreshold() { 68 | return failureThreshold; 69 | } 70 | 71 | public String getNewFailureThreshold() { 72 | return newFailureThreshold; 73 | } 74 | 75 | public String getHealthy() { 76 | return healthy; 77 | } 78 | 79 | public String getUnHealthy() { 80 | return unHealthy; 81 | } 82 | 83 | public String getThresholdLimit() { 84 | return thresholdLimit; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckMetricUtil.java: -------------------------------------------------------------------------------- 1 | package com.thalesgroup.hudson.plugins.cppcheck; 2 | 3 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 4 | import org.apache.commons.lang.StringUtils; 5 | 6 | public class CppcheckMetricUtil { 7 | 8 | public static int convert(String threshold) { 9 | if (isValid(threshold)) { 10 | if (StringUtils.isNotBlank(threshold)) { 11 | try { 12 | return Integer.parseInt(threshold); 13 | } catch (NumberFormatException exception) { 14 | // not valid 15 | } 16 | } 17 | } 18 | throw new IllegalArgumentException("Not a parsable integer value >= 0: " + threshold); 19 | } 20 | 21 | public static boolean isValid(final String threshold) { 22 | if (StringUtils.isNotBlank(threshold)) { 23 | try { 24 | return Integer.parseInt(threshold) >= 0; 25 | } catch (NumberFormatException exception) { 26 | // not valid 27 | } 28 | } 29 | return false; 30 | } 31 | 32 | public static String getMessageSelectedSeverties(CppcheckConfig cppcheckConfig) { 33 | StringBuffer sb = new StringBuffer(); 34 | 35 | if (cppcheckConfig.getConfigSeverityEvaluation().isAllSeverities()) { 36 | sb.append("with all severities"); 37 | return sb.toString(); 38 | } 39 | 40 | if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityError()) { 41 | sb.append(" and "); 42 | sb.append("severity 'error'"); 43 | } 44 | 45 | if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError()) { 46 | sb.append(" and "); 47 | sb.append("severity 'possible error'"); 48 | } 49 | 50 | 51 | if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle()) { 52 | sb.append(" and "); 53 | sb.append("severity 'possible style'"); 54 | } 55 | 56 | 57 | if (cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle()) { 58 | sb.append(" and "); 59 | sb.append("severity 'style'"); 60 | } 61 | 62 | if (sb.length() != 0) 63 | sb.delete(0, 5); 64 | 65 | return sb.toString(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckProjectAction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckProjectAction; 27 | import hudson.model.AbstractBuild; 28 | import hudson.model.AbstractProject; 29 | import hudson.model.Result; 30 | 31 | 32 | public class CppcheckProjectAction extends AbstractCppcheckProjectAction { 33 | 34 | public String getSearchUrl() { 35 | return getUrlName(); 36 | } 37 | 38 | public CppcheckProjectAction(final AbstractProject project) { 39 | super(project); 40 | } 41 | 42 | public AbstractBuild getLastFinishedBuild() { 43 | AbstractBuild lastBuild = project.getLastBuild(); 44 | while (lastBuild != null && (lastBuild.isBuilding() || lastBuild.getAction(CppcheckBuildAction.class) == null)) { 45 | lastBuild = lastBuild.getPreviousBuild(); 46 | } 47 | return lastBuild; 48 | } 49 | 50 | @SuppressWarnings("unused") 51 | public final boolean isDisplayGraph() { 52 | //Latest 53 | AbstractBuild b = getLastFinishedBuild(); 54 | if (b == null) { 55 | return false; 56 | } 57 | 58 | //Affect previous 59 | b = b.getPreviousBuild(); 60 | if (b != null) { 61 | 62 | for (; b != null; b = b.getPreviousBuild()) { 63 | if (b.getResult().isWorseOrEqualTo(Result.FAILURE)) { 64 | continue; 65 | } 66 | CppcheckBuildAction action = b.getAction(CppcheckBuildAction.class); 67 | if (action == null || action.getResult() == null) { 68 | continue; 69 | } 70 | CppcheckResult result = action.getResult(); 71 | if (result == null) 72 | continue; 73 | 74 | return true; 75 | } 76 | } 77 | return false; 78 | } 79 | 80 | public Integer getLastResultBuild() { 81 | for (AbstractBuild b = (AbstractBuild) project.getLastBuild(); b != null; b = b.getPreviousNotFailedBuild()) { 82 | if (b.getResult() == Result.FAILURE) 83 | continue; 84 | CppcheckBuildAction r = b.getAction(CppcheckBuildAction.class); 85 | if (r != null) 86 | return b.getNumber(); 87 | } 88 | return null; 89 | } 90 | 91 | 92 | public String getDisplayName() { 93 | return "Cppcheck Results"; 94 | } 95 | 96 | public String getUrlName() { 97 | return CppcheckBuildAction.URL_NAME; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckPublisher.java: -------------------------------------------------------------------------------- 1 | package com.thalesgroup.hudson.plugins.cppcheck; 2 | 3 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 4 | import hudson.model.AbstractProject; 5 | import hudson.tasks.BuildStepDescriptor; 6 | import hudson.tasks.BuildStepMonitor; 7 | import hudson.tasks.Publisher; 8 | import hudson.tasks.Recorder; 9 | 10 | /** 11 | * @author Gregory Boissinot 12 | */ 13 | @Deprecated 14 | public class CppcheckPublisher extends Recorder { 15 | 16 | private transient CppcheckConfig cppcheckConfig; 17 | 18 | public BuildStepMonitor getRequiredMonitorService() { 19 | return BuildStepMonitor.BUILD; 20 | } 21 | 22 | public static final CppcheckDescriptor DESCRIPTOR = new CppcheckDescriptor(); 23 | 24 | /** 25 | * The Cppcheck Descriptor 26 | */ 27 | public static final class CppcheckDescriptor extends BuildStepDescriptor { 28 | 29 | @SuppressWarnings("deprecation") 30 | public CppcheckDescriptor() { 31 | super(CppcheckPublisher.class); 32 | load(); 33 | } 34 | 35 | public boolean isApplicable(Class jobType) { 36 | return false; 37 | } 38 | 39 | @Override 40 | public String getDisplayName() { 41 | return "Publish Cppcheck results"; 42 | } 43 | 44 | } 45 | 46 | 47 | @SuppressWarnings("unused") 48 | private Object readResolve() { 49 | 50 | org.jenkinsci.plugins.cppcheck.config.CppcheckConfig config = new org.jenkinsci.plugins.cppcheck.config.CppcheckConfig(); 51 | config.setPattern(cppcheckConfig.getCppcheckReportPattern()); 52 | config.setIgnoreBlankFiles(cppcheckConfig.isIgnoreBlankFiles()); 53 | 54 | org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation configSeverityEvaluation = new org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation( 55 | cppcheckConfig.getConfigSeverityEvaluation().getThreshold(), 56 | cppcheckConfig.getConfigSeverityEvaluation().getNewThreshold(), 57 | cppcheckConfig.getConfigSeverityEvaluation().getFailureThreshold(), 58 | cppcheckConfig.getConfigSeverityEvaluation().getNewFailureThreshold(), 59 | cppcheckConfig.getConfigSeverityEvaluation().getHealthy(), 60 | cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy(), 61 | cppcheckConfig.getConfigSeverityEvaluation().isSeverityError(), 62 | cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError(), 63 | cppcheckConfig.getConfigSeverityEvaluation().isSeverityStyle(), 64 | cppcheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle(), 65 | true, true, true); 66 | config.setConfigSeverityEvaluation(configSeverityEvaluation); 67 | 68 | org.jenkinsci.plugins.cppcheck.config.CppcheckConfigGraph configGraph = new org.jenkinsci.plugins.cppcheck.config.CppcheckConfigGraph( 69 | cppcheckConfig.getConfigGraph().getXSize(), 70 | cppcheckConfig.getConfigGraph().getYSize(), 71 | 0, 72 | cppcheckConfig.getConfigGraph().isDiplayAllError(), 73 | cppcheckConfig.getConfigGraph().isDisplaySeverityError(), 74 | cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleError(), 75 | cppcheckConfig.getConfigGraph().isDisplaySeverityStyle(), 76 | cppcheckConfig.getConfigGraph().isDisplaySeverityPossibleStyle(), 77 | true, true, true); 78 | config.setConfigGraph(configGraph); 79 | 80 | org.jenkinsci.plugins.cppcheck.CppcheckPublisher cppcheckPublisher = new org.jenkinsci.plugins.cppcheck.CppcheckPublisher(config); 81 | return cppcheckPublisher; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckSummary.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | public class CppcheckSummary { 27 | 28 | private CppcheckSummary() { 29 | } 30 | 31 | 32 | /** 33 | * Creates an HTML Cppcheck summary. 34 | * 35 | * @param result the cppcheck result object 36 | * @return the HTML fragment representing the cppcheck report summary 37 | */ 38 | public static String createReportSummary(CppcheckResult result) { 39 | 40 | StringBuilder summary = new StringBuilder(); 41 | int nbErrors = result.getReport().getNumberTotal(); 42 | 43 | summary.append(Messages.cppcheck_Errors_ProjectAction_Name()); 44 | summary.append(": "); 45 | if (nbErrors == 0) { 46 | summary.append(Messages.cppcheck_ResultAction_NoError()); 47 | } else { 48 | summary.append(""); 49 | 50 | if (nbErrors == 1) { 51 | summary.append(Messages.cppcheck_ResultAction_OneError()); 52 | } else { 53 | summary.append(Messages.cppcheck_ResultAction_MultipleErrors(nbErrors)); 54 | } 55 | summary.append(""); 56 | } 57 | summary.append("."); 58 | 59 | return summary.toString(); 60 | } 61 | 62 | 63 | /** 64 | * Creates an HTML Cppcheck detailed summary. 65 | * 66 | * @param result the cppcheck result object 67 | * @return the HTML fragment representing the cppcheck report details summary 68 | */ 69 | public static String createReportSummaryDetails(CppcheckResult result) { 70 | 71 | StringBuilder builder = new StringBuilder(); 72 | int nbNewErrors = result.getNumberNewErrorsFromPreviousBuild(); 73 | 74 | builder.append("
  • "); 75 | 76 | if (nbNewErrors == 0) { 77 | builder.append(Messages.cppcheck_ResultAction_Detail_NoNewError()); 78 | } else if (nbNewErrors == 1) { 79 | builder.append(Messages.cppcheck_ResultAction_Detail_NewOneError()); 80 | } else { 81 | builder.append(Messages.cppcheck_ResultAction_Detail_NewMultipleErrors()); 82 | builder.append(": "); 83 | builder.append(nbNewErrors); 84 | } 85 | builder.append("
  • "); 86 | 87 | return builder.toString(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/config/CppcheckConfigGraph.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.config; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.graph.CppcheckGraph; 27 | 28 | import java.io.Serializable; 29 | 30 | public class CppcheckConfigGraph implements Serializable { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | private int xSize = CppcheckGraph.DEFAULT_CHART_WIDTH; 35 | 36 | private int ySize = CppcheckGraph.DEFAULT_CHART_HEIGHT; 37 | 38 | private boolean diplayAllError = true; 39 | 40 | private boolean displaySeverityError = true; 41 | 42 | private boolean displaySeverityPossibleError = true; 43 | 44 | private boolean displaySeverityStyle = true; 45 | 46 | private boolean displaySeverityPossibleStyle = true; 47 | 48 | 49 | public CppcheckConfigGraph() { 50 | } 51 | 52 | public CppcheckConfigGraph(int xSize, int ySize, boolean diplayAllError, 53 | boolean displaySeverityError, boolean displaySeverityPossibleError, 54 | boolean displaySeverityStyle, boolean displaySeverityPossibleStyle) { 55 | super(); 56 | this.xSize = xSize; 57 | this.ySize = ySize; 58 | this.diplayAllError = diplayAllError; 59 | this.displaySeverityError = displaySeverityError; 60 | this.displaySeverityPossibleError = displaySeverityPossibleError; 61 | this.displaySeverityStyle = displaySeverityStyle; 62 | this.displaySeverityPossibleStyle = displaySeverityPossibleStyle; 63 | } 64 | 65 | public int getXSize() { 66 | return xSize; 67 | } 68 | 69 | public int getYSize() { 70 | return ySize; 71 | } 72 | 73 | public boolean isDiplayAllError() { 74 | return diplayAllError; 75 | } 76 | 77 | public boolean isDisplaySeverityError() { 78 | return displaySeverityError; 79 | } 80 | 81 | public boolean isDisplaySeverityPossibleError() { 82 | return displaySeverityPossibleError; 83 | } 84 | 85 | public boolean isDisplaySeverityStyle() { 86 | return displaySeverityStyle; 87 | } 88 | 89 | public boolean isDisplaySeverityPossibleStyle() { 90 | return displaySeverityPossibleStyle; 91 | } 92 | 93 | // public Object readResolve() { 94 | // return new org.jenkinsci.plugins.cppcheck.config.CppcheckConfigGraph( 95 | // xSize, 96 | // ySize, diplayAllError, displaySeverityError, displaySeverityPossibleError, displaySeverityStyle, displaySeverityPossibleStyle, true); 97 | // } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/exception/CppcheckException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.exception; 25 | 26 | public class CppcheckException extends RuntimeException { 27 | 28 | public CppcheckException() { 29 | } 30 | 31 | public CppcheckException(String message) { 32 | super(message); 33 | } 34 | 35 | public CppcheckException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | 39 | public CppcheckException(Throwable cause) { 40 | super(cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckFile.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009-2011 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.model; 25 | 26 | import hudson.model.ModelObject; 27 | 28 | import org.apache.commons.lang.StringEscapeUtils; 29 | import org.kohsuke.stapler.export.Exported; 30 | import org.kohsuke.stapler.export.ExportedBean; 31 | 32 | import java.io.Serializable; 33 | 34 | @ExportedBean(defaultVisibility = 999) 35 | public class CppcheckFile implements ModelObject, Serializable { 36 | 37 | private static final long serialVersionUID = 3L; 38 | 39 | private Integer key; 40 | 41 | private String fileName; 42 | 43 | private int lineNumber; 44 | 45 | private String severity; 46 | 47 | private String cppCheckId; 48 | 49 | private String message; 50 | 51 | /** Verbose message, optional. */ 52 | private String verbose = null; 53 | 54 | /** The issue may be false positive. */ 55 | private boolean inconclusive = false; 56 | 57 | @Exported 58 | public String getFileName() { 59 | return fileName; 60 | } 61 | 62 | /** 63 | * Get the filename. 64 | * 65 | * @return the filename or empty string if the filename is null 66 | */ 67 | public String getFileNameNotNull() { 68 | return (fileName != null) ? fileName : ""; 69 | } 70 | 71 | public void setFileName(String filename) { 72 | this.fileName = filename; 73 | } 74 | 75 | @Exported 76 | public int getLineNumber() { 77 | return lineNumber; 78 | } 79 | 80 | /** 81 | * Get line number depending on availability of the file name. 82 | * 83 | * @return the line number or empty string if the file name is empty 84 | */ 85 | public String getLineNumberString() { 86 | return ("".equals(getFileNameNotNull())) ? "" : String.valueOf(lineNumber); 87 | } 88 | 89 | /** 90 | * Returns the line number that should be shown on top of the source code view. 91 | * 92 | * @return the line number 93 | */ 94 | public int getLinkLineNumber() { 95 | return Math.max(1, lineNumber - 10); 96 | } 97 | 98 | public void setLineNumber(int lineNumber) { 99 | this.lineNumber = lineNumber; 100 | } 101 | 102 | @Exported 103 | public String getCppCheckId() { 104 | return cppCheckId; 105 | } 106 | 107 | public void setCppCheckId(String cppCheckId) { 108 | this.cppCheckId = cppCheckId; 109 | } 110 | 111 | @Exported 112 | public String getMessage() { 113 | return message; 114 | } 115 | 116 | public String getMessageHtml() { 117 | return StringEscapeUtils.escapeHtml(message); 118 | } 119 | 120 | public void setMessage(String message) { 121 | this.message = message; 122 | } 123 | 124 | @Exported 125 | public String getSeverity() { 126 | return severity; 127 | } 128 | 129 | public void setSeverity(String severity) { 130 | this.severity = severity; 131 | } 132 | 133 | @Exported 134 | public Integer getKey() { 135 | return key; 136 | } 137 | 138 | public void setKey(Integer key) { 139 | this.key = key; 140 | } 141 | 142 | @Exported 143 | public String getVerbose() { 144 | return verbose; 145 | } 146 | 147 | public String getVerboseHtml() { 148 | return StringEscapeUtils.escapeHtml(verbose); 149 | } 150 | 151 | public void setVerbose(String verbose) { 152 | this.verbose = verbose; 153 | } 154 | 155 | @Exported 156 | public boolean isInconclusive() { 157 | return inconclusive; 158 | } 159 | 160 | public void setInconclusive(boolean inconclusive) { 161 | this.inconclusive = inconclusive; 162 | } 163 | 164 | public String getDisplayName() { 165 | return "cppcheckFile"; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckSourceContainer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.model; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckLogger; 27 | 28 | import hudson.FilePath; 29 | import hudson.model.BuildListener; 30 | 31 | import java.io.IOException; 32 | import java.io.Serializable; 33 | import java.util.HashMap; 34 | import java.util.List; 35 | import java.util.Map; 36 | 37 | public class CppcheckSourceContainer implements Serializable { 38 | /** Serial version UID. */ 39 | private static final long serialVersionUID = 1L; 40 | 41 | private Map internalMap = new HashMap(); 42 | 43 | public CppcheckSourceContainer(BuildListener listener, FilePath basedir, List files) throws IOException, InterruptedException { 44 | int key = 1; 45 | for (CppcheckFile cppcheckFile : files) { 46 | 47 | CppcheckWorkspaceFile cppcheckWorkspaceFile = new CppcheckWorkspaceFile(); 48 | 49 | String cppcheckFileName = cppcheckFile.getFileName(); 50 | if (cppcheckFileName == null) { 51 | cppcheckWorkspaceFile.setFileName(null); 52 | cppcheckWorkspaceFile.setSourceIgnored(true); 53 | } else { 54 | FilePath sourceFilePath = new FilePath(basedir, cppcheckFileName); 55 | if (!sourceFilePath.exists()) { 56 | CppcheckLogger.log(listener, "[WARNING] - The source file '" + sourceFilePath.toURI() + "' doesn't exist on the slave. The ability to display its source code has been removed."); 57 | cppcheckWorkspaceFile.setFileName(null); 58 | cppcheckWorkspaceFile.setSourceIgnored(true); 59 | } else if (sourceFilePath.isDirectory()) { 60 | cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote()); 61 | cppcheckWorkspaceFile.setSourceIgnored(true); 62 | } else { 63 | cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote()); 64 | cppcheckWorkspaceFile.setSourceIgnored(false); 65 | } 66 | } 67 | 68 | //The key must be unique for all the files/errors through the merge 69 | cppcheckFile.setKey(key); 70 | cppcheckWorkspaceFile.setCppcheckFile(cppcheckFile); 71 | internalMap.put(key, cppcheckWorkspaceFile); 72 | ++key; 73 | } 74 | } 75 | 76 | public Map getInternalMap() { 77 | return internalMap; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/model/CppcheckWorkspaceFile.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.model; 25 | 26 | import hudson.model.Run; 27 | 28 | import org.apache.commons.lang.StringUtils; 29 | import org.jenkinsci.plugins.cppcheck.CppcheckDiffState; 30 | 31 | import java.io.File; 32 | import java.io.Serializable; 33 | 34 | public class CppcheckWorkspaceFile implements Serializable { 35 | /** Serial version UID. */ 36 | private static final long serialVersionUID = 1L; 37 | 38 | /** 39 | * Subdirectory of build directory to store the workspace files. 40 | */ 41 | public static final String DIR_WORKSPACE_FILES = "workspace-files"; 42 | 43 | private String fileName; 44 | 45 | private CppcheckFile cppcheckFile; 46 | 47 | /** 48 | * Useful for files that are not found on the build file system 49 | */ 50 | private boolean sourceIgnored; 51 | 52 | /** 53 | * State of compare. It is a runtime parameter, don't store it anywhere 54 | * (transient). 55 | * 56 | * @since 1.15 57 | */ 58 | private transient CppcheckDiffState diffState = null; 59 | 60 | public CppcheckWorkspaceFile(File file) { 61 | if (file != null) 62 | this.fileName = file.getAbsolutePath().replace('\\', '/'); 63 | } 64 | 65 | public CppcheckWorkspaceFile() { 66 | 67 | } 68 | 69 | 70 | public CppcheckFile getCppcheckFile() { 71 | return cppcheckFile; 72 | } 73 | 74 | 75 | public void setCppcheckFile(CppcheckFile cppcheckFile) { 76 | this.cppcheckFile = cppcheckFile; 77 | } 78 | 79 | 80 | public void setFileName(String fileName) { 81 | this.fileName = fileName; 82 | if (fileName == null) { 83 | setSourceIgnored(true); 84 | } 85 | } 86 | 87 | 88 | /** 89 | * Returns a file name for a temporary file that will hold the contents of the source. 90 | * 91 | * @return the temporary name 92 | */ 93 | public String getTempName() { 94 | return Integer.toHexString(getFileName().hashCode()) + ".tmp"; 95 | } 96 | 97 | /** 98 | * Returns the name of this file. 99 | * 100 | * @return the name of this file 101 | */ 102 | public final String getFileName() { 103 | return fileName; 104 | } 105 | 106 | public String getTempName(final Run owner) { 107 | if (fileName != null) { 108 | return owner.getRootDir().getAbsolutePath() + "/" 109 | + DIR_WORKSPACE_FILES + "/" 110 | + Integer.toHexString(fileName.hashCode()) + ".tmp"; 111 | } 112 | return StringUtils.EMPTY; 113 | } 114 | 115 | public boolean isSourceIgnored() { 116 | return sourceIgnored; 117 | } 118 | 119 | public void setSourceIgnored(boolean sourceIgnored) { 120 | this.sourceIgnored = sourceIgnored; 121 | } 122 | 123 | public CppcheckDiffState getDiffState() { 124 | return diffState; 125 | } 126 | 127 | public void setDiffState(CppcheckDiffState diffState) { 128 | this.diffState = diffState; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/AbstractCppcheckBuildAction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | package com.thalesgroup.hudson.plugins.cppcheck.util; 24 | 25 | import hudson.model.*; 26 | import org.kohsuke.stapler.StaplerProxy; 27 | import jenkins.model.RunAction2; 28 | 29 | public abstract class AbstractCppcheckBuildAction extends Actionable implements RunAction2, HealthReportingAction, StaplerProxy { 30 | protected transient Run owner; 31 | 32 | protected AbstractCppcheckBuildAction(Run owner) { 33 | this.owner = owner; 34 | } 35 | 36 | public T getPreviousResult() { 37 | Run b = owner; 38 | while (true) { 39 | b = b.getPreviousBuild(); 40 | if (b == null) 41 | return null; 42 | if (b.getResult() == Result.FAILURE) 43 | continue; 44 | AbstractCppcheckBuildAction r = b.getAction(this.getClass()); 45 | if (r != null) 46 | return (T) r; 47 | } 48 | } 49 | 50 | public Run getOwner() { 51 | return owner; 52 | } 53 | 54 | public void setOwner(Run owner) { 55 | this.owner = owner; 56 | } 57 | 58 | public void onAttached(Run r) { 59 | setOwner(r); 60 | } 61 | 62 | public void onLoad(Run r) { 63 | setOwner(r); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/AbstractCppcheckProjectAction.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.util; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.CppcheckBuildAction; 27 | import hudson.model.AbstractBuild; 28 | import hudson.model.AbstractProject; 29 | import hudson.model.Actionable; 30 | import hudson.model.ProminentProjectAction; 31 | import org.kohsuke.stapler.StaplerRequest; 32 | import org.kohsuke.stapler.StaplerResponse; 33 | 34 | import java.io.IOException; 35 | 36 | public abstract class AbstractCppcheckProjectAction extends Actionable implements ProminentProjectAction { 37 | 38 | protected final AbstractProject project; 39 | 40 | public AbstractCppcheckProjectAction(AbstractProject project) { 41 | this.project = project; 42 | } 43 | 44 | public AbstractProject getProject() { 45 | return project; 46 | } 47 | 48 | public String getIconFileName() { 49 | return "/plugin/cppcheck/icons/cppcheck-24.png"; 50 | } 51 | 52 | public String getSearchUrl() { 53 | return getUrlName(); 54 | } 55 | 56 | protected abstract AbstractBuild getLastFinishedBuild(); 57 | 58 | protected abstract Integer getLastResultBuild(); 59 | 60 | public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { 61 | AbstractBuild lastBuild = getLastFinishedBuild(); 62 | CppcheckBuildAction cppcheckBuildAction = lastBuild.getAction(CppcheckBuildAction.class); 63 | if (cppcheckBuildAction != null) { 64 | cppcheckBuildAction.doGraph(req, rsp); 65 | } 66 | } 67 | 68 | public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException { 69 | Integer buildNumber = getLastResultBuild(); 70 | if (buildNumber == null) { 71 | rsp.sendRedirect2("nodata"); 72 | } else { 73 | rsp.sendRedirect2("../" + buildNumber + "/" + getUrlName()); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/CppcheckBuildHealthEvaluator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.util; 25 | 26 | import org.jenkinsci.plugins.cppcheck.Messages; 27 | 28 | import com.thalesgroup.hudson.plugins.cppcheck.CppcheckMetricUtil; 29 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 30 | 31 | import hudson.model.HealthReport; 32 | 33 | public class CppcheckBuildHealthEvaluator { 34 | 35 | public HealthReport evaluatBuildHealth(CppcheckConfig cppcheckConfig, int nbErrorForSeverity) { 36 | 37 | if (cppcheckConfig == null) { 38 | // no thresholds => no report 39 | return null; 40 | } 41 | 42 | if (isHealthyReportEnabled(cppcheckConfig)) { 43 | int percentage; 44 | 45 | if (nbErrorForSeverity < CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getHealthy())) { 46 | percentage = 100; 47 | } else if (nbErrorForSeverity > CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy())) { 48 | percentage = 0; 49 | } else { 50 | percentage = 100 - ((nbErrorForSeverity - CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getHealthy())) * 100 51 | / (CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy()) - CppcheckMetricUtil.convert(cppcheckConfig.getConfigSeverityEvaluation().getHealthy()))); 52 | } 53 | 54 | return new HealthReport(percentage, Messages.cppcheck_BuildHealthEvaluatorDescription(CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig))); 55 | } 56 | return null; 57 | } 58 | 59 | 60 | private boolean isHealthyReportEnabled(CppcheckConfig cppcheckconfig) { 61 | if (CppcheckMetricUtil.isValid(cppcheckconfig.getConfigSeverityEvaluation().getHealthy()) && CppcheckMetricUtil.isValid(cppcheckconfig.getConfigSeverityEvaluation().getUnHealthy())) { 62 | int healthyNumber = CppcheckMetricUtil.convert(cppcheckconfig.getConfigSeverityEvaluation().getHealthy()); 63 | int unHealthyNumber = CppcheckMetricUtil.convert(cppcheckconfig.getConfigSeverityEvaluation().getUnHealthy()); 64 | return unHealthyNumber > healthyNumber; 65 | } 66 | return false; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/CppcheckBuildResultEvaluator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.util; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.CppcheckMetricUtil; 27 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 28 | import hudson.model.BuildListener; 29 | import hudson.model.Result; 30 | 31 | public class CppcheckBuildResultEvaluator { 32 | 33 | private boolean isErrorCountExceeded(final int errorCount, final String errorThreshold) { 34 | if (errorCount > 0 && CppcheckMetricUtil.isValid(errorThreshold)) { 35 | return errorCount > CppcheckMetricUtil.convert(errorThreshold); 36 | } 37 | return false; 38 | } 39 | 40 | public Result evaluateBuildResult( 41 | final BuildListener listener, 42 | int errorsCount, 43 | int newErrorsCount, 44 | CppcheckConfig cppcheckConfig) { 45 | 46 | if (isErrorCountExceeded(errorsCount, cppcheckConfig.getConfigSeverityEvaluation().getFailureThreshold())) { 47 | CppcheckLogger.log(listener, "Setting build status to FAILURE since total number of errors (" 48 | + CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig) 49 | + ") exceeds the threshold value ;" + cppcheckConfig.getConfigSeverityEvaluation().getFailureThreshold() + "'."); 50 | return Result.FAILURE; 51 | } 52 | if (isErrorCountExceeded(newErrorsCount, cppcheckConfig.getConfigSeverityEvaluation().getNewFailureThreshold())) { 53 | CppcheckLogger.log(listener, "Setting build status to FAILURE since total number of new errors (" 54 | + CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig) 55 | + ") exceeds the threshold value '" + cppcheckConfig.getConfigSeverityEvaluation().getNewFailureThreshold() + "'."); 56 | return Result.FAILURE; 57 | } 58 | if (isErrorCountExceeded(errorsCount, cppcheckConfig.getConfigSeverityEvaluation().getThreshold())) { 59 | CppcheckLogger.log(listener, "Setting build status to UNSTABLE since total number of errors (" 60 | + CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig) 61 | + ") exceeds the threshold value '" + cppcheckConfig.getConfigSeverityEvaluation().getThreshold() + "'."); 62 | return Result.UNSTABLE; 63 | } 64 | if (isErrorCountExceeded(newErrorsCount, cppcheckConfig.getConfigSeverityEvaluation().getNewThreshold())) { 65 | CppcheckLogger.log(listener, "Setting build status to UNSTABLE since total number of new errors (" 66 | + CppcheckMetricUtil.getMessageSelectedSeverties(cppcheckConfig) 67 | + ") exceeds the threshold value '" + cppcheckConfig.getConfigSeverityEvaluation().getNewThreshold() + "'."); 68 | return Result.UNSTABLE; 69 | } 70 | 71 | CppcheckLogger.log(listener, "Not changing build status, since no threshold has been exceeded"); 72 | return Result.SUCCESS; 73 | } 74 | 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/CppcheckLogger.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.util; 25 | 26 | import hudson.model.BuildListener; 27 | 28 | import java.io.Serializable; 29 | 30 | public class CppcheckLogger implements Serializable { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | /** 35 | * Log output to the given logger, using the Cppcheck identifier 36 | * 37 | * @param listener The current listener 38 | * @param message The message to be outputted 39 | */ 40 | public static void log(BuildListener listener, final String message) { 41 | listener.getLogger().println("[Cppcheck] " + message); 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/com/thalesgroup/hudson/plugins/cppcheck/util/CppcheckUtil.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck.util; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.CppcheckResult; 27 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 28 | 29 | public class CppcheckUtil { 30 | 31 | /** 32 | * Gets the number of errors 33 | * 34 | * @param cppecheckConfig configuration of CppCheck run 35 | * @param result results of the CPPCheck runs 36 | * @param checkNewError check is the number of errors is increasing 37 | * @return number of errors 38 | */ 39 | public static int getNumberErrors(CppcheckConfig cppecheckConfig, CppcheckResult result, boolean checkNewError) { 40 | 41 | int nbErrors = 0; 42 | int nbPreviousError = 0; 43 | CppcheckResult previousResult = result.getPreviousResult(); 44 | 45 | if (cppecheckConfig.getConfigSeverityEvaluation().isSeverityPossibleError()) { 46 | nbErrors = result.getReport().getPossibleErrorSeverities().size(); 47 | if (previousResult != null) { 48 | nbPreviousError = previousResult.getReport().getPossibleErrorSeverities().size(); 49 | } 50 | } 51 | 52 | if (cppecheckConfig.getConfigSeverityEvaluation().isSeverityStyle()) { 53 | nbErrors = nbErrors + result.getReport().getStyleSeverities().size(); 54 | if (previousResult != null) { 55 | nbPreviousError = nbPreviousError + previousResult.getReport().getStyleSeverities().size(); 56 | } 57 | 58 | } 59 | 60 | if (cppecheckConfig.getConfigSeverityEvaluation().isSeverityPossibleStyle()) { 61 | nbErrors = nbErrors + result.getReport().getPossibleStyleSeverities().size(); 62 | if (previousResult != null) { 63 | nbPreviousError = nbPreviousError + previousResult.getReport().getPossibleStyleSeverities().size(); 64 | } 65 | } 66 | 67 | if (cppecheckConfig.getConfigSeverityEvaluation().isSeverityError()) { 68 | nbErrors = nbErrors + result.getReport().getErrorSeverities().size(); 69 | if (previousResult != null) { 70 | nbPreviousError = nbPreviousError + previousResult.getReport().getErrorSeverities().size(); 71 | } 72 | } 73 | 74 | if (checkNewError) { 75 | if (previousResult != null) { 76 | return nbErrors - nbPreviousError; 77 | } else { 78 | return 0; 79 | } 80 | } else 81 | return nbErrors; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckBuildAction.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Collections; 8 | import java.util.List; 9 | 10 | import com.thalesgroup.hudson.plugins.cppcheck.util.AbstractCppcheckBuildAction; 11 | 12 | import hudson.model.Run; 13 | import jenkins.tasks.SimpleBuildStep; 14 | import hudson.model.Action; 15 | import hudson.model.HealthReport; 16 | 17 | import org.jenkinsci.plugins.cppcheck.config.CppcheckConfig; 18 | import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation; 19 | import org.jenkinsci.plugins.cppcheck.util.CppcheckBuildHealthEvaluator; 20 | 21 | import javax.annotation.Nonnull; 22 | 23 | /** 24 | * @author Gregory Boissinot 25 | */ 26 | public class CppcheckBuildAction extends AbstractCppcheckBuildAction implements SimpleBuildStep.LastBuildAction { 27 | 28 | public static final String URL_NAME = "cppcheckResult"; 29 | 30 | private final CppcheckResult result; 31 | private final CppcheckConfig config; 32 | 33 | /** 34 | * The health report percentage. 35 | * 36 | * @since 1.15 37 | */ 38 | private int healthReportPercentage; 39 | 40 | public CppcheckBuildAction(@Nonnull Run owner, @Nonnull CppcheckResult result, @Nonnull CppcheckConfig config, 41 | int healthReportPercentage) { 42 | super(owner); 43 | 44 | this.result = result; 45 | this.config = config; 46 | this.healthReportPercentage = healthReportPercentage; 47 | 48 | } 49 | 50 | public String getIconFileName() { 51 | return "/plugin/cppcheck/icons/cppcheck-24.png"; 52 | } 53 | 54 | public String getDisplayName() { 55 | return Messages.cppcheck_CppcheckResults(); 56 | } 57 | 58 | public String getUrlName() { 59 | return URL_NAME; 60 | } 61 | 62 | public String getSearchUrl() { 63 | return getUrlName(); 64 | } 65 | 66 | public CppcheckResult getResult() { 67 | return this.result; 68 | } 69 | 70 | public CppcheckConfig getConfig() { 71 | return this.config; 72 | } 73 | 74 | Run getBuild() { 75 | return this.owner; 76 | } 77 | 78 | public Object getTarget() { 79 | return this.result; 80 | } 81 | 82 | public HealthReport getBuildHealth() { 83 | if(healthReportPercentage >= 0 && healthReportPercentage <= 100) { 84 | return new HealthReport(healthReportPercentage, 85 | Messages._cppcheck_BuildStability()); 86 | } else { 87 | return null; 88 | } 89 | } 90 | 91 | public static int computeHealthReportPercentage(CppcheckResult result, 92 | CppcheckConfigSeverityEvaluation severityEvaluation) { 93 | try { 94 | return new CppcheckBuildHealthEvaluator().evaluatBuildHealth(severityEvaluation, 95 | result.getNumberErrorsAccordingConfiguration(severityEvaluation, 96 | false)); 97 | } catch (IOException e) { 98 | return -1; 99 | } 100 | } 101 | 102 | // Backward compatibility 103 | @Deprecated 104 | private Run build; 105 | 106 | /** Backward compatibility with version 1.14 and less. */ 107 | @Deprecated 108 | private CppcheckConfig cppcheckConfig; 109 | 110 | /** 111 | * Initializes members that were not present in previous versions of this plug-in. 112 | * 113 | * @return the created object 114 | */ 115 | private Object readResolve() { 116 | if (build != null) { 117 | this.owner = build; 118 | } 119 | 120 | // Backward compatibility with version 1.14 and less 121 | if (cppcheckConfig != null) { 122 | healthReportPercentage = 100; 123 | } 124 | 125 | return this; 126 | } 127 | 128 | @Override 129 | public Collection getProjectActions() { 130 | 131 | if (this.owner == null) { 132 | return Collections.emptySet(); 133 | } else { 134 | return Collections.singleton(new CppcheckProjectAction(owner.getParent())); 135 | } 136 | } 137 | 138 | @Override 139 | public synchronized void setOwner(Run owner) { 140 | super.setOwner(owner); 141 | 142 | this.result.setOwner(owner); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckDiffState.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | /** 4 | * Status of comparison of two reports. 5 | * 6 | * Implementation note: The upper case of the constants and declaration order 7 | * are significant, the second one is used in sorting. 8 | * 9 | * @see CppcheckResult#diffCurrentAndPrevious(java.util.Set) 10 | * @author Michal Turek 11 | */ 12 | public enum CppcheckDiffState { 13 | /** The issue is present only in the current report. */ 14 | NEW { 15 | @Override 16 | public String getCss() { 17 | return "new"; 18 | } 19 | 20 | @Override 21 | public String getText() { 22 | return Messages.cppcheck_DiffNew(); 23 | } 24 | }, 25 | 26 | /** The issue is present only in the previous report. */ 27 | SOLVED { 28 | @Override 29 | public String getCss() { 30 | return "solved"; 31 | } 32 | 33 | @Override 34 | public String getText() { 35 | return Messages.cppcheck_DiffSolved(); 36 | } 37 | }, 38 | 39 | /** The issue is present in both the current and the previous report. */ 40 | UNCHANGED { 41 | @Override 42 | public String getCss() { 43 | return "unchanged"; 44 | } 45 | 46 | @Override 47 | public String getText() { 48 | return Messages.cppcheck_DiffUnchanged(); 49 | } 50 | }; 51 | 52 | /** 53 | * Get CSS class. 54 | * 55 | * @return the class 56 | */ 57 | public abstract String getCss(); 58 | 59 | /** 60 | * Get localized text. 61 | * 62 | * @return the localized text 63 | */ 64 | public abstract String getText(); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckParserResult.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | 4 | import hudson.FilePath; 5 | import hudson.Util; 6 | import hudson.model.TaskListener; 7 | import hudson.remoting.VirtualChannel; 8 | import jenkins.security.Roles; 9 | import org.apache.tools.ant.BuildException; 10 | import org.apache.tools.ant.DirectoryScanner; 11 | import org.apache.tools.ant.types.FileSet; 12 | import org.apache.tools.ant.types.selectors.FileSelector; 13 | import org.jenkinsci.plugins.cppcheck.model.Cppcheck; 14 | import org.jenkinsci.plugins.cppcheck.parser.CppcheckParser; 15 | import org.jenkinsci.plugins.cppcheck.util.CppcheckLogger; 16 | import org.jenkinsci.remoting.RoleChecker; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | 21 | /** 22 | * @author Gregory Boissinot 23 | */ 24 | public class CppcheckParserResult implements FilePath.FileCallable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | private final TaskListener listener; 29 | 30 | private final String cppcheckReportPattern; 31 | 32 | private final boolean ignoreBlankFiles; 33 | 34 | public static final String DEFAULT_REPORT_MAVEN = "**/cppcheck-result.xml"; 35 | 36 | public CppcheckParserResult(final TaskListener listener, String cppcheckReportPattern, boolean ignoreBlankFiles) { 37 | 38 | if (cppcheckReportPattern == null) { 39 | cppcheckReportPattern = DEFAULT_REPORT_MAVEN; 40 | } 41 | 42 | if (cppcheckReportPattern.trim().length() == 0) { 43 | cppcheckReportPattern = DEFAULT_REPORT_MAVEN; 44 | } 45 | 46 | this.listener = listener; 47 | this.cppcheckReportPattern = cppcheckReportPattern; 48 | this.ignoreBlankFiles = ignoreBlankFiles; 49 | } 50 | 51 | public CppcheckReport invoke(java.io.File basedir, VirtualChannel channel) throws IOException { 52 | 53 | CppcheckReport cppcheckReportResult = new CppcheckReport(); 54 | try { 55 | String[] cppcheckReportFiles = findCppcheckReports(basedir); 56 | if (cppcheckReportFiles.length == 0) { 57 | String msg = "No cppcheck test report file(s) were found with the pattern '" 58 | + cppcheckReportPattern + "' relative to '" 59 | + basedir + "'." 60 | + " Did you enter a pattern relative to the correct directory?" 61 | + " Did you generate the XML report(s) for Cppcheck?"; 62 | CppcheckLogger.log(listener, msg); 63 | throw new IllegalArgumentException(msg); 64 | } 65 | 66 | CppcheckLogger.log(listener, "Processing " + cppcheckReportFiles.length + " files with the pattern '" + cppcheckReportPattern + "'."); 67 | 68 | for (String cppcheckReportFileName : cppcheckReportFiles) { 69 | CppcheckReport cppcheckReport = new CppcheckParser().parse(new File(basedir, cppcheckReportFileName), listener); 70 | mergeReport(cppcheckReportResult, cppcheckReport); 71 | } 72 | } catch (Exception e) { 73 | String stack_trace = org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(e); 74 | CppcheckLogger.log(listener, "Parsing throws exceptions. " + e.getMessage()); 75 | CppcheckLogger.log(listener, stack_trace); 76 | return null; 77 | } 78 | 79 | return cppcheckReportResult; 80 | } 81 | 82 | 83 | private static void mergeReport(CppcheckReport cppcheckReportResult, CppcheckReport cppcheckReport) { 84 | cppcheckReportResult.getErrorSeverityList().addAll(cppcheckReport.getErrorSeverityList()); 85 | cppcheckReportResult.getWarningSeverityList().addAll(cppcheckReport.getWarningSeverityList()); 86 | cppcheckReportResult.getStyleSeverityList().addAll(cppcheckReport.getStyleSeverityList()); 87 | cppcheckReportResult.getPerformanceSeverityList().addAll(cppcheckReport.getPerformanceSeverityList()); 88 | cppcheckReportResult.getInformationSeverityList().addAll(cppcheckReport.getInformationSeverityList()); 89 | cppcheckReportResult.getNoCategorySeverityList().addAll(cppcheckReport.getNoCategorySeverityList()); 90 | cppcheckReportResult.getPortabilitySeverityList().addAll(cppcheckReport.getPortabilitySeverityList()); 91 | cppcheckReportResult.getAllErrors().addAll(cppcheckReport.getAllErrors()); 92 | cppcheckReportResult.getVersions().add(cppcheckReport.getVersion()); 93 | } 94 | 95 | /** 96 | * Return all cppcheck report files 97 | * 98 | * @param parentPath parent 99 | * @return an array of strings 100 | */ 101 | private String[] findCppcheckReports(File parentPath) { 102 | FileSet fs = Util.createFileSet(parentPath, this.cppcheckReportPattern); 103 | if (this.ignoreBlankFiles) { 104 | fs.add(new FileSelector() { 105 | public boolean isSelected(File basedir, String filename, File file) throws BuildException { 106 | return file != null && file.length() != 0; 107 | } 108 | }); 109 | } 110 | DirectoryScanner ds = fs.getDirectoryScanner(); 111 | return ds.getIncludedFiles(); 112 | } 113 | 114 | public String getCppcheckReportPattern() { 115 | return cppcheckReportPattern; 116 | } 117 | 118 | public void checkRoles(RoleChecker checker) throws SecurityException { 119 | checker.check(this, Roles.SLAVE); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckSourceAll.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileNotFoundException; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.nio.charset.StandardCharsets; 10 | import java.util.Collection; 11 | 12 | import org.apache.commons.io.IOUtils; 13 | import org.apache.commons.lang.StringEscapeUtils; 14 | 15 | import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile; 16 | 17 | import hudson.model.Run; 18 | 19 | /** 20 | * Show all violations highlighted on a single page. 21 | * 22 | * @author Michal Turek 23 | * @since 1.16 24 | */ 25 | public class CppcheckSourceAll { 26 | /** The related build. */ 27 | private final Run owner; 28 | 29 | /** The files to show. */ 30 | private final Collection files; 31 | 32 | /** Number of lines to show before the highlighted line. */ 33 | private final int linesBefore; 34 | 35 | /** Number of lines to show after the highlighted line. */ 36 | private final int linesAfter; 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param owner 42 | * the related build 43 | * @param files 44 | * the files to show 45 | * @param linesBefore 46 | * number of lines to show before the highlighted line 47 | * @param linesAfter 48 | * number of lines to show after the highlighted line 49 | */ 50 | public CppcheckSourceAll(Run owner, 51 | Collection files, int linesBefore, 52 | int linesAfter) { 53 | this.owner = owner; 54 | this.files = files; 55 | this.linesBefore = linesBefore; 56 | this.linesAfter = linesAfter; 57 | } 58 | 59 | public Run getOwner() { 60 | return owner; 61 | } 62 | 63 | public Collection getFiles() { 64 | return files; 65 | } 66 | 67 | public int getLinesBefore() { 68 | return linesBefore; 69 | } 70 | 71 | public int getLinesAfter() { 72 | return linesAfter; 73 | } 74 | 75 | /** 76 | * Get specified lines of source code from the file. 77 | * 78 | * @param file 79 | * the input file 80 | * @return the related lines of code with HTML formatting 81 | */ 82 | public String getSourceCode(CppcheckWorkspaceFile file) { 83 | File tempFile = new File(file.getTempName(owner)); 84 | 85 | if (!tempFile.exists()) { 86 | return "Can't read file: " + tempFile.getAbsolutePath(); 87 | } 88 | 89 | BufferedReader reader = null; 90 | 91 | try { 92 | reader = new BufferedReader(new InputStreamReader(new FileInputStream(tempFile), StandardCharsets.UTF_8));//new FileReader(tempFile)); 93 | return getRelatedLines(reader, file.getCppcheckFile() 94 | .getLineNumber()); 95 | } catch (FileNotFoundException e) { 96 | return "Can't read file: " + e; 97 | } catch (IOException e) { 98 | return "Reading file failed: " + e; 99 | } finally { 100 | IOUtils.closeQuietly(reader); 101 | } 102 | } 103 | 104 | /** 105 | * Get specified lines from a stream. 106 | * 107 | * @param reader 108 | * the input stream 109 | * @param lineNumber 110 | * the base line 111 | * @return the lines with HTML formatting 112 | * @throws IOException 113 | * if something fails 114 | */ 115 | private String getRelatedLines(BufferedReader reader, int lineNumber) 116 | throws IOException { 117 | final int start = (lineNumber > linesBefore) ? lineNumber - linesBefore : 1; 118 | final int end = lineNumber + linesAfter; 119 | final String numberFormat = "%0" + String.valueOf(end).length() + "d"; 120 | 121 | StringBuilder builder = new StringBuilder(); 122 | int current = 1; 123 | String line = ""; 124 | 125 | while ((line = reader.readLine()) != null && current <= end) { 126 | if (current >= start) { 127 | if (current == lineNumber) { 128 | builder.append("
    "); 129 | } else { 130 | builder.append("
    "); 131 | } 132 | 133 | builder.append(""); 134 | builder.append(String.format(numberFormat, current)); 135 | builder.append(" ");// The space separates line number and code 136 | builder.append(StringEscapeUtils.escapeHtml(line)); 137 | builder.append("
    \n"); 138 | } 139 | 140 | ++current; 141 | } 142 | 143 | return builder.toString(); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckSourceContainer.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile; 4 | import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckWorkspaceFile; 5 | import hudson.FilePath; 6 | import hudson.model.TaskListener; 7 | import org.jenkinsci.plugins.cppcheck.util.CppcheckLogger; 8 | 9 | import java.io.IOException; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author Gregory Boissinot 16 | */ 17 | public class CppcheckSourceContainer { 18 | 19 | private Map internalMap = new HashMap(); 20 | 21 | public CppcheckSourceContainer(Map internalMap) { 22 | this.internalMap = internalMap; 23 | } 24 | 25 | public CppcheckSourceContainer(TaskListener listener, 26 | FilePath workspace, 27 | FilePath scmRootDir, 28 | List files) throws IOException, InterruptedException { 29 | 30 | int key = 1; 31 | for (CppcheckFile cppcheckFile : files) { 32 | CppcheckWorkspaceFile cppcheckWorkspaceFile = getCppcheckWorkspaceFile(listener, workspace, scmRootDir, cppcheckFile); 33 | //The key must be unique for all the files/errors through the merge 34 | cppcheckFile.setKey(key); 35 | cppcheckWorkspaceFile.setCppcheckFile(cppcheckFile); 36 | internalMap.put(key, cppcheckWorkspaceFile); 37 | ++key; 38 | } 39 | } 40 | 41 | private CppcheckWorkspaceFile getCppcheckWorkspaceFile(TaskListener listener, 42 | FilePath workspace, 43 | FilePath scmRootDir, 44 | CppcheckFile cppcheckFile) throws IOException, InterruptedException { 45 | 46 | String cppcheckFileName = cppcheckFile.getFileName(); 47 | 48 | if (cppcheckFileName == null) { 49 | CppcheckWorkspaceFile cppcheckWorkspaceFile = new CppcheckWorkspaceFile(); 50 | cppcheckWorkspaceFile.setFileName(null); 51 | cppcheckWorkspaceFile.setSourceIgnored(true); 52 | return cppcheckWorkspaceFile; 53 | } 54 | 55 | CppcheckWorkspaceFile cppcheckWorkspaceFile = new CppcheckWorkspaceFile(); 56 | FilePath sourceFilePath = getSourceFile(workspace, scmRootDir, cppcheckFileName); 57 | if (!sourceFilePath.exists()) { 58 | CppcheckLogger.log(listener, "[WARNING] - The source file '" + sourceFilePath.toURI() + "' doesn't exist on the slave. The ability to display its source code has been removed."); 59 | cppcheckWorkspaceFile.setFileName(null); 60 | cppcheckWorkspaceFile.setSourceIgnored(true); 61 | } else if (sourceFilePath.isDirectory()) { 62 | cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote()); 63 | cppcheckWorkspaceFile.setSourceIgnored(true); 64 | } else { 65 | cppcheckWorkspaceFile.setFileName(sourceFilePath.getRemote()); 66 | cppcheckWorkspaceFile.setSourceIgnored(false); 67 | } 68 | 69 | return cppcheckWorkspaceFile; 70 | } 71 | 72 | private FilePath getSourceFile(FilePath workspace, FilePath scmRootDir, String cppcheckFileName) throws IOException, InterruptedException { 73 | FilePath sourceFilePath = new FilePath(scmRootDir, cppcheckFileName); 74 | if (!sourceFilePath.exists()) { 75 | //try from workspace 76 | sourceFilePath = new FilePath(workspace, cppcheckFileName); 77 | } 78 | return sourceFilePath; 79 | } 80 | 81 | 82 | public Map getInternalMap() { 83 | return internalMap; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckStatistics.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | import java.io.Serializable; 4 | import java.util.Collections; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import org.kohsuke.stapler.export.Exported; 9 | import org.kohsuke.stapler.export.ExportedBean; 10 | 11 | /** 12 | * Statistics for a report to be stored in build.xml file. Details are lazy 13 | * loaded from external file after they are needed. 14 | * 15 | * @author Michal Turek 16 | * @since 1.15 17 | */ 18 | @ExportedBean 19 | public class CppcheckStatistics implements Serializable { 20 | /** Serial version UID. */ 21 | private static final long serialVersionUID = 1L; 22 | 23 | /** Count of error issues. */ 24 | private final int errorCount; 25 | 26 | /** Count of warning issues. */ 27 | private final int warningCount; 28 | 29 | /** Count of style issues. */ 30 | private final int styleCount; 31 | 32 | /** Count of performance issues. */ 33 | private final int performanceCount; 34 | 35 | /** Count of information issues. */ 36 | private final int informationCount; 37 | 38 | /** Count of issues with no category. */ 39 | private final int noCategoryCount; 40 | 41 | /** Count of portability issues. */ 42 | private final int portabilityCount; 43 | 44 | /** Cppcheck versions used for generating of the report. */ 45 | private final Set versions; 46 | 47 | /** 48 | * Constructor, create an empty object. 49 | */ 50 | public CppcheckStatistics() { 51 | this(0, 0, 0, 0, 0, 0, 0, Collections. emptySet()); 52 | } 53 | 54 | /** 55 | * @param errorCount 56 | * count of error issues 57 | * @param warningCount 58 | * count of warning issues 59 | * @param styleCount 60 | * count of style issues 61 | * @param performanceCount 62 | * count of performance issues 63 | * @param informationCount 64 | * count of information issues 65 | * @param noCategoryCount 66 | * count of issues with no category 67 | * @param portabilityCount 68 | * count of portability issues 69 | * @param versions 70 | * Cppcheck versions used for generating of the report 71 | */ 72 | public CppcheckStatistics(int errorCount, int warningCount, int styleCount, 73 | int performanceCount, int informationCount, int noCategoryCount, 74 | int portabilityCount, Set versions) { 75 | this.errorCount = errorCount; 76 | this.warningCount = warningCount; 77 | this.styleCount = styleCount; 78 | this.performanceCount = performanceCount; 79 | this.informationCount = informationCount; 80 | this.noCategoryCount = noCategoryCount; 81 | this.portabilityCount = portabilityCount; 82 | this.versions = (versions != null) ? new HashSet(versions) 83 | : null; 84 | } 85 | 86 | /** 87 | * Get total count of all issues. 88 | * 89 | * @return the sum of issues of all severities 90 | */ 91 | @Exported 92 | public int getNumberTotal() { 93 | return errorCount + warningCount + styleCount + performanceCount 94 | + informationCount + noCategoryCount + portabilityCount; 95 | } 96 | 97 | @Exported 98 | public int getNumberErrorSeverity() { 99 | return errorCount; 100 | } 101 | 102 | @Exported 103 | public int getNumberWarningSeverity() { 104 | return warningCount; 105 | } 106 | 107 | @Exported 108 | public int getNumberStyleSeverity() { 109 | return styleCount; 110 | } 111 | 112 | @Exported 113 | public int getNumberPerformanceSeverity() { 114 | return performanceCount; 115 | } 116 | 117 | @Exported 118 | public int getNumberInformationSeverity() { 119 | return informationCount; 120 | } 121 | 122 | @Exported 123 | public int getNumberNoCategorySeverity() { 124 | return noCategoryCount; 125 | } 126 | 127 | @Exported 128 | public int getNumberPortabilitySeverity() { 129 | return portabilityCount; 130 | } 131 | 132 | public Set getVersions() { 133 | return (versions != null) ? Collections.unmodifiableSet(versions) 134 | : null; 135 | } 136 | 137 | public String formatDiff(int value) { 138 | if (value == 0) { 139 | return ""; 140 | } 141 | 142 | return String.format("%+d", value); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckTablePortlet.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | import org.kohsuke.stapler.DataBoundConstructor; 4 | 5 | import hudson.Extension; 6 | import hudson.model.Descriptor; 7 | import hudson.model.Job; 8 | import hudson.model.Run; 9 | import hudson.plugins.view.dashboard.DashboardPortlet; 10 | 11 | /** 12 | * Dashboard portlet that shows a sortable table with jobs and Cppcheck 13 | * statistics per severity type. 14 | * 15 | * @author Michal Turek 16 | */ 17 | public class CppcheckTablePortlet extends DashboardPortlet { 18 | /** 19 | * Constructor. 20 | * 21 | * @param name 22 | * the name of the portlet 23 | */ 24 | @DataBoundConstructor 25 | public CppcheckTablePortlet(String name) { 26 | super(name); 27 | } 28 | 29 | /** 30 | * Get latest available Cppcheck statistics of a job. 31 | * 32 | * @param job 33 | * the job 34 | * @return the statistics, always non-null value 35 | */ 36 | public CppcheckStatistics getStatistics(Job job) { 37 | Run build = job.getLastBuild(); 38 | 39 | while(build != null){ 40 | CppcheckBuildAction action = build.getAction(CppcheckBuildAction.class); 41 | 42 | if (action != null) { 43 | CppcheckResult result = action.getResult(); 44 | 45 | if(result != null) { 46 | return result.getStatistics(); 47 | } 48 | } 49 | 50 | build = build.getPreviousBuild(); 51 | } 52 | 53 | return new CppcheckStatistics(); 54 | } 55 | 56 | /** 57 | * Extension point registration. 58 | * 59 | * @author Michal Turek 60 | */ 61 | @Extension(optional = true) 62 | public static class CppcheckTableDescriptor extends Descriptor { 63 | @Override 64 | public String getDisplayName() { 65 | return Messages.cppcheck_PortletName(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/config/CppcheckConfig.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.config; 2 | import org.kohsuke.stapler.DataBoundSetter; 3 | 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author Gregory Boissinot 9 | */ 10 | public class CppcheckConfig implements Serializable { 11 | /** Serial version UID. */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | private String pattern; 15 | private boolean ignoreBlankFiles; 16 | private boolean allowNoReport; 17 | private CppcheckConfigSeverityEvaluation configSeverityEvaluation = new CppcheckConfigSeverityEvaluation(); 18 | private CppcheckConfigGraph configGraph = new CppcheckConfigGraph(); 19 | 20 | @DataBoundSetter 21 | public void setPattern(String pattern) { 22 | this.pattern = pattern; 23 | } 24 | 25 | @DataBoundSetter 26 | public void setIgnoreBlankFiles(boolean ignoreBlankFiles) { 27 | this.ignoreBlankFiles = ignoreBlankFiles; 28 | } 29 | @DataBoundSetter 30 | public void setAllowNoReport(boolean allowNoReport) { 31 | this.allowNoReport = allowNoReport; 32 | } 33 | @DataBoundSetter 34 | public void setConfigSeverityEvaluation(CppcheckConfigSeverityEvaluation configSeverityEvaluation) { 35 | this.configSeverityEvaluation = configSeverityEvaluation; 36 | } 37 | @DataBoundSetter 38 | public void setConfigGraph(CppcheckConfigGraph configGraph) { 39 | this.configGraph = configGraph; 40 | } 41 | @DataBoundSetter 42 | public void setCppcheckReportPattern(String cppcheckReportPattern) { 43 | this.cppcheckReportPattern = cppcheckReportPattern; 44 | } 45 | @DataBoundSetter 46 | public void setUseWorkspaceAsRootPath(boolean useWorkspaceAsRootPath) { 47 | this.useWorkspaceAsRootPath = useWorkspaceAsRootPath; 48 | } 49 | 50 | public String getPattern() { 51 | return pattern; 52 | } 53 | 54 | @Deprecated 55 | public String getCppcheckReportPattern() { 56 | return cppcheckReportPattern; 57 | } 58 | 59 | public boolean isUseWorkspaceAsRootPath() { 60 | return useWorkspaceAsRootPath; 61 | } 62 | 63 | public boolean getIgnoreBlankFiles() { 64 | return ignoreBlankFiles; 65 | } 66 | public boolean isIgnoreBlankFiles() { 67 | return ignoreBlankFiles; 68 | } 69 | 70 | public boolean getAllowNoReport() { 71 | return allowNoReport; 72 | } 73 | 74 | public CppcheckConfigSeverityEvaluation getConfigSeverityEvaluation() { 75 | return configSeverityEvaluation; 76 | } 77 | 78 | public CppcheckConfigGraph getConfigGraph() { 79 | return configGraph; 80 | } 81 | 82 | /* 83 | Backward compatibility 84 | */ 85 | private transient String cppcheckReportPattern; 86 | private transient boolean useWorkspaceAsRootPath; 87 | 88 | private Object readResolve() { 89 | if (this.cppcheckReportPattern != null) { 90 | this.pattern = cppcheckReportPattern; 91 | } 92 | return this; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/config/CppcheckConfigGraph.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.config; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Gregory Boissinot 7 | */ 8 | public class CppcheckConfigGraph implements Serializable { 9 | /** Serial version UID. */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | public static final int DEFAULT_CHART_WIDTH = 500; 13 | public static final int DEFAULT_CHART_HEIGHT = 200; 14 | 15 | private int xSize = DEFAULT_CHART_WIDTH; 16 | private int ySize = DEFAULT_CHART_HEIGHT; 17 | private int numBuildsInGraph = 0; // numBuildsInGraph <= 1 means unlimited 18 | private boolean displayAllErrors = true; 19 | private boolean displayErrorSeverity; 20 | private boolean displayWarningSeverity; 21 | private boolean displayStyleSeverity; 22 | private boolean displayPerformanceSeverity; 23 | private boolean displayInformationSeverity; 24 | private boolean displayNoCategorySeverity; 25 | private boolean displayPortabilitySeverity; 26 | 27 | public CppcheckConfigGraph() { 28 | } 29 | 30 | public CppcheckConfigGraph(int xSize, int ySize, int numBuildsInGraph, 31 | boolean displayAllErrors, 32 | boolean displayErrorSeverity, boolean displayWarningSeverity, 33 | boolean displayStyleSeverity, boolean displayPerformanceSeverity, 34 | boolean displayInformationSeverity, boolean displayNoCategorySeverity, 35 | boolean displayPortabilitySeverity) { 36 | this.xSize = xSize; 37 | this.ySize = ySize; 38 | this.numBuildsInGraph = numBuildsInGraph; 39 | this.displayAllErrors = displayAllErrors; 40 | this.displayErrorSeverity = displayErrorSeverity; 41 | this.displayWarningSeverity = displayWarningSeverity; 42 | this.displayStyleSeverity = displayStyleSeverity; 43 | this.displayPerformanceSeverity = displayPerformanceSeverity; 44 | this.displayInformationSeverity = displayInformationSeverity; 45 | this.displayNoCategorySeverity = displayNoCategorySeverity; 46 | this.displayPortabilitySeverity = displayPortabilitySeverity; 47 | } 48 | 49 | public int getXSize() { 50 | return xSize; 51 | } 52 | public void setXSize(int xSize) { 53 | this.xSize = xSize; 54 | } 55 | public int getYSize() { 56 | return ySize; 57 | } 58 | public void setYSize(int ySize) { 59 | this.ySize = ySize; 60 | } 61 | 62 | public int getNumBuildsInGraph() { 63 | return numBuildsInGraph; 64 | } 65 | public void setNumBuildsInGraph(int numBuildsInGraph) { 66 | this.numBuildsInGraph = numBuildsInGraph; 67 | } 68 | 69 | public boolean isDisplayAllErrors() { 70 | return displayAllErrors; 71 | } 72 | public boolean getDisplayAllErrors() { 73 | return displayAllErrors; 74 | } 75 | public void setDisplayAllErrors(boolean displayAllErrors) { 76 | this.displayAllErrors = displayAllErrors; 77 | } 78 | 79 | public boolean isDisplayErrorSeverity() { 80 | return displayErrorSeverity; 81 | } 82 | public boolean getDisplayErrorSeverity() { 83 | return displayErrorSeverity; 84 | } 85 | public void setDisplayErrorSeverity(boolean displayErrorSeverity) { 86 | this.displayErrorSeverity = displayErrorSeverity; 87 | } 88 | 89 | public boolean isDisplayWarningSeverity() { 90 | return displayWarningSeverity; 91 | } 92 | public boolean getDisplayWarningSeverity() { 93 | return displayWarningSeverity; 94 | } 95 | public void setDisplayWarningSeverity(boolean displayWarningSeverity) { 96 | this.displayWarningSeverity = displayWarningSeverity; 97 | } 98 | 99 | public boolean isDisplayStyleSeverity() { 100 | return displayStyleSeverity; 101 | } 102 | public boolean getDisplayStyleSeverity() { 103 | return displayStyleSeverity; 104 | } 105 | public void setDisplayStyleSeverity(boolean displayStyleSeverity) { 106 | this.displayStyleSeverity = displayStyleSeverity; 107 | } 108 | 109 | public boolean isDisplayPerformanceSeverity() { 110 | return displayPerformanceSeverity; 111 | } 112 | public boolean getDisplayPerformanceSeverity() { 113 | return displayPerformanceSeverity; 114 | } 115 | public void setDisplayPerformanceSeverity(boolean displayPerformanceSeverity) { 116 | this.displayPerformanceSeverity = displayPerformanceSeverity; 117 | } 118 | public boolean isDisplayInformationSeverity() { 119 | return displayInformationSeverity; 120 | } 121 | public boolean getDisplayInformationSeverity() { 122 | return displayInformationSeverity; 123 | } 124 | public void setDisplayInformationSeverity(boolean displayInformationSeverity) { 125 | this.displayInformationSeverity = displayInformationSeverity; 126 | } 127 | 128 | public boolean isDisplayNoCategorySeverity() { 129 | return displayNoCategorySeverity; 130 | } 131 | public boolean getDisplayNoCategorySeverity() { 132 | return displayNoCategorySeverity; 133 | } 134 | public void setDisplayNoCategorySeverity(boolean displayNoCategorySeverity) { 135 | this.displayNoCategorySeverity = displayNoCategorySeverity; 136 | } 137 | 138 | public boolean isDisplayPortabilitySeverity() { 139 | return displayPortabilitySeverity; 140 | } 141 | public boolean getDisplayPortabilitySeverity() { 142 | return displayPortabilitySeverity; 143 | } 144 | public void setDisplayPortabilitySeverity(boolean displayPortabilitySeverity) { 145 | this.displayPortabilitySeverity = displayPortabilitySeverity; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/util/AbstractCppcheckProjectAction.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.util; 2 | 3 | import hudson.model.Actionable; 4 | import hudson.model.ProminentProjectAction; 5 | import hudson.model.Job; 6 | import hudson.model.Run; 7 | 8 | import org.kohsuke.stapler.StaplerRequest; 9 | import org.kohsuke.stapler.StaplerResponse; 10 | 11 | import java.io.IOException; 12 | import javax.annotation.Nonnull; 13 | 14 | /** 15 | * @author Gregory Boissinot 16 | */ 17 | public abstract class AbstractCppcheckProjectAction extends Actionable implements ProminentProjectAction { 18 | 19 | protected final transient Job job; 20 | 21 | public AbstractCppcheckProjectAction(@Nonnull Job job) { 22 | this.job = job; 23 | } 24 | 25 | @Nonnull public Job getJob() { 26 | return job; 27 | } 28 | 29 | public String getIconFileName() { 30 | return "/plugin/cppcheck/icons/cppcheck-24.png"; 31 | } 32 | 33 | public String getSearchUrl() { 34 | return getUrlName(); 35 | } 36 | 37 | protected abstract Run getLastFinishedBuild(); 38 | 39 | protected abstract Run getLastResultBuild(); 40 | 41 | public abstract void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException; 42 | 43 | public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException { 44 | Integer buildNumber = (getLastResultBuild() != null) ? getLastResultBuild().getNumber() : null; 45 | if (buildNumber == null) { 46 | rsp.sendRedirect2("nodata"); 47 | } else { 48 | rsp.sendRedirect2("../" + buildNumber + "/" + getUrlName()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/util/CppcheckBuildHealthEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.util; 2 | 3 | import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation; 4 | 5 | /** 6 | * @author Gregory Boissinot 7 | */ 8 | public class CppcheckBuildHealthEvaluator { 9 | public int evaluatBuildHealth(CppcheckConfigSeverityEvaluation severityEvaluation, 10 | int nbErrorForSeverity) { 11 | if (severityEvaluation == null) { 12 | // no thresholds => no report 13 | return -1; 14 | } 15 | 16 | if (isHealthyReportEnabled(severityEvaluation)) { 17 | int percentage; 18 | 19 | int healthyNumber = CppcheckMetricUtil.convert(severityEvaluation.getHealthy()); 20 | int unHealthyNumber = CppcheckMetricUtil.convert(severityEvaluation.getUnHealthy()); 21 | 22 | if (nbErrorForSeverity < healthyNumber) { 23 | percentage = 100; 24 | } else if (nbErrorForSeverity > unHealthyNumber) { 25 | percentage = 0; 26 | } else { 27 | percentage = 100 - ((nbErrorForSeverity - healthyNumber) * 100 28 | / (unHealthyNumber - healthyNumber)); 29 | } 30 | 31 | return percentage; 32 | } 33 | return -1; 34 | } 35 | 36 | 37 | private boolean isHealthyReportEnabled(CppcheckConfigSeverityEvaluation severityEvaluation) { 38 | if (CppcheckMetricUtil.isValid(severityEvaluation.getHealthy()) 39 | && CppcheckMetricUtil.isValid(severityEvaluation.getUnHealthy())) { 40 | int healthyNumber = CppcheckMetricUtil.convert(severityEvaluation.getHealthy()); 41 | int unHealthyNumber = CppcheckMetricUtil.convert(severityEvaluation.getUnHealthy()); 42 | return unHealthyNumber > healthyNumber; 43 | } 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/util/CppcheckBuildResultEvaluator.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.util; 2 | 3 | 4 | import hudson.model.TaskListener; 5 | import hudson.model.Result; 6 | 7 | import org.jenkinsci.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation; 8 | 9 | /** 10 | * @author Gregory Boissinot 11 | */ 12 | public class CppcheckBuildResultEvaluator { 13 | public Result evaluateBuildResult( 14 | final TaskListener listener, 15 | int errorsCount, 16 | int newErrorsCount, 17 | CppcheckConfigSeverityEvaluation severityEvaluation) { 18 | 19 | if (isErrorCountExceeded(errorsCount, severityEvaluation.getFailureThreshold())) { 20 | CppcheckLogger.log(listener, 21 | "Setting build status to FAILURE since total number of issues '" 22 | + errorsCount + "' exceeds the threshold value '" 23 | + severityEvaluation.getFailureThreshold() + "'."); 24 | return Result.FAILURE; 25 | } 26 | if (isErrorCountExceeded(newErrorsCount, severityEvaluation.getNewFailureThreshold())) { 27 | CppcheckLogger.log(listener, 28 | "Setting build status to FAILURE since number of new issues '" 29 | + newErrorsCount + "' exceeds the threshold value '" 30 | + severityEvaluation.getNewFailureThreshold() + "'."); 31 | return Result.FAILURE; 32 | } 33 | if (isErrorCountExceeded(errorsCount, severityEvaluation.getThreshold())) { 34 | CppcheckLogger.log(listener, 35 | "Setting build status to UNSTABLE since total number of issues '" 36 | + errorsCount + "' exceeds the threshold value '" 37 | + severityEvaluation.getThreshold() + "'."); 38 | return Result.UNSTABLE; 39 | } 40 | if (isErrorCountExceeded(newErrorsCount, severityEvaluation.getNewThreshold())) { 41 | CppcheckLogger.log(listener, 42 | "Setting build status to UNSTABLE since number of new issues '" 43 | + newErrorsCount + "' exceeds the threshold value '" 44 | + severityEvaluation.getNewThreshold() + "'."); 45 | return Result.UNSTABLE; 46 | } 47 | 48 | CppcheckLogger.log(listener, 49 | "Not changing build status, since no threshold has been exceeded."); 50 | return Result.SUCCESS; 51 | } 52 | 53 | private boolean isErrorCountExceeded(final int errorCount, final String errorThreshold) { 54 | if (errorCount > 0 && CppcheckMetricUtil.isValid(errorThreshold)) { 55 | return errorCount >= CppcheckMetricUtil.convert(errorThreshold); 56 | } 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/util/CppcheckLogger.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.util; 2 | 3 | import hudson.model.BuildListener; 4 | import hudson.model.TaskListener; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Gregory Boissinot 10 | */ 11 | public class CppcheckLogger implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | /** 16 | * Log output to the given logger, using the Cppcheck identifier 17 | * 18 | * @param listener The current listener 19 | * @param message The message to be outputted 20 | */ 21 | public static void log(BuildListener listener, final String message) { 22 | listener.getLogger().println("[Cppcheck] " + message); 23 | } 24 | 25 | public static void log(TaskListener listener, final String message) { 26 | listener.getLogger().println("[Cppcheck] " + message); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cppcheck/util/CppcheckMetricUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck.util; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | /** 6 | * @author Gregory Boissinot 7 | */ 8 | public class CppcheckMetricUtil { 9 | public static int convert(String threshold) { 10 | if (isValid(threshold)) { 11 | if (StringUtils.isNotBlank(threshold)) { 12 | try { 13 | return Integer.parseInt(threshold); 14 | } catch (NumberFormatException exception) { 15 | // not valid 16 | } 17 | } 18 | } 19 | throw new IllegalArgumentException("Not a parsable integer value >= 0: " + threshold); 20 | } 21 | 22 | public static boolean isValid(final String threshold) { 23 | if (StringUtils.isNotBlank(threshold)) { 24 | try { 25 | return Integer.parseInt(threshold) >= 0; 26 | } catch (NumberFormatException exception) { 27 | // not valid 28 | } 29 | } 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckBuildAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 32 | 33 | ${it.result.summary} 34 |
      35 | ${it.result.details} 36 |
    37 |
    38 |
    -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckProjectAction/floatingBox.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 28 | 29 |
    30 |

    31 |

    Cppcheck Trend
    32 |
    33 | 34 | 35 | 36 |
    37 |
    38 |
    39 |
    -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckProjectAction/nodata.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 27 | 28 | 29 | 30 |

    ${%No valid Cppcheck data available}

    31 |

    32 | ${%This plugin will not report Cppcheck result until there is at least one success or unstable build.} 33 |

    34 |
    35 |
    36 |
    37 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckPublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckPublisher/config.properties: -------------------------------------------------------------------------------- 1 | description.pattern=Cppcheck must be configured to generate XML reports for this plugin to function. \ 2 | Fileset 'includes' \ 3 | setting that specifies the generated cppcheck XML report files, such as '**/cppcheck-result-*.xml'. \ 4 | Basedir of the fileset is relative to the workspace root. \ 5 | If no value is set, then the default '**/cppcheck-result.xml' is used. Be sure not to include any \ 6 | non-report files into this pattern.\ 7 | 8 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckResult/index.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 29 | 30 | 31 | 32 |

    Cppcheck Result

    33 | 34 |

    Errors Trend

    35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
    All errorsNew errors
    ${it.report.numberTotal}${it.numberNewErrorsFromPreviousBuild}
    47 | 48 | 49 |

    Summary

    50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
    TotalSeverity 'error'Severity 'possible error'Severity 'style'Severity 'possible style'no category
    ${it.report.numberTotal}${it.report.numberSeverityError}${it.report.numberSeverityPossibleError}${it.report.numberSeverityStyle}${it.report.numberSeverityPossibleStyle}${it.report.numberSeverityNoCategory}
    70 | 71 | 72 |
    73 |
    74 |
    75 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckResult/nosourcepermission.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 27 | 28 | 29 | 30 |

    ${%No valid permission}

    31 |

    32 | ${%The current user must have the WORKSPACE permission for the job.} 33 |

    34 |
    35 |
    36 |
    37 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckResult/summary.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 |
    FilenameLineNumberCppCheckIdSeverityMessage
    44 | 45 | ${cppcheckfile.fileName} 46 | 47 | 48 | ${cppcheckfile.fileName} 49 | 50 | 51 | 52 |
    63 |
    64 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckSource/index.jelly: -------------------------------------------------------------------------------- 1 | 25 | 26 | 29 | 30 | 31 | 32 | 33 |

    ${%Cppcheck Results}

    34 | 35 |

    ${%sourcedetail.header(it.cppcheckWorkspaceFile.cppcheckFile.fileName)}

    36 | 37 | ${it.sourceCode} 38 |
    39 |
    40 |
    41 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/CppcheckSource/index.properties: -------------------------------------------------------------------------------- 1 | sourcedetail.header=Content of file {0} -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/Messages.properties: -------------------------------------------------------------------------------- 1 | cppcheck.Errors_ProjectAction_Name=Cppcheck 2 | cppcheck.ResultAction.NoError=no error 3 | cppcheck.ResultAction.OneError=1 error 4 | cppcheck.ResultAction.MultipleErrors={0} errors 5 | 6 | cppcheck.ResultAction.Detail.NoNewError=No new error 7 | cppcheck.ResultAction_Detail_NewOneError=One new error 8 | cppcheck.ResultAction_Detail_NewMultipleErrors=New Errors 9 | -------------------------------------------------------------------------------- /src/main/resources/com/thalesgroup/hudson/plugins/cppcheck/cppcheck-1.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
    3 | This plug-in collects the 4 | Cppcheck 5 | analysis results of the project and visualizes the found errors. 6 |
    7 | -------------------------------------------------------------------------------- /src/main/resources/jelly/cppcheck/format.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | ${value} 16 | 17 | 18 | 19 | ${value} 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/jelly/cppcheck/taglib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/src/main/resources/jelly/cppcheck/taglib -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckBuildAction/statistics.jelly: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
    ${%Severity}${%Count}${%Delta}
    ${%Error}${stat.numberErrorSeverity}${diff.formatDiff(diff.numberErrorSeverity)}
    ${%Warning}${stat.numberWarningSeverity}${diff.formatDiff(diff.numberWarningSeverity)}
    ${%Style}${stat.numberStyleSeverity}${diff.formatDiff(diff.numberStyleSeverity)}
    ${%Performance}${stat.numberPerformanceSeverity}${diff.formatDiff(diff.numberPerformanceSeverity)}
    ${%Portability}${stat.numberPortabilitySeverity}${diff.formatDiff(diff.numberPortabilitySeverity)}
    ${%Information}${stat.numberInformationSeverity}${diff.formatDiff(diff.numberInformationSeverity)}
    ${%No category}${stat.numberNoCategorySeverity}${diff.formatDiff(diff.numberNoCategorySeverity)}
    ${%Total}${stat.numberTotal}${diff.formatDiff(diff.numberTotal)}
    73 | 74 |
    -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckBuildAction/summary.jelly: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckProjectAction/floatingBox.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
    5 |

    6 |

    ${%Cppcheck Trend}
    7 |
    8 | 9 | 10 | 11 |
    12 |
    13 |
    14 |
    -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckProjectAction/jobMain.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
    16 |
    17 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckProjectAction/nodata.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

    ${%No valid Cppcheck data available}

    7 |

    8 | ${%This plugin will not report Cppcheck result until there is at least one success or unstable build.} 9 |

    10 |
    11 |
    12 |
    13 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckPublisher/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckPublisher/help-pattern.html: -------------------------------------------------------------------------------- 1 |

    Cppcheck must be executed to generate XML reports for this plugin to function. 2 | Fileset 3 | 'includes' setting specifies the generated Cppcheck XML report files, 4 | such as '**/cppcheck-result-*.xml'. Base directory of the fileset is relative 5 | to the workspace root directory.

    6 | 7 |

    If no value is set, then the default '**/cppcheck-result.xml' will be used. 8 | Be sure to never include any non-report files into this pattern.

    9 | 10 |

    The plugin is able to work with both XML formats produced by Cppcheck, 11 | but always prefer to use the newer version 2. Cppcheck doesn't report some 12 | issues with the legacy format.

    13 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckPublisher/help-severity.html: -------------------------------------------------------------------------------- 1 | Determines which severity of issues should be considered when evaluating the 2 | build status and health. -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckPublisher/help-thresholds.html: -------------------------------------------------------------------------------- 1 | Configure the build status and health. A build is considered as unstable or 2 | failure if the new or total number of issues exceeds the specified thresholds. 3 | The build health is also determined by thresholds. If the actual number of 4 | issues is between the provided thresholds, then the build health is interpolated. -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckResult/details.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

    ${%Details}

    8 | 9 | 17 | 18 |

    Show issues highlighted on a single page

    19 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 58 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
    ${%State}${%File}${%Line}${%Severity}${%Type}${%Inconclusive}${%Message}
    ${elt.diffState.text} 51 | 52 | ${cppcheckFile.fileName} 53 | 54 | 55 | ${cppcheckFile.fileName} 56 | 57 | 59 | 60 | ${cppcheckFile.lineNumberString} 61 | 62 | 63 | ${cppcheckFile.lineNumberString} 64 | 65 | ${cppcheckFile.severity}${cppcheckFile.cppCheckId}${cppcheckFile.inconclusive}${cppcheckFile.messageHtml}
    74 |
    75 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckResult/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

    ${%Cppcheck Results}

    8 | 9 |

    ${%Summary}

    10 | 11 | 12 | 13 | 14 | 15 |

    ${%Cppcheck Engine}

    16 |

    ${stat.versions}

    17 |
    18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckResult/nosourcepermission.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

    ${%No valid permission}

    7 |

    8 | ${%The current user must have the WORKSPACE permission for the job.} 9 |

    10 |
    11 |
    12 |
    13 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckSourceAll/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 24 | 25 |

    ${%Cppcheck Results}

    26 | 27 | 28 |

    ${%The result set is empty.}

    29 |
    30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
    38 |

    ${file.cppcheckFile.messageHtml}

    39 | 40 | 41 | 42 |
    43 | ${%Location:}&nbsp; 44 | ${file.cppcheckFile.fileName}:${file.cppcheckFile.lineNumber} 45 |
    46 |
    47 | 48 | 54 | 55 |
    56 | 57 |
    ${%State:}&nbsp;${file.diffState.text}
    58 |
    ${%Severity:}&nbsp;${file.cppcheckFile.severity}
    59 |
    ${%Type:}&nbsp;${file.cppcheckFile.cppCheckId}
    60 | 61 | 62 |
    ${%Inconclusive:}&nbsp;${file.cppcheckFile.inconclusive}
    63 |
    64 | 65 | 66 |

    ${file.cppcheckFile.verboseHtml}

    67 |
    68 | 69 | 70 | 71 | ${it.getSourceCode(file)} 72 | 73 | 74 |
    75 |
    76 | 77 |
    78 |
    79 |
    80 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckTablePortlet/portlet.jelly: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 |
    14 | 15 |
    16 | 17 |
    18 |
    19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/CppcheckTablePortlet/table.jelly: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
    ${%Job}${%Total}${%Error}${%Warning}${%Style}${%Performance}${%Portability}${%Information}${%No category}
    ${stats.numberTotal}${stats.numberErrorSeverity}${stats.numberWarningSeverity}${stats.numberStyleSeverity}${stats.numberPerformanceSeverity}${stats.numberPortabilitySeverity}${stats.numberInformationSeverity}${stats.numberNoCategorySeverity}
    ${%Total}${numberTotal}${numberErrorSeverity}${numberWarningSeverity}${numberStyleSeverity}${numberPerformanceSeverity}${numberPortabilitySeverity}${numberInformationSeverity}${numberNoCategorySeverity}
    75 |
    76 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/Messages.properties: -------------------------------------------------------------------------------- 1 | cppcheck.BuildHealthEvaluatorDescription=Build stability for Cppcheck errors ({0}). 2 | cppcheck.Errors_ProjectAction_Name=Cppcheck 3 | cppcheck.ResultAction.NoError=no error 4 | cppcheck.ResultAction.OneError=1 error 5 | cppcheck.ResultAction.MultipleErrors={0} errors 6 | 7 | cppcheck.PublishResults=Publish Cppcheck results 8 | cppcheck.CppcheckResults=Cppcheck Results 9 | cppcheck.NumberOfErrors=Number of errors 10 | cppcheck.Error=Error 11 | cppcheck.Warning=Warning 12 | cppcheck.Style=Style 13 | cppcheck.Performance=Performance 14 | cppcheck.Information=Information 15 | cppcheck.NoCategory=No category 16 | cppcheck.Portability=Portability 17 | cppcheck.AllErrors=All errors 18 | 19 | cppcheck.BuildStability=Build stability for Cppcheck errors. 20 | cppcheck.PortletName=Cppcheck Statistics 21 | 22 | cppcheck.DiffNew=new 23 | cppcheck.DiffSolved=solved 24 | cppcheck.DiffUnchanged=unchanged 25 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cppcheck/cppcheck-2.0.xsd: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/util/taglib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/src/main/resources/util/taglib -------------------------------------------------------------------------------- /src/main/resources/util/thresholds.properties: -------------------------------------------------------------------------------- 1 | description.threshold=If the total number of issues exceeds this threshold then a build is \ 2 | considered as unstable. Leave this field empty if the unstable state of the build \ 3 | should not depend on the total number of issues. 4 | description.newThreshold=If the number of new issues exceeds this threshold then a build is \ 5 | considered as unstable. Leave this field empty if the unstable state of the build \ 6 | should not depend on the number of new issues. 7 | description.failureThreshold=If the total number of issues exceeds this threshold then a build is \ 8 | considered as failed. Leave this field empty if the failed state of the build \ 9 | should not depend on the total number of issues. 10 | description.newFailureThreshold=If the number of new issues exceeds this threshold then a build is \ 11 | considered as failed. Leave this field empty if the failed state of the build \ 12 | should not depend on the number of new issues. 13 | description.healthy=Report health as 100% when the number of issues is less than this value. 14 | description.unhealthy=Report health as 0% when the number of issues is greater than this value. 15 | 16 | severity.evaluation=Severity evaluation 17 | 18 | graph.configuration=Graph configuration 19 | 20 | description.numBuildsInGraph=Maximal number of the latest builds that are displayed in the trend graph. Use 1 or less for unlimited. 21 | -------------------------------------------------------------------------------- /src/main/webapp/help.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Jenkins understands the Cppcheck report XML format. 3 | When this option is configured, Jenkins can provide useful information about results in different views: 4 | historical result trend, analysis reports.

    5 | 6 |

    You need to set up your build to run Cppcheck in order to use 7 | this feature - this Jenkins plug-in does not perform the actual analysis! 8 | This plug-in is not invoked for failed builds, it is only called for 9 | stable or unstable builds (i.e., a build with failed tests).

    10 |
    11 | -------------------------------------------------------------------------------- /src/main/webapp/icons/cppcheck-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/src/main/webapp/icons/cppcheck-24.png -------------------------------------------------------------------------------- /src/main/webapp/icons/cppcheck-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/src/main/webapp/icons/cppcheck-32.png -------------------------------------------------------------------------------- /src/main/webapp/icons/cppcheck-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/cppcheck-plugin/4bf8f5b01ad1f13295b6943e0f65d709b2926728/src/main/webapp/icons/cppcheck-48.png -------------------------------------------------------------------------------- /src/test/java/com/thalesgroup/hudson/plugins/cppcheck/AbstractWorkspaceTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import hudson.FilePath; 27 | import hudson.Util; 28 | 29 | import java.io.File; 30 | 31 | public abstract class AbstractWorkspaceTest { 32 | 33 | protected File parentFile; 34 | protected FilePath workspace; 35 | 36 | public void createWorkspace() throws Exception { 37 | parentFile = Util.createTempDir(); 38 | workspace = new FilePath(parentFile); 39 | if (workspace.exists()) { 40 | workspace.deleteRecursive(); 41 | } 42 | workspace.mkdirs(); 43 | } 44 | 45 | public void deleteWorkspace() throws Exception { 46 | if(workspace != null) { 47 | workspace.deleteRecursive(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckBuildHealthEvaluatorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfig; 27 | import com.thalesgroup.hudson.plugins.cppcheck.config.CppcheckConfigSeverityEvaluation; 28 | import com.thalesgroup.hudson.plugins.cppcheck.util.CppcheckBuildHealthEvaluator; 29 | import hudson.model.HealthReport; 30 | import junit.framework.Assert; 31 | import org.junit.Before; 32 | import org.junit.Test; 33 | 34 | import static org.mockito.Mockito.mock; 35 | import static org.mockito.Mockito.when; 36 | 37 | public class CppcheckBuildHealthEvaluatorTest { 38 | 39 | 40 | private CppcheckBuildHealthEvaluator cppcheckBuildHealthEvaluator; 41 | CppcheckConfig cppcheckConfig; 42 | 43 | @Before 44 | public void initialize() { 45 | cppcheckConfig = mock(CppcheckConfig.class); 46 | cppcheckBuildHealthEvaluator = new CppcheckBuildHealthEvaluator(); 47 | } 48 | 49 | private int processSetThreshold(int healthy, int unHealthy, int errorsForSevrity) { 50 | CppcheckConfigSeverityEvaluation configSeverityEvaluation = mock(CppcheckConfigSeverityEvaluation.class); 51 | when(cppcheckConfig.getConfigSeverityEvaluation()).thenReturn(configSeverityEvaluation); 52 | when(cppcheckConfig.getConfigSeverityEvaluation().getHealthy()).thenReturn(String.valueOf(healthy)); 53 | when(cppcheckConfig.getConfigSeverityEvaluation().getUnHealthy()).thenReturn(String.valueOf(unHealthy)); 54 | HealthReport healthReport = cppcheckBuildHealthEvaluator.evaluatBuildHealth(cppcheckConfig, errorsForSevrity); 55 | return healthReport.getScore(); 56 | } 57 | 58 | @Test 59 | public void testScore() { 60 | Assert.assertEquals(0, processSetThreshold(0, 10, 11)); 61 | Assert.assertEquals(0, processSetThreshold(0, 10, 10)); 62 | Assert.assertEquals(10, processSetThreshold(0, 10, 9)); 63 | Assert.assertEquals(20, processSetThreshold(0, 10, 8)); 64 | Assert.assertEquals(30, processSetThreshold(0, 10, 7)); 65 | Assert.assertEquals(40, processSetThreshold(0, 10, 6)); 66 | Assert.assertEquals(50, processSetThreshold(0, 10, 5)); 67 | Assert.assertEquals(60, processSetThreshold(0, 10, 4)); 68 | Assert.assertEquals(70, processSetThreshold(0, 10, 3)); 69 | Assert.assertEquals(80, processSetThreshold(0, 10, 2)); 70 | Assert.assertEquals(90, processSetThreshold(0, 10, 1)); 71 | Assert.assertEquals(100, processSetThreshold(0, 10, 0)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckParserResultTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import hudson.model.BuildListener; 27 | import hudson.remoting.VirtualChannel; 28 | import junit.framework.Assert; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | 32 | import java.io.ByteArrayOutputStream; 33 | import java.io.File; 34 | import java.io.PrintStream; 35 | 36 | import static org.mockito.Mockito.mock; 37 | import static org.mockito.Mockito.when; 38 | 39 | public class CppcheckParserResultTest extends AbstractWorkspaceTest { 40 | 41 | private BuildListener listener; 42 | private VirtualChannel channel; 43 | 44 | @Before 45 | public void setUp() throws Exception { 46 | listener = mock(BuildListener.class); 47 | when(listener.getLogger()).thenReturn(new PrintStream(new ByteArrayOutputStream())); 48 | channel = mock(VirtualChannel.class); 49 | super.createWorkspace(); 50 | } 51 | 52 | @Test 53 | public void testNullPattern() { 54 | CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null, false); 55 | Assert.assertEquals("With none pattern, the default pattern must be " + CppcheckParserResult.DELAULT_REPORT_MAVEN, CppcheckParserResult.DELAULT_REPORT_MAVEN, cppcheckParserResult.getCppcheckReportPattern()); 56 | } 57 | 58 | @Test 59 | public void testEmptyPattern() { 60 | CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, null, false); 61 | Assert.assertEquals("With empty pattern, the default pattern must be " + CppcheckParserResult.DELAULT_REPORT_MAVEN, CppcheckParserResult.DELAULT_REPORT_MAVEN, cppcheckParserResult.getCppcheckReportPattern()); 62 | } 63 | 64 | @Test 65 | public void testNoMatch() throws Exception { 66 | CppcheckParserResult cppcheckParserResult = new CppcheckParserResult(listener, "*.xml", false); 67 | CppcheckReport report = cppcheckParserResult.invoke(new File(workspace.toURI()), channel); 68 | Assert.assertEquals("A pattern with no match files is not allowed.", null, report); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/thalesgroup/hudson/plugins/cppcheck/CppcheckSummaryTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2009 Thales Corporate Services SAS * 3 | * Author : Gregory Boissinot * 4 | * * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy * 6 | * of this software and associated documentation files (the "Software"), to deal* 7 | * in the Software without restriction, including without limitation the rights * 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * 9 | * copies of the Software, and to permit persons to whom the Software is * 10 | * furnished to do so, subject to the following conditions: * 11 | * * 12 | * The above copyright notice and this permission notice shall be included in * 13 | * all copies or substantial portions of the Software. * 14 | * * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * 21 | * THE SOFTWARE. * 22 | *******************************************************************************/ 23 | 24 | package com.thalesgroup.hudson.plugins.cppcheck; 25 | 26 | import junit.framework.Assert; 27 | import org.junit.Before; 28 | import org.junit.Test; 29 | 30 | import java.util.Locale; 31 | 32 | import static org.mockito.Mockito.mock; 33 | import static org.mockito.Mockito.when; 34 | 35 | public class CppcheckSummaryTest { 36 | 37 | /** 38 | * Initializes the locale to English. 39 | */ 40 | @Before 41 | public void initializeLocale() { 42 | Locale.setDefault(Locale.ENGLISH); 43 | } 44 | 45 | 46 | /** 47 | * Parameterized test case to check the message text for the specified 48 | * number of erors 49 | * 50 | * @param numberOfErrors the number of errors 51 | * @param expectedMessage the expected message 52 | */ 53 | private void checkSummaryText(final int numberOfErrors, 54 | final String expectedMessage) { 55 | 56 | CppcheckReport report = mock(CppcheckReport.class); 57 | CppcheckResult result = mock(CppcheckResult.class); 58 | 59 | when(result.getReport()).thenReturn(report); 60 | when(result.getReport().getNumberTotal()).thenReturn(numberOfErrors); 61 | 62 | Assert.assertEquals("Wrong summary detail message created.", expectedMessage, CppcheckSummary.createReportSummary(result)); 63 | } 64 | 65 | /** 66 | * Checks the text for 0 error. 67 | */ 68 | @Test 69 | public void test0Errors() { 70 | checkSummaryText(0, "Cppcheck: no error."); 71 | } 72 | 73 | /** 74 | * Checks the text for one error. 75 | */ 76 | @Test 77 | public void test1Errors() { 78 | checkSummaryText(1, "Cppcheck: 1 error."); 79 | } 80 | 81 | /** 82 | * Checks the text for 5 errors. 83 | */ 84 | @Test 85 | public void test5Errors() { 86 | checkSummaryText(5, "Cppcheck: 5 errors."); 87 | } 88 | 89 | 90 | /** 91 | * Parameterized test case to check the detail message text for the 92 | * specified number of erors 93 | * 94 | * @param numberOfErrors the number of errors 95 | * @param expectedMessage the expected message 96 | */ 97 | private void checkSummaryDetailsText(final int numberOfErrors, 98 | final String expectedMessage) { 99 | 100 | CppcheckResult result = mock(CppcheckResult.class); 101 | 102 | when(result.getNumberNewErrorsFromPreviousBuild()).thenReturn(numberOfErrors); 103 | 104 | Assert.assertEquals("Wrong summary detail message created.", expectedMessage, CppcheckSummary.createReportSummaryDetails(result)); 105 | 106 | } 107 | 108 | /** 109 | * Checks the text for no new errors. 110 | */ 111 | @Test 112 | public void test0NewErrors() { 113 | checkSummaryDetailsText(0, "
  • No new error
  • "); 114 | } 115 | 116 | /** 117 | * Checks the text for one new error. 118 | */ 119 | @Test 120 | public void test1NewErrors() { 121 | checkSummaryDetailsText(1, "
  • One new error
  • "); 122 | } 123 | 124 | /** 125 | * Checks the text for one fives errors. 126 | */ 127 | @Test 128 | public void test5NewErrors() { 129 | checkSummaryDetailsText(5, "
  • New Errors: 5
  • "); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/cppcheck/CppcheckParserTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cppcheck; 2 | 3 | import com.thalesgroup.hudson.plugins.cppcheck.CppcheckReport; 4 | import com.thalesgroup.hudson.plugins.cppcheck.model.CppcheckFile; 5 | import com.thalesgroup.hudson.plugins.cppcheck.parser.CppcheckParser; 6 | import junit.framework.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.io.File; 11 | import java.util.List; 12 | 13 | /** 14 | * @author Gregory Boissinot 15 | */ 16 | public class CppcheckParserTest { 17 | 18 | 19 | CppcheckParser cppcheckParser; 20 | 21 | @Before 22 | public void setUp() throws Exception { 23 | cppcheckParser = new CppcheckParser(); 24 | } 25 | 26 | @Test 27 | public void testcppcheck1Version2() throws Exception { 28 | processCppcheck("version2/testCppcheck.xml", 16, 1, 13, 0, 2, 0); 29 | } 30 | 31 | private void processCppcheck(String filename, 32 | int nbErrors, 33 | int nbSeveritiesPossibleError, 34 | int nbSeveritiesPossibleStyle, 35 | int nbStyleErrors, 36 | int nbSeveritiesError, 37 | int nbSeveritiesNoCategory) throws Exception { 38 | 39 | CppcheckReport cppcheckReport = cppcheckParser.parse(new File(CppcheckParserTest.class.getResource(filename).toURI())); 40 | 41 | List everyErrors = cppcheckReport.getEverySeverities(); 42 | List possibileErrorSeverities = cppcheckReport.getPossibleErrorSeverities(); 43 | List styleErrors = cppcheckReport.getStyleSeverities(); 44 | List possibleStyleSeverities = cppcheckReport.getPossibleStyleSeverities(); 45 | List errorSeverities = cppcheckReport.getErrorSeverities(); 46 | List noCategorySeverities = cppcheckReport.getNoCategorySeverities(); 47 | 48 | assert possibileErrorSeverities != null; 49 | assert possibleStyleSeverities != null; 50 | assert errorSeverities != null; 51 | assert everyErrors != null; 52 | assert styleErrors != null; 53 | assert noCategorySeverities != null; 54 | 55 | Assert.assertEquals("Wrong computing of list of errors", everyErrors.size(), 56 | noCategorySeverities.size() + possibleStyleSeverities.size() + errorSeverities.size() + possibileErrorSeverities.size() + styleErrors.size()); 57 | 58 | Assert.assertEquals("Wrong total number of errors", nbErrors, everyErrors.size()); 59 | Assert.assertEquals("Wrong total number of errors for the severity 'possible error'", nbSeveritiesPossibleError, possibileErrorSeverities.size()); 60 | Assert.assertEquals("Wrong total number of errors for the severity 'possible style'", nbSeveritiesPossibleStyle, possibleStyleSeverities.size()); 61 | Assert.assertEquals("Wrong total number of errors for the severity 'style'", nbStyleErrors, styleErrors.size()); 62 | Assert.assertEquals("Wrong total number of errors for the severity 'error'", nbSeveritiesError, errorSeverities.size()); 63 | Assert.assertEquals("Wrong total number of errors with no category", nbSeveritiesNoCategory, noCategorySeverities.size()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck-part1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | -------------------------------------------------------------------------------- /src/test/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck-part2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck.cpp: -------------------------------------------------------------------------------- 1 | char *foo() 2 | { 3 | char str[10]; 4 | 5 | // array index out of bounds (the trailing zero is written at str[10]) 6 | strcpy(str, "1234567890"); 7 | 8 | // Array index out of bounds.. array[0xffffffffff] 9 | int array[256]; 10 | char a = 0xff; 11 | array[a] = 0; 12 | 13 | // array index out of bounds 14 | for (unsigned int i = 0; i <= sizeof(str); i++) 15 | str[i] = 0; 16 | 17 | // unsigned division error, the result will not be -10 18 | unsigned int ten = 10; 19 | int result = -100 / ten; 20 | 21 | // unusual pointer arithmetic.. the abcde string will not get the value "abcde" 22 | std::string abcde = "abcd" + 'e'; 23 | 24 | // sprintf: overlapping data used in input/output. the result is undefined 25 | sprintf(str, " %s", str); 26 | 27 | // mismatching allocation size.. 28 | int *p = malloc(25); 29 | free(p); 30 | 31 | // mismatching allocation and deallocation.. 32 | char *str2 = new char[100]; 33 | delete str2; 34 | 35 | // resource leak.. 36 | FILE *f = fopen("foo.txt", "wt"); 37 | // no fclose 38 | 39 | std::list ints1; 40 | std::list ints2; 41 | ints1.push_back(1); 42 | ints1.push_back(2); 43 | ints1.push_back(3); 44 | // iterator loop problem.. the "ints2.end()" has a typo 45 | for (std::list::iterator it = ints1.begin(); it != ints2.end(); it++) 46 | { 47 | /* ... */ 48 | } 49 | 50 | // Returning pointer to local stack variable 51 | return str; 52 | } -------------------------------------------------------------------------------- /src/test/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 10 | 12 | 14 | 15 | 17 | 18 | 19 | 20 | 22 | 23 | -------------------------------------------------------------------------------- /src/test/resources/com/thalesgroup/hudson/plugins/cppcheck/testcppcheck2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Checking /tmp/cppcheck/testcppcheck.cpp... 4 | 6 | 8 | 10 | 12 | 14 | 16 | 17 | 19 | 21 | 1/2 files checked 50% done 22 | Checking /tmp/cppcheck/testcppcheck2.cpp... 23 | 25 | 27 | 29 | 31 | 33 | 35 | 36 | 38 | 40 | 2/2 files checked 100% done 41 | -------------------------------------------------------------------------------- /src/test/resources/org/jenkinsci/plugins/cppcheck/version2/testCppcheck.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 13 | 14 | 15 | 18 | 19 | 20 | 23 | 24 | 25 | 27 | 28 | 29 | 32 | 33 | 34 | 36 | 37 | 38 | 41 | 42 | 43 | 45 | 46 | 47 | 50 | 51 | 52 | 55 | 56 | 57 | 60 | 61 | 62 | 65 | 66 | 67 | 70 | 71 | 72 | 75 | 76 | 77 | 80 | 81 | 82 | 83 | 84 | --------------------------------------------------------------------------------