diff --git a/src/scala/org/pantsbuild/zinc/compiler/OutputUtils.scala b/src/scala/org/pantsbuild/zinc/compiler/OutputUtils.scala index d6fa0ea94fba..bfeb8e50f8d9 100644 --- a/src/scala/org/pantsbuild/zinc/compiler/OutputUtils.scala +++ b/src/scala/org/pantsbuild/zinc/compiler/OutputUtils.scala @@ -19,17 +19,21 @@ object OutputUtils { * @param dir File handle containing the contents to sort * @return sorted set of all paths within the `dir` */ - def sort(dir:File): mutable.TreeSet[(Path, Boolean)] = { - val sorted = new mutable.TreeSet[(Path, Boolean)]() + def sort(dir:File): mutable.TreeSet[Path] = { + val sorted = new mutable.TreeSet[Path]() val fileSortVisitor = new SimpleFileVisitor[Path]() { override def preVisitDirectory(path: Path, attrs: BasicFileAttributes): FileVisitResult = { - sorted.add(path, false) + if (!path.endsWith("/")) { + sorted.add(Paths.get(path.toString, "/")) + } else { + sorted.add(path) + } FileVisitResult.CONTINUE } override def visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult = { - sorted.add(path, true) + sorted.add(path) FileVisitResult.CONTINUE } } @@ -50,25 +54,30 @@ object OutputUtils { * @param jarEntryTime time to be set for each JAR entry */ def createJar( - base: String, filePaths: mutable.TreeSet[(Path, Boolean)], outputJarPath: Path, jarEntryTime: Long) { + base: String, filePaths: mutable.TreeSet[Path], outputJarPath: Path, jarEntryTime: Long) { val target = new JarOutputStream(Files.newOutputStream(outputJarPath)) - def addToJar(source: (Path, Boolean), entryName: String): FileVisitResult = { - val jarEntry = new JarEntry(entryName) + def jarEntry(name: String): JarEntry = { + val jarEntry = new JarEntry(name) // setting jarEntry time to a fixed value for all entries within the jar so that jars are // byte-for-byte reproducible. jarEntry.setTime(jarEntryTime) + jarEntry + } - target.putNextEntry(jarEntry) - if (source._2) { - Files.copy(source._1, target) + def addToJar(source: Path, entryName: String): FileVisitResult = { + if (source.toFile.isDirectory) { + target.putNextEntry(jarEntry(entryName)) + } else { + target.putNextEntry(jarEntry(entryName)) + Files.copy(source, target) } target.closeEntry() FileVisitResult.CONTINUE } - val pathToName = filePaths.zipWithIndex.map{case(k, v) => (k, relativize(base, k._1))}.toMap + val pathToName = filePaths.zipWithIndex.map{case(k, v) => (k, relativize(base, k))}.toMap pathToName.map(e => addToJar(e._1, e._2)) target.close() } diff --git a/src/scala/org/pantsbuild/zinc/compiler/Settings.scala b/src/scala/org/pantsbuild/zinc/compiler/Settings.scala index 5df34cd75638..c361d2350e88 100644 --- a/src/scala/org/pantsbuild/zinc/compiler/Settings.scala +++ b/src/scala/org/pantsbuild/zinc/compiler/Settings.scala @@ -50,7 +50,7 @@ case class Settings( sbt: SbtJars = SbtJars(), _incOptions: IncOptions = IncOptions(), analysis: AnalysisOptions = AnalysisOptions(), - creationTime: Long = System.currentTimeMillis() + creationTime: Long = 0 ) { import Settings._ diff --git a/tests/scala/org/pantsbuild/zinc/compiler/JarCreationSpec.scala b/tests/scala/org/pantsbuild/zinc/compiler/JarCreationSpec.scala index 8f5f8334af9f..96dfed959a05 100644 --- a/tests/scala/org/pantsbuild/zinc/compiler/JarCreationSpec.scala +++ b/tests/scala/org/pantsbuild/zinc/compiler/JarCreationSpec.scala @@ -15,7 +15,7 @@ class JarCreationSpec extends WordSpec with MustMatchers { "JarCreationWithoutClasses" should { "succeed when input classes are not provided" in { IO.withTemporaryDirectory { tempInputDir => - val filePaths = new mutable.TreeSet[(Path, Boolean)]() + val filePaths = new mutable.TreeSet[Path]() IO.withTemporaryDirectory { tempOutputDir => val jarOutputPath = Paths.get(tempOutputDir.toString, "spec-empty-output.jar") @@ -26,11 +26,12 @@ class JarCreationSpec extends WordSpec with MustMatchers { } } } + "JarCreationWithClasses" should { "succeed when input classes are provided" in { IO.withTemporaryDirectory { tempInputDir => val tempFile = File.createTempFile("Temp", ".class", tempInputDir) - val filePaths = mutable.TreeSet((tempFile.toPath, true)) + val filePaths = mutable.TreeSet(tempFile.toPath) IO.withTemporaryDirectory { tempOutputDir => val jarOutputPath = Paths.get(tempOutputDir.toString, "spec-valid-output.jar") @@ -48,7 +49,7 @@ class JarCreationSpec extends WordSpec with MustMatchers { IO.withTemporaryDirectory { tempInputDir => val nestedTempDir = Files.createTempDirectory(tempInputDir.toPath, "tmp") val nestedTempClass = File.createTempFile("NestedTemp", ".class", nestedTempDir.toFile) - val filePaths = mutable.TreeSet((nestedTempDir, false), (nestedTempClass.toPath, true)) + val filePaths = mutable.TreeSet(nestedTempDir, nestedTempClass.toPath) IO.withTemporaryDirectory { tempOutputDir => val jarOutputPath = Paths.get(tempOutputDir.toString, "spec-valid-output.jar")