Compare commits
2 Commits
753fbddae6
...
cb5e6b2931
Author | SHA1 | Date |
---|---|---|
RenFengJiang | cb5e6b2931 | 10 months ago |
RenFengJiang | 6fb1fd3963 | 10 months ago |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved. |
||||||
|
* 项目名称:信息安全性设计准则检查插件 |
||||||
|
* 项目描述:用于检查源代码的安全性设计准则的Sonarqube插件 |
||||||
|
* 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。 |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.keyware.sonar.cxx; |
||||||
|
|
||||||
|
import org.sonar.api.resources.AbstractLanguage; |
||||||
|
|
||||||
|
import java.lang.module.Configuration; |
||||||
|
|
||||||
|
/** |
||||||
|
* TODO LogLanguage |
||||||
|
* |
||||||
|
* @author RenFengJiang |
||||||
|
* @date 2024/1/16 |
||||||
|
*/ |
||||||
|
public final class LogLanguage extends AbstractLanguage { |
||||||
|
public static final String NAME = "LOG"; |
||||||
|
public static final String KEY = "log"; |
||||||
|
|
||||||
|
private final Configuration config; |
||||||
|
|
||||||
|
public LogLanguage( Configuration config) { |
||||||
|
super(KEY, NAME); |
||||||
|
this.config = config; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String[] getFileSuffixes() { |
||||||
|
String[] arr = new String[1]; |
||||||
|
arr[0] = ".log"; |
||||||
|
return arr; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved. |
||||||
|
* 项目名称:信息安全性设计准则检查插件 |
||||||
|
* 项目描述:用于检查源代码的安全性设计准则的Sonarqube插件 |
||||||
|
* 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。 |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.keyware.sonar.cxx.rules.checkers; |
||||||
|
|
||||||
|
import com.sonar.cxx.sslr.api.AstNode; |
||||||
|
import com.sonar.cxx.sslr.api.Grammar; |
||||||
|
import org.sonar.check.Rule; |
||||||
|
import org.sonar.cxx.squidbridge.annotations.ActivatedByDefault; |
||||||
|
import org.sonar.cxx.squidbridge.annotations.SqaleConstantRemediation; |
||||||
|
import org.sonar.cxx.squidbridge.checks.SquidCheck; |
||||||
|
|
||||||
|
import javax.annotation.Nullable; |
||||||
|
/** |
||||||
|
* TODO LogChecker |
||||||
|
* |
||||||
|
* @author RenFengJiang |
||||||
|
* @date 2024/1/16 |
||||||
|
*/ |
||||||
|
@Rule(key = "LogChecker", name = "日志文件检查", description = "在产品发布之前移除产生日志文件的代码") |
||||||
|
@ActivatedByDefault |
||||||
|
@SqaleConstantRemediation("5min") |
||||||
|
public class LogChecker extends SquidCheck<Grammar> { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void visitFile(@Nullable AstNode astNode) { |
||||||
|
super.visitFile(astNode); |
||||||
|
if(getContext().getInputFile().filename().endsWith(".log")){ |
||||||
|
getContext().createFileViolation(this, "日志文件检查"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved. |
||||||
|
* 项目名称:信息安全性设计准则检查插件 |
||||||
|
* 项目描述:用于检查源代码的安全性设计准则的Sonarqube插件 |
||||||
|
* 版权说明:本软件属北京关键科技股份有限公司所有,在未获得北京关键科技股份有限公司正式授权情况下,任何企业和个人,不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。 |
||||||
|
*/ |
||||||
|
|
||||||
|
package com.keyware.sonar.cxx.rules.checkers; |
||||||
|
|
||||||
|
import com.keyware.sonar.cxx.CxxFileTesterHelper; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.sonar.cxx.CxxAstScanner; |
||||||
|
import org.sonar.cxx.squidbridge.api.SourceFile; |
||||||
|
import org.sonar.cxx.squidbridge.checks.CheckMessagesVerifier; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
|
||||||
|
/** |
||||||
|
* TODO LogCheckerTest |
||||||
|
* |
||||||
|
* @author RenFengJiang |
||||||
|
* @date 2024/1/16 |
||||||
|
*/ |
||||||
|
public class LogCheckerTest { |
||||||
|
@Test |
||||||
|
public void checkTest() throws IOException { |
||||||
|
|
||||||
|
var checker = new LogChecker(); |
||||||
|
|
||||||
|
var tester = CxxFileTesterHelper.create("LogChecker.log"); |
||||||
|
SourceFile file = CxxAstScanner.scanSingleInputFile(tester.asInputFile(), checker); |
||||||
|
CheckMessagesVerifier.verify(file.getCheckMessages()) |
||||||
|
.next().withMessage("日志文件检查"); |
||||||
|
} |
||||||
|
} |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue