aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-07-11 10:37:58 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-07-11 10:57:13 +0200
commitdc30e81c42c883e38d525e1d44a3a663306859db (patch)
tree2224bcbfdbf1f0bd0a8974ddf6fc4f5dcb913c0e /src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java
parente9e02123ba84bf05eca9c047278895b9158ea4cd (diff)
AndroidResourceOutputs: fix ZipEntry paths
Make sure that ZipEntry paths always use forward slashes, even on Windows. Also add a test. See https://github.com/bazelbuild/bazel/issues/3264 Change-Id: I4508e46dde49cd44c8e3792017d0d280a51dc565 PiperOrigin-RevId: 161500049
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java b/src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java
new file mode 100644
index 0000000000..9c10944285
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/android/AndroidResourceOutputsTest.java
@@ -0,0 +1,68 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.android;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.jimfs.Jimfs;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link AndroidResourceOutputsTest}. */
+@RunWith(JUnit4.class)
+public class AndroidResourceOutputsTest {
+ private Path tmp;
+
+ @Before
+ public void setUp() throws Exception {
+ tmp =
+ Files.createTempDirectory(
+ Jimfs.newFileSystem().getRootDirectories().iterator().next(),
+ getClass().getSimpleName());
+ }
+
+ @Test
+ public void testZipEntryPaths() throws Exception {
+ Path output = tmp.resolve("actual.zip");
+ Files.createDirectories(tmp.resolve("foo/bar"));
+ Files.write(tmp.resolve("foo/data1.txt"), "hello".getBytes(Charset.defaultCharset()));
+ Files.write(tmp.resolve("foo/bar/data2.txt"), "world".getBytes(Charset.defaultCharset()));
+
+ try (ZipOutputStream zout = new ZipOutputStream(Files.newOutputStream(output))) {
+ AndroidResourceOutputs.ZipBuilderVisitor visitor =
+ new AndroidResourceOutputs.ZipBuilderVisitor(zout, tmp.resolve("foo"), "some/prefix");
+ Files.walkFileTree(tmp.resolve("foo"), visitor);
+ visitor.writeEntries();
+ }
+
+ List<String> entries = new ArrayList<>();
+ try (ZipInputStream zin = new ZipInputStream(Files.newInputStream(output))) {
+ ZipEntry entry = null;
+ while ((entry = zin.getNextEntry()) != null) {
+ entries.add(entry.getName());
+ }
+ }
+ assertThat(entries).containsExactly("some/prefix/data1.txt", "some/prefix/bar/data2.txt");
+ }
+}