From 5ae8d0be9674314ccb3988b2c732110714fffffc Mon Sep 17 00:00:00 2001 From: MohamedSabthar Date: Thu, 9 Nov 2023 12:39:57 +0530 Subject: [PATCH] Fix clean command falling with permission error --- .../ballerina/plugin/BallerinaPlugin.groovy | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy index 6446ef2..b2b74d0 100644 --- a/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy +++ b/src/main/groovy/io/ballerina/plugin/BallerinaPlugin.groovy @@ -468,9 +468,28 @@ class BallerinaPlugin implements Plugin { } project.tasks.register('clean', Delete.class) { - delete "$project.projectDir/target" - delete "$project.projectDir/build" - delete "$project.rootDir/target" + doLast { + if (buildOnDocker) { + project.exec { + def deleteUsingDocker = """ + docker run --user 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 && rm -rf build target" + """ + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "$deleteUsingDocker" + } else { + commandLine 'sh', '-c', "$deleteUsingDocker" + } + } + } else { + delete "$project.projectDir/target" + delete "$project.projectDir/build" + } + delete "$project.rootDir/target" + } } }