Skip to content

Commit

Permalink
Merge pull request #129 from Nuvindu/connector-fix
Browse files Browse the repository at this point in the history
Fix unnecessary checks in the package build
  • Loading branch information
Nuvindu authored Jan 5, 2024
2 parents 5d089df + af88463 commit 34e53b6
Showing 1 changed file with 71 additions and 115 deletions.
186 changes: 71 additions & 115 deletions src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class BallerinaPlugin implements Plugin<Project> {
def debugParams = ''
def balJavaDebugParam = ''
def testCoverageParams = ''
def needSeparateTest = false
def needBuildWithTest = false
def needPublishToCentral = false
def needPublishToLocalCentral = false
def skipTests = true
Expand Down Expand Up @@ -228,15 +226,6 @@ class BallerinaPlugin implements Plugin<Project> {
}

project.gradle.taskGraph.whenReady { graph ->
if (!(project.hasProperty('disable') || project.hasProperty('groups')) &&
(graph.hasTask(":${packageName}-ballerina:build") ||
graph.hasTask(":${packageName}-ballerina:publish") ||
graph.hasTask(":${packageName}-ballerina:publishToMavenLocal"))) {
needSeparateTest = false
needBuildWithTest = true
} else {
needSeparateTest = true
}
if (graph.hasTask(":${packageName}-ballerina:test")) {
if (!project.hasProperty('balGraalVMTest')) {
if (ballerinaExtension.testCoverageParam == null) {
Expand Down Expand Up @@ -276,128 +265,97 @@ class BallerinaPlugin implements Plugin<Project> {
} else {
packageOrg = ballerinaExtension.packageOrganization
}
if (needBuildWithTest) {
// Pack bala first
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
createDockerEnvFile("$project.projectDir/docker.env")
def balPackWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
/bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && \
$balJavaDebugParam bal pack --target-dir ${balBuildTarget} ${debugParams}"
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balPackWithDocker"
} else {
commandLine 'sh', '-c', "$balPackWithDocker"
}
// Pack bala first
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
createDockerEnvFile("$project.projectDir/docker.env")
def balPackWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
/bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && \
bal pack --target-dir ${balBuildTarget}"
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balPackWithDocker"
} 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}"
}
commandLine 'sh', '-c', "$balPackWithDocker"
}
} else {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$distributionBinPath/bal.bat pack --target-dir ${balBuildTarget} --offline && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$distributionBinPath/bal pack --target-dir ${balBuildTarget} --offline"
}
}
// Run tests
if (!skipTests) {
}
// extract bala file to balaArtifact
new File("$project.projectDir/${balBuildTarget}/bala").eachFileMatch(~/.*.bala/) { balaFile ->
project.copy {
from project.zipTree(balaFile)
into new File("$balaArtifact/bala/${packageOrg}/${packageName}/${balaVersion}/${platform}")
}
}
project.copy {
from "$balaArtifact/bala"
into "${project.rootDir}/target/ballerina-runtime/repo/bala"
}
if (needPublishToCentral) {
if (project.version.endsWith('-SNAPSHOT') ||
project.version.matches(project.ext.timestampedVersionRegex)) {
println("[Info] skipping publishing to central: project version is SNAPSHOT or Timestamped SNAPSHOT")
return
}
if (ballerinaCentralAccessToken != null) {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
def balTestWithDocker = """
def balPushWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
/bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && \
bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala"
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balTestWithDocker"
commandLine 'cmd', '/c', "$balPushWithDocker"
} else {
commandLine 'sh', '-c', "$balTestWithDocker"
commandLine 'sh', '-c', "$balPushWithDocker"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$balJavaDebugParam $distributionBinPath/bal test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
commandLine 'sh', '-c', "$distributionBinPath/bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala"
}

}
} else {
throw new InvalidUserDataException('Central Access Token is not present')
}
// extract bala file to balaArtifact
new File("$project.projectDir/${balBuildTarget}/bala").eachFileMatch(~/.*.bala/) { balaFile ->
project.copy {
from project.zipTree(balaFile)
into new File("$balaArtifact/bala/${packageOrg}/${packageName}/${balaVersion}/${platform}")
}
}
project.copy {
from "$balaArtifact/bala"
into "${project.rootDir}/target/ballerina-runtime/repo/bala"
}
if (needPublishToCentral) {
if (project.version.endsWith('-SNAPSHOT') ||
project.version.matches(project.ext.timestampedVersionRegex)) {
println("[Info] skipping publishing to central: project version is SNAPSHOT or Timestamped SNAPSHOT")
return
}
if (ballerinaCentralAccessToken != null) {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (buildOnDocker) {
def balPushWithDocker = """
docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \
-v $parentDirectory:/home/ballerina/$parentDirectory.name \
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
/bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && \
bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala"
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balPushWithDocker"
} else {
commandLine 'sh', '-c', "$balPushWithDocker"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$distributionBinPath/bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala"
}
} else if (needPublishToLocalCentral) {
println("[Info] Publishing to the ballerina local central repository")
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (!ballerinaExtension.isConnector) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$distributionBinPath/bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local"
}
} else {
throw new InvalidUserDataException('Central Access Token is not present')
}
} else if (needPublishToLocalCentral) {
println("[Info] Publishing to the ballerina local central repository")
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
if (!ballerinaExtension.isConnector) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$distributionBinPath/bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "$distributionBinPath/bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local"
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local && exit %%ERRORLEVEL%%"
} else {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "bal.bat push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local"
}
}
commandLine 'sh', '-c', "bal push ${balBuildTarget}/bala/${packageOrg}-${packageName}-${platform}-${balaVersion}.bala --repository=local"
}
}
}
}
}
doLast {
if (buildOnDocker) {
deleteFile("$project.projectDir/docker.env")
}
Expand All @@ -415,7 +373,8 @@ class BallerinaPlugin implements Plugin<Project> {
dependsOn(project.updateTomlFiles)
finalizedBy(project.commitTomlFiles)
doLast {
if (needSeparateTest) {
// Run tests
if (!skipTests) {
project.exec {
workingDir project.projectDir
environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true'
Expand All @@ -427,24 +386,21 @@ class BallerinaPlugin implements Plugin<Project> {
-v $projectDirectory:/home/ballerina/$parentDirectory.name/$projectDirectory.name \
ballerina/ballerina:$ballerinaDockerTag \
/bin/sh -c "cd $parentDirectory.name/$projectDirectory.name && \
bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
$balJavaDebugParam bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
"""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balTestWithDocker"
} else {
commandLine 'sh', '-c', "$balTestWithDocker"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
} else {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', "${balJavaDebugParam} ${distributionBinPath}/bal.bat test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%"
} else {
commandLine 'sh', '-c', "${balJavaDebugParam} ${distributionBinPath}/bal test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}
commandLine 'sh', '-c', "$balJavaDebugParam $distributionBinPath/bal test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}"
}

}
}
}
doLast {
if (buildOnDocker) {
deleteFile("$project.projectDir/docker.env")
}
Expand Down

0 comments on commit 34e53b6

Please sign in to comment.