Skip to content

Commit

Permalink
Merge pull request #77 from MohamedSabthar/main
Browse files Browse the repository at this point in the history
Extends the plugin to check for breaking changes with docker image
  • Loading branch information
niveathika authored Jun 20, 2022
2 parents 39e190f + f10fcb5 commit b32ce02
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 60 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=io.ballerina
version=0.14.4-SNAPSHOT
version=0.15.0-SNAPSHOT
159 changes: 100 additions & 59 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,7 @@ class BallerinaPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.extensions.create('ballerina', BallerinaExtension)

project.configurations {
jbalTools
}

project.dependencies {
if (project.extensions.ballerina.langVersion == null) {
jbalTools("org.ballerinalang:jballerina-tools:${project.ballerinaLangVersion}") {
transitive = false
}
} else {
jbalTools("org.ballerinalang:jballerina-tools:${project.extensions.ballerina.langVersion}") {
transitive = false
}
}
}


def packageOrg = ''
def platform = 'java11'
def tomlVersion
Expand All @@ -75,6 +59,12 @@ class BallerinaPlugin implements Plugin<Project> {
def needPublishToCentral = false
def needPublishToLocalCentral = false
def skipTests = true
def checkForBreakingChanges = project.hasProperty('buildUsingDocker')
def ballerinaDockerTag = project.findProperty('buildUsingDocker')
if (ballerinaDockerTag == '') {
ballerinaDockerTag = 'nightly'
}


if (project.version.matches(project.ext.timestampedVersionRegex)) {
def splitVersion = project.version.split('-')
Expand All @@ -88,79 +78,112 @@ class BallerinaPlugin implements Plugin<Project> {
tomlVersion = project.version.replace("${project.ext.snapshotVersion}", '')
}

project.configurations {
jbalTools
}

project.tasks.register('copyToLib', Copy.class) {
into "$project.projectDir/lib"
from project.configurations.externalJars
}

project.dependencies {
if (checkForBreakingChanges) {
println("WARNING! jbalTools dependency skiped; project uses docker to build the module")
} else {
if (project.extensions.ballerina.langVersion == null) {
jbalTools("org.ballerinalang:jballerina-tools:${project.ballerinaLangVersion}") {
transitive = false
}
} else {
jbalTools("org.ballerinalang:jballerina-tools:${project.extensions.ballerina.langVersion}") {
transitive = false
}
}
}
}

project.tasks.register('unpackJballerinaTools') {
project.configurations.each { configuration ->
if (configuration.name == "externalJars") {
dependsOn(project.copyToLib)
}
}
doLast {
project.configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact ->
project.copy {
from project.zipTree(artifact.getFile())
into new File("${project.buildDir}/")
}

project.copy {
from(project.zipTree(artifact.getFile())) {
eachFile { fcd ->
fcd.relativePath = new RelativePath(!fcd.file.isDirectory(), fcd.relativePath.segments.drop(1))
if (checkForBreakingChanges) {
println("WARNING! task unpackJballerinaTools skiped; project uses docker to build the module")
} else {
doLast {
project.configurations.jbalTools.resolvedConfiguration.resolvedArtifacts.each { artifact ->
project.copy {
from project.zipTree(artifact.getFile())
into new File("${project.buildDir}/")
}

project.copy {
from(project.zipTree(artifact.getFile())) {
eachFile { fcd ->
fcd.relativePath = new RelativePath(!fcd.file.isDirectory(), fcd.relativePath.segments.drop(1))
}
includeEmptyDirs = false
}
includeEmptyDirs = false
into "${project.rootDir}/target/ballerina-runtime"
}
into "${project.rootDir}/target/ballerina-runtime"
}
}
}
}

project.tasks.register('unpackStdLibs') {
dependsOn(project.unpackJballerinaTools)
doLast {
project.configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact ->
project.copy {
from project.zipTree(artifact.getFile())
into new File("${project.buildDir}/extracted-stdlibs", artifact.name + '-zip')
if (checkForBreakingChanges) {
println("WARNING! task unpackStdLibs skiped; project uses docker to build the module")
} else {
doLast {
project.configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact ->
project.copy {
from project.zipTree(artifact.getFile())
into new File("${project.buildDir}/extracted-stdlibs", artifact.name + '-zip')
}
}
}
}
}

project.tasks.register('copyStdlibs') {
dependsOn(project.unpackStdLibs)
doLast {
/* Standard Libraries */
project.configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def artifactExtractedPath = "${project.buildDir}/extracted-stdlibs/" + artifact.name + '-zip'
project.copy {
def ballerinaDist = "build/jballerina-tools-${project.ballerinaLangVersion}"
into ballerinaDist
into('repo/bala') {
from "${artifactExtractedPath}/bala"
}
into('repo/cache') {
from "${artifactExtractedPath}/cache"
}
}
project.copy {
def runtimePath = "${project.rootDir}/target/ballerina-runtime"
into runtimePath
into('repo/bala') {
from "${artifactExtractedPath}/bala"
if (checkForBreakingChanges) {
println("WARNING! task copyStdlibs skiped; project uses docker to build the module")
} else {
doLast {
/* Standard Libraries */
project.configurations.ballerinaStdLibs.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def artifactExtractedPath = "${project.buildDir}/extracted-stdlibs/" + artifact.name + '-zip'
project.copy {
def ballerinaDist = "build/jballerina-tools-${project.ballerinaLangVersion}"
into ballerinaDist
into('repo/bala') {
from "${artifactExtractedPath}/bala"
}
into('repo/cache') {
from "${artifactExtractedPath}/cache"
}
}
into('repo/cache') {
from "${artifactExtractedPath}/cache"
project.copy {
def runtimePath = "${project.rootDir}/target/ballerina-runtime"
into runtimePath
into('repo/bala') {
from "${artifactExtractedPath}/bala"
}
into('repo/cache') {
from "${artifactExtractedPath}/cache"
}
}
}
}
}
}

project.tasks.register('initializeVariables') {
String packageName = project.extensions.ballerina.module
String organisation
Expand Down Expand Up @@ -240,7 +263,13 @@ class BallerinaPlugin implements Plugin<Project> {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
if (checkForBreakingChanges) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal pack --target-dir ${balBuildTarget} --offline ${debugParams}"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal pack --target-dir ${balBuildTarget} --offline ${debugParams}"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat pack --target-dir ${balBuildTarget} --offline ${debugParams} && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$balJavaDebugParam $distributionBinPath/bal pack --target-dir ${balBuildTarget} --offline ${debugParams}"
Expand All @@ -251,7 +280,13 @@ class BallerinaPlugin implements Plugin<Project> {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
if (checkForBreakingChanges) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v $project.projectDir/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag $balJavaDebugParam bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$balJavaDebugParam $distributionBinPath/bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
Expand Down Expand Up @@ -322,7 +357,13 @@ class BallerinaPlugin implements Plugin<Project> {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
if (checkForBreakingChanges) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
} else {
commandLine 'sh', '-c', "docker run --rm --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v $project.projectDir:/home/ballerina ballerina/ballerina:$ballerinaDockerTag bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "${balJavaDebugParam} ${distributionBinPath}/bal.bat test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "${balJavaDebugParam} ${distributionBinPath}/bal test --offline ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
Expand Down

0 comments on commit b32ce02

Please sign in to comment.