From ab0bd3497f4032da1b7f75ea2c1eae6563be4889 Mon Sep 17 00:00:00 2001 From: Tharana Wanigaratne Date: Tue, 16 Apr 2024 09:25:11 +0530 Subject: [PATCH] Update doc comments and project file namings --- ScanCommand/build.gradle | 11 ++++---- .../main/java/io/ballerina/scan/Reporter.java | 4 +-- .../io/ballerina/scan/ScannerContext.java | 6 ++--- .../{IssueIml.java => IssueImpl.java} | 27 ++++++++++--------- .../ballerina/scan/internal/ReporterImpl.java | 4 +-- .../internal/{RuleIml.java => RuleImpl.java} | 4 +-- 6 files changed, 29 insertions(+), 27 deletions(-) rename ScanCommand/src/main/java/io/ballerina/scan/internal/{IssueIml.java => IssueImpl.java} (69%) rename ScanCommand/src/main/java/io/ballerina/scan/internal/{RuleIml.java => RuleImpl.java} (92%) diff --git a/ScanCommand/build.gradle b/ScanCommand/build.gradle index c1a345c..8cf7470 100644 --- a/ScanCommand/build.gradle +++ b/ScanCommand/build.gradle @@ -18,6 +18,8 @@ import org.apache.tools.ant.taskdefs.condition.Os +import java.nio.file.Paths + plugins { id 'java' id 'application' @@ -159,12 +161,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}" @@ -277,6 +273,9 @@ build { // Configuring tests tasks.test { + systemProperty "ballerina.home", Paths.get(System.getenv("BALLERINA_HOME")).resolve("distributions") + .resolve("ballerina-${ballerinaLangVersion}").toString() + useTestNG() { suites 'src/test/resources/testng.xml' } diff --git a/ScanCommand/src/main/java/io/ballerina/scan/Reporter.java b/ScanCommand/src/main/java/io/ballerina/scan/Reporter.java index 6135128..67984c7 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/Reporter.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/Reporter.java @@ -22,7 +22,7 @@ import io.ballerina.tools.diagnostics.Location; /** - * This class represents the reporter used for reporting {@link Issue} instances during analysis. + * This class represents the reporter used for reporting {@link Issue} instances during static code analysis. * * @since 0.1.0 * */ @@ -37,7 +37,7 @@ public interface Reporter { void reportIssue(Document reportedDocument, Location location, int ruleId); /** - * This method is used for reporting an analysis issue. + * This method is used for reporting an issue identified during static code analysis. * * @param reportedDocument Ballerina document * @param location location of reported issue diff --git a/ScanCommand/src/main/java/io/ballerina/scan/ScannerContext.java b/ScanCommand/src/main/java/io/ballerina/scan/ScannerContext.java index e9356a1..63b5418 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/ScannerContext.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/ScannerContext.java @@ -19,15 +19,15 @@ package io.ballerina.scan; /** - * {@code ScannerContext} represents a generic context that provides functionalities relevant to the scan process. + * {@code ScannerContext} represents a context that exposes properties required by scanner plugins from the scan tool. * * @since 0.1.0 * */ public interface ScannerContext { /** - * Returns the {@link Reporter} associated with the scanner context. + * Returns the {@link Reporter} that needs to be used to report issues identified. * - * @return reporter associated with the scanner context + * @return reporter that needs to be used to report issues identified. * */ Reporter getReporter(); } diff --git a/ScanCommand/src/main/java/io/ballerina/scan/internal/IssueIml.java b/ScanCommand/src/main/java/io/ballerina/scan/internal/IssueImpl.java similarity index 69% rename from ScanCommand/src/main/java/io/ballerina/scan/internal/IssueIml.java rename to ScanCommand/src/main/java/io/ballerina/scan/internal/IssueImpl.java index e881159..e1702d3 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/internal/IssueIml.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/internal/IssueImpl.java @@ -22,6 +22,8 @@ import io.ballerina.scan.Rule; import io.ballerina.scan.Source; import io.ballerina.tools.diagnostics.Location; +import io.ballerina.tools.text.LineRange; +import io.ballerina.tools.text.TextRange; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLocation; /** @@ -29,23 +31,24 @@ * * @since 0.1.0 * */ -public class IssueIml implements Issue { +public class IssueImpl implements Issue { private final BLangDiagnosticLocation location; - private final RuleIml rule; + private final RuleImpl rule; private final Source source; private final String fileName; private final String filePath; - IssueIml(Location location, - Rule rule, - Source source, - String fileName, - String filePath) { - this.location = new BLangDiagnosticLocation(location.lineRange().fileName(), - location.lineRange().startLine().line(), location.lineRange().endLine().line(), - location.lineRange().startLine().offset(), location.lineRange().endLine().offset(), - location.textRange().startOffset(), location.textRange().length()); - this.rule = (RuleIml) rule; + IssueImpl(Location location, + Rule rule, + Source source, + String fileName, + String filePath) { + LineRange lineRange = location.lineRange(); + TextRange textRange = location.textRange(); + this.location = new BLangDiagnosticLocation(lineRange.fileName(), lineRange.startLine().line(), + lineRange.endLine().line(), lineRange.startLine().offset(), lineRange.endLine().offset(), + textRange.startOffset(), textRange.length()); + this.rule = (RuleImpl) rule; this.source = source; this.fileName = fileName; this.filePath = filePath; diff --git a/ScanCommand/src/main/java/io/ballerina/scan/internal/ReporterImpl.java b/ScanCommand/src/main/java/io/ballerina/scan/internal/ReporterImpl.java index 1e78c43..e147fb2 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/internal/ReporterImpl.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/internal/ReporterImpl.java @@ -30,7 +30,7 @@ import java.util.List; /** - * This class represents the reporter implementation used for reporting {@link Issue} instances during analysis. + * This class implements the {@link Reporter} interface . * * @since 0.1.0 * */ @@ -48,7 +48,7 @@ public void reportIssue(Document reportedDocument, Location location, Rule rule) Path issuesFilePath = reportedDocument.module().project().documentPath(reportedDocument.documentId()) .orElse(Path.of(documentName)); - IssueIml issue = new IssueIml(location, rule, Source.BUILT_IN, + IssueImpl issue = new IssueImpl(location, rule, Source.BUILT_IN, moduleName + System.lineSeparator() + documentName, issuesFilePath.toString()); issues.add(issue); diff --git a/ScanCommand/src/main/java/io/ballerina/scan/internal/RuleIml.java b/ScanCommand/src/main/java/io/ballerina/scan/internal/RuleImpl.java similarity index 92% rename from ScanCommand/src/main/java/io/ballerina/scan/internal/RuleIml.java rename to ScanCommand/src/main/java/io/ballerina/scan/internal/RuleImpl.java index 5606183..3b1f207 100644 --- a/ScanCommand/src/main/java/io/ballerina/scan/internal/RuleIml.java +++ b/ScanCommand/src/main/java/io/ballerina/scan/internal/RuleImpl.java @@ -26,14 +26,14 @@ * * @since 0.1.0 * */ -public class RuleIml implements Rule { +public class RuleImpl implements Rule { private final String id; private final int numericId; private final String description; private final Severity severity; - RuleIml(String id, int numericId, String description, Severity severity) { + RuleImpl(String id, int numericId, String description, Severity severity) { this.id = id; this.numericId = numericId; this.description = description;