|
| 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" |
0 commit comments