parent
1534e32307
commit
102558ec39
@ -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<String> 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; |
||||
} |
||||
} |
||||
} |
@ -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<Class> 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(); |
||||
} |
||||
} |
Loading…
Reference in new issue