diff --git a/build.gradle b/build.gradle index 16587b6e..b0904366 100644 --- a/build.gradle +++ b/build.gradle @@ -30,9 +30,6 @@ project(':scan-command') { dependsOn ':test-compiler-plugins:exampleOrg-plugin:build' dependsOn ':test-compiler-plugins:ballerina-plugin:build' dependsOn ':test-compiler-plugins:ballerinax-plugin:build' - dependsOn ':test-compiler-plugins:invalid-rules-plugin:build' - dependsOn ':test-compiler-plugins:invalid-ruleformat-plugin:build' - dependsOn ':test-compiler-plugins:invalid-rulekind-plugin:build' dependsOn ':test-static-code-analysis-platform-plugins:exampleOrg-static-code-analysis-platform-plugin:build' } } @@ -56,24 +53,6 @@ project(':test-compiler-plugins:ballerinax-plugin') { } } -project(':test-compiler-plugins:invalid-rules-plugin') { - dependencies { - implementation project(':scan-command') - } -} - -project(':test-compiler-plugins:invalid-ruleformat-plugin') { - dependencies { - implementation project(':scan-command') - } -} - -project(':test-compiler-plugins:invalid-rulekind-plugin') { - dependencies { - implementation project(':scan-command') - } -} - project(':test-static-code-analysis-platform-plugins:exampleOrg-static-code-analysis-platform-plugin') { dependencies { implementation project(':scan-command') diff --git a/scan-command-test-utils/src/main/java/io/ballerina/scan/test/TestReporter.java b/scan-command-test-utils/src/main/java/io/ballerina/scan/test/TestReporter.java index cecbdd2d..72706fd5 100644 --- a/scan-command-test-utils/src/main/java/io/ballerina/scan/test/TestReporter.java +++ b/scan-command-test-utils/src/main/java/io/ballerina/scan/test/TestReporter.java @@ -35,7 +35,7 @@ class TestReporter extends ReporterImpl { } @Override - protected List getIssues() { + public List getIssues() { return super.getIssues(); } } diff --git a/scan-command/src/main/java/io/ballerina/scan/ExternalCodeAnalyzer.java b/scan-command/src/main/java/io/ballerina/scan/ExternalCodeAnalyzer.java new file mode 100644 index 00000000..4cca392d --- /dev/null +++ b/scan-command/src/main/java/io/ballerina/scan/ExternalCodeAnalyzer.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) + * + * 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; + +import io.ballerina.projects.plugins.CodeAnalyzer; + +/** + * This class provides a convenient abstraction for creating external analyzers + * that need to provide rules through the service loading mechanism. + * + *

+ * External analyzer implementations should extend this class and provide + * implementations for the abstract methods. The class handles the integration + * with the Ballerina compiler plugin framework and the static code analysis + * tool. + *

+ * + * @since 0.10.0 + */ +public abstract class ExternalCodeAnalyzer extends CodeAnalyzer implements RuleProvider { + /** + * Default constructor for the external code analyzer. + * This constructor is used for service loading and should not be called directly. + */ + protected ExternalCodeAnalyzer() { + // Default constructor for service loading + } +} diff --git a/scan-command/src/main/java/io/ballerina/scan/RuleProvider.java b/scan-command/src/main/java/io/ballerina/scan/RuleProvider.java new file mode 100644 index 00000000..74c0af6d --- /dev/null +++ b/scan-command/src/main/java/io/ballerina/scan/RuleProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) + * + * 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; + +/** + * Service provider interface for discovering rules from code analyzers. + * This interface should be implemented by classes that extend CodeAnalyzer + * and want to provide rules through the service loading mechanism. + * + * @since 0.10.0 + */ +public interface RuleProvider { + /** + * Returns all Rule instances provided by this analyzer. + * + * @return an iterable of rules provided by this analyzer + */ + Iterable getRules(); +} diff --git a/scan-command/src/main/java/io/ballerina/scan/internal/ProjectAnalyzer.java b/scan-command/src/main/java/io/ballerina/scan/internal/ProjectAnalyzer.java index d68cbb60..473b4b0d 100644 --- a/scan-command/src/main/java/io/ballerina/scan/internal/ProjectAnalyzer.java +++ b/scan-command/src/main/java/io/ballerina/scan/internal/ProjectAnalyzer.java @@ -18,10 +18,6 @@ package io.ballerina.scan.internal; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import io.ballerina.compiler.api.SemanticModel; import io.ballerina.projects.CompilerPluginCache; import io.ballerina.projects.Document; @@ -37,55 +33,41 @@ import io.ballerina.projects.internal.model.CompilerPluginDescriptor; import io.ballerina.scan.Issue; import io.ballerina.scan.Rule; -import io.ballerina.scan.RuleKind; +import io.ballerina.scan.RuleProvider; import io.ballerina.scan.ScannerContext; import io.ballerina.scan.utils.DiagnosticCode; import io.ballerina.scan.utils.DiagnosticLog; import io.ballerina.scan.utils.ScanTomlFile; import io.ballerina.scan.utils.ScanToolException; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; +import java.util.ServiceLoader; import java.util.Set; import java.util.UUID; import java.util.function.Consumer; -import java.util.stream.Collectors; import static io.ballerina.projects.util.ProjectConstants.IMPORT_PREFIX; -import static io.ballerina.scan.internal.ScanToolConstants.BUG; -import static io.ballerina.scan.internal.ScanToolConstants.CODE_SMELL; import static io.ballerina.scan.internal.ScanToolConstants.FORWARD_SLASH; import static io.ballerina.scan.internal.ScanToolConstants.IMPORT_GENERATOR_FILE; -import static io.ballerina.scan.internal.ScanToolConstants.RULES_FILE; -import static io.ballerina.scan.internal.ScanToolConstants.RULE_DESCRIPTION; -import static io.ballerina.scan.internal.ScanToolConstants.RULE_ID; -import static io.ballerina.scan.internal.ScanToolConstants.RULE_KIND; import static io.ballerina.scan.internal.ScanToolConstants.SCANNER_CONTEXT; import static io.ballerina.scan.internal.ScanToolConstants.USE_IMPORT_AS_UNDERSCORE; -import static io.ballerina.scan.internal.ScanToolConstants.VULNERABILITY; /** * Represents the project analyzer used for analyzing projects. * * @since 0.1.0 - * */ + */ public class ProjectAnalyzer { private final Project project; private final ScanTomlFile scanTomlFile; - private final Gson gson = new Gson(); private String pluginImportsDocumentName; protected ProjectAnalyzer(Project project, ScanTomlFile scanTomlFile) { @@ -144,26 +126,66 @@ Map> getExternalAnalyzers() { ResolvedPackageDependency rootPkgNode = new ResolvedPackageDependency(project.currentPackage(), PackageDependencyScope.DEFAULT); Map> externalAnalyzers = new HashMap<>(); + packageResolution.dependencyGraph().getDirectDependencies(rootPkgNode).stream() .map(ResolvedPackageDependency::packageInstance).forEach(pkgDependency -> { PackageManifest pkgManifest = pkgDependency.manifest(); String org = pkgManifest.org().value(); String name = pkgManifest.name().value(); - String pluginName = org + FORWARD_SLASH + name; if (pkgManifest.compilerPluginDescriptor().isEmpty()) { return; } - CompilerPluginDescriptor pluginDesc = pkgManifest.compilerPluginDescriptor().get(); - Optional ruleFileContent = loadRuleFileContent(pluginName, pluginDesc); - if (ruleFileContent.isEmpty()) { + + CompilerPluginDescriptor pluginDesc = pkgDependency.manifest().compilerPluginDescriptor() + .orElse(null); + if (pluginDesc == null) { + externalAnalyzers.put(pkgDependency.manifest().compilerPluginDescriptor().toString(), + new ArrayList<>()); return; } - List externalRules = loadExternalRules(org, name, pluginName, ruleFileContent.get()); + List externalRules; + try { + externalRules = loadRulesFromEnum(pluginDesc, org, name); + } catch (IOException e) { + DiagnosticLog.error(DiagnosticCode.FAILED_TO_LOAD_COMPILER_PLUGIN, + "IOException occurred while loading rules: " + e.getMessage()); + externalRules = new ArrayList<>(); + } catch (ScanToolException e) { + DiagnosticLog.error(DiagnosticCode.FAILED_TO_LOAD_COMPILER_PLUGIN, + "ScanToolException occurred while loading rules: " + e.getMessage()); + externalRules = new ArrayList<>(); + } externalAnalyzers.put(pluginDesc.plugin().getClassName(), externalRules); }); return externalAnalyzers; } + private List loadRulesFromEnum(CompilerPluginDescriptor pluginDesc, String org, String name) + throws IOException { + List jarUrls = pluginDesc.dependencies().stream().map(dependency -> { + try { + return Path.of(dependency.getPath()).toUri().toURL(); + } catch (MalformedURLException ex) { + throw new ScanToolException( + DiagnosticLog.error(DiagnosticCode.FAILED_TO_LOAD_COMPILER_PLUGIN, ex.getMessage())); + } + }).toList(); + + try (URLClassLoader ucl = URLClassLoader.newInstance(jarUrls.toArray(URL[]::new), + this.getClass().getClassLoader())) { + ServiceLoader loader = ServiceLoader.load(RuleProvider.class, ucl); + List rules = new ArrayList<>(); + for (RuleProvider provider : loader) { + for (Rule r : provider.getRules()) { + Rule inMemoryRule = RuleFactory.createRule(r.numericId(), + r.description(), r.kind(), org, name); + rules.add(inMemoryRule); + } + } + return rules; + } + } + private void extractAnalyzerImportsAndDependencies(ScanTomlFile.Analyzer analyzer, StringBuilder imports, StringBuilder dependencies) { String org = analyzer.org(); @@ -190,104 +212,12 @@ private void buildStringWithNewLine(StringBuilder stringBuilder, String content) stringBuilder.append(content).append(System.lineSeparator()); } - private Optional loadRuleFileContent(String pluginName, CompilerPluginDescriptor pluginDesc) { - InputStream resource = loadResource(pluginDesc); - if (resource == null) { - return Optional.empty(); - } - - String resourceContent; - try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource, - StandardCharsets.UTF_8))) { - resourceContent = reader.lines().collect(Collectors.joining()); - } catch (IOException ex) { - throw new ScanToolException(DiagnosticLog.error(DiagnosticCode.READING_RULES_FILE, RULES_FILE, pluginName, - ex.getMessage())); - } - return Optional.of(resourceContent); - } - - private InputStream loadResource(CompilerPluginDescriptor pluginDesc) { - List jarUrls = pluginDesc.dependencies().stream().map(dependency -> { - try { - return Path.of(dependency.getPath()).toUri().toURL(); - } catch (MalformedURLException ex) { - throw new ScanToolException( - DiagnosticLog.error(DiagnosticCode.FAILED_TO_LOAD_COMPILER_PLUGIN, - ex.getMessage())); - } - }).toList(); - - URLClassLoader ucl = URLClassLoader.newInstance(jarUrls.toArray(URL[]::new), - this.getClass().getClassLoader()); - return ucl.getResourceAsStream(RULES_FILE); - } - - private List loadExternalRules(String org, String name, String pluginName, String ruleFileContent) { - List rules = new ArrayList<>(); - JsonArray ruleArray = getRuleJsonArray(pluginName, ruleFileContent); - for (JsonElement rule : ruleArray) { - JsonObject ruleObject = getRuleObject(pluginName, rule); - RuleKind ruleKind = getRuleKind(pluginName, ruleObject.get(RULE_KIND).getAsString()); - Rule inMemoryRule = RuleFactory.createRule(ruleObject.get(RULE_ID).getAsInt(), - ruleObject.get(RULE_DESCRIPTION).getAsString(), ruleKind, org, name); - rules.add(inMemoryRule); - } - return rules; - } - - private JsonArray getRuleJsonArray(String pluginName, String ruleFileContent) { - Gson gson = new Gson(); - JsonElement element = gson.fromJson(ruleFileContent, JsonElement.class); - if (!element.isJsonArray()) { - throw new ScanToolException(DiagnosticLog.error(DiagnosticCode.INVALID_JSON_FORMAT, RULES_FILE, - pluginName, gson.toJson(element))); - } - return element.getAsJsonArray(); - } - - private JsonObject getRuleObject(String pluginName, JsonElement rule) { - JsonObject ruleObject = rule.getAsJsonObject(); - if (!isValidRule(ruleObject)) { - throw new ScanToolException(DiagnosticLog.error(DiagnosticCode.INVALID_JSON_FORMAT_RULE, - pluginName, gson.toJson(ruleObject))); - } - return ruleObject; - } - - private boolean isValidRule(JsonObject ruleObject) { - return ruleObject.has(RULE_ID) && - ruleObject.get(RULE_ID).isJsonPrimitive() && - ruleObject.get(RULE_ID).getAsJsonPrimitive().isNumber() && - ruleObject.has(RULE_KIND) && - ruleObject.has(RULE_DESCRIPTION); - } - - private RuleKind getRuleKind(String pluginName, String kind) { - switch (kind) { - case BUG -> { - return RuleKind.BUG; - } - case VULNERABILITY -> { - return RuleKind.VULNERABILITY; - } - case CODE_SMELL -> { - return RuleKind.CODE_SMELL; - } - default -> { - throw new ScanToolException(DiagnosticLog.error(DiagnosticCode.INVALID_JSON_FORMAT_RULE_KIND, - pluginName, Arrays.toString(RuleKind.values()), kind)); - } - } - } - List runExternalAnalyzers(Map> externalAnalyzers) { List scannerContextList = new ArrayList<>(externalAnalyzers.size()); for (Map.Entry> externalAnalyzer : externalAnalyzers.entrySet()) { ScannerContext scannerContext = getScannerContext(externalAnalyzer.getValue()); scannerContextList.add(scannerContext); - // Save the scanner context to plugin cache for the compiler plugin to use during package compilation Map pluginProperties = new HashMap<>(); pluginProperties.put(SCANNER_CONTEXT, scannerContext); project.projectEnvironmentContext() diff --git a/scan-command/src/main/java/module-info.java b/scan-command/src/main/java/module-info.java index fccf3af1..923c4d3c 100644 --- a/scan-command/src/main/java/module-info.java +++ b/scan-command/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.scan { uses io.ballerina.scan.StaticCodeAnalysisPlatformPlugin; + uses io.ballerina.scan.RuleProvider; requires io.ballerina.cli; requires io.ballerina.lang; requires io.ballerina.parser; diff --git a/scan-command/src/test/java/io/ballerina/scan/internal/ProjectAnalyzerTest.java b/scan-command/src/test/java/io/ballerina/scan/internal/ProjectAnalyzerTest.java index 2fa55a04..36f7fdc2 100644 --- a/scan-command/src/test/java/io/ballerina/scan/internal/ProjectAnalyzerTest.java +++ b/scan-command/src/test/java/io/ballerina/scan/internal/ProjectAnalyzerTest.java @@ -30,14 +30,12 @@ import io.ballerina.scan.RuleKind; import io.ballerina.scan.Source; import io.ballerina.scan.utils.ScanTomlFile; -import io.ballerina.scan.utils.ScanToolException; import io.ballerina.scan.utils.ScanUtils; import io.ballerina.tools.text.LineRange; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Optional; @@ -150,70 +148,4 @@ private void assertIssue(Issue issue, String fileName, int startLine, int startO Assert.assertEquals(rule.description(), description); Assert.assertEquals(rule.kind(), kind); } - - @Test(description = "Test analyzing project with invalid external analyzer rules.json configurations") - void testAnalyzingProjectWithInvalidExternalAnalyzerRules() throws IOException { - Project invalidProject = BuildProject.load(testResources.resolve("test-resources") - .resolve("bal-project-with-invalid-external-analyzer-rules")); - System.setProperty("user.dir", invalidProject.sourceRoot().toString()); - ScanTomlFile scanTomlFile = ScanUtils.loadScanTomlConfigurations(invalidProject, printStream) - .orElse(null); - Assert.assertNotNull(scanTomlFile); - System.setProperty("user.dir", userDir); - projectAnalyzer = new ProjectAnalyzer(invalidProject, scanTomlFile); - Map> externalAnalyzers = null; - String result = null; - try { - externalAnalyzers = projectAnalyzer.getExternalAnalyzers(); - } catch (ScanToolException ex) { - result = ex.getMessage(); - } - Assert.assertNull(externalAnalyzers); - String expected = getExpectedOutput("invalid-json-format-for-rules.txt"); - Assert.assertEquals(result, expected); - } - - @Test(description = "Test analyzing project with invalid external analyzer rule format") - void testAnalyzingProjectWithInvalidExternalAnalyzerRuleFormat() throws IOException { - Project invalidProject = BuildProject.load(testResources.resolve("test-resources") - .resolve("bal-project-with-invalid-external-analyzer-rule-format")); - System.setProperty("user.dir", invalidProject.sourceRoot().toString()); - ScanTomlFile scanTomlFile = ScanUtils.loadScanTomlConfigurations(invalidProject, printStream) - .orElse(null); - Assert.assertNotNull(scanTomlFile); - System.setProperty("user.dir", userDir); - projectAnalyzer = new ProjectAnalyzer(invalidProject, scanTomlFile); - Map> externalAnalyzers = null; - String result = null; - try { - externalAnalyzers = projectAnalyzer.getExternalAnalyzers(); - } catch (ScanToolException ex) { - result = ex.getMessage(); - } - Assert.assertNull(externalAnalyzers); - String expected = getExpectedOutput("invalid-json-rule-format.txt"); - Assert.assertEquals(result, expected); - } - - @Test(description = "Test analyzing project with invalid external analyzer rule kind") - void testAnalyzingProjectWithInvalidExternalAnalyzerRuleKind() throws IOException { - Project invalidProject = BuildProject.load(testResources.resolve("test-resources") - .resolve("bal-project-with-invalid-external-analyzer-rule-kind")); - System.setProperty("user.dir", invalidProject.sourceRoot().toString()); - ScanTomlFile scanTomlFile = ScanUtils.loadScanTomlConfigurations(invalidProject, printStream) - .orElse(null); - Assert.assertNotNull(scanTomlFile); - System.setProperty("user.dir", userDir); - projectAnalyzer = new ProjectAnalyzer(invalidProject, scanTomlFile); - Map> externalAnalyzers = null; - String result = null; - try { - externalAnalyzers = projectAnalyzer.getExternalAnalyzers(); - } catch (ScanToolException ex) { - result = ex.getMessage(); - } - Assert.assertNull(externalAnalyzers); - String expected = getExpectedOutput("invalid-json-rule-kind.txt"); - Assert.assertEquals(result, expected); - } } diff --git a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule-kind.txt b/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule-kind.txt deleted file mode 100644 index 1c1d9474..00000000 --- a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule-kind.txt +++ /dev/null @@ -1 +0,0 @@ -invalid kind for rule object in plugin 'exampleOrg/exampleName'. kind should be one of [CODE_SMELL, BUG, VULNERABILITY] but found: 'SECURITY_HOTSPOT' \ No newline at end of file diff --git a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule.txt b/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule.txt deleted file mode 100644 index 40f0c0df..00000000 --- a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rule.txt +++ /dev/null @@ -1 +0,0 @@ -invalid json format for rule object in plugin 'exampleOrg/exampleName'. rule object should contain 'numeric id', 'kind', and 'description' but found: {'id':'1', 'severity':'BUG', 'description':'rule 1'} \ No newline at end of file diff --git a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rules.txt b/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rules.txt deleted file mode 100644 index cef6087c..00000000 --- a/scan-command/src/test/resources/command-outputs/common/invalid-json-format-for-rules.txt +++ /dev/null @@ -1 +0,0 @@ -invalid json format for 'rules.json' in plugin 'invalid/invalid_module_rules_static_code_analyzer'. expected an array, but found: {"id":1,"kind":"CODE_SMELL","description":"rule 1"} \ No newline at end of file diff --git a/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-format.txt b/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-format.txt deleted file mode 100644 index 71fd1a9e..00000000 --- a/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-format.txt +++ /dev/null @@ -1 +0,0 @@ -invalid json format for rule object in plugin 'invalid/invalid_module_ruleformat_static_code_analyzer'. rule object should contain 'id', 'kind', and 'description' but found: {"id":1,"severity":"CODE_SMELL","description":"rule 1"} \ No newline at end of file diff --git a/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-kind.txt b/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-kind.txt deleted file mode 100644 index 0964781c..00000000 --- a/scan-command/src/test/resources/command-outputs/common/invalid-json-rule-kind.txt +++ /dev/null @@ -1 +0,0 @@ -invalid kind for rule object in plugin 'invalid/invalid_module_rulekind_static_code_analyzer'. Expected one of [CODE_SMELL, BUG, VULNERABILITY], but found: 'SECURITY_HOTSPOT' \ No newline at end of file diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/.gitignore b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/.gitignore deleted file mode 100644 index 3749d15a..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -generated -Config.toml -Dependencies.toml diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Ballerina.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Ballerina.toml deleted file mode 100644 index 9f09fdfe..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Ballerina.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -org = "ballerina" -name = "bal_project_with_invalid_external_analyzer_rule_format" -version = "0.1.0" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Scan.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Scan.toml deleted file mode 100644 index cd72247f..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/Scan.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[analyzer]] -org = "invalid" -name = "invalid_module_ruleformat_static_code_analyzer" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/main.bal b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/main.bal deleted file mode 100644 index 011d9b36..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-format/main.bal +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. - -function getResult() returns int|error => 1; - -public function main() { - // Non-compliant - int result = checkpanic getResult(); -} diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/.gitignore b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/.gitignore deleted file mode 100644 index 3749d15a..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -generated -Config.toml -Dependencies.toml diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Ballerina.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Ballerina.toml deleted file mode 100644 index c2ec0bf5..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Ballerina.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -org = "ballerina" -name = "bal_project_with_invalid_external_analyzer_rule_kind" -version = "0.1.0" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Scan.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Scan.toml deleted file mode 100644 index 577dcedc..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/Scan.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[analyzer]] -org = "invalid" -name = "invalid_module_rulekind_static_code_analyzer" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/main.bal b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/main.bal deleted file mode 100644 index 011d9b36..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rule-kind/main.bal +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. - -function getResult() returns int|error => 1; - -public function main() { - // Non-compliant - int result = checkpanic getResult(); -} diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/.gitignore b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/.gitignore deleted file mode 100644 index 3749d15a..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -target -generated -Config.toml -Dependencies.toml diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Ballerina.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Ballerina.toml deleted file mode 100644 index c7ef5a77..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Ballerina.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -org = "ballerina" -name = "bal_project_with_invalid_external_analyzer_rules" -version = "0.1.0" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Scan.toml b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Scan.toml deleted file mode 100644 index a65d2585..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/Scan.toml +++ /dev/null @@ -1,3 +0,0 @@ -[[analyzer]] -org = "invalid" -name = "invalid_module_rules_static_code_analyzer" diff --git a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/main.bal b/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/main.bal deleted file mode 100644 index 011d9b36..00000000 --- a/scan-command/src/test/resources/test-resources/bal-project-with-invalid-external-analyzer-rules/main.bal +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. - -function getResult() returns int|error => 1; - -public function main() { - // Non-compliant - int result = checkpanic getResult(); -} diff --git a/scan-command/tool-scan/BalTool.toml b/scan-command/tool-scan/BalTool.toml index 773954e3..4d577017 100644 --- a/scan-command/tool-scan/BalTool.toml +++ b/scan-command/tool-scan/BalTool.toml @@ -2,4 +2,4 @@ id = "scan" [[dependency]] -path = "../build/libs/scan-command-0.10.0.jar" +path = "../build/libs/scan-command-0.10.1-SNAPSHOT.jar" diff --git a/scan-command/tool-scan/Ballerina.toml b/scan-command/tool-scan/Ballerina.toml index 27f8f905..ea387e4e 100644 --- a/scan-command/tool-scan/Ballerina.toml +++ b/scan-command/tool-scan/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "tool_scan" -version = "0.10.0" +version = "0.10.1-SNAPSHOT" distribution = "2201.12.0" authors = ["Ballerina"] keywords = ["scan", "static code analysis"] diff --git a/scan-command/tool-scan/Dependencies.toml b/scan-command/tool-scan/Dependencies.toml index d357cff3..f36c61b7 100644 --- a/scan-command/tool-scan/Dependencies.toml +++ b/scan-command/tool-scan/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.12.0" [[package]] org = "ballerina" name = "tool_scan" -version = "0.10.0" +version = "0.10.1-SNAPSHOT" modules = [ {org = "ballerina", packageName = "tool_scan", moduleName = "tool_scan"} ] diff --git a/settings.gradle b/settings.gradle index 252f6c17..66b45cd5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -36,9 +36,6 @@ include 'scan-command-test-utils' include 'test-compiler-plugins:exampleOrg-plugin' include 'test-compiler-plugins:ballerina-plugin' include 'test-compiler-plugins:ballerinax-plugin' -include 'test-compiler-plugins:invalid-rules-plugin' -include 'test-compiler-plugins:invalid-ruleformat-plugin' -include 'test-compiler-plugins:invalid-rulekind-plugin' include 'test-static-code-analysis-platform-plugins:exampleOrg-static-code-analysis-platform-plugin' if (gradle.startParameter.buildScan) { diff --git a/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomCodeAnalyzer.java b/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomCodeAnalyzer.java index 00d0b2a5..22abf0a3 100644 --- a/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomCodeAnalyzer.java +++ b/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomCodeAnalyzer.java @@ -20,16 +20,23 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; +import io.ballerina.scan.ExternalCodeAnalyzer; +import io.ballerina.scan.Rule; import io.ballerina.scan.ScannerContext; +import java.util.List; + /** * Represents a code analyzer for a ballerina module. * * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; + */ +public class CustomCodeAnalyzer extends ExternalCodeAnalyzer { + private ScannerContext scannerContext; + + public CustomCodeAnalyzer() { + // Default constructor for service loading + } public CustomCodeAnalyzer(ScannerContext scannerContext) { this.scannerContext = scannerContext; @@ -39,4 +46,14 @@ public CustomCodeAnalyzer(ScannerContext scannerContext) { public void init(CodeAnalysisContext codeAnalysisContext) { codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); } + + /** + * Returns all Rule instances provided by this analyzer. + * + * @return an iterable of rules provided by this analyzer + */ + @Override + public Iterable getRules() { + return List.of(CustomRule.values()); + } } diff --git a/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomRule.java b/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomRule.java new file mode 100644 index 00000000..48da4a92 --- /dev/null +++ b/test-compiler-plugins/ballerina-plugin/src/main/java/io/ballerina/examplestaticcodeanalyzer/CustomRule.java @@ -0,0 +1,45 @@ +package io.ballerina.examplestaticcodeanalyzer; + +import io.ballerina.scan.Rule; +import io.ballerina.scan.RuleKind; + +import static io.ballerina.scan.RuleKind.BUG; +import static io.ballerina.scan.RuleKind.CODE_SMELL; +import static io.ballerina.scan.RuleKind.VULNERABILITY; + +public enum CustomRule implements Rule { + RULE_1(1, "rule 1", CODE_SMELL), + RULE_2(2, "rule 2", + BUG), + RULE_3(3, "rule 3", VULNERABILITY); + + private final int id; + private final String description; + private final RuleKind kind; + + CustomRule(int id, String description, RuleKind kind) { + this.id = id; + this.description = description; + this.kind = kind; + } + + @Override + public String id() { + return ""; + } + + @Override + public int numericId() { + return id; + } + + @Override + public String description() { + return description; + } + + @Override + public RuleKind kind() { + return kind; + } +} diff --git a/test-compiler-plugins/ballerina-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider b/test-compiler-plugins/ballerina-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider new file mode 100644 index 00000000..8457a39c --- /dev/null +++ b/test-compiler-plugins/ballerina-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider @@ -0,0 +1 @@ +io.ballerina.examplestaticcodeanalyzer.CustomCodeAnalyzer \ No newline at end of file diff --git a/test-compiler-plugins/ballerina-plugin/src/main/resources/rules.json b/test-compiler-plugins/ballerina-plugin/src/main/resources/rules.json deleted file mode 100644 index 98bf00bd..00000000 --- a/test-compiler-plugins/ballerina-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id": 1, - "kind": "CODE_SMELL", - "description": "rule 1" - }, - { - "id": 2, - "kind": "BUG", - "description": "rule 2" - }, - { - "id": 3, - "kind": "VULNERABILITY", - "description": "rule 3" - } -] diff --git a/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomCodeAnalyzer.java b/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomCodeAnalyzer.java index 6c433a2e..2c95530a 100644 --- a/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomCodeAnalyzer.java +++ b/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomCodeAnalyzer.java @@ -20,16 +20,23 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; +import io.ballerina.scan.ExternalCodeAnalyzer; +import io.ballerina.scan.Rule; import io.ballerina.scan.ScannerContext; +import java.util.List; + /** * Represents a code analyzer for a ballerinax module. * * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; + */ +public class CustomCodeAnalyzer extends ExternalCodeAnalyzer { + private ScannerContext scannerContext; + + public CustomCodeAnalyzer() { + // Default constructor for service loading + } public CustomCodeAnalyzer(ScannerContext scannerContext) { this.scannerContext = scannerContext; @@ -39,4 +46,14 @@ public CustomCodeAnalyzer(ScannerContext scannerContext) { public void init(CodeAnalysisContext codeAnalysisContext) { codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); } + + /** + * Returns all Rule instances provided by this analyzer. + * + * @return an iterable of rules provided by this analyzer + */ + @Override + public Iterable getRules() { + return List.of(CustomRule.values()); + } } diff --git a/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomRule.java b/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomRule.java new file mode 100644 index 00000000..44df77dc --- /dev/null +++ b/test-compiler-plugins/ballerinax-plugin/src/main/java/io/ballerinax/examplestaticcodeanalyzer/CustomRule.java @@ -0,0 +1,45 @@ +package io.ballerinax.examplestaticcodeanalyzer; + +import io.ballerina.scan.Rule; +import io.ballerina.scan.RuleKind; + +import static io.ballerina.scan.RuleKind.BUG; +import static io.ballerina.scan.RuleKind.CODE_SMELL; +import static io.ballerina.scan.RuleKind.VULNERABILITY; + +public enum CustomRule implements Rule { + RULE_1(1, "rule 1", CODE_SMELL), + RULE_2(2, "rule 2", + BUG), + RULE_3(3, "rule 3", VULNERABILITY); + + private final int id; + private final String description; + private final RuleKind kind; + + CustomRule(int id, String description, RuleKind kind) { + this.id = id; + this.description = description; + this.kind = kind; + } + + @Override + public String id() { + return ""; + } + + @Override + public int numericId() { + return id; + } + + @Override + public String description() { + return description; + } + + @Override + public RuleKind kind() { + return kind; + } +} diff --git a/test-compiler-plugins/ballerinax-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider b/test-compiler-plugins/ballerinax-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider new file mode 100644 index 00000000..561defae --- /dev/null +++ b/test-compiler-plugins/ballerinax-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider @@ -0,0 +1 @@ +io.ballerinax.examplestaticcodeanalyzer.CustomCodeAnalyzer \ No newline at end of file diff --git a/test-compiler-plugins/ballerinax-plugin/src/main/resources/rules.json b/test-compiler-plugins/ballerinax-plugin/src/main/resources/rules.json deleted file mode 100644 index 98bf00bd..00000000 --- a/test-compiler-plugins/ballerinax-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id": 1, - "kind": "CODE_SMELL", - "description": "rule 1" - }, - { - "id": 2, - "kind": "BUG", - "description": "rule 2" - }, - { - "id": 3, - "kind": "VULNERABILITY", - "description": "rule 3" - } -] diff --git a/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomCodeAnalyzer.java b/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomCodeAnalyzer.java index c70d4ae7..2ebafd64 100644 --- a/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomCodeAnalyzer.java +++ b/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomCodeAnalyzer.java @@ -20,16 +20,23 @@ import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; +import io.ballerina.scan.ExternalCodeAnalyzer; +import io.ballerina.scan.Rule; import io.ballerina.scan.ScannerContext; +import java.util.List; + /** - * Represents a code analyzer for a custom module. + * Represents a code analyzer for a example module. * * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; + */ +public class CustomCodeAnalyzer extends ExternalCodeAnalyzer { + private ScannerContext scannerContext; + + public CustomCodeAnalyzer() { + // Default constructor for service loading + } public CustomCodeAnalyzer(ScannerContext scannerContext) { this.scannerContext = scannerContext; @@ -39,4 +46,14 @@ public CustomCodeAnalyzer(ScannerContext scannerContext) { public void init(CodeAnalysisContext codeAnalysisContext) { codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); } + + /** + * Returns all Rule instances provided by this analyzer. + * + * @return an iterable of rules provided by this analyzer + */ + @Override + public Iterable getRules() { + return List.of(CustomRule.values()); + } } diff --git a/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomRule.java b/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomRule.java new file mode 100644 index 00000000..235938d3 --- /dev/null +++ b/test-compiler-plugins/exampleOrg-plugin/src/main/java/org/example/examplestaticcodeanalyzer/CustomRule.java @@ -0,0 +1,45 @@ +package org.example.examplestaticcodeanalyzer; + +import io.ballerina.scan.Rule; +import io.ballerina.scan.RuleKind; + +import static io.ballerina.scan.RuleKind.BUG; +import static io.ballerina.scan.RuleKind.CODE_SMELL; +import static io.ballerina.scan.RuleKind.VULNERABILITY; + +public enum CustomRule implements Rule { + RULE_1(1, "rule 1", CODE_SMELL), + RULE_2(2, "rule 2", + BUG), + RULE_3(3, "rule 3", VULNERABILITY); + + private final int id; + private final String description; + private final RuleKind kind; + + CustomRule(int id, String description, RuleKind kind) { + this.id = id; + this.description = description; + this.kind = kind; + } + + @Override + public String id() { + return ""; + } + + @Override + public int numericId() { + return id; + } + + @Override + public String description() { + return description; + } + + @Override + public RuleKind kind() { + return kind; + } +} diff --git a/test-compiler-plugins/exampleOrg-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider b/test-compiler-plugins/exampleOrg-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider new file mode 100644 index 00000000..7e34b840 --- /dev/null +++ b/test-compiler-plugins/exampleOrg-plugin/src/main/resources/META-INF/services/io.ballerina.scan.RuleProvider @@ -0,0 +1 @@ +org.example.examplestaticcodeanalyzer.CustomCodeAnalyzer \ No newline at end of file diff --git a/test-compiler-plugins/exampleOrg-plugin/src/main/resources/rules.json b/test-compiler-plugins/exampleOrg-plugin/src/main/resources/rules.json deleted file mode 100644 index 98bf00bd..00000000 --- a/test-compiler-plugins/exampleOrg-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id": 1, - "kind": "CODE_SMELL", - "description": "rule 1" - }, - { - "id": 2, - "kind": "BUG", - "description": "rule 2" - }, - { - "id": 3, - "kind": "VULNERABILITY", - "description": "rule 3" - } -] diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/build.gradle b/test-compiler-plugins/invalid-ruleformat-plugin/build.gradle deleted file mode 100644 index 4a6ed012..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/build.gradle +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2024, 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 -import org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'java-library' - id 'checkstyle' - id "com.github.spotbugs" - id "de.undercouch.download" -} - -group = 'org.invalid.ruleformat' -version = "0.1.0" - -repositories { - mavenLocal() - mavenCentral() - - maven { - url = uri('https://repo.maven.apache.org/maven2/') - } - - maven { - url = 'https://maven.pkg.github.com/ballerina-platform/*' - credentials { - username System.getenv("packageUser") - password System.getenv("packagePAT") - } - } -} - -dependencies { - implementation "com.google.code.gson:gson:${gsonVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'jballerina-tools', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'toml-parser', version: "${ballerinaLangVersion}" - - checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}" - - // Adding dependency to the scan-command module to use interfaces - implementation project(':scan-command') -} - -tasks.withType(JavaExec).configureEach { - systemProperty 'ballerina.home', System.getenv("BALLERINA_HOME") -} - -// Setting up checkstyles -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) - -// Setting up spotbugs -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 - } -} - -spotbugsTest { - 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 - } -} - -// Configurations to automatically build and deploy custom static code analyzer compiler plugin -def packageOrg = "invalid" -def packageName = "invalid_module_ruleformat_static_code_analyzer" -def pluginCentralDirectory = System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io/bala/${packageOrg}" -def pluginLocalDir = System.getProperty("user.home") + "/.ballerina/repositories/local/bala/${packageOrg}" -def balCentralCacheDir = project.file(System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io") - -tasks.register('buildCompilerPlugin') { - doLast { - // Pack and push to local repo of distribution - exec { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', 'cd invalid-module-ruleformat-static-code-analyzer & bal pack & bal push --repository=local' - } else { - commandLine 'sh', '-c', 'cd invalid-module-ruleformat-static-code-analyzer ; bal pack ; bal push --repository=local' - } - } - println("Successfully build and pushed the package ${packageOrg}/${packageName} to the local repository") - - // Remove the cache directories in the central repository - delete { - fileTree(balCentralCacheDir).matching { - include 'cache-*' - } - } - println("Successfully cleaned the .ballerina/cache* directories") - - // Update the central repository - def balDestinationDir = "$pluginCentralDirectory/$packageName" - def balSourceDir = "$pluginLocalDir/$packageName" - if (file(balDestinationDir).exists()) { - file(balDestinationDir).deleteDir() - } - copy { - from balSourceDir - into balDestinationDir - } - println("Successfully copied package ${packageOrg}/${packageName} from local/bala the central.ballerina.io/bala directory") - } -} - -build { - dependsOn buildCompilerPlugin -} diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/.gitignore b/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/.gitignore deleted file mode 100644 index 010e3c58..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml - -## Ballerina maintains the dependencies of the project here. -## Ignored since this is a test resource. -Dependencies.toml diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/Ballerina.toml b/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/Ballerina.toml deleted file mode 100644 index e9b405ce..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/Ballerina.toml +++ /dev/null @@ -1,5 +0,0 @@ -[package] -org = "invalid" -name = "invalid_module_ruleformat_static_code_analyzer" -version = "0.1.0" -distribution = "2201.9.1" diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/CompilerPlugin.toml b/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/CompilerPlugin.toml deleted file mode 100644 index 6f249805..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/CompilerPlugin.toml +++ /dev/null @@ -1,5 +0,0 @@ -[plugin] # Have to check if below path is needed -class = "org.invalid.ruleformat.CustomStaticCodeAnalyzer" - -[[dependency]] -path = "../build/libs/invalid-ruleformat-plugin-0.1.0.jar" diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/README.md b/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/README.md deleted file mode 100644 index 161e4795..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/README.md +++ /dev/null @@ -1 +0,0 @@ -# invalid/invalid_module_ruleformat_static_code_analyzer \ No newline at end of file diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/main.bal b/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/main.bal deleted file mode 100644 index 42249c2b..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/invalid-module-ruleformat-static-code-analyzer/main.bal +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomAnalysisTask.java b/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomAnalysisTask.java deleted file mode 100644 index 2652c917..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomAnalysisTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.ruleformat; - -import io.ballerina.compiler.syntax.tree.ModulePartNode; -import io.ballerina.projects.Document; -import io.ballerina.projects.Module; -import io.ballerina.projects.plugins.AnalysisTask; -import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; -import io.ballerina.scan.Reporter; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a syntax node analysis task for a custom module. - * - * @since 0.1.0 - * */ -public class CustomAnalysisTask implements AnalysisTask { - private final Reporter reporter; - - public CustomAnalysisTask(ScannerContext scannerContext) { - this.reporter = scannerContext.getReporter(); - } - - @Override - public void perform(SyntaxNodeAnalysisContext context) { - Module module = context.currentPackage().module(context.moduleId()); - Document document = module.document(context.documentId()); - ModulePartNode modulePartNode = (ModulePartNode) context.node(); - reporter.reportIssue(document, modulePartNode.location(), 1); - } -} diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomCodeAnalyzer.java b/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomCodeAnalyzer.java deleted file mode 100644 index c1a4a3ae..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomCodeAnalyzer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.ruleformat; - -import io.ballerina.compiler.syntax.tree.SyntaxKind; -import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a code analyzer for a custom module. - * - * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; - - public CustomCodeAnalyzer(ScannerContext scannerContext) { - this.scannerContext = scannerContext; - } - - @Override - public void init(CodeAnalysisContext codeAnalysisContext) { - codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); - } -} diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomStaticCodeAnalyzer.java b/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomStaticCodeAnalyzer.java deleted file mode 100644 index 3f3ed66a..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/java/org/invalid/ruleformat/CustomStaticCodeAnalyzer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.ruleformat; - -import io.ballerina.projects.plugins.CompilerPlugin; -import io.ballerina.projects.plugins.CompilerPluginContext; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a compiler plugin for a custom module. - * - * @since 0.1.0 - * */ -public class CustomStaticCodeAnalyzer extends CompilerPlugin { - @Override - public void init(CompilerPluginContext compilerPluginContext) { - Object context = compilerPluginContext.userData().get("ScannerContext"); - if (context != null) { - ScannerContext scannerContext = (ScannerContext) context; - compilerPluginContext.addCodeAnalyzer(new CustomCodeAnalyzer(scannerContext)); - } - } -} diff --git a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/resources/rules.json b/test-compiler-plugins/invalid-ruleformat-plugin/src/main/resources/rules.json deleted file mode 100644 index 3a17fd25..00000000 --- a/test-compiler-plugins/invalid-ruleformat-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id": 1, - "severity": "CODE_SMELL", - "description": "rule 1" - }, - { - "id": 2, - "severity": "BUG", - "description": "rule 2" - }, - { - "id": 3, - "severity": "VULNERABILITY", - "description": "rule 3" - } -] \ No newline at end of file diff --git a/test-compiler-plugins/invalid-rulekind-plugin/build.gradle b/test-compiler-plugins/invalid-rulekind-plugin/build.gradle deleted file mode 100644 index 3aadc6dc..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/build.gradle +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2024, 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 -import org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'java-library' - id 'checkstyle' - id "com.github.spotbugs" - id "de.undercouch.download" -} - -group = 'org.invalid.rulekind' -version = "0.1.0" - -repositories { - mavenLocal() - mavenCentral() - - maven { - url = uri('https://repo.maven.apache.org/maven2/') - } - - maven { - url = 'https://maven.pkg.github.com/ballerina-platform/*' - credentials { - username System.getenv("packageUser") - password System.getenv("packagePAT") - } - } -} - -dependencies { - implementation "com.google.code.gson:gson:${gsonVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'jballerina-tools', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'toml-parser', version: "${ballerinaLangVersion}" - - checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}" - - // Adding dependency to the scan-command module to use interfaces - implementation project(':scan-command') -} - -tasks.withType(JavaExec).configureEach { - systemProperty 'ballerina.home', System.getenv("BALLERINA_HOME") -} - -// Setting up checkstyles -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) - -// Setting up spotbugs -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 - } -} - -spotbugsTest { - 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 - } -} - -// Configurations to automatically build and deploy custom static code analyzer compiler plugin -def packageOrg = "invalid" -def packageName = "invalid_module_rulekind_static_code_analyzer" -def pluginCentralDirectory = System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io/bala/${packageOrg}" -def pluginLocalDir = System.getProperty("user.home") + "/.ballerina/repositories/local/bala/${packageOrg}" -def balCentralCacheDir = project.file(System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io") - -tasks.register('buildCompilerPlugin') { - doLast { - // Pack and push to local repo of distribution - exec { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', 'cd invalid-module-rulekind-static-code-analyzer & bal pack & bal push --repository=local' - } else { - commandLine 'sh', '-c', 'cd invalid-module-rulekind-static-code-analyzer ; bal pack ; bal push --repository=local' - } - } - println("Successfully build and pushed the package ${packageOrg}/${packageName} to the local repository") - - // Remove the cache directories in the central repository - delete { - fileTree(balCentralCacheDir).matching { - include 'cache-*' - } - } - println("Successfully cleaned the .ballerina/cache* directories") - - // Update the central repository - def balDestinationDir = "$pluginCentralDirectory/$packageName" - def balSourceDir = "$pluginLocalDir/$packageName" - if (file(balDestinationDir).exists()) { - file(balDestinationDir).deleteDir() - } - copy { - from balSourceDir - into balDestinationDir - } - println("Successfully copied package ${packageOrg}/${packageName} from local/bala the central.ballerina.io/bala directory") - } -} - -build { - dependsOn buildCompilerPlugin -} diff --git a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/.gitignore b/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/.gitignore deleted file mode 100644 index 010e3c58..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml - -## Ballerina maintains the dependencies of the project here. -## Ignored since this is a test resource. -Dependencies.toml diff --git a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/Ballerina.toml b/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/Ballerina.toml deleted file mode 100644 index 959f7c36..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/Ballerina.toml +++ /dev/null @@ -1,5 +0,0 @@ -[package] -org = "invalid" -name = "invalid_module_rulekind_static_code_analyzer" -version = "0.1.0" -distribution = "2201.9.1" diff --git a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/CompilerPlugin.toml b/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/CompilerPlugin.toml deleted file mode 100644 index 3c6f0587..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/CompilerPlugin.toml +++ /dev/null @@ -1,5 +0,0 @@ -[plugin] # Have to check if below path is needed -class = "org.invalid.rulekind.CustomStaticCodeAnalyzer" - -[[dependency]] -path = "../build/libs/invalid-rulekind-plugin-0.1.0.jar" diff --git a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/README.md b/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/README.md deleted file mode 100644 index 5d6f5a5f..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/README.md +++ /dev/null @@ -1 +0,0 @@ -# invalid/invalid_module_rulekind_static_code_analyzer \ No newline at end of file diff --git a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/main.bal b/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/main.bal deleted file mode 100644 index 42249c2b..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/invalid-module-rulekind-static-code-analyzer/main.bal +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. diff --git a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomAnalysisTask.java b/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomAnalysisTask.java deleted file mode 100644 index 9a8431e5..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomAnalysisTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rulekind; - -import io.ballerina.compiler.syntax.tree.ModulePartNode; -import io.ballerina.projects.Document; -import io.ballerina.projects.Module; -import io.ballerina.projects.plugins.AnalysisTask; -import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; -import io.ballerina.scan.Reporter; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a syntax node analysis task for a custom module. - * - * @since 0.1.0 - * */ -public class CustomAnalysisTask implements AnalysisTask { - private final Reporter reporter; - - public CustomAnalysisTask(ScannerContext scannerContext) { - this.reporter = scannerContext.getReporter(); - } - - @Override - public void perform(SyntaxNodeAnalysisContext context) { - Module module = context.currentPackage().module(context.moduleId()); - Document document = module.document(context.documentId()); - ModulePartNode modulePartNode = (ModulePartNode) context.node(); - reporter.reportIssue(document, modulePartNode.location(), 1); - } -} diff --git a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomCodeAnalyzer.java b/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomCodeAnalyzer.java deleted file mode 100644 index b506311b..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomCodeAnalyzer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rulekind; - -import io.ballerina.compiler.syntax.tree.SyntaxKind; -import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a code analyzer for a custom module. - * - * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; - - public CustomCodeAnalyzer(ScannerContext scannerContext) { - this.scannerContext = scannerContext; - } - - @Override - public void init(CodeAnalysisContext codeAnalysisContext) { - codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); - } -} diff --git a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomStaticCodeAnalyzer.java b/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomStaticCodeAnalyzer.java deleted file mode 100644 index 77642bee..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/src/main/java/org/invalid/rulekind/CustomStaticCodeAnalyzer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rulekind; - -import io.ballerina.projects.plugins.CompilerPlugin; -import io.ballerina.projects.plugins.CompilerPluginContext; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a compiler plugin for a custom module. - * - * @since 0.1.0 - * */ -public class CustomStaticCodeAnalyzer extends CompilerPlugin { - @Override - public void init(CompilerPluginContext compilerPluginContext) { - Object context = compilerPluginContext.userData().get("ScannerContext"); - if (context != null) { - ScannerContext scannerContext = (ScannerContext) context; - compilerPluginContext.addCodeAnalyzer(new CustomCodeAnalyzer(scannerContext)); - } - } -} diff --git a/test-compiler-plugins/invalid-rulekind-plugin/src/main/resources/rules.json b/test-compiler-plugins/invalid-rulekind-plugin/src/main/resources/rules.json deleted file mode 100644 index 1479c69c..00000000 --- a/test-compiler-plugins/invalid-rulekind-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "id": 1, - "kind": "CODE_SMELL", - "description": "rule 1" - }, - { - "id": 2, - "kind": "BUG", - "description": "rule 2" - }, - { - "id": 3, - "kind": "SECURITY_HOTSPOT", - "description": "rule 3" - } -] diff --git a/test-compiler-plugins/invalid-rules-plugin/build.gradle b/test-compiler-plugins/invalid-rules-plugin/build.gradle deleted file mode 100644 index a8715c9f..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/build.gradle +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2024, 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 -import org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'java-library' - id 'checkstyle' - id "com.github.spotbugs" - id "de.undercouch.download" -} - -group = 'org.invalid.rules' -version = "0.1.0" - -repositories { - mavenLocal() - mavenCentral() - - maven { - url = uri('https://repo.maven.apache.org/maven2/') - } - - maven { - url = 'https://maven.pkg.github.com/ballerina-platform/*' - credentials { - username System.getenv("packageUser") - password System.getenv("packagePAT") - } - } -} - -dependencies { - implementation "com.google.code.gson:gson:${gsonVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'jballerina-tools', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}" - implementation group: 'org.ballerinalang', name: 'toml-parser', version: "${ballerinaLangVersion}" - - checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}" - - // Adding dependency to the scan-command module to use interfaces - implementation project(':scan-command') -} - -tasks.withType(JavaExec).configureEach { - systemProperty 'ballerina.home', System.getenv("BALLERINA_HOME") -} - -// Setting up checkstyles -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) - -// Setting up spotbugs -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 - } -} - -spotbugsTest { - 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 - } -} - -// Configurations to automatically build and deploy custom static code analyzer compiler plugin -def packageOrg = "invalid" -def packageName = "invalid_module_rules_static_code_analyzer" -def pluginCentralDirectory = System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io/bala/${packageOrg}" -def pluginLocalDir = System.getProperty("user.home") + "/.ballerina/repositories/local/bala/${packageOrg}" -def balCentralCacheDir = project.file(System.getProperty("user.home") + "/.ballerina/repositories/central.ballerina.io") - -tasks.register('buildCompilerPlugin') { - doLast { - // Pack and push to local repo of distribution - exec { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', 'cd invalid-module-rules-static-code-analyzer & bal pack & bal push --repository=local' - } else { - commandLine 'sh', '-c', 'cd invalid-module-rules-static-code-analyzer ; bal pack ; bal push --repository=local' - } - } - println("Successfully build and pushed the package ${packageOrg}/${packageName} to the local repository") - - // Remove the cache directories in the central repository - delete { - fileTree(balCentralCacheDir).matching { - include 'cache-*' - } - } - println("Successfully cleaned the .ballerina/cache* directories") - - // Update the central repository - def balDestinationDir = "$pluginCentralDirectory/$packageName" - def balSourceDir = "$pluginLocalDir/$packageName" - if (file(balDestinationDir).exists()) { - file(balDestinationDir).deleteDir() - } - copy { - from balSourceDir - into balDestinationDir - } - println("Successfully copied package ${packageOrg}/${packageName} from local/bala the central.ballerina.io/bala directory") - } -} - -build { - dependsOn buildCompilerPlugin -} diff --git a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/.gitignore b/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/.gitignore deleted file mode 100644 index 010e3c58..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml - -## Ballerina maintains the dependencies of the project here. -## Ignored since this is a test resource. -Dependencies.toml diff --git a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/Ballerina.toml b/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/Ballerina.toml deleted file mode 100644 index deab2687..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/Ballerina.toml +++ /dev/null @@ -1,5 +0,0 @@ -[package] -org = "invalid" -name = "invalid_module_rules_static_code_analyzer" -version = "0.1.0" -distribution = "2201.9.1" diff --git a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/CompilerPlugin.toml b/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/CompilerPlugin.toml deleted file mode 100644 index 57174cdf..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/CompilerPlugin.toml +++ /dev/null @@ -1,5 +0,0 @@ -[plugin] # Have to check if below path is needed -class = "org.invalid.rules.CustomStaticCodeAnalyzer" - -[[dependency]] -path = "../build/libs/invalid-rules-plugin-0.1.0.jar" diff --git a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/README.md b/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/README.md deleted file mode 100644 index 13592aaf..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/README.md +++ /dev/null @@ -1 +0,0 @@ -# invalid/invalid_module_rules_static_code_analyzer \ No newline at end of file diff --git a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/main.bal b/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/main.bal deleted file mode 100644 index 42249c2b..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/invalid-module-rules-static-code-analyzer/main.bal +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 Inc. 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. diff --git a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomAnalysisTask.java b/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomAnalysisTask.java deleted file mode 100644 index c555e0e1..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomAnalysisTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rules; - -import io.ballerina.compiler.syntax.tree.ModulePartNode; -import io.ballerina.projects.Document; -import io.ballerina.projects.Module; -import io.ballerina.projects.plugins.AnalysisTask; -import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; -import io.ballerina.scan.Reporter; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a syntax node analysis task for a custom module. - * - * @since 0.1.0 - * */ -public class CustomAnalysisTask implements AnalysisTask { - private final Reporter reporter; - - public CustomAnalysisTask(ScannerContext scannerContext) { - this.reporter = scannerContext.getReporter(); - } - - @Override - public void perform(SyntaxNodeAnalysisContext context) { - Module module = context.currentPackage().module(context.moduleId()); - Document document = module.document(context.documentId()); - ModulePartNode modulePartNode = (ModulePartNode) context.node(); - reporter.reportIssue(document, modulePartNode.location(), 1); - } -} diff --git a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomCodeAnalyzer.java b/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomCodeAnalyzer.java deleted file mode 100644 index 471674e4..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomCodeAnalyzer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rules; - -import io.ballerina.compiler.syntax.tree.SyntaxKind; -import io.ballerina.projects.plugins.CodeAnalysisContext; -import io.ballerina.projects.plugins.CodeAnalyzer; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a code analyzer for a custom module. - * - * @since 0.1.0 - * */ -public class CustomCodeAnalyzer extends CodeAnalyzer { - private final ScannerContext scannerContext; - - public CustomCodeAnalyzer(ScannerContext scannerContext) { - this.scannerContext = scannerContext; - } - - @Override - public void init(CodeAnalysisContext codeAnalysisContext) { - codeAnalysisContext.addSyntaxNodeAnalysisTask(new CustomAnalysisTask(scannerContext), SyntaxKind.MODULE_PART); - } -} diff --git a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomStaticCodeAnalyzer.java b/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomStaticCodeAnalyzer.java deleted file mode 100644 index 7ea9d7a2..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/src/main/java/org/invalid/rules/CustomStaticCodeAnalyzer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2024, 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 org.invalid.rules; - -import io.ballerina.projects.plugins.CompilerPlugin; -import io.ballerina.projects.plugins.CompilerPluginContext; -import io.ballerina.scan.ScannerContext; - -/** - * Represents a compiler plugin for a custom module. - * - * @since 0.1.0 - * */ -public class CustomStaticCodeAnalyzer extends CompilerPlugin { - @Override - public void init(CompilerPluginContext compilerPluginContext) { - Object context = compilerPluginContext.userData().get("ScannerContext"); - if (context != null) { - ScannerContext scannerContext = (ScannerContext) context; - compilerPluginContext.addCodeAnalyzer(new CustomCodeAnalyzer(scannerContext)); - } - } -} diff --git a/test-compiler-plugins/invalid-rules-plugin/src/main/resources/rules.json b/test-compiler-plugins/invalid-rules-plugin/src/main/resources/rules.json deleted file mode 100644 index b1c10a54..00000000 --- a/test-compiler-plugins/invalid-rules-plugin/src/main/resources/rules.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": 1, - "kind": "CODE_SMELL", - "description": "rule 1" -} \ No newline at end of file