# Sorald support scripts
This directory contains a Python package with support scripts for Sorald.
## Requirements
Python 3.8+ and Git 2.x. Some scripts also require Sorald to be available from
the command line, which in that case is detailed in the individual script's
description.
## Install
Assuming that you are currently in this directory, install the support scripts
package like so.
```bash
$ python3 -m pip install .
```
It is however strongly recommended that you install the scripts inside of a
[virtual environment (link to a good article about it)](https://realpython.com/effective-python-environment/#virtual-environments),
to avoid polluting your system-wide or user packages. One way to do that is
to use the `venv` module, which normally ships with Python.
```bash
$ python3 -m venv env # creates a virtual environment in directory "env"
$ source env/bin/activate # activates the virtual environment
[ ... work on your stuff ... ]
$ deactivate # exits the virtual environment
```
Once the virtual environment is active, any package installed with `pip
install` will end up in the local `env` directory.
> **Note:** On some Linux distributions, such as Debian-based ones, `venv` is
> not always shipped with `python3`, and you may need to install a separate
> `python3-venv` or `python3-dev` system package.
For development, add the `-e` flag to make an editable install.
```bash
$ python3 -m pip install -e .
```
An editable install lets any changes you make to your source code be visible in
the installed package immediately, whereas a normal install requires you to
reinstall the package for each change.
## Uninstall
```bash
$ python3 -m pip uninstall soraldscripts
```
## Running tests
To run the tests for the helper scripts, first install the test dependencies.
```bash
$ python3 -m pip install -e .[TEST]
```
Then execute `pytest`.
```bash
$ python3 -m pytest tests/
```
## Adding a new script
Simply put a Python script into the `sorald` directory. That makes it part of
the `sorald` package. Assuming that the script is called `script.py`, you can
run the script (after installing the support scripts package according to the
instructions in this README) like so:
```bash
$ python3 -m sorald.script
```
To test the script, you can add a new file in the `tests` directory, called
`tests/test_script.py`. Those tests can be executed as described in [Running
tests](#running-tests).
> **Important:** Don't forget to add a description of the new script in the
> [Scripts](#scripts) section.
## Scripts
This section details usage of the scripts in the support package.
### `sorald.achievements`
The achievements script can be used to generate an "achievements" file for
Sorald, detailing the pull requests performed with it. It's essentially a
human-readable version of the PRs JSON file.
The script is only usable in a single way: given a `prs.json` file, it
generates a human-readable Markdown file with some of the interesting content.
Use like so:
```bash
$ python3 -m sorald.achievements --prs-json-file path/to/prs.json --output ACHIEVEMENTS.md
```
### `sorald.handled_rules`
The handled_rules script generates a markdown file for listing all the Sonar
rules which are currently repaired by sorald. Each rule is accompanied by the
corresponding processor summary and example repairs.
The script outputs a markdown file whose name is given as parameter to the
command like so:
```bash
python3 -m sorald.handled_rules --output HANDLED_RULES.md
```
### `sorald.prmessage`
The PR message script can be used to easily generate a PR message with
information about the repairs that have been made. The current version
is tailored for repair of a single rule, as that's what we have been
targeting with our PRs thus far. It could fairly easily be extended
to encompass multi-rule repairs, for example by parsing the JSON stats
output from Sorald.
The script currently just prints the message to standard output, with the first
line being the title (make sure to remove the `PULL REQUEST TITLE: ` prefix).
Usage is currently like so:
```
$ python3 -m sorald.prmessage --rule-key <RULE_KEY> --num-repairs <NUM_REPAIRS>
```
For example, generating a PR message for a patch in which Sorald has repaired 2
violations of Sonar Rule 2111, one would call the script like so.
```
$ python3 -m sorald.prmessage --rule-key 2111 --num-repairs 2
```
This generates a PR message with some appropriate text and links to both
Sorald's and Sonar's documentation for the given rule.
### `sorald.prrecorder`
The PR recorder script can be used to collect data from pull requests made with
sorald. It is the JSON file generated by this script that's used by
`sorald.achievements`.
One can run the PR recorder by executing the `sorald.prrecorder` script with Python.
```bash
$ python3 -m sorald.prrecorder [options]
```
To show the available commands, run with the `--help` flag.
```
$ python3 sorald.prrecorder --help
usage: sorald.prrecorder [-h] {record-initial,record-final,add-manual-edit} ...
positional arguments:
{record-initial,record-final,add-manual-edit}
record-initial make the initial record for a PR
record-final make the final record for a PR
add-manual-edit add a diff representing a manual edit of a PR
optional arguments:
-h, --help show this help message and exit
```
In general, one must always make an initial and final record using the
`record-initial` and `record-final` commands. Running `add-manual-edit` is
optional and allows one to record manual edits performed on the PR, i.e. edits
that were not made with Sorald itself.
The rest of this section contains an example use case of recording the PR
[redhat-developer/rsp-server#619](https://github.com/redhat-developer/rsp-server/pulls/619).
#### Step 1: Make the initial record (`record-initial`)
When the PR has been opened, one should make the initial record. It can be done like so.
```bash
$ python3 -m sorald.prrecorder record-initial \
--owner redhat-developer \
--repo-name rsp-server \
--pr-number 619 \
--sorald-stats-file stats.json
```
Note that `stats.json` is the statistics file generated by Sorald when running
with statistics collection.
The command executed above creates a file `prs.json` with an initial record
like this:
```json
{
"redhat-developer/rsp-server#619": {
"repoSlug": "redhat-developer/rsp-server",
"prMetadata": {
"url": "https://github.com/redhat-developer/rsp-server/pull/619",
"createdAt": "2020-11-25 12:01:06",
"closedAt": null,
"mergedAt": null",
"state": "open",
"isMerged": false,
"number": 619
},
"soraldStatistics": {
"repairs": [
{
"nbPerformedRepairs": 4,
"ruleName": "XxeProcessing",
"crashedRepairsLocations": [],
"nbCrashedRepairs": 0,
"ruleKey": "2755",
"nbViolationsBefore": 4,
"performedRepairsLocations": [
{
"endLine": 85,
"endColumn": 52,
"startColumn": 41,
"startLine": 85,
"filePath": "framework/bundles/org.jboss.tools.rsp.launching.java/src/main/java/org/jboss/tools/rsp/internal/launching/java/util/LaunchingSupportUtils.java",
"violationSpecifier": "2755:framework/bundles/org.jboss.tools.rsp.launching.java/src/main/java/org/jboss/tools/rsp/internal/launching/java/util/LaunchingSupportUtils.java:85:41:85:52"
},
{
"endLine": 92,
"endColumn": 70,
"startColumn": 59,
"startLine": 92,
"filePa
没有合适的资源?快使用搜索试试~ 我知道了~
来自SonarQube的SonarJava的静态分析警告自动修复系统_Java_Python_下载.zip
共492个文件
java:251个
expected:78个
md:39个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 196 浏览量
2023-04-28
13:53:33
上传
评论
收藏 84.13MB ZIP 举报
温馨提示
来自SonarQube的SonarJava的静态分析警告自动修复系统_Java_Python_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
来自SonarQube的SonarJava的静态分析警告自动修复系统_Java_Python_下载.zip (492个子文件)
repair.adoc 6KB
mine.adoc 3KB
CITATION.cff 765B
benchmark_baseline.csv 83KB
SlingAuthenticator.diff 72KB
CopyFilesAndFoldersOperation.diff 65KB
XMLEncodingDetector.diff 57KB
Main.diff 39KB
WikiSession.diff 37KB
PDPageTree.diff 33KB
VotingView.diff 30KB
TagFileProcessor.diff 29KB
CodeFactory.diff 28KB
Module.diff 25KB
MainDelegate.diff 17KB
StringToNumberConverter.diff 16KB
SniperPrettyPrinter.diff 14KB
AbstractSourceFragment.diff 12KB
StringToNumberParser.diff 10KB
StringToNumberConverterTest.diff 10KB
InsertPage.diff 10KB
ProjectLocationSelectionDialog.diff 10KB
TilingPaint.diff 10KB
NumberToStringConverterTest.diff 8KB
StringToNumberParserTestHarness.diff 7KB
ChangeResolver.diff 3KB
Bundles.diff 3KB
CtIterator.diff 3KB
PDOutlineItemIterator.diff 2KB
CtBFSIterator.diff 2KB
NumberToBigIntegerConverter.diff 0B
NumberToBigDecimalConverter.diff 0B
StringToDoubleValidatorTest.diff 0B
NumberToDoubleValidatorTest.diff 0B
NumberToDoubleConverterTest.diff 0B
NOCOMPILE_RepairAndFieldTypePrint.java.exact 8KB
NOCOMPILE_RepairAndDoNotRemoveImports.java.exact 1KB
NOCOMPILE_RepairAndTryWithResourcePrint.java.exact 509B
UpperClass.java.exact 156B
CatchMultipleTypes.java.exact 143B
DeadVariableWithMultipleDeadStores.java.exact 129B
SimpleEqualsMissingArgumentTypeCheck.java.exact 95B
LiteralIntOperand.java.exact 76B
SingleUnusedThrowable.java.exact 45B
StringLiteralInsideEqualsAndNullCheckShouldBeRemoved.java.exact 34B
InterruptedExceptionForTesting.java.expected 3KB
CompareStringsBoxedTypesWithEquals.java.expected 2KB
BigDecimalDoubleConstructor.java.expected 1KB
DeadStoreInLoopHeader.java.expected 1KB
CatchesWithNestedExits.java.expected 1KB
BadCloseInFinally.java.expected 1KB
SetFeatureSecureProcessing.java.expected 1KB
JointLocalVarDeclaration.java.expected 1KB
InsecureTransformerFactoryUsage.java.expected 1KB
InsecureXMLInputFactoryUsage.java.expected 1KB
ReferenceInCatcherAndFinalizerToFieldWithSameNameAsResource.java.expected 1KB
MathOnFloat.java.expected 934B
ArrayHashCodeAndToString.java.expected 906B
ArraysAsList.java.expected 855B
OneClosedOneUnclosed.java.expected 833B
DocumentBuilderLocalVariable.java.expected 812B
DeadInitializerWithRootWriteInNestedBlock.java.expected 789B
DocumentBuilderChainedLocalVariable.java.expected 779B
DeadInitializerWithUseInMultipleNestedBlocks.java.expected 765B
DocumentBuilderFullyChainedParse.java.expected 733B
ExistingQualifiedNamesRemainQualified.java.expected 724B
CatchMultipleTypes.java.expected 712B
NestedInNestedGuiClass.java.expected 706B
MultiLineJointLocalVariableDeclarations.java.expected 654B
ReferenceInCatcher.java.expected 641B
UnclosedResourceWithinTryWithResources.java.expected 634B
SonarFalseNegatives.java.expected 618B
LiteralIntOperand.java.expected 610B
ReadFromDeadStore.expected 574B
SimpleEqualsMissingArgumentTypeCheck.java.expected 565B
MultipleCloseablesInSingleTry.java.expected 529B
FlippedBinaryOperator.java.expected 515B
DeadInitializerWithUseInNestedBlock.java.expected 504B
SynchronizationOnSimilarVariables.java.expected 494B
GreaterThan.java.expected 487B
CollectionsEmptyConstants.java.expected 474B
StringLiteralInsideEqualsAndNullCheckShouldNotBeRemoved.expected 459B
EqualsWithStrangeParamName.java.expected 459B
ShouldNotRemoveInvocations.java.expected 432B
DeadStoreWithInvocation.java.expected 420B
UnaryOpsInStatementPosition.java.expected 409B
StringLiteralInsideEqualsSimpleCaseWithEqualsIgnoreCase.java.expected 394B
ShouldNotRemoveListAddAll.java.expected 381B
NestedInThrowable.expected 379B
NullReturningToString.java.expected 364B
MultipleDeadStoresInARow.java.expected 361B
NestedInAbstract.java.expected 356B
UnusedVariableInForLoopHeader.java.expected 354B
SupertypeImplementsSerializable.java.expected 347B
VariableIntOperand.java.expected 343B
StringLiteralInsideEqualsAndNullCheckShouldBeRemoved.java.expected 343B
NOCOMPILE_ShouldNotRemoveUnresolvedMethod.java.expected 343B
StringLiteralInsideEqualsSimpleCaseWithEquals.java.expected 330B
JointDeclarationsOfMultipleFields.java.expected 329B
CatchBlockWithContinue.expected 313B
共 492 条
- 1
- 2
- 3
- 4
- 5
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功