Skip to content

Commit

Permalink
Update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Dec 18, 2024
1 parent a1022a2 commit df4837a
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 109 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
113 changes: 82 additions & 31 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions build-config/resources/CompilerPlugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[plugin]
class = "io.ballerina.stdlib.mi.plugin.MICompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/[email protected]@.jar"

[[dependency]]
path = "build/antlr4-runtime-4.5.1-1.jar"

[[dependency]]
path = "build/handlebars-4.0.6.jar"
23 changes: 19 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}'
Expand All @@ -72,4 +86,5 @@ release {

task build {
dependsOn ":mi-ballerina:build"
dependsOn ":mi-tests:test"
}
3 changes: 2 additions & 1 deletion compiler-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ plugins {
id 'java'
}

description = 'Ballerina - Module WSO2 MI Compiler Plugin'

group = project.group
version = project.version

Expand All @@ -39,7 +41,6 @@ dependencies {
implementation group: 'org.ow2.asm', name: 'asm', version: "${asmVersion}"
}


jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from('src/main/resources') {
Expand Down
22 changes: 20 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
37 changes: 1 addition & 36 deletions tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'java'
id "de.undercouch.download" version "5.4.0"
}

group = project.group
Expand All @@ -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")
30 changes: 18 additions & 12 deletions tests/src/test/java/org/ballerina/test/ModuleCompilationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,23 +39,21 @@
*/
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);
}

@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);
Expand All @@ -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()
Expand Down Expand Up @@ -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();
}
}
Loading

0 comments on commit df4837a

Please sign in to comment.