From a6da00cdc497ede8ac995a0e2c7c8a18a91ce097 Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Tue, 5 Dec 2023 16:02:48 +0530 Subject: [PATCH] Update logic to override docker tag using buildUsingDocker flag --- .../ballerina/plugin/BallerinaPlugin.groovy | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy index cc17ed2..ac7b593 100644 --- a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy +++ b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy @@ -30,11 +30,11 @@ class BallerinaExtension { String module String langVersion - String buildOnDockerImage String testCoverageParam String packageOrganization String customTomlVersion String platform + boolean isConnector = false } class BallerinaPlugin implements Plugin { @@ -79,18 +79,14 @@ class BallerinaPlugin implements Plugin { } project.afterEvaluate { - if (ballerinaExtension.hasProperty('buildOnDockerImage') && ballerinaExtension.buildOnDockerImage.asType(boolean) == true) { + if (ballerinaExtension.isConnector == true) { buildOnDocker = true - ballerinaDockerTag = extractVersion(project.findProperty('ballerinaLangVersion')) + ballerinaDockerTag = getDockerImageTag(project) } if (project.hasProperty('buildUsingDocker')) { buildOnDocker = true - ballerinaDockerTag = project.findProperty('buildUsingDocker') - } - - if (ballerinaDockerTag == '') { - ballerinaDockerTag = 'nightly' + ballerinaDockerTag = getDockerImageTag(project) } if (buildOnDocker) { @@ -293,10 +289,7 @@ class BallerinaPlugin implements Plugin { workingDir project.projectDir environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true' if (buildOnDocker) { - String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion')) - if (dockerTag != null && dockerTag != '') { - ballerinaDockerTag = dockerTag - } + ballerinaDockerTag = getDockerImageTag(project) createDockerEnvFile("$project.projectDir/docker.env") def balPackWithDocker = """ docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \ @@ -325,10 +318,7 @@ class BallerinaPlugin implements Plugin { workingDir project.projectDir environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true' if (buildOnDocker) { - String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion')) - if (dockerTag != null && dockerTag != '') { - ballerinaDockerTag = dockerTag - } + ballerinaDockerTag = getDockerImageTag(project) def balTestWithDocker = """ docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \ -v $parentDirectory:/home/ballerina/$parentDirectory.name \ @@ -372,10 +362,7 @@ class BallerinaPlugin implements Plugin { workingDir project.projectDir environment 'JAVA_OPTS', '-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true' if (buildOnDocker) { - String dockerTag = extractVersion(project.findProperty('ballerinaLangVersion')) - if (dockerTag != null && dockerTag != '') { - ballerinaDockerTag = dockerTag - } + ballerinaDockerTag = getDockerImageTag(project) def balPushWithDocker = """ docker run --env-file $project.projectDir/docker.env --rm --net=host -u root \ -v $parentDirectory:/home/ballerina/$parentDirectory.name \ @@ -511,7 +498,21 @@ class BallerinaPlugin implements Plugin { } } - static String extractVersion(String versionWithTimeStamp) { - return versionWithTimeStamp.trim().split("-")[0] + static String getDockerImageTag(Project project) { + def ballerinaDockerTag = project.findProperty('ballerinaLangVersion') + if (project.hasProperty('buildUsingDocker')) { + ballerinaDockerTag = project.findProperty('buildUsingDocker') + if (ballerinaDockerTag == '') { + return 'nightly' + } + } + if (isTimeStampVersion(ballerinaDockerTag)) { + return 'nightly' + } + return ballerinaDockerTag + } + + static boolean isTimeStampVersion(String version) { + return version.trim().split("-").length > 1 } }