diff --git a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy index 01be1ee..0e6abea 100644 --- a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy +++ b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy @@ -50,6 +50,7 @@ class BallerinaPlugin implements Plugin { def balBuildTarget = 'build/bal_build_target' def balaArtifact = new File("$project.projectDir/build/bala_unzipped/") def projectDirectory = new File("$project.projectDir") + def parentDirectory = new File("$projectDirectory.parent") def ballerinaCentralAccessToken = System.getenv('BALLERINA_CENTRAL_ACCESS_TOKEN') def groupParams = '' def disableGroups = '' @@ -298,9 +299,9 @@ class BallerinaPlugin implements Plugin { } startBallerinaContainer(project, ballerinaDockerTag) if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}" + commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}" } else { - commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}" + commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal pack --target-dir ${balBuildTarget} ${debugParams}" } } else { String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin" @@ -323,9 +324,9 @@ class BallerinaPlugin implements Plugin { } startBallerinaContainer(project, ballerinaDockerTag) if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" + commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" } else { - commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" + commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" } } else if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine 'cmd', '/c', "$balJavaDebugParam $distributionBinPath/bal.bat test --offline ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams} && exit %%ERRORLEVEL%%" @@ -400,9 +401,9 @@ class BallerinaPlugin implements Plugin { if (buildOnDocker) { startBallerinaContainer(project, ballerinaDockerTag) if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" + commandLine 'cmd', '/c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" } else { - commandLine 'sh', '-c', "docker exec $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" + commandLine 'sh', '-c', "docker exec -w /home/ballerina/$parentDirectory.name/$projectDirectory.name $CONTAINER_NAME bal test ${graalvmFlag} ${testCoverageParams} ${groupParams} ${disableGroups} ${debugParams}" } } else { String distributionBinPath = project.projectDir.absolutePath + "/build/jballerina-tools-${ballerinaExtension.langVersion}/bin" @@ -462,10 +463,12 @@ class BallerinaPlugin implements Plugin { if (!stdOut.toString().contains(CONTAINER_NAME)) { project.exec { println "Starting Ballerina container." + def projectDir = new File(project.projectDir.toString()) + def parentDir = new File(projectDir.parent.toString()) if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v ${project.projectDir}:/home/ballerina ballerina/ballerina:$ballerinaDockerTag" + commandLine 'cmd', '/c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user ballerina:\$(id -g) -v $parentDir:/home/ballerina/$parentDir.name -v $projectDir:/home/ballerina/$parentDir.name/$projectDir.name ballerina/ballerina:$ballerinaDockerTag" } else { - commandLine 'sh', '-c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user \$(id -u):\$(id -g) -v ${project.projectDir}/..:/home -v ${project.projectDir}:/home/ballerina ballerina/ballerina:$ballerinaDockerTag" + commandLine 'sh', '-c', "docker run --rm -dt --name $CONTAINER_NAME --net=host --user ballerina:\$(id -g) -v $parentDir:/home/ballerina/$parentDir.name -v $projectDir:/home/ballerina/$parentDir.name/$projectDir.name ballerina/ballerina:$ballerinaDockerTag" } } } else {