From 1ab8493693e8a8d3374b49012a2f834a5a4780bf Mon Sep 17 00:00:00 2001 From: Rafal Garbat Date: Tue, 9 Apr 2024 12:53:55 +0200 Subject: [PATCH] feat: add new premium checks --- .../core/command/TestVersion.java | 22 +++++ .../core/IPreferenceConstants.java | 9 ++ .../core/command/CppcheckCommand.java | 34 +++++++ .../cppcheclipse/core/command/Version.java | 8 ++ .../googlecode/cppcheclipse/ui/Messages.java | 16 +++- .../cppcheclipse/ui/messages.properties | 9 ++ .../preferences/BinaryPathPreferencePage.java | 5 + .../ExclusiveBooleanFieldEditor.java | 57 ++++++++++++ .../preferences/SettingsPreferencePage.java | 92 ++++++++++++++++++- 9 files changed, 248 insertions(+), 4 deletions(-) create mode 100644 com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/preferences/ExclusiveBooleanFieldEditor.java diff --git a/com.googlecode.cppcheclipse.core.tests/src/com/googlecode/cppcheclipse/core/command/TestVersion.java b/com.googlecode.cppcheclipse.core.tests/src/com/googlecode/cppcheclipse/core/command/TestVersion.java index 74f22e3..e827fe4 100644 --- a/com.googlecode.cppcheclipse.core.tests/src/com/googlecode/cppcheclipse/core/command/TestVersion.java +++ b/com.googlecode.cppcheclipse.core.tests/src/com/googlecode/cppcheclipse/core/command/TestVersion.java @@ -340,4 +340,26 @@ public void testCompatibility() { assertTrue(version3.isCompatible()); } + @Test + public void testPremium() { + Version version1 = new Version("cppcheck 1.56"); + Version version2 = new Version("cppcheck 1.56.0"); + Version version3 = new Version("cppcheck 1.56.0.0"); + assertFalse(version1.isPremium()); + assertFalse(version2.isPremium()); + assertFalse(version3.isPremium()); + version1 = new Version("cppcheck premium 1.56"); + version2 = new Version("cppcheck premium 1.56.0"); + version3 = new Version("cppcheck premium 1.56.0.0"); + assertTrue(version1.isPremium()); + assertTrue(version2.isPremium()); + assertTrue(version3.isPremium()); + version1 = new Version("cppcheck premium 1.56s"); + version2 = new Version("cppcheck premium 1.56.0s"); + version3 = new Version("cppcheck premium 1.56.0.0s"); + assertTrue(version1.isPremium()); + assertTrue(version2.isPremium()); + assertTrue(version3.isPremium()); + } + } diff --git a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/IPreferenceConstants.java b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/IPreferenceConstants.java index e223b57..da9df16 100644 --- a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/IPreferenceConstants.java +++ b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/IPreferenceConstants.java @@ -4,6 +4,7 @@ * Constant definitions for plug-in preferences */ public interface IPreferenceConstants { + public static final String P_PREMIUM = "premium"; public static final String P_RUN_ON_BUILD = "runOnBuild"; public static final String P_PROBLEMS = "problems"; public static final String P_USE_PARENT_SUFFIX = "_useParentScope"; @@ -18,6 +19,14 @@ public interface IPreferenceConstants { public static final String P_CHECK_INCONCLUSIVE = "checkInconclusive"; public static final String P_CHECK_FORCE = "checkForce"; public static final String P_CHECK_DEBUG = "checkDebug"; + public static final String P_PREMIUM_BUG_HUNTING = "bughunting"; + public static final String P_PREMIUM_MISRA_C_12 = "misrac12"; + public static final String P_PREMIUM_MISRA_C_23 = "misrac23"; + public static final String P_PREMIUM_MISRA_CPP_08 = "misracpp08"; + public static final String P_PREMIUM_MISRA_CPP_23 = "misracpp23"; + public static final String P_PREMIUM_CERT_C = "certc"; + public static final String P_PREMIUM_CERT_CPP = "certcpp"; + public static final String P_PREMIUM_AUTOSAR = "autosar"; public static final String P_USE_INLINE_SUPPRESSIONS = "useInlineSuppressions"; public static final String P_CHECK_UNUSED_FUNCTIONS = "checkUnusedFunctions"; public static final String P_FOLLOW_SYSTEM_INCLUDES = "followSystemIncludes"; diff --git a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java index 84e96bd..b796134 100644 --- a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java +++ b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java @@ -55,9 +55,39 @@ public class CppcheckCommand extends AbstractCppcheckCommand { private final static Pattern FILE_PATTERN = Pattern .compile("^Checking (.*)..."); + private static final String CPPCHECK_PROJ_STRING = ".cppcheck"; + private final Collection arguments; private String advancedArguments; + + private void addPremiumChecks(IPreferenceStore settingsStore) { + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_BUG_HUNTING)) { + arguments.add("--premium=bughunting"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_MISRA_C_12)) { + arguments.add("--premium=misra-c-2012"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_MISRA_C_23)) { + arguments.add("--premium=misra-c-2023"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_MISRA_CPP_08)) { + arguments.add("--premium=misra-c++-2008"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_MISRA_CPP_23)) { + arguments.add("--premium=misra-c++-2023"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_CERT_C)) { + arguments.add("--premium=cert-c-2016"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_CERT_CPP)) { + arguments.add("--premium=cert-c++-2016"); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_PREMIUM_AUTOSAR)) { + arguments.add("--premium=autosar"); + } + } + /** * For testing purposes either use interfaces or simple types as parameters. * No dependency to Eclipse classes allowed. @@ -132,6 +162,10 @@ public CppcheckCommand(IConsole console, String binaryPath, arguments.add("--file-list=-"); } + if (projectFile.isEmpty() || !projectFile.endsWith(CPPCHECK_PROJ_STRING)) { + addPremiumChecks(settingsStore); + } + if (settingsStore.getBoolean(IPreferenceConstants.P_CHECK_VERBOSE)) { arguments.add("--verbose"); } diff --git a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/Version.java b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/Version.java index cb1b2be..584e242 100644 --- a/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/Version.java +++ b/com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/Version.java @@ -124,6 +124,14 @@ public boolean isCompatible() { } + /** + * @return true if the version is a premium version + */ + public boolean isPremium() { + return getType() == VersionType.PREMIUM || getType() == VersionType.PREMIUM_SAFETY_CERTIFIED; + } + + @Override public String toString() { StringBuffer version = new StringBuffer(); diff --git a/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java b/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java index ea347d3..45b0cae 100644 --- a/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java +++ b/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java @@ -100,11 +100,21 @@ public class Messages extends NLS { public static String SettingsPreferencePage_Debug; public static String SettingsPreferencePage_ChecksLabel; public static String SettingsPreferencePage_InlineSuppressions; - + + public static String SettingsPreferencePage_PremiumBugHunting; + public static String SettingsPreferencePage_PremiumMisraC2012; + public static String SettingsPreferencePage_PremiumMisraC2023; + public static String SettingsPreferencePage_PremiumMisraCpp2008; + public static String SettingsPreferencePage_PremiumMisraCpp2023; + public static String SettingsPreferencePage_PremiumCertC; + public static String SettingsPreferencePage_PremiumCertCpp; + public static String SettingsPreferencePage_PremiumAutosar; + public static String SettingsPreferencePage_PremiumLabel; + public static String SymbolsPropertyPage_Description; public static String SettingsPreferencePage_Inconclusive; - + public static String SettingsPreferencePage_TargetPlatform; public static String SettingsPreferencePage_LanguageStandard_Posix; @@ -112,7 +122,7 @@ public class Messages extends NLS { public static String SettingsPreferencePage_LanguageStandard_C99; public static String SettingsPreferencePage_LanguageStandardsLabel; - + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties b/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties index 77e8b94..d05edd4 100644 --- a/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties +++ b/com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties @@ -38,6 +38,15 @@ SettingsPreferencePage_CheckPortability=Check for portability issues (portabilit SettingsPreferencePage_CheckInformation=Informative checks (information) SettingsPreferencePage_CheckMissingInclude=Check for missing includes (missingInclude) SettingsPreferencePage_ChecksLabel=Checks (--enable=) +SettingsPreferencePage_PremiumBugHunting=Bug Hunting +SettingsPreferencePage_PremiumMisraC2012=Misra C 2012 +SettingsPreferencePage_PremiumMisraC2023=Misra C 2023 +SettingsPreferencePage_PremiumMisraCpp2008=Misra C++ 2008 +SettingsPreferencePage_PremiumMisraCpp2023=Misra C++ 2023 +SettingsPreferencePage_PremiumCertC=Cert C 2016 +SettingsPreferencePage_PremiumCertCpp=Cert C++ 2016 +SettingsPreferencePage_PremiumAutosar=Autosar +SettingsPreferencePage_PremiumLabel=Premium (--premium=