jenkins - Sonarqube PLSQL 自定义规则,用于在 SQL 脚本文件中检测正确的 SQL 终止符分号

标签 jenkins plsql sonarqube sonarqube-scan sonar-plugin

我正在使用 Jenkins 和 SONARQUBE PL/SQL 插件进行 Oracle SQL 代码分析,
我需要使用 创建自定义规则XPATH 用于对通过 Jenkins 发送以进行部署的 SQL 脚本文件的质量分析。

我正在尝试创建一个自定义规则,用于检测任何 SQL 命令末尾是否缺少分号 ("; ")。
SQL 终止(“分号”)对于使用 SQLPLUS 部署 SQL 脚本很重要。

代码示例

 insert into table_name values('wait','for','completion'); -- compliant with script 
 insert into table_name values('somename','for','good'); -- compliant with script 
 **insert into table_name values('someplace','for','game')** -- non compliant as semicolon missing
 insert into table_name values('something','for','change'); -- compliant with script 
 delete from table_name ; -- compliant with script 
 delete from table_name ; -- compliant with script 
 update table_name set name='james' where id='22';

有一个插入查询是 缺少分号 ,因此 sonarqube 应该检测到这一点,并使 jenkins 构建失败或未通过 SONAR 质量测试。

请帮助创建 PLSQL 自定义规则,以通过分号检测正确的 SQL 终止。

xpath 的例子是:
/COMPILATION_UNIT/ANY_DML_EXPRESSION/following-sibling::SEMICOLON——类似这样的

最佳答案

您可以按照指南“Create a plugin with custom rules”,使用模板项目 plsql-custom-rules .
这比 更复杂adding a rule to XPATH ,但您将拥有更多控制权。

To create a check, you can create a subclass of org.sonar.plsqlopen.checks.AbstractBaseCheck.
You can use the org.sonar.check.Rule and org.sonar.squidbridge.annotations.SqaleConstantRemediation annotations to configure the check metadata (name, description, key...).

Very often you'll need to override just two methods:

  • init(): subscribe to the desired grammar rules
  • visitNode(AstNode): analyze the nodes that match the subscribed grammar rules


但首先,如 issue 21 中所示,请检查您的代码是否没有出现“无法解析文件”消息的错误。

I just need to know a parser like sonarqube analysis to detect compilation errors in the script file



检查您的案例是否不是可选的分号,如“Semicolon is not required in CREATE VIEW ”。
查看该源代码是检查诸如 Sonar 分析之类的解析器如何检测脚本文件中的编译错误的好方法。

关于jenkins - Sonarqube PLSQL 自定义规则,用于在 SQL 脚本文件中检测正确的 SQL 终止符分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50703661/

相关文章:

jenkins - 将 JSHint 集成到 Jenkins 中,无需使用 Checkstyle 或 JSLint 报告器

Jenkins - 将构建发布到文件夹

powershell - msdeploy密码未知字符

sql - 从旧样式到新样式的加入

java - mvn sonar :sonar do? 是什么

sonarqube - 使用绑定(bind)安装卷通过 docker-compose 运行 Sonarqube

java - 自定义 Collectors.toMap 时如何替换通配符泛型

jenkins - 别名 Jenkins 工件URL

regex - 我想优化使用 IN 子句和 regex_str 函数的存储过程。我不确定我应该如何优化它?

java - AES256 的 Oracle DBMS_CRYPTO.ENCRYPT 初始化 vector 长度