diff options
author | Ian Zerny <zerny@google.com> | 2017-10-26 09:11:54 +0200 |
---|---|---|
committer | Ian Zerny <zerny@google.com> | 2017-10-26 09:11:54 +0200 |
commit | 2e49cc0222901d4220fbd46b1785187b7e98d0e8 (patch) | |
tree | 57bac5ad0b1158c19911ab466d0717d285da5593 | |
parent | b2a5217985db7c9e40268a3237f1c0c0519a43e9 (diff) | |
download | r8-2e49cc0222901d4220fbd46b1785187b7e98d0e8.tar.gz |
Limit use of jar building utility.
R=ager
Bug:
Change-Id: Ia77925c0c0c02c1f91352b8f4943e90fb8bc7336
3 files changed, 26 insertions, 51 deletions
diff --git a/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java b/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java index 92de2688c..4f3a4c8b2 100644 --- a/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java +++ b/src/test/java/com/android/tools/r8/R8RunArtTestsTest.java @@ -19,7 +19,6 @@ import com.android.tools.r8.utils.ArtErrorParser; import com.android.tools.r8.utils.ArtErrorParser.ArtErrorInfo; import com.android.tools.r8.utils.DexInspector; import com.android.tools.r8.utils.FileUtils; -import com.android.tools.r8.utils.JarBuilder; import com.android.tools.r8.utils.ListUtils; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; @@ -30,6 +29,7 @@ import com.google.common.collect.ObjectArrays; import com.google.common.collect.Sets; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -45,6 +45,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.function.BiFunction; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; import java.util.stream.Collectors; import org.junit.ComparisonFailure; import org.junit.Rule; @@ -1576,7 +1578,7 @@ public abstract class R8RunArtTestsTest { // Run Art on JAR file with multiple dex files. processedFile = temp.getRoot().toPath().resolve(specification.name + ".jar").toFile(); - JarBuilder.buildJar(outputFiles, processedFile); + buildJar(outputFiles, processedFile); } boolean compileOnly = System.getProperty("jctf_compile_only", "0").equals("1"); @@ -1762,7 +1764,7 @@ public abstract class R8RunArtTestsTest { // Run Art on JAR file with multiple dex files. processedFile = temp.getRoot().toPath().resolve(specification.name + ".jar").toFile(); - JarBuilder.buildJar(outputFiles, processedFile); + buildJar(outputFiles, processedFile); } File expectedFile = specification.resolveFile("expected.txt"); @@ -1874,4 +1876,18 @@ public abstract class R8RunArtTestsTest { } throw errors.get(errors.size() - 1); } + + // TODO(zerny): Refactor tests to output jar files directly and eliminate this method. + private static void buildJar(File[] files, File jarFile) throws IOException { + try (JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile))) { + for (File file : files) { + // Only use the file name in the JAR entry (classes.dex, classes2.dex, ...) + JarEntry entry = new JarEntry(file.getName()); + entry.setTime(file.lastModified()); + target.putNextEntry(entry); + Files.copy(file.toPath(), target); + target.closeEntry(); + } + } + } } diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java index 614f771ca..f1ebcbb3f 100644 --- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java +++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java @@ -15,10 +15,8 @@ import com.android.tools.r8.ToolHelper.DexVm; import com.android.tools.r8.ToolHelper.DexVm.Version; import com.android.tools.r8.errors.Unreachable; import com.android.tools.r8.shaking.ProguardRuleParserException; -import com.android.tools.r8.utils.JarBuilder; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -163,6 +161,10 @@ public class R8RunExamplesTest { this.mainClass = mainClass; } + private Path getOutputFile() { + return temp.getRoot().toPath().resolve("out.jar"); + } + private Path getInputFile() { switch(input) { case DX: @@ -201,7 +203,7 @@ public class R8RunExamplesTest { case D8: { ToolHelper.runD8(D8Command.builder() .addProgramFiles(getInputFile()) - .setOutputPath(out) + .setOutputPath(getOutputFile()) .setMode(mode) .build()); break; @@ -209,7 +211,7 @@ public class R8RunExamplesTest { case R8: { ToolHelper.runR8(R8Command.builder() .addProgramFiles(getInputFile()) - .setOutputPath(out) + .setOutputPath(getOutputFile()) .setMode(mode) .build()); break; @@ -226,19 +228,7 @@ public class R8RunExamplesTest { } String original = getOriginalDexFile().toString(); - - File generated; - // Collect the generated dex files. - File[] outputFiles = - temp.getRoot().listFiles((File file) -> file.getName().endsWith(".dex")); - if (outputFiles.length == 1) { - // Just run Art on classes.dex. - generated = outputFiles[0]; - } else { - // Run Art on JAR file with multiple dex files. - generated = temp.getRoot().toPath().resolve(pkg + ".jar").toFile(); - JarBuilder.buildJar(outputFiles, generated); - } + Path generated = getOutputFile(); ToolHelper.ProcessResult javaResult = ToolHelper.runJava(ImmutableList.of(getOriginalJarFile("").toString()), mainClass); diff --git a/src/test/java/com/android/tools/r8/utils/JarBuilder.java b/src/test/java/com/android/tools/r8/utils/JarBuilder.java deleted file mode 100644 index 9186ff44a..000000000 --- a/src/test/java/com/android/tools/r8/utils/JarBuilder.java +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2016, 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.utils; - -import com.google.common.io.ByteStreams; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; - -public class JarBuilder { - public static void buildJar(File[] files, File jarFile) throws IOException { - JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile)); - for (File file : files) { - // Only use the file name in the JAR entry (classes.dex, classes2.dex, ...) - JarEntry entry = new JarEntry(file.getName()); - entry.setTime(file.lastModified()); - target.putNextEntry(entry); - InputStream in = new BufferedInputStream(new FileInputStream(file)); - ByteStreams.copy(in, target); - in.close(); - target.closeEntry(); - } - target.close(); - } -} |