Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#27 from eazence/issue_26
Browse files Browse the repository at this point in the history
feat: 支持国际化 TencentBlueKing#26
  • Loading branch information
Yuanruitao authored Feb 22, 2023
2 parents 92adccf + a8b3f9e commit 1d5dc27
Show file tree
Hide file tree
Showing 26 changed files with 513 additions and 290 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.codecc
.idea
.vscode
62 changes: 62 additions & 0 deletions doc/aboutCodeCC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 插件功能

支持Linux、MacOS、Windows系统下执行所有CodeCC代码检查工具,包括代码缺陷(bkcheck等)、安全漏洞(敏感信息、高危组件等)、代码规范(CppLint、CheckStyle等)、圈复杂度、重复率等。

# 适用场景

## Linux:
公共构建机(已预装Docker)
私有构建机(需安装Docker)
私有构建集群(需安装Docker)

## MacOS:
私有构建机(需安装Docker)
私有构建集群(需安装Docker)

## Windows(win10及以上):
私有构建机(需安装Docker)
私有构建集群(需安装Docker)

# 使用限制和受限解决方案
私有构建机需要安装Docker


# CodeCC特色功能
CodeCC是腾讯领先的代码分析平台,提供专业的代码检查解决方案及服务,为产品质量保驾护航。

- 目前已集成十余款含商用、开源、自研的代码检查工具,覆盖代码缺陷、安全漏洞、编码规范、圈复杂度、代码重复率五大维度;

- 支持规则开发框架和工具开发框架,可自主将开发的规则或工具集成到CodeCC平台;

- 自研bkcheck缺陷检查工具,可以支持游戏C++后台、Unreal客户端、Unity客户端的缺陷检查;

- 与蓝盾流水线进行了深度整合,通过质量红线服务,可以在流水线中使用CodeCC的检查结果来控制代码库MR/PR、转测、部署等流程,从而使得每一阶段的流水线产出都符合质量标准。

# CodeCC能发现什么代码问题

## 发现代码缺陷

代表工具:ClangWarning、Clang
代表规则:API使用、内存非法访问、程序卡死、资源泄露、空指针、性能低效……

## 发现安全漏洞

代表工具:敏感信息、高危组件
代表规则:密码/密钥等信息泄露、加密风险、XSS、CSRF、注入攻击……

## 代码规范,检查一些逻辑错误

代表工具:CppLint、CheckStyle、ESLint、StyleCop、Gometalinter、detekt、PHPCS、PyLint等
代表规则:注释、空代码块、异常处理、命名、格式化、风格……

## 控制复杂度
代表工具:圈复杂度
代表规则:函数圈复杂度>=20

## 检测重复率
代表工具:重复率
代表规则:文件代码重复率>=5%

## 统计代码行数
代表工具:代码统计
代表规则:统计代码中各类语言代码行、注释行、空白行的情况
62 changes: 62 additions & 0 deletions doc/aboutCodeCC_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Plugin function

Support all CodeCC code inspection tools under Linux, MacOS, and Windows systems, including code defects (bkcheck, etc.), security vulnerabilities (sensitive information, high-risk components, etc.), code specifications (CppLint, CheckStyle, etc.), cyclomatic complexity, repetition rate, etc. .

# Applicable scene

## Linux:
Public build machine (with Docker pre-installed)
Private build machine (docker needs to be installed)
Build a cluster privately (Docker needs to be installed)

## MacOS:
Private build machine (docker needs to be installed)
Build a cluster privately (Docker needs to be installed)

## Windows (win10 and above):
Private build machine (docker needs to be installed)
Build a cluster privately (Docker needs to be installed)

# Use restricted and restricted solutions
Private build machines need to install Docker


# CodeCC Features
CodeCC is Tencent's leading code analysis platform, providing professional code inspection solutions and services to protect product quality.

- At present, more than ten code inspection tools including commercial, open source, and self-developed have been integrated, covering five dimensions of code defects, security vulnerabilities, coding standards, cyclomatic complexity, and code repetition rate;

- Support rule development framework and tool development framework, and can independently integrate the developed rules or tools into the CodeCC platform;

- Self-developed bkcheck defect inspection tool, which can support defect inspection of game C++ background, Unreal client, and Unity client;

- Deeply integrated with the Blue Shield pipeline, through the quality red line service, you can use the inspection results of CodeCC in the pipeline to control the code base MR/PR, transfer test, deployment and other processes, so that the output of each stage of the pipeline can meet the Quality Standard.

# CodeCC can find what code problems

## Find code bugs

Representative tools: ClangWarning, Clang
Representative rules: API usage, illegal memory access, program freezes, resource leaks, null pointers, inefficient performance...

## Security vulnerabilities found

Representative tools: sensitive information, high-risk components
Representative rules: information leakage such as passwords/keys, encryption risks, XSS, CSRF, injection attacks...

## Code specification, check some logic errors

Representative tools: CppLint, CheckStyle, ESLint, StyleCop, Gometalinter, detekt, PHPCS, PyLint, etc.
Representative rules: comments, empty code blocks, exception handling, naming, formatting, style...

## Control complexity
Representative Tool: Cyclomatic Complexity
Representative rules: function cyclomatic complexity>=20

## Detect repetition rate
Rep Tool: Repetition Rate
Representative rule: file code repetition rate>=5%

## Count the number of lines of code
Representative Tool: Code Statistics
Representative rules: Statistical code lines, comment lines, and blank lines of various languages in the code.
Empty file added doc/desc.md
Empty file.
Empty file added doc/desc_en.md
Empty file.
Binary file added images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/backend/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildscript {
jacksonVersion = "2.9.2"
jacksonDatabindVersion = "2.13.4.2"
compressVersion = "1.15"
javaPluginSdkVersion = "1.1.5"
javaPluginSdkVersion = "1.1.7"
kotlinVersion = "1.5.30"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ object DockerRun {
projectId = commandParam.landunParam.devopsProjectId,
pipelineId = commandParam.landunParam.devopsPipelineId,
buildId = commandParam.landunParam.buildId,
param = param
param = param,
taskId = null
).data!!

var extraOptions = dockerRunResponse.extraOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class Scm(
try {
DockerRun.runImage(imageParam, commandParam, toolName)
} catch (e: Throwable) {
LogUtils.printLog("Scm operate exception, message: ${e.message}")
LogUtils.printErrorLog("Scm operate exception, message: ${e.message}", e)
scmOpFail(inputFile)
throw CodeccTaskExecException(errorMsg = e.message ?: "", toolName = toolName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ object LogUtils {
logger.errorInTag("[${getToolName()}]" + msg?.toString(), getToolName())
}

fun printErrorLog(msg: Any?, e : Throwable) {
logger.error("[${getToolName()}]" + msg?.toString(), e)
}

fun printStr(msg: Any?) {
print(msg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/Async.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="task-content" :style="{height: extraHeight + 'px'}">
<div class="atom-txt"><i class="bk-icon icon-exclamation-circle-shape"></i>如流水线配置了质量红线请谨慎使用异步功能,可能会由于结果异步输出导致红线拦截</div>
<div class="atom-txt"><i class="bk-icon icon-exclamation-circle-shape"></i>{{$t('如流水线配置了质量红线请谨慎使用异步功能,可能会由于结果异步输出导致红线拦截')}}</div>
<template v-for="(obj, key) in asyncModel">
<form-field
class="head-level"
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/AuthorTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:handle-change="(name, value) => handleParamChange(name, value, index)"
v-validate.initial="`required`"
name="sourceAuthor"
placeholder="原处理人"
:placeholder="$t('原处理人')"
:value="param.sourceAuthor" />
</form-field>
<form-field :is-error="errors.has(`param-${index}.targetAuthor`)" :error-msg="errors.first(`param-${index}.targetAuthor`)">
Expand All @@ -20,15 +20,15 @@
:handle-change="(name, value) => handleParamChange(name, value, index)"
v-validate.initial="`required`"
name="targetAuthor"
placeholder="目标处理人"
:placeholder="$t('目标处理人')"
:value="param.targetAuthor" />
</form-field>
<i @click.stop.prevent="editParam(index, false)" class="bk-icon icon-minus hover-click" v-if="!disabled" />
</li>
</template>
<a class="text-link hover-click" v-if="!disabled" @click.stop.prevent="editParam(paramList.length, true)">
<i class="bk-icon icon-plus-circle" />
<span>添加处理人转换</span>
<span>{{$t('添加处理人转换')}}</span>
</a>
</ul>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/frontend/src/components/Basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<section class="bk-form">
<template>
<div class="atom-txt" v-if="envSupport">
<span>Linux私有构建机/Mac/Win10需安装docker,Win7仅支持Coverity。
<a target="_blank" :href="dockerHref">具体请见>></a>
<span>{{$t('Linux私有构建机/Mac/Win10需安装docker,Win7仅支持Coverity。')}}
<a target="_blank" :href="dockerHref">{{$t('具体请见')}}>></a>
</span>
</div>
<template v-for="(obj, key) in basicTabModel">
Expand Down Expand Up @@ -82,7 +82,7 @@
groupList: [
{
id: 'script',
label: '编译脚本',
label: this.$t('编译脚本'),
rely: ['COVERITY', 'KLOCWORK', 'PINPOINT', 'CODEQL', 'CLANG', 'CLANGWARNING', 'SPOTBUGS'],
item: ['scriptType', 'script']
}
Expand Down Expand Up @@ -141,7 +141,7 @@
return curTool && curTool.name || tool
})
}
return toolsCn.length ? `涉及工具:${toolsCn.join('')}` : ''
return toolsCn.length ? `${this.$t('涉及工具')}${toolsCn.join('')}` : ''
},
envSupport () {
return ['MACOS', 'WINDOWS'].includes(this.containerInfo.baseOS) || (this.containerInfo.dispatchType && this.containerInfo.dispatchType.buildType.indexOf('THIRD_PARTY') !== -1)
Expand All @@ -158,9 +158,9 @@
"value": "BAT",
"label": "bat"
}]
this.atomModel.script.default = "# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.bat\n# 确保build.bat能够编译代码\n# cd path/to/build.bat\n# call build.bat"
if (this.atomValue.script === "# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.sh\n# 确保build.sh能够编译代码\n# cd path/to/build.sh\n# sh build.sh") {
this.atomValue.script = "# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.bat\n# 确保build.bat能够编译代码\n# cd path/to/build.bat\n# call build.bat"
this.atomModel.script.default = this.$t("# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.bat\n# 确保build.bat能够编译代码\n# cd path/to/build.bat\n# call build.bat")
if (this.atomValue.script === this.$t("# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.sh\n# 确保build.sh能够编译代码\n# cd path/to/build.sh\n# sh build.sh")) {
this.atomValue.script = this.$t("# Coverity/Klocwork将通过调用编译脚本来编译您的代码,以追踪深层次的缺陷\n# 请使用依赖的构建工具如maven/cmake等写一个编译脚本build.bat\n# 确保build.bat能够编译代码\n# cd path/to/build.bat\n# call build.bat")
}
}
}
Expand Down Expand Up @@ -201,7 +201,7 @@
return lang
})
this.groupList.unshift({ id: 'ruleSet', label: '规则集', item:ruleModelNameList })
this.groupList.unshift({ id: 'ruleSet', label: this.$t('规则集'), item:ruleModelNameList })
})
this.$store.dispatch('getToolList').then(res => {
this.atomModel.tools.list = res.map(item => {
Expand Down Expand Up @@ -234,9 +234,9 @@
const res = await this.$store.dispatch('listPageable', params)
this.list = res
} catch (err) {
console.log(err, '获取规则集失败')
console.log(err, this.$t('获取规则集失败'))
this.$bkMessage({
message: '获取规则集失败',
message: this.$t('获取规则集失败'),
theme: 'error'
})
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/CodeccAccordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</span>
<span v-if="desc" class="desc" v-bk-tooltips.top="desc">{{ desc }}</span>
<span class="fold-open">
{{ isShow ? '收起' : '展开' }}
{{ isShow ? $t('收起') : $t('展开') }}
<i class="bk-icon icon-angle-down" style="display:inline-block">
</i>
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/ItemEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>
<a class="text-link hover-click" v-if="!disabled" @click.stop.prevent="editParam(paramList.length, true)">
<i class="bk-icon icon-plus-circle" />
<span>{{ addBtnText }}</span>
<span>{{$t(addBtnText)}}</span>
</a>
</ul>
</div>
Expand Down
Loading

0 comments on commit 1d5dc27

Please sign in to comment.