Enable writing to jar files as well as zip files.
We used to allow writing to both zip and jar files but accidentally
disabled that when moving to output sinks. This enables it again
and adds a regression test.
R=herhut@google.com
Change-Id: I82e4ac8ff280456901b072932d1140a0a0ff7954
diff --git a/src/main/java/com/android/tools/r8/utils/FileSystemOutputSink.java b/src/main/java/com/android/tools/r8/utils/FileSystemOutputSink.java
index e007147..9ceee1f 100644
--- a/src/main/java/com/android/tools/r8/utils/FileSystemOutputSink.java
+++ b/src/main/java/com/android/tools/r8/utils/FileSystemOutputSink.java
@@ -20,7 +20,7 @@
public static FileSystemOutputSink create(Path outputPath, InternalOptions options)
throws IOException {
- if (FileUtils.isZipFile(outputPath)) {
+ if (FileUtils.isArchive(outputPath)) {
return new ZipFileOutputSink(outputPath, options);
} else {
return new DirectoryOutputSink(outputPath, options);
diff --git a/src/test/java/com/android/tools/r8/d8/WriteToArchiveTest.java b/src/test/java/com/android/tools/r8/d8/WriteToArchiveTest.java
new file mode 100644
index 0000000..8892cfc
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/d8/WriteToArchiveTest.java
@@ -0,0 +1,43 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.d8;
+
+import com.android.tools.r8.CompilationException;
+import com.android.tools.r8.D8;
+import com.android.tools.r8.D8Command;
+import com.android.tools.r8.ToolHelper;
+import java.io.IOException;
+import java.nio.file.Paths;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+// Test that we allow writing to zip and jar archives.
+public class WriteToArchiveTest {
+
+ private static final String input = ToolHelper.EXAMPLES_BUILD_DIR + "/trivial.jar";
+
+ @Rule public TemporaryFolder zipFolder = ToolHelper.getTemporaryFolderForTest();
+ @Rule public TemporaryFolder jarFolder = ToolHelper.getTemporaryFolderForTest();
+
+ @Test
+ public void writeToZip() throws IOException, CompilationException {
+ D8Command command =
+ D8Command.builder()
+ .addProgramFiles(Paths.get(input))
+ .setOutputPath(Paths.get(zipFolder.getRoot().toString() + "/output.zip"))
+ .build();
+ D8.run(command);
+ }
+
+ @Test
+ public void writeToJar() throws IOException, CompilationException {
+ D8Command command =
+ D8Command.builder()
+ .addProgramFiles(Paths.get(input))
+ .setOutputPath(Paths.get(jarFolder.getRoot().toString() + "/output.jar"))
+ .build();
+ D8.run(command);
+ }
+}