Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=io.ballerina.scan
version=0.9.1-SNAPSHOT
version=0.10.0-SNAPSHOT

# Plugin versions
spotbugsPluginVersion=6.1.5
Expand Down
123 changes: 123 additions & 0 deletions scan-command-test-utils/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort

plugins {
id 'java-library'
id 'checkstyle'
id 'maven-publish'
id 'com.github.spotbugs'
id 'de.undercouch.download'
}

group = "${group}"
version = "${version}"

repositories {
mavenLocal()
mavenCentral()
maven {
url = 'https://maven.pkg.github.com/ballerina-platform/*'
credentials {
username System.getenv("packageUser")
password System.getenv("packagePAT")
}
}
}

dependencies {
implementation project(':scan-command')
implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}"
implementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
}

// Publish scan-command-test-utils package to GitHub packages
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId group
artifactId project.name
version version
}
}

repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ballerina-platform/static-code-analysis-tool")
credentials {
username = System.getenv("publishUser")
password = System.getenv("publishPAT")
}
}
}
}

tasks.register('downloadCheckstyleRuleFiles', Download) {
src([
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml',
'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.xml'
])
overwrite false
onlyIfNewer true
dest buildDir
}

artifacts.add('default', file("${project.buildDir}/checkstyle.xml")) {
builtBy(downloadCheckstyleRuleFiles)
}

artifacts.add('default', file("${project.buildDir}/suppressions.xml")) {
builtBy(downloadCheckstyleRuleFiles)
}

def excludePattern = '**/module-info.java'
tasks.withType(Checkstyle).configureEach {
exclude excludePattern
}

checkstyle {
toolVersion "${project.puppycrawlCheckstyleVersion}"
configFile rootProject.file("${project.buildDir}/checkstyle.xml")
configProperties = ["suppressionFile": file("${project.buildDir}/suppressions.xml")]
}

checkstyleMain.dependsOn(downloadCheckstyleRuleFiles)
checkstyleTest.dependsOn(downloadCheckstyleRuleFiles)

spotbugsMain {
effort = Effort.valueOf("MAX")
reportLevel = Confidence.valueOf("LOW")

reportsDir = file("$project.buildDir/reports/spotbugs")

reports {
html.required.set(true)
text.required.set(true)
}

def excludeFile = file("${projectDir}/spotbugs-exclude.xml")
if (excludeFile.exists()) {
excludeFilter = excludeFile
}
}
25 changes: 25 additions & 0 deletions scan-command-test-utils/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
~ Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
~
~ WSO2 LLC. licenses this file to you 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.
-->

<FindBugsFilter>
<Match>
<Class name="io.ballerina.scan.test.TestOptions$TestOptionsBuilder"/>
<Method name="setOutputStream"/>
<Bug code="EI2" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.
*/

package io.ballerina.scan.test;

import io.ballerina.scan.Issue;
import io.ballerina.scan.Rule;
import io.ballerina.scan.RuleKind;
import io.ballerina.scan.Source;
import org.testng.Assert;

import java.util.List;
import java.util.stream.Collectors;

/**
* Test utility class to assert the issues found during a scan.
*
* @since 0.10.0
Comment thread
gayaldassanayake marked this conversation as resolved.
*/
public class Assertions {

private Assertions() {
}

/**
* Assert that the list of issues contains an issue with the given rule ID, file name, start line, end line,
* and source at the given index.
*
* @param issues list of issues from which the issue should be found
* @param index index of the issue to check
* @param ruleId rule ID to check for
* @param fileName file name to check for
* @param startLine start line to check for
* @param endLine end line to check for
* @param source source to check for
*/
public static void assertIssue(List<Issue> issues,
int index,
String ruleId,
String fileName,
int startLine,
int endLine,
Source source) {
Assert.assertTrue(index < issues.size(), "Index out of bounds for the issues list");
Issue issue = issues.get(index);
Assert.assertEquals(issue.rule().id(), ruleId, "Rule ID mismatch");
Assert.assertEquals(issue.source(), source, "Source mismatch");
Assert.assertEquals(issue.location().lineRange().fileName(), fileName, "File name mismatch");
Assert.assertEquals(issue.location().lineRange().startLine().line(), startLine, "Start line mismatch");
Assert.assertEquals(issue.location().lineRange().endLine().line(), endLine, "End line mismatch");
}

/**
* Assert that the list of rules contains a rule with the given ID, description, and kind.
*
* @param rules list of rules from which the rule should be found
* @param id rule ID to check for
* @param description rule description to check for
* @param kind rule kind to check for
*/
public static void assertRule(List<Rule> rules, String id, String description, RuleKind kind) {
boolean found = rules.stream().anyMatch(rule ->
rule.id().equals(id) &&
rule.description().equals(description) &&
rule.kind() == kind);

if (!found) {
String summary = rules.stream()
.map(rule -> String.format("Rule ID: %s, Description: %s, Kind: %s", rule.id(),
rule.description(), rule.kind()))
.collect(Collectors.joining("\n"));
Assert.fail(String.format("Expected rule with ID '%s' not found.%nFound rules:%n%s", id, summary));
}
}
}
Loading
Loading