diff --git a/gradle.properties b/gradle.properties index b4cbc5f..0835fb7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=io.ballerina -version=0.14.4-SNAPSHOT +version=0.15.0-SNAPSHOT diff --git a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy index 82dbb79..b2fd32e 100644 --- a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy +++ b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy @@ -41,23 +41,7 @@ class BallerinaPlugin implements Plugin { @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 @@ -75,6 +59,12 @@ class BallerinaPlugin implements Plugin { 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('-') @@ -88,32 +78,57 @@ class BallerinaPlugin implements Plugin { 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" } } } @@ -121,11 +136,15 @@ class BallerinaPlugin implements Plugin { 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') + } } } } @@ -133,34 +152,38 @@ class BallerinaPlugin implements Plugin { 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 @@ -240,7 +263,13 @@ class BallerinaPlugin implements Plugin { 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}" @@ -251,7 +280,13 @@ class BallerinaPlugin implements Plugin { 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}" @@ -322,7 +357,13 @@ class BallerinaPlugin implements Plugin { 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}"