Skip to content

Commit 724ff71

Browse files
authored
Merge pull request #1358 from ballerina-platform/revert-1357-revert-scan-tool
Revert "Revert static rule change"
2 parents cd105ce + 36bc790 commit 724ff71

File tree

25 files changed

+1096
-2
lines changed

25 files changed

+1096
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ velocity.log*
4747
examples/**/Dependencies.toml
4848
load-tests/**/Dependencies.toml
4949
ballerina/Dependencies 2.toml
50+
51+
compiler-plugin-tests/**/target

ballerina/CompilerPlugin.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[plugin]
2+
id = "io-compiler-plugin"
3+
class = "io.ballerina.stdlib.io.compiler.IOCompilerPlugin"
4+
5+
[[dependency]]
6+
path = "../compiler-plugin/build/libs/io-compiler-plugin-1.8.0-SNAPSHOT.jar"

ballerina/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,32 @@
1717

1818
import org.apache.tools.ant.taskdefs.condition.Os
1919

20-
plugins {
21-
id 'io.ballerina.plugin'
20+
buildscript {
21+
repositories {
22+
maven {
23+
url = 'https://maven.pkg.github.com/ballerina-platform/plugin-gradle'
24+
credentials {
25+
username System.getenv("packageUser")
26+
password System.getenv("packagePAT")
27+
}
28+
}
29+
}
30+
dependencies {
31+
classpath "io.ballerina:plugin-gradle:${project.ballerinaGradlePluginVersion}"
32+
}
2233
}
2334

35+
apply plugin: 'io.ballerina.plugin'
36+
2437
description = 'Ballerina - I/O Ballerina Generator'
2538

2639
def packageName = "io"
2740
def packageOrg = "ballerina"
2841
def tomlVersion = stripBallerinaExtensionVersion("${project.version}")
2942
def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml")
3043
def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml")
44+
def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml")
45+
def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml")
3146

3247
def stripBallerinaExtensionVersion(String extVersion) {
3348
if (extVersion.matches(project.ext.timestampedVersionRegex)) {
@@ -52,8 +67,10 @@ ballerina {
5267
task updateTomlFiles {
5368
doLast {
5469
def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version)
70+
def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version)
5571
newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion)
5672
ballerinaTomlFile.text = newBallerinaToml
73+
compilerPluginTomlFile.text = newCompilerPluginToml
5774
}
5875
}
5976

@@ -94,6 +111,8 @@ updateTomlFiles.dependsOn unpackJballerinaTools
94111
test.dependsOn ":${packageName}-native:build"
95112
test.dependsOn ":${packageName}-native:test"
96113
test.dependsOn ":${packageName}-test-utils:build"
114+
test.dependsOn ":${packageName}-compiler-plugin:build"
115+
build.dependsOn ":${packageName}-compiler-plugin:build"
97116
build.dependsOn "generatePomFileForMavenPublication"
98117
build.dependsOn ":${packageName}-native:build"
99118
build.dependsOn ":${packageName}-native:test"

build-config/resources/Ballerina.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ artifactId = "io-native"
1818
path = "../native/build/libs/io-native-@project.version@.jar"
1919
version = "@toml.version@"
2020

21+
[[platform.java21.dependency]]
22+
groupId = "io.ballerina.stdlib"
23+
artifactId = "io-compiler-plugin"
24+
version = "@toml.version@"
25+
path = "../compiler-plugin/build/libs/io-compiler-plugin-@project.version@.jar"
2126

2227
[[platform.java21.dependency]]
2328
path = "../test-utils/build/libs/io-test-utils-@project.version@.jar"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[plugin]
2+
id = "io-compiler-plugin"
3+
class = "io.ballerina.stdlib.io.compiler.IOCompilerPlugin"
4+
5+
[[dependency]]
6+
path = "../compiler-plugin/build/libs/io-compiler-plugin-@project.version@.jar"

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This file contains all the notable changes done to the Ballerina I/O package thr
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66
## [Unreleased]
7+
### Added
8+
- [Add static code rules](https://github.com/ballerina-platform/ballerina-library/issues/7283)
9+
710
### Fixed
811
- [The CSV file read as a record failed when a nillable field was empty](https://github.com/ballerina-platform/ballerina-library/issues/7433)
912

compiler-plugin-tests/build.gradle

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org)
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
plugins {
20+
id 'java'
21+
id 'checkstyle'
22+
id 'com.github.spotbugs'
23+
id 'jacoco'
24+
}
25+
26+
description = 'Ballerina - IO Compiler Plugin Tests'
27+
28+
jacoco {
29+
toolVersion = "${jacocoVersion}"
30+
reportsDirectory = file("$project.buildDir/reports/jacoco")
31+
}
32+
33+
jacocoTestReport {
34+
reports {
35+
xml.required = true
36+
csv.required = false
37+
html.required = false
38+
}
39+
sourceSets project(':io-compiler-plugin').sourceSets.main
40+
}
41+
42+
dependencies {
43+
checkstyle project(':checkstyle')
44+
checkstyle "com.puppycrawl.tools:checkstyle:${checkstylePluginVersion}"
45+
46+
implementation project(':io-compiler-plugin')
47+
48+
testImplementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}"
49+
testImplementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}"
50+
testImplementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}"
51+
52+
testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
53+
}
54+
tasks.withType(JavaCompile) {
55+
options.encoding = 'UTF-8'
56+
}
57+
58+
sourceCompatibility = JavaVersion.VERSION_21
59+
60+
test {
61+
systemProperty "ballerina.offline.flag", "true"
62+
useTestNG() {
63+
suites 'src/test/resources/testng.xml'
64+
}
65+
testLogging.showStandardStreams = true
66+
testLogging {
67+
events "PASSED", "FAILED", "SKIPPED"
68+
afterSuite { desc, result ->
69+
if (!desc.parent) { // will match the outermost suite
70+
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
71+
def startItem = '| ', endItem = ' |'
72+
def repeatLength = startItem.length() + output.length() + endItem.length()
73+
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
74+
}
75+
}
76+
}
77+
finalizedBy jacocoTestReport
78+
}
79+
80+
jacocoTestReport {
81+
dependsOn test
82+
reports {
83+
xml.required = true
84+
}
85+
sourceSets project(':io-compiler-plugin').sourceSets.main
86+
}
87+
88+
spotbugsTest {
89+
def classLoader = plugins["com.github.spotbugs"].class.classLoader
90+
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
91+
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
92+
ignoreFailures = true
93+
effort = SpotBugsEffort.MAX
94+
reportLevel = SpotBugsConfidence.LOW
95+
reportsDir = file("$project.buildDir/reports/spotbugs")
96+
def excludeFile = file("${rootDir}/build-config/spotbugs-exclude.xml")
97+
if (excludeFile.exists()) {
98+
it.excludeFilter = excludeFile
99+
}
100+
reports {
101+
text.enabled = true
102+
}
103+
}
104+
105+
spotbugsMain {
106+
enabled false
107+
}
108+
109+
task validateSpotbugs() {
110+
doLast {
111+
if (spotbugsMain.reports.size() > 0 &&
112+
spotbugsMain.reports[0].destination.exists() &&
113+
spotbugsMain.reports[0].destination.text.readLines().size() > 0) {
114+
spotbugsMain.reports[0].destination?.eachLine {
115+
println 'Failure: ' + it
116+
}
117+
throw new GradleException("Spotbugs rule violations were found.");
118+
}
119+
}
120+
}
121+
122+
tasks.withType(Checkstyle) {
123+
exclude '**/module-info.java'
124+
}
125+
126+
checkstyle {
127+
toolVersion "${project.checkstylePluginVersion}"
128+
configFile rootProject.file("build-config/checkstyle/build/checkstyle.xml")
129+
configProperties = ["suppressionFile": file("${rootDir}/build-config/checkstyle/build/suppressions.xml")]
130+
}
131+
132+
checkstyleMain {
133+
enabled false
134+
}
135+
136+
spotbugsTest.finalizedBy validateSpotbugs
137+
checkstyleTest.dependsOn ':checkstyle:downloadCheckstyleRuleFiles'
138+
139+
compileJava {
140+
doFirst {
141+
options.compilerArgs = [
142+
'--module-path', classpath.asPath,
143+
]
144+
classpath = files()
145+
}
146+
}
147+
148+
test.dependsOn ":io-ballerina:build"
149+
build.dependsOn ":io-ballerina:build"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org)
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package io.ballerina.stdlib.io.compiler.staticcodeanalyzer;
20+
21+
import java.io.BufferedReader;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.InputStreamReader;
25+
import java.nio.charset.StandardCharsets;
26+
27+
/**
28+
* Helper class to consume the process streams.
29+
*/
30+
class ProcessOutputGobbler implements Runnable {
31+
private final InputStream inputStream;
32+
private final StringBuilder output;
33+
private int exitCode;
34+
35+
public ProcessOutputGobbler(InputStream inputStream) {
36+
this.inputStream = inputStream;
37+
this.output = new StringBuilder();
38+
}
39+
40+
@Override
41+
public void run() {
42+
try (BufferedReader reader = new BufferedReader(
43+
new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
44+
String line;
45+
while ((line = reader.readLine()) != null) {
46+
output.append(line).append("\n");
47+
}
48+
} catch (IOException e) {
49+
this.output.append(e.getMessage());
50+
}
51+
}
52+
53+
public String getOutput() {
54+
return output.toString();
55+
}
56+
57+
public int getExitCode() {
58+
return exitCode;
59+
}
60+
61+
public void setExitCode(int exitCode) {
62+
this.exitCode = exitCode;
63+
}
64+
}

0 commit comments

Comments
 (0)