diff --git a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/CxxPlugin.java b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/CxxPlugin.java index 442ec20..22c0e20 100644 --- a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/CxxPlugin.java +++ b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/CxxPlugin.java @@ -6,7 +6,7 @@ */ package com.keyware.sonar.cxx; -import com.keyware.sonar.cxx.rules.CxxSecurityDesignRulesRepository; +import com.keyware.sonar.cxx.rules.SecurityDesignRuleRepository; import org.sonar.api.Plugin; import org.sonar.cxx.AggregateMeasureComputer; import org.sonar.cxx.DensityMeasureComputer; @@ -64,7 +64,7 @@ public final class CxxPlugin implements Plugin { l.add(CxxLanguage.class); l.add(CxxSonarWayProfile.class); l.add(CxxRuleRepository.class); - l.add(CxxSecurityDesignRulesRepository.class); + l.add(SecurityDesignRuleRepository.class); // reusable elements l.addAll(getSensorsImpl()); diff --git a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/CxxSecurityDesignRulesRepository.java b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/CxxSecurityDesignRulesRepository.java deleted file mode 100644 index b007f8e..0000000 --- a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/CxxSecurityDesignRulesRepository.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved. - * 项目名称:C++ 信息安全性设计准则 - * 项目描述:用于检查C++源代码的安全性设计准则的Sonarqube插件 - * 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。 - */ -package com.keyware.sonar.cxx.rules; - -import com.keyware.sonar.cxx.CustomCxxRulesDefinition; -import com.keyware.sonar.cxx.CxxLanguage; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarProduct; -import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarRuntime; -import org.sonar.api.resources.Language; -import org.sonar.api.server.rule.RulesDefinition; -import org.sonar.api.utils.Version; - -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - -/** - * TODO CxxSecurityDesignRulesRepository - * - * @author GuoXin - * @date 2024/1/6 - */ -public class CxxSecurityDesignRulesRepository extends CustomCxxRulesDefinition { - // 不要修改这个值,因为路径在 CheckVerifier 中是硬编码的 - private static final String RESOURCE_BASE_PATH = "org/sonar/l10n/java/rules/java"; - - public static final String REPOSITORY_KEY = "keyware-cxx-security-design"; - public static final String REPOSITORY_NAME = "C++ 安全性设计准则"; - - - // 添加需要视为模板规则的规则的规则键 - private static final Set RULE_TEMPLATES_KEY = Collections.emptySet(); - - private final SonarRuntime runtime; - - public CxxSecurityDesignRulesRepository(SonarRuntime runtime) { - this.runtime = runtime; - } - - @Override - public void define(RulesDefinition.Context context) { - RulesDefinition.NewRepository repository = context.createRepository(REPOSITORY_KEY, "cxx").setName(REPOSITORY_NAME); - - - setTemplates(repository); - - repository.done(); - } - - @Override - public Language getLanguage() { - return new CxxLanguage(null) { - public String[] getFileSuffixes() { - return new String[]{".cxx", ".cpp", ".cc", ".c", ".hxx", ".hpp", ".hh", ".h"}; - } - }; - } - - @Override - public String repositoryName() { - return REPOSITORY_NAME; - } - - @Override - public String repositoryKey() { - return REPOSITORY_KEY; - } - - @Override - public Class[] checkClasses() { - return new Class[0]; - } - - private static void setTemplates(RulesDefinition.NewRepository repository) { - RULE_TEMPLATES_KEY.stream() - .map(repository::rule) - .filter(Objects::nonNull) - .forEach(rule -> rule.setTemplate(true)); - } - - - public static class MockedSonarRuntime implements SonarRuntime { - - @Override - public Version getApiVersion() { - return Version.create(9, 9); - } - - @Override - public SonarProduct getProduct() { - return SonarProduct.SONARQUBE; - } - - @Override - public SonarQubeSide getSonarQubeSide() { - return SonarQubeSide.SCANNER; - } - - @Override - public SonarEdition getEdition() { - return SonarEdition.COMMUNITY; - } - } -} diff --git a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/SecurityDesignRuleRepository.java b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/SecurityDesignRuleRepository.java new file mode 100644 index 0000000..0410b0e --- /dev/null +++ b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/SecurityDesignRuleRepository.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved. + * 项目名称:C++ 信息安全性设计准则 + * 项目描述:用于检查C++源代码的安全性设计准则的Sonarqube插件 + * 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。 + */ +package com.keyware.sonar.cxx.rules; + +import com.keyware.sonar.cxx.CxxLanguage; +import com.keyware.sonar.cxx.rules.checkers.ABCVarNameChecker; +import org.sonar.api.server.rule.RulesDefinition; +import org.sonar.cxx.squidbridge.annotations.AnnotationBasedRulesDefinition; + +import java.util.Arrays; +import java.util.List; + +/** + * TODO SecurityDesignRuleRepository + * + * @author GuoXin + * @date 2024/1/9 + */ +public class SecurityDesignRuleRepository implements RulesDefinition { + private final String REPOSITORY_NAME = "C++信息安全性设计准则"; + private final List RULES_DEFINITIONS = Arrays.asList(ABCVarNameChecker.class); + @Override + public void define(Context context) { + var repository = context.createRepository("cxx-security-design-rules", CxxLanguage.KEY). + setName(REPOSITORY_NAME); + new AnnotationBasedRulesDefinition(repository, CxxLanguage.KEY).addRuleClasses(false, RULES_DEFINITIONS); + repository.done(); + } +} diff --git a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/ABCVarNameChecker.java b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/ABCVarNameChecker.java index 1d3f5ba..9835c35 100644 --- a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/ABCVarNameChecker.java +++ b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/ABCVarNameChecker.java @@ -25,7 +25,7 @@ import static javax.swing.Action.DEFAULT; * @author GuoXin * @date 2024/1/6 */ -@Rule(key = "ABCVarNameChecker", name = "变量名称不可以是ABC", description = "变量名称不可以是ABC", priority = Priority.INFO, tags = {"28Suo"}) +@Rule(key = "ABCVarNameChecker", name = "变量名称不可以是ABC", description = "变量名称不可以是ABC", priority = Priority.INFO, tags = {"28suo"}) @ActivatedByDefault @SqaleConstantRemediation("5min") public class ABCVarNameChecker extends SquidCheck {