diff options
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/BasicBuild.scala | 5 | ||||
-rw-r--r-- | stage2/Lib.scala | 41 |
2 files changed, 45 insertions, 1 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 42384db..f784299 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -136,6 +136,11 @@ trait BaseBuild extends DependencyImplementation with BuildInterface with Trigge def runClass: String = "Main" def run: ExitCode = lib.runMainIfFound( runClass, context.args, classLoader(context.classLoaderCache) ) + def clean = { + val arg = if (context.args.length > 1) context.args(1) else "" + lib.clean(scalaTarget, arg) + } + def test: Option[ExitCode] = Some(new lib.ReflectBuild( DirectoryDependency(projectDirectory++"/test").build diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 118c9a4..e05085e 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -4,7 +4,7 @@ import java.io._ import java.net._ import java.lang.reflect.InvocationTargetException import java.nio.file.{Path =>_,_} -import java.nio.file.Files.readAllBytes +import java.nio.file.Files.{readAllBytes, deleteIfExists} import java.security.MessageDigest import java.util.jar._ import java.lang.reflect.Method @@ -199,6 +199,45 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } } + def clean (compileTarget : File, option: String) : ExitCode = { + /* recursively deletes folders*/ + def deleteRecursive(file: File): Boolean = { + if (file.isDirectory) { + file.listFiles.map(deleteRecursive(_)) + } + deleteIfExists(file.toPath) + } + + def listFilesToDelete(file: File): Unit = { + if (file.isDirectory) { + file.listFiles.map(listFilesToDelete(_)) + } + println(file.toString) + } + listFilesToDelete(compileTarget) + val delete = if (option != "-f") { + Option(System.console).getOrElse( + throw new Exception("Can't access Console. Try running `cbt direct clean` or `cbt clean -f`.") + ).readLine( + "Delete file(s) [y/n]: " + ).head.toLower + } else 'y' + + if (delete == 'y') { + logger.lib(s"""Cleaning ${compileTarget}""") + if (!compileTarget.exists) return ExitCode.Success + if (deleteRecursive(compileTarget)) { + logger.lib("Succeeded") + ExitCode.Success + } else { + logger.lib("Failed") + ExitCode.Failure + } + } else { + ExitCode.Failure + } + } + // file system helpers def basename(path: File): String = path.toString.stripSuffix("/").split("/").last def dirname(path: File): File = new File(realpath(path).string.stripSuffix("/").split("/").dropRight(1).mkString("/")) |