diff options
author | tim-zh <tim.zhlobich@gmail.com> | 2016-11-14 22:05:07 +0300 |
---|---|---|
committer | tim-zh <tim.zhlobich@gmail.com> | 2016-11-14 22:05:07 +0300 |
commit | bdf9f2cea42dcf2429e3ccbe458ff8c432f45770 (patch) | |
tree | 4929c7b957bc55e215a4baf3905a03bc1fc60edd /tools/gui/src | |
parent | 9269863fbdcd94cce39582f6638d9f94bdaa1706 (diff) | |
download | cbt-bdf9f2cea42dcf2429e3ccbe458ff8c432f45770.tar.gz cbt-bdf9f2cea42dcf2429e3ccbe458ff8c432f45770.tar.bz2 cbt-bdf9f2cea42dcf2429e3ccbe458ff8c432f45770.zip |
code highlighting, copy files update
Diffstat (limited to 'tools/gui/src')
-rw-r--r-- | tools/gui/src/Main.scala | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/tools/gui/src/Main.scala b/tools/gui/src/Main.scala index f2f8ee1..8dd2c3e 100644 --- a/tools/gui/src/Main.scala +++ b/tools/gui/src/Main.scala @@ -1,7 +1,6 @@ import java.io.{File, IOException} import java.net.MalformedURLException -import java.nio.file.attribute.BasicFileAttributes -import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor} +import java.nio.file.Files import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer @@ -46,7 +45,7 @@ object Main { val source = new File(cbt_home / "examples" / name) val target = new File(projectDirectory.getAbsolutePath / name) handleIoException { - new FileCopier(source, target).copy() + copyTree(source, target) Success("[]") } case ("GET", "/dependency") => @@ -141,20 +140,17 @@ object Main { renderer.render(document) } - private class FileCopier(source: File, target: File) extends SimpleFileVisitor[Path] { - - def copy() = Files.walkFileTree(source.toPath, this) - - override def preVisitDirectory(dir: Path, attrs: BasicFileAttributes) = { - Files.createDirectories(target.toPath.resolve(source.toPath.relativize(dir))) - FileVisitResult.CONTINUE + private def copyTree(sourceRoot: File, targetRoot: File) = + listFilesRecursive(sourceRoot).sorted.foreach { source => + val path = source.getAbsolutePath.replace(sourceRoot.getAbsolutePath, targetRoot.getAbsolutePath) + val file = new File(path) + if (source.isDirectory) + file.mkdirs() + else + Files.copy(source.toPath, file.toPath) } - override def visitFile(file: Path, attrs: BasicFileAttributes) = { - Files.copy(file, target.toPath.resolve(source.toPath.relativize(file))) - FileVisitResult.CONTINUE - } - - } + private def listFilesRecursive(f: File): Seq[File] = + f +: (if (f.isDirectory) f.listFiles.flatMap(listFilesRecursive).toVector else Vector[File]()) } |