sorald

Automatic repair system for static analysis warnings from SonarQube's SonarJava, TDSC 2022 http://arxiv.org/pdf/2103.12033

https://github.com/assert-kth/sorald

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, ieee.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.6%) to scientific vocabulary

Keywords

kth program-repair sonarjava sonarqube ssf
Last synced: 6 months ago · JSON representation ·

Repository

Automatic repair system for static analysis warnings from SonarQube's SonarJava, TDSC 2022 http://arxiv.org/pdf/2103.12033

Basic Info
  • Host: GitHub
  • Owner: ASSERT-KTH
  • License: mit
  • Language: Java
  • Default Branch: master
  • Homepage:
  • Size: 212 MB
Statistics
  • Stars: 95
  • Watchers: 5
  • Forks: 26
  • Open Issues: 63
  • Releases: 17
Topics
kth program-repair sonarjava sonarqube ssf
Created almost 8 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing License Citation

README.md

Sorald GHA tests Workflow Status Code Coverage Supported Platforms

Sorald is a tool to automatically repair violations of static analysis rules checked with SonarQube. It can currently repair violations of 25+ rules based on the design described in Sorald: Automatic Patch Suggestions for SonarQube Static Analysis Violations (doi:10.1109/TDSC.2022.3167316).

If you use Sorald in an academic context, please copy BibTeX or APA citation from the citation widget on the sidebar of main page.

Talks

Getting started

Prerequisites

Sorald supports macOS, Linux, and Windows.

For running Sorald, all you need is a Java 11+ runtime.

For building Sorald from source, you need a Java 11+ JDK, Maven >=3.6.3, and Git.

Running Sorald in 2 seconds

Sorald is available as a maven-plugin so you can run it from the command line with Maven.

bash mvn se.kth.castor:sorald:repair -DruleKey=<ruleKey>

Note: Sorald maven-plugin is still in rudimentary stages. We have added two goals to it - mine and repair. They both are analogous to the CLI tool. However, not all parameters are supported yet. We are working on adding more.

Use describe goal of maven-help-plugin to see the list of parameters supported by the plugin. Example: bash mvn help:describe -Dplugin=se.kth.castor:sorald -Ddetail

For example, the following commands repair violations of S1132 in SonarSource/sonar-scanner-cli@5c518d6.

```bash

Cloning and moving into the project

git clone git@github.com:SonarSource/sonar-scanner-cli.git cd sonar-scanner-cli/ git checkout 5c518d6a

Running Sorald

mvn se.kth.castor:sorald:repair -DruleKey=S1132

Checking the result

git diff ```

You may also see the demo video:

https://user-images.githubusercontent.com/35191225/199800315-d5180de6-1fd1-44b2-95d3-82d51140073e.mp4

Getting a Sorald JAR

To run Sorald, you need to first get your hands on the program. You can do this either by building from source, or going to the latest release and downloading the file called sorald-<VERSION>-jar-with-dependencies.jar listed under Assets. Unless you keep multiple versions of Sorald, we recommend renaming the JAR to sorald.jar for the sake of simplicity.

Build

  1. Clone this repository: git clone https://github.com/SpoonLabs/sorald.git

  2. Build:

bash $ cd sorald $ mvn package -DskipTests $ cp sorald/target/sorald-*-jar-with-dependencies.jar sorald.jar

The Sorald application can now be found in sorald.jar in the current working directory.

Usage

Sorald can perform two different tasks: automatically repair violations of Sonar rules in a project, or mine projects for rule violations. These two modes of operations are available as the two commands repair and mine, respectively.

For the remainder of this section, assume that we have defined the following alias:

bash alias sorald='java -jar /abs/path/to/sorald.jar'

If you don't like using aliases, simply substitute in java -jar sorald.jar for any occurrence of sorald in these instructions.

Repairing rule violations (the repair command)

To repair rule violations, use the repair command.

bash $ sorald repair <arguments ...>

Basic usage consists of specifying a project to target and a rule to repair violations of. The available rules can be found here, and are specified by their key. For example, to repair violations of the rule 2111: "BigDecimal(double)" should not be used in a project at some/project/path, one can invoke Sorald like so.

bash $ sorald repair --source some/project/path --rule-key 2111

The full list of options is documented here (and can also be found by running sorald repair --help):

Mining Sonar warnings (the mine command)

To mine projects for Sonar warnings, use the mine command. Its most basic usage consists of simply pointing it to a project directory.

bash $ sorald mine --source path/to/project

It will then output statistics for that project with the Sonar checks available in Sorald.

Another option is to execute the miner on a list of remote Git repositories, which can be done like so.

bash $ sorald mine --stats-on-git-repos --git-repos-list repos.txt --stats-output-file output.txt --temp-dir /tmp

The --gitReposList should be a plain text file with one remote repository url (e.g. https://github.com/SpoonLabs/sorald.git) per line. Sorald clones each repository and runs Sonar checks on the head of the default branch.

The full list of options documented here (and can also be found by running sorald mine --help).

Running Sorald on GitHub projects to propose PRs with fixes

To run Sorald on projects towards proposing fixes in the form of PRs, look at this Git repository for an example. In it, Sorald is ran on the three Apache projects defined in the projectsformodel_1.txt file.

Releases

Our releases are signed using travis-gumtree-spoon's GPG key. The key is hosted here. You may run the following commands to verify the signature of a release. shell gpg --recv-keys 1429025e3eda19a5 gpg --verify sorald-<VERSION>-jar-with-dependencies.jar.asc

This signature is a type of detaached signature, so you need to have the JAR file as well to verify the signature.

Academic bibliographic references

"Sorald: Automatic Patch Suggestions for SonarQube Static Analysis Violations" (Khashayar Etemadi, Nicolas Harrand, Simon Larsen, Haris Adzemovic, Henry Luong Phu, Ashutosh Verma, Fernanda Madeiral, Douglas Wikstrom and Martin Monperrus), Technical report, arXiv 2103.12033, 2021.

"A template-based approach to automatic program repair of Sonarqube static warnings", by Haris Adzemovic, Master's thesis, KTH, School of Electrical Engineering and Computer Science (EECS), 2020. (bibtex)

Experiments with Sorald

Sorald-Experiments repository includes the data related to our experiments with Sorald that are part of a recently conducted research project.

Sorald downloads sonar-java-plugin.jar at runtime. See config file for its URL. Although most of the time it automatically downloads and loads it, you can manually download and store it if needed. See https://github.com/ASSERT-KTH/sorald/blob/02c07213264663f4fbc4728009dc4fbe7a4c00e5/sorald/src/main/java/sorald/FileUtils.java#L127 for the name of the directory for different filesystems. The file is called sonar-java-plugin.jar. In linux, ~/.cache/sorald/sonar-java-plugin.jar is the path of the downloaded jar.

Contributing

Contributions are welcome! Feel free to open issues on this GitHub repository, and also to open pull requests for making this project nicer (see instructions here).

Owner

  • Name: ASSERT
  • Login: ASSERT-KTH
  • Kind: organization
  • Location: Sweden

assertEquals("Research group at KTH Royal Institute of Technology, Stockholm, Sweden", description);

Citation (CITATION.cff)

cff-version: 1.2.0
preferred-citation:
  title: "Sorald: Automatic Patch Suggestions for SonarQube Static Analysis Violations"
  doi: "10.1109/TDSC.2022.3167316"
  year: "2022"
  type: article
  journal: "IEEE Transactions on Dependable and Secure Computing"
  authors:
    - family-names: Etemadi
      given-names: Khashayar
    - family-names: Harrand
      given-names: Nicolas
    - family-names: Larsén
      given-names: Simon
    - family-names: Adzemovic
      given-names: Haris
    - family-names: Luong
      given-names: Henry
    - family-names: Verma
      given-names: Ashutosh
    - family-names: Madeiral
      given-names: Fernanda
    - family-names: Wikström
      given-names: Douglas
    - family-names: Monperrus
      given-names: Martin

GitHub Events

Total
  • Watch event: 7
  • Delete event: 24
  • Push event: 125
  • Pull request event: 50
  • Create event: 22
Last Year
  • Watch event: 7
  • Delete event: 24
  • Push event: 125
  • Pull request event: 50
  • Create event: 22

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 46
  • Average time to close issues: N/A
  • Average time to close pull requests: about 2 months
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 32
  • Bot issues: 0
  • Bot pull requests: 45
Past Year
  • Issues: 0
  • Pull requests: 27
  • Average time to close issues: N/A
  • Average time to close pull requests: 2 days
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 20
  • Bot issues: 0
  • Bot pull requests: 26
Top Authors
Issue Authors
Pull Request Authors
  • renovate[bot] (45)
  • andre15silva (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/combine_prs.yml actions
  • github/combine-prs v3.1.2 composite
.github/workflows/deploy.yml actions
  • actions/checkout f43a0e5ff2bd294095638e18286ca9a3d1956744 composite
  • actions/setup-java cd89f46ac9d01407894225f350157564c9c7cee2 composite
.github/workflows/jreleaser.yml actions
  • actions-js/push master composite
  • actions/checkout 8e5e7e5ab8b370d6c329ec480221332ada57f0ab composite
  • actions/setup-go 4d34df0c2316fe8122ab82dc22947d607c0c91f9 composite
  • actions/setup-java 5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 composite
  • actions/upload-artifact 0b7f8abb1508181956e8e162db84b466c27e18ce composite
  • jreleaser/release-action v2 composite
.github/workflows/sorald_buildbreaker.yml actions
  • SpoonLabs/sorald-buildbreaker 45bafb6db29a466080328864cecf9b20d9ace3de composite
  • actions/checkout v3 composite
.github/workflows/support.yml actions
  • actions/checkout f43a0e5ff2bd294095638e18286ca9a3d1956744 composite
  • actions/setup-java cd89f46ac9d01407894225f350157564c9c7cee2 composite
  • actions/setup-python 61a6322f88396a6271a6ee3565807d608ecaddd1 composite
.github/workflows/tests.yml actions
  • actions/cache 704facf57e6136b1bc63b828d79edcd491f0ee84 composite
  • actions/checkout f43a0e5ff2bd294095638e18286ca9a3d1956744 composite
  • actions/setup-java cd89f46ac9d01407894225f350157564c9c7cee2 composite
  • actions/setup-python 61a6322f88396a6271a6ee3565807d608ecaddd1 composite
  • codecov/codecov-action eaaf4bedf32dbdc6b720b63067d99c4d77d6047d composite
pom.xml maven
experimentation/tools/setup.py pypi
sorald/pom.xml maven
  • info.picocli:picocli 4.7.6
  • info.picocli:picocli-codegen 4.7.6
  • org.apache.maven.plugin-tools:maven-plugin-annotations 3.15.1
  • org.apache.maven:maven-plugin-api 3.9.9
  • org.json:json 20231013
  • org.sonarsource.sonarlint.core:sonarlint-core 8.15.0.65216
  • se.kth.castor:sorald-api 0.8.7-SNAPSHOT
  • com.soebes.itf.jupiter.extension:itf-assertj 0.13.1 test
  • com.soebes.itf.jupiter.extension:itf-jupiter-extension 0.13.1 test
  • org.assertj:assertj-core 3.26.3 test
  • org.junit.jupiter:junit-jupiter-engine 5.11.3 test
sorald/src/test/resources/scenario_test_files/classpath-dependent-project/pom.xml maven
  • fr.inria.gforge.spoon.labs:gumtree-spoon-ast-diff 1.62
sorald/src/test/resources/scenario_test_files/simple-java8-maven-project/pom.xml maven
  • junit:junit 3.8.1 test
sorald/src/test/resources-its/sorald/it/MineMojoIT/empty_project/pom.xml maven
sorald/src/test/resources-its/sorald/it/MineMojoIT/handled_rules/pom.xml maven
sorald/src/test/resources-its/sorald/it/MineMojoIT/mine_for_violations/pom.xml maven
sorald/src/test/resources-its/sorald/it/MineMojoIT/pom_configured/pom.xml maven
sorald/src/test/resources-its/sorald/it/MineMojoIT/stats_output_file/pom.xml maven
sorald/src/test/resources-its/sorald/it/RepairMojoIT/do_nothing_when_there_are_no_violations/pom.xml maven
sorald/src/test/resources-its/sorald/it/RepairMojoIT/empty_project/pom.xml maven
sorald/src/test/resources-its/sorald/it/RepairMojoIT/fails_without_ruleKey_parameter/pom.xml maven
sorald/src/test/resources-its/sorald/it/RepairMojoIT/perform_repairs/pom.xml maven
sorald/src/test/resources-its/sorald/it/RepairMojoIT/stats_output_file/pom.xml maven
sorald-api/pom.xml maven