Skip to content

Commit

Permalink
Merge pull request #79 from olafurpg/clean-target-first
Browse files Browse the repository at this point in the history
Respect --clean-target-first
  • Loading branch information
olafurpg committed Oct 10, 2017
2 parents 08753bc + 56e59b8 commit 6368d63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
14 changes: 11 additions & 3 deletions metadoc-cli/src/main/scala/metadoc/cli/MetadocCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ case class MetadocOptions(
zip: Boolean = false,
@HelpMessage("Disable fancy progress bar")
nonInteractive: Boolean = false
)
) {
def targetPath: AbsolutePath = AbsolutePath(target.get)
}

case class Target(target: AbsolutePath, onClose: () => Unit)

class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
val Target(target, onClose) = if (options.zip) {
// For large corpora (>1M LOC) writing the symbol/ directory is the
// bottle-neck unless --zip is enabled.
val out = AbsolutePath(options.target.get).resolve("metadoc.zip")
val out = options.targetPath.resolve("metadoc.zip")
Files.createDirectories(out.toNIO.getParent)
val zipfs = FileSystems.newFileSystem(
URI.create(s"jar:file:${out.toURI.getPath}"), {
Expand All @@ -70,7 +72,7 @@ class CliRunner(classpath: Seq[AbsolutePath], options: MetadocOptions) {
)
Target(AbsolutePath(zipfs.getPath("/")), () => zipfs.close())
} else {
Target(AbsolutePath(options.target.get), () => ())
Target(options.targetPath, () => ())
}
private val display = new TermDisplay(
new OutputStreamWriter(System.out),
Expand Down Expand Up @@ -326,6 +328,12 @@ object MetadocCli extends CaseApp[MetadocOptions] {
error("--target is required")
}

if (options.cleanTargetFirst) {
import better.files._
val file = options.targetPath.toFile.toScala
if (file.exists) file.delete()
}

val classpath = remainingArgs.remainingArgs.flatMap { cp =>
cp.split(File.pathSeparator).map(AbsolutePath(_))
}
Expand Down
21 changes: 13 additions & 8 deletions metadoc-tests/src/test/scala/metadoc/tests/MetadocCliTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ class MetadocCliTest
with BeforeAndAfterAll
with DiffAssertions {
var out: AbsolutePath = _
def options = MetadocOptions(
Some(out.toString()),
cleanTargetFirst = true,
nonInteractive = true
)
def files = BuildInfo.exampleClassDirectory.map(_.getAbsolutePath)

def runCli(): Unit = MetadocCli.run(options, RemainingArgs(files, Nil))

override def beforeAll(): Unit = {
out = AbsolutePath(Files.createTempDirectory("metadoc"))
out.toFile.deleteOnExit()

val options = MetadocOptions(
Some(out.toString()),
cleanTargetFirst = true,
nonInteractive = true
)
val files = BuildInfo.exampleClassDirectory.map(_.getAbsolutePath)
MetadocCli.run(options, RemainingArgs(files, Nil))
runCli()
}

val expectedFiles =
Expand Down Expand Up @@ -310,4 +312,7 @@ class MetadocCliTest
|}
|""".stripMargin
)
test("--clean-target-first") {
runCli() // assert no error
}
}

0 comments on commit 6368d63

Please sign in to comment.