diff --git a/.github/workflows/full_build.yml b/.github/workflows/full_build.yml index 4c6bd25..da701b3 100644 --- a/.github/workflows/full_build.yml +++ b/.github/workflows/full_build.yml @@ -39,6 +39,29 @@ jobs: packagePAT: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew build + - name: Generate Jacoco report + run: ./gradlew createCodeCoverageReport + + - name: Generate Codecov Report + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./.jacoco/reports/jacoco/report.xml + + - name: Cache SonarCloud packages for faster analysis + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Generate SonarCloud Report + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: "${{ env.SONAR_TOKEN != '' }}" + run: ./gradlew sonar --info + windows_build: name: Build runs-on: windows-latest @@ -65,4 +88,4 @@ jobs: env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew.bat build + run: ./gradlew build diff --git a/.gitignore b/.gitignore index 02db86c..7935880 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ build/ # IntelliJ IDEA .idea/ + +# Coverage reports +.jacoco/ diff --git a/ScanCommand/build.gradle b/ScanCommand/build.gradle index 679dcc5..d293794 100644 --- a/ScanCommand/build.gradle +++ b/ScanCommand/build.gradle @@ -23,8 +23,10 @@ plugins { id 'application' id 'java-library' id 'checkstyle' - id "com.github.spotbugs" version "${spotbugsPluginVersion}" - id "de.undercouch.download" version "${downloadPluginVersion}" + id 'jacoco' + id 'com.github.spotbugs' + id 'de.undercouch.download' + id 'org.sonarqube' } group = "${group}" @@ -57,11 +59,15 @@ dependencies { implementation group: 'org.ballerinalang', name: 'jballerina-tools', version: "${ballerinaLangVersion}" implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}" - checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}" - // Required for determining the platform a java process is running on implementation group: 'org.apache.commons', name: 'commons-lang3', version: "${apacheCommonsLang3Version}" + // Required dependencies for jacoco + implementation group: 'org.jacoco', name: 'org.jacoco.core', version: "${jacocoVersion}" + implementation group: 'org.jacoco', name: 'org.jacoco.report', version: "${jacocoVersion}" + + checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}" + // Required dependencies for running scan tool tests testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}" } @@ -153,12 +159,6 @@ task validateSpotbugs() { spotbugsMain.finalizedBy validateSpotbugs -tasks.test { - useTestNG() { - suites 'src/test/resources/testng.xml' - } -} - // Configurations to automatically build and deploy scan tool def packageName = "tool_scan" def tomlVersion = "${project.scanToolVersion}" @@ -268,3 +268,53 @@ build { dependsOn createBallerinaToolConfigFile dependsOn buildScanTool } + +// Configuring tests +tasks.test { + useTestNG() { + suites 'src/test/resources/testng.xml' + } +} + +// Codecove configurations +def execFile; +def classFileArray = [] +task copyExecFilesAndJavaClassFiles { + execFile = new File("${buildDir}/jacoco/test.exec") + if (execFile.exists()) { + fileTree("${buildDir}/classes").matching { + exclude '**/test/*' + exclude '**/module-info.class' + }.each { file -> classFileArray.push(file) } + } +} + +task createCodeCoverageReport(type: JacocoReport) { + executionData file(execFile) + additionalClassDirs files(classFileArray) + + reports { + xml.required = true + html.required = true + xml.destination new File("${rootDir}/.jacoco/reports/jacoco/report.xml") + html.destination new File("${rootDir}/.jacoco/reports/jacoco/report.html") + } + onlyIf = { + true + } +} + +createCodeCoverageReport.dependsOn(copyExecFilesAndJavaClassFiles) + +// SonarCloud Configurations +sonar { + properties { + property "sonar.projectKey", "ballerina-platform_static-code-analysis-tool" + property "sonar.organization", "ballerina-platform" + property "sonar.host.url", "https://sonarcloud.io" + + // Additional properties + // To Add test coverage + property "sonar.coverage.jacoco.xmlReportPaths", "${rootDir}/.jacoco/reports/jacoco/*.xml" + } +} diff --git a/ScanCommand/src/main/java/io/ballerina/scan/ScanCmd.java b/ScanCommand/src/main/java/io/ballerina/scan/ScanCmd.java index 1c7531b..befa20f 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/ScanCmd.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/ScanCmd.java @@ -60,7 +60,7 @@ public class ScanCmd implements BLauncherCmd { private boolean scanReport; @CommandLine.Option(names = "--list-rules", - description = "List the rules available in the Ballerina scan tool.") + description = "List the rules available in the Ballerina scan tool") private boolean listRules; @CommandLine.Option(names = "--include-rules", diff --git a/ScanCommand/src/main/java/io/ballerina/scan/Severity.java b/ScanCommand/src/main/java/io/ballerina/scan/Severity.java index cb88d4b..018e3f2 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/Severity.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/Severity.java @@ -20,10 +20,6 @@ /** * Represents the kind of severity of a {@link Rule} instance. - *

- * There are three known kinds of severities at the moment: {@link #CODE_SMELL}, {@link #BUG} - * and {@link #VULNERABILITY}. - *

* * @since 0.1.0 */ diff --git a/gradle.properties b/gradle.properties index a98205e..fe55c7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,16 @@ group=io.ballerina.scan scanToolVersion=0.1.0 -# Dependency versions +# Plugin versions spotbugsPluginVersion=5.0.14 downloadPluginVersion=5.4.0 +sonarqubeGradlePluginVersion=4.0.0.2929 + +# Dependency versions picoCLIVersion=4.7.5 gsonVersion=2.10.1 ballerinaLangVersion=2201.8.6 puppycrawlCheckstyleVersion=10.12.1 apacheCommonsLang3Version=3.0 testngVersion=7.6.1 +jacocoVersion=0.8.10 diff --git a/settings.gradle b/settings.gradle index ff5a87a..6be1254 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,5 +16,18 @@ * under the License. */ +pluginManagement { + plugins { + id 'java' + id 'application' + id 'java-library' + id 'checkstyle' + id 'jacoco' + id 'com.github.spotbugs' version "${spotbugsPluginVersion}" + id 'de.undercouch.download' version "${downloadPluginVersion}" + id 'org.sonarqube' version "${sonarqubeGradlePluginVersion}" + } +} + rootProject.name = 'static-code-analysis-tool' include 'ScanCommand'