19 Star 96 Fork 21

donghui / sonar-mybatis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Build Status GitHub release (latest by date) GitHub All Releases

README 英文版

SonarQube MyBatis 插件

MyBatis SonarQube Plugin :自定义规则用于检查 MyBatis Mapper XML 文件中的风险 SQL。

什么是风险 SQL?

风险 SQL 是指在 mybatis mapper 文件中,有一些动态 SQL,例如 <if test=""></if> 元素, 如果 Mapper XML 中的 SQL 语句中的所有参数为 null,那么 SQL 会有比较大的风险。

示例如下:

DELETE FROM table_name
WHERE 1=1
<if test="startTime != null">
    AND start_time <![CDATA[=]]> #{startTime}
</if>
<if test="endTime != null">
    AND end_time <![CDATA[=]]> #{endTime}
</if>

MyBatis 规则

有7个内置的规则,select 语句有3个规则,update 以及 delete 语句分别有2个规则。

mybatis-rules

如何安装?

在SonarQube中安装插件有两种选择:

  • 应用市场(Marketplace) - 自动从 SonarQube UI 安装插件。
  • 手动安装 - 如果您的 SonarQube 实例无法访问互联网,请将使用此方法。

应用市场(Marketplace)

如果您能够访问互联网,并且您的用户具有全局权限“管理系统”的权限,则可以访问"配置 > 应用市场"。

  • 通过搜索 mybatis 找到该插件
  • 点击安装然后等待下载完成

下载完成后,将使用“重启”按钮重新启动 SonarQube 实例。

手动安装

该插件可以从 github release 下载。

将下载的 jar 放到 $SONARQUBE_HOME/extensions/plugins 目录,并移除该插件的旧版本。

一旦完成,您将需要重新启动 SonarQube 服务器。

如何使用?

使用 maven 构建命令的示例如下:

mvn clean compile -U -Dmaven.test.skip=true -Dmaven.javadoc.skip=true sonar:sonar -Dsonar.host.url=http://127.0.0.1:9000/ -Dsonar.projectKey=demo -Dsonar.projectName=demo -Dsonar.sourceEncoding=UTF-8 -Dsonar.sources=. -Dsonar.inclusions=src/main/** -Dsonar.exclusions==src/main/webapp/**

要想分析 mybatis mapper 文件, src/main/resources 目录必须在 sonar.sources 中。

支持全局 Stmt ID 排除列表

对于一些特殊语句的问题,要想忽略它们,可以将附带 namespace 的 statement id 放入全局 stmt id 排除列表。

stmt-id-exclude

跳过 MyBatis 扫描

如果有时候想要跳过 MyBatis 扫描,你可以修改全局属性 sonar.mybatis.skiptrue 或者在命令行中添加参数: -Dsonar.mybatis.skip=true

贡献

可以在 https://github.com/donhui/sonar-mybatis/issues 提交 bug 和新功能请求。

或者可以提交 pull requests 用于修复 bug 或提交新功能,欢迎任何形式的贡献。

Star 趋势图

Star History

Star History Chart

Apache License, Version 2.0 Copyright 2019 donghui Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

MyBatis SonarQube Plugin :自定义规则用于检查 MyBatis Mapper XML 文件中的风险 SQL 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/donhui/sonar-mybatis.git
git@gitee.com:donhui/sonar-mybatis.git
donhui
sonar-mybatis
sonar-mybatis
master

搜索帮助