diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 633eb80..996ad99 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -40,8 +40,7 @@ jobs: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} run: | - ./gradlew clean -x test -x check :mi-ballerina:localPublish - ./gradlew build + ./gradlew clean build - name: Generate Codecov Report uses: codecov/codecov-action@v3 diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 720b5b1..e8e5114 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -18,61 +18,112 @@ import org.apache.tools.ant.taskdefs.condition.Os +buildscript { + repositories { + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/plugin-gradle' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } + dependencies { + classpath "io.ballerina:plugin-gradle:${project.ballerinaGradlePluginVersion}" + } +} + plugins { - id 'java' id "de.undercouch.download" version "5.4.0" } -group = project.group -version = project.version +description = 'Ballerina - Module WSO2 MI' + +def packageName = "mi" +def packageOrg = "wso2" -repositories { - mavenCentral() +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") +def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") +def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") +def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-'); + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } } -dependencies { +apply plugin: 'io.ballerina.plugin' + +ballerina { + testCoverageParam = "--code-coverage --coverage-format=xml" + packageOrganization = packageOrg + module = packageName + langVersion = ballerinaLangVersion } -build { - dependsOn(":mi-compiler-plugin:jar") - dependsOn("downloadDependencies") +task updateTomlFiles { + doLast { + def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@toml.version@", tomlVersion) + ballerinaTomlFile.text = newBallerinaToml + + def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version) + compilerPluginTomlFile.text = newCompilerPluginToml + } } -task localPublish { - dependsOn(":mi-compiler-plugin:jar") - dependsOn("downloadDependencies") +task commitTomlFiles { doLast { - // Push the MI Tools package to the local repository - exec { + project.exec { + ignoreExitValue true if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', "/c", "bal pack && bal push --repository=local" + commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the toml files\" Ballerina.toml Dependencies.toml CompilerPlugin.toml " } else { - commandLine 'sh', "-c", "bal pack && bal push --repository=local" + commandLine 'sh', '-c', "git commit -m '[Automated] Update the toml files' Ballerina.toml Dependencies.toml CompilerPlugin.toml" } } - println("Successfully pushed the MI Package to the local.") } } -task release { - dependsOn("publishBallerinaPackage") -} - -task publishBallerinaPackage { - dependsOn(":mi-compiler-plugin:jar") - dependsOn("downloadDependencies") - doLast { - exec { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', "/c", "bal pack && bal push" - } else { - commandLine 'sh', "-c", "bal pack && bal push" +publishing { + publications { + maven(MavenPublication) { + artifact source: createArtifactZip, extension: 'zip' + } + } + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-${packageOrg}-${packageName}") + credentials { + username = System.getenv("publishUser") + password = System.getenv("publishPAT") } } - println("Successfully pushed the MI Library package to the local.") } } +clean { + delete 'build' +} + +updateTomlFiles.dependsOn copyStdlibs +build.dependsOn "generatePomFileForMavenPublication" +build.dependsOn ":${packageName}-compiler-plugin:build" +build.dependsOn "downloadDependencies" + +publishToMavenLocal.dependsOn build +publish.dependsOn build + task downloadDependencies(type: Download) { src([ 'https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.1-1/antlr4-runtime-4.5.1-1.jar', diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index e69de29..2e3ef60 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -0,0 +1,11 @@ +[package] +org = "wso2" +name = "mi" +version = "@toml.version@" +authors = ["Ballerina"] +keywords = ["wso2-mi"] +repository = "https://github.com/wso2-extensions/ballerina-module-wso2-mi.git" +license = ["Apache-2.0"] +distribution = "2201.9.2" +export = ["mi"] +readme = "Package.md" diff --git a/build-config/resources/CompilerPlugin.toml b/build-config/resources/CompilerPlugin.toml new file mode 100644 index 0000000..ad9493f --- /dev/null +++ b/build-config/resources/CompilerPlugin.toml @@ -0,0 +1,11 @@ +[plugin] +class = "io.ballerina.stdlib.mi.plugin.MICompilerPlugin" + +[[dependency]] +path = "../compiler-plugin/build/libs/mi-compiler-plugin-@project.version@.jar" + +[[dependency]] +path = "build/antlr4-runtime-4.5.1-1.jar" + +[[dependency]] +path = "build/handlebars-4.0.6.jar" diff --git a/build.gradle b/build.gradle index 385b65a..c9c73ef 100644 --- a/build.gradle +++ b/build.gradle @@ -17,10 +17,7 @@ */ plugins { - id "com.github.spotbugs-base" version "${spotbugsPluginVersion}" - id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}" - id "de.undercouch.download" version "${downloadPluginVersion}" - id "net.researchgate.release" version "${releasePluginVersion}" + id 'net.researchgate.release' } allprojects { @@ -58,9 +55,26 @@ allprojects { } } + +subprojects { + + configurations { + jbalTools + ballerinaStdLibs + } + + dependencies { + jbalTools ("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") { + transitive = false + } + } +} + + def moduleVersion = project.version.replace("-SNAPSHOT", "") release { + buildTasks = ['build'] failOnSnapshotDependencies = true versionPropertyFile = 'gradle.properties' tagTemplate = 'v${version}' @@ -72,4 +86,5 @@ release { task build { dependsOn ":mi-ballerina:build" + dependsOn ":mi-tests:test" } diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle index 64832cc..820e1ca 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -20,6 +20,8 @@ plugins { id 'java' } +description = 'Ballerina - Module WSO2 MI Compiler Plugin' + group = project.group version = project.version @@ -39,7 +41,6 @@ dependencies { implementation group: 'org.ow2.asm', name: 'asm', version: "${asmVersion}" } - jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE from('src/main/resources') { diff --git a/settings.gradle b/settings.gradle index 5f6f3a7..00fc489 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,16 +7,34 @@ * in the user manual at https://docs.gradle.org/6.3/userguide/multi_project_builds.html */ +pluginManagement { + plugins { + id "net.researchgate.release" version "${releasePluginVersion}" + id "io.ballerina.plugin" version "${ballerinaGradlePluginVersion}" + } + + repositories { + gradlePluginPortal() + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/*' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } +} + plugins { id "com.gradle.enterprise" version "3.2" } -rootProject.name = 'module-ballerinax-wso2.mi' +rootProject.name = 'ballerina-module-wso2-mi' include(':checkstyle') include(':mi-ballerina') include(':mi-compiler-plugin') -include('mi-tests') +include(':mi-tests') project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") project(':mi-ballerina').projectDir = file('ballerina') diff --git a/tests/build.gradle b/tests/build.gradle index 372aefa..d9531af 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -1,6 +1,5 @@ plugins { id 'java' - id "de.undercouch.download" version "5.4.0" } group = project.group @@ -21,44 +20,10 @@ dependencies { testImplementation 'org.testng:testng:7.7.0' } -def projects = ['project1'] - test { - systemProperty "ballerina.home", "build/ballerina/ballerina-${ballerinaLangVersion}-swan-lake/" + - "distributions/ballerina-${ballerinaLangVersion}" useTestNG() { suites 'src/test/resources/testng.xml' } - dependencies { - implementation fileTree(dir: 'src/test/resources/libs', include: '*.jar') - } -} - -task downloadBallerina(type: Download) { - src([ - "https://dist.ballerina.io/downloads/${ballerinaLangVersion}/" + - "ballerina-${ballerinaLangVersion}-swan-lake.zip" - ]) - dest file("build") - overwrite false -} - -task unzipFile(type: Copy) { - dependsOn("downloadBallerina") - from(zipTree("build/ballerina-${ballerinaLangVersion}-swan-lake.zip")) - into("build/ballerina") -} - - -test.dependsOn(":mi-ballerina:localPublish") -test.dependsOn("unzipFile") - -task deleteFiles(type: Delete) { - doLast { - projects.each { project -> - delete("src/test/resources/ballerina/${project}/target") - } - } } -clean.dependsOn("deleteFiles") +test.dependsOn(":mi-ballerina:build") diff --git a/tests/src/test/java/org/ballerina/test/ModuleCompilationTests.java b/tests/src/test/java/org/ballerina/test/ModuleCompilationTests.java index a51fe06..dcad62e 100644 --- a/tests/src/test/java/org/ballerina/test/ModuleCompilationTests.java +++ b/tests/src/test/java/org/ballerina/test/ModuleCompilationTests.java @@ -18,9 +18,11 @@ import io.ballerina.projects.DiagnosticResult; import io.ballerina.projects.PackageCompilation; -import io.ballerina.projects.Project; import io.ballerina.projects.Package; -import io.ballerina.projects.directory.ProjectLoader; +import io.ballerina.projects.ProjectEnvironmentBuilder; +import io.ballerina.projects.directory.BuildProject; +import io.ballerina.projects.environment.Environment; +import io.ballerina.projects.environment.EnvironmentBuilder; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.text.LinePosition; @@ -37,13 +39,13 @@ */ public class ModuleCompilationTests { - public static final Path RES_DIR = Paths.get("src/test/resources/ballerina").toAbsolutePath(); + public static final Path RESOURCE_DIRECTORY = Paths.get("src/test/resources/ballerina").toAbsolutePath(); + private static final Path DISTRIBUTION_PATH = Paths.get("../", "target", "ballerina-runtime") + .toAbsolutePath(); @Test public void testProjectCompilation() { - Path path = RES_DIR.resolve("project1"); - Project project = ProjectLoader.loadProject(path); - Package pkg = project.currentPackage(); + Package pkg = loadPackage("project1"); PackageCompilation packageCompilation = pkg.getCompilation(); DiagnosticResult diagnosticResult = packageCompilation.diagnosticResult(); Assert.assertEquals(diagnosticResult.diagnosticCount(), 0); @@ -51,9 +53,7 @@ public void testProjectCompilation() { @Test public void testUnsupportedParamAndReturnType() { - Path path = RES_DIR.resolve("project2"); - Project project = ProjectLoader.loadProject(path); - Package pkg = project.currentPackage(); + Package pkg = loadPackage("project2"); PackageCompilation packageCompilation = pkg.getCompilation(); DiagnosticResult diagnosticResult = packageCompilation.diagnosticResult(); Assert.assertEquals(diagnosticResult.diagnosticCount(), 2); @@ -64,9 +64,7 @@ public void testUnsupportedParamAndReturnType() { @Test public void testErrorsOnServiceDefinition() { - Path path = RES_DIR.resolve("project3"); - Project project = ProjectLoader.loadProject(path); - Package pkg = project.currentPackage(); + Package pkg = loadPackage("project3"); PackageCompilation packageCompilation = pkg.getCompilation(); DiagnosticResult diagnosticResult = packageCompilation.diagnosticResult(); Diagnostic[] errorDiagnosticsList = diagnosticResult.diagnostics().stream() @@ -106,4 +104,12 @@ private void validateError(Diagnostic[] diagnostics, int errorIndex, String expe Assert.assertEquals(linePosition.line() + 1, expectedErrLine); Assert.assertEquals(linePosition.offset() + 1, expectedErrCol); } + + static Package loadPackage(String path) { + Path projectDirPath = RESOURCE_DIRECTORY.resolve(path); + Environment environment = EnvironmentBuilder.getBuilder().setBallerinaHome(DISTRIBUTION_PATH).build(); + ProjectEnvironmentBuilder projectEnvironmentBuilder = ProjectEnvironmentBuilder.getBuilder(environment); + BuildProject project = BuildProject.load(projectEnvironmentBuilder, projectDirPath); + return project.currentPackage(); + } } diff --git a/tests/src/test/resources/ballerina/project1/Ballerina.toml b/tests/src/test/resources/ballerina/project1/Ballerina.toml index d53eb5a..2159dd8 100644 --- a/tests/src/test/resources/ballerina/project1/Ballerina.toml +++ b/tests/src/test/resources/ballerina/project1/Ballerina.toml @@ -6,9 +6,3 @@ distribution = "2201.9.2" [build-options] observabilityIncluded = true - -[[dependency]] -org = "ballerinax" -name = "mi" -version = "0.1.3" -repository = "local" diff --git a/tests/src/test/resources/ballerina/project1/main.bal b/tests/src/test/resources/ballerina/project1/main.bal index 20bff61..dcb7448 100644 --- a/tests/src/test/resources/ballerina/project1/main.bal +++ b/tests/src/test/resources/ballerina/project1/main.bal @@ -1,4 +1,4 @@ -import ballerinax/mi; +import wso2/mi; @mi:ConnectorInfo { } diff --git a/tests/src/test/resources/ballerina/project2/Ballerina.toml b/tests/src/test/resources/ballerina/project2/Ballerina.toml index 5b5f8f8..bca2297 100644 --- a/tests/src/test/resources/ballerina/project2/Ballerina.toml +++ b/tests/src/test/resources/ballerina/project2/Ballerina.toml @@ -6,9 +6,3 @@ distribution = "2201.9.2" [build-options] observabilityIncluded = true - -[[dependency]] -org = "ballerinax" -name = "mi" -version = "0.1.3" -repository = "local" diff --git a/tests/src/test/resources/ballerina/project2/main.bal b/tests/src/test/resources/ballerina/project2/main.bal index 849486d..2ac2c98 100644 --- a/tests/src/test/resources/ballerina/project2/main.bal +++ b/tests/src/test/resources/ballerina/project2/main.bal @@ -1,4 +1,4 @@ -import ballerinax/mi; +import wso2/mi; @mi:ConnectorInfo { } diff --git a/tests/src/test/resources/ballerina/project3/Ballerina.toml b/tests/src/test/resources/ballerina/project3/Ballerina.toml index f88a33e..b408727 100644 --- a/tests/src/test/resources/ballerina/project3/Ballerina.toml +++ b/tests/src/test/resources/ballerina/project3/Ballerina.toml @@ -6,9 +6,3 @@ distribution = "2201.9.2" [build-options] observabilityIncluded = true - -[[dependency]] -org = "ballerinax" -name = "mi" -version = "0.1.3" -repository = "local" diff --git a/tests/src/test/resources/ballerina/project3/main.bal b/tests/src/test/resources/ballerina/project3/main.bal index a7b3851..4c853b7 100644 --- a/tests/src/test/resources/ballerina/project3/main.bal +++ b/tests/src/test/resources/ballerina/project3/main.bal @@ -17,7 +17,7 @@ import ballerina/graphql; import ballerina/http; import ballerina/lang.runtime; -import ballerinax/mi; +import wso2/mi; service / on new http:Listener(9090) { resource function get greeting() returns string { diff --git a/tests/src/test/resources/testng.xml b/tests/src/test/resources/testng.xml index e5a171c..f9d8dec 100644 --- a/tests/src/test/resources/testng.xml +++ b/tests/src/test/resources/testng.xml @@ -20,6 +20,7 @@ +