diff options
author | ChavXO <mchavinda@colgate.edu> | 2016-07-17 20:59:44 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-08-28 23:37:16 -0400 |
commit | 2d291a4fe19330020d7c1845bbb1deee204c6d69 (patch) | |
tree | 52f6bb16a1a6faf2e93675ed5c22f58ac21d8404 /stage2 | |
parent | c35fd1fd51c44cbb954084d0e048b3613c7cdd45 (diff) | |
download | cbt-2d291a4fe19330020d7c1845bbb1deee204c6d69.tar.gz cbt-2d291a4fe19330020d7c1845bbb1deee204c6d69.tar.bz2 cbt-2d291a4fe19330020d7c1845bbb1deee204c6d69.zip |
Add clean task
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("/")) |