Refactor backported_fixes rules to share with cts
The sharable rules include
proto libary and file
Combining BackportedFix files
Converting BockportedFix text protos to binary protos
Test: atest backported_fixes_main_lib_test backported_fixes_common_test
Bug: 375460641
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:13a26b80a4250ff54bc6364ea01e1b9ede8558f5)
Merged-In: Ie75ede120d5555119ad265e4def728af9535bb1f
Change-Id: Ie75ede120d5555119ad265e4def728af9535bb1f
diff --git a/backported_fixes/Android.bp b/backported_fixes/Android.bp
index a20f3fc..243e77e 100644
--- a/backported_fixes/Android.bp
+++ b/backported_fixes/Android.bp
@@ -19,19 +19,24 @@
genrule {
name: "applied_backported_fixes",
- tools: ["applied_backported_fixes_main"],
+ tools: ["applied_backported_fixes_property_writer"],
srcs: [":applied_backported_fix_binpbs"],
out: ["applied_backported_fixes.prop"],
- cmd: "$(location applied_backported_fixes_main)" +
+ cmd: "$(location applied_backported_fixes_property_writer)" +
" -p $(location applied_backported_fixes.prop)" +
" $(in)",
}
-java_library {
- name: "backported_fixes_proto",
+filegroup {
+ name: "backported_fixes_proto_file",
srcs: [
"backported_fixes.proto",
],
+}
+
+java_library {
+ name: "backported_fixes_proto",
+ srcs: ["backported_fixes.proto"],
host_supported: true,
}
@@ -63,7 +68,7 @@
}
java_library {
- name: "applied_backported_fixes_lib",
+ name: "backported_fixes_main_lib",
srcs: ["src/java/com/android/build/backportedfixes/*.java"],
static_libs: [
"backported_fixes_common",
@@ -75,18 +80,35 @@
}
java_binary_host {
- name: "applied_backported_fixes_main",
- main_class: "com.android.build.backportedfixes.Main",
+ name: "applied_backported_fixes_property_writer",
+ main_class: "com.android.build.backportedfixes.WriteBackportedFixesPropFile",
static_libs: [
- "applied_backported_fixes_lib",
+ "backported_fixes_main_lib",
],
}
+java_binary_host {
+ name: "backported_fixes_combiner",
+ main_class: "com.android.build.backportedfixes.CombineBackportedFixes",
+ static_libs: [
+ "backported_fixes_main_lib",
+ ],
+}
+
+// Combines BackportedFix binary proto files into a single BackportedFixes binary proto file.
+genrule_defaults {
+ name: "default_backported_fixes_combiner",
+ tools: ["backported_fixes_combiner"],
+ cmd: "$(location backported_fixes_combiner)" +
+ " -o $(out)" +
+ " $(in)",
+}
+
java_test_host {
- name: "applied_backported_fixes_test",
+ name: "backported_fixes_main_lib_test",
srcs: ["tests/java/com/android/build/backportedfixes/*.java"],
static_libs: [
- "applied_backported_fixes_lib",
+ "backported_fixes_main_lib",
"backported_fixes_proto",
"junit",
"truth",
@@ -97,19 +119,25 @@
test_suites: ["general-tests"],
}
+// Converts BackprotedFix text protos to binary protos
+genrule_defaults {
+ name: "default_backported_fix_binpbs",
+ tools: ["aprotoc"],
+ tool_files: [
+ ":backported_fixes_proto_file",
+ ],
+ cmd: "$(location aprotoc) " +
+ " --encode=com.android.build.backportedfixes.BackportedFix" +
+ " $(location :backported_fixes_proto_file)" +
+ " < $(in)" +
+ " > $(out); echo $(out)",
+}
+
gensrcs {
name: "applied_backported_fix_binpbs",
- tools: ["aprotoc"],
+ defaults: ["default_backported_fix_binpbs"],
+ output_extension: "binpb",
srcs: [
"applied_fixes/*.txtpb",
],
- tool_files: [
- "backported_fixes.proto",
- ],
- output_extension: "binpb",
- cmd: "$(location aprotoc) " +
- " --encode=com.android.build.backportedfixes.BackportedFix" +
- " $(location backported_fixes.proto)" +
- " < $(in)" +
- " > $(out); echo $(out)",
}
diff --git a/backported_fixes/src/java/com/android/build/backportedfixes/CombineBackportedFixes.java b/backported_fixes/src/java/com/android/build/backportedfixes/CombineBackportedFixes.java
new file mode 100644
index 0000000..0592cc1
--- /dev/null
+++ b/backported_fixes/src/java/com/android/build/backportedfixes/CombineBackportedFixes.java
@@ -0,0 +1,65 @@
+
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * 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.android.build.backportedfixes;
+
+import com.android.build.backportedfixes.common.Parser;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.converters.FileConverter;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+
+/** Creates a BackportedFixes binary proto file from a list of BackportedFix proto binary files. */
+public final class CombineBackportedFixes {
+
+ @Parameter(description = "BackportedFix proto binary files",
+ converter = FileConverter.class,
+ required = true)
+ List<File> fixFiles;
+ @Parameter(description = "Write the BackportedFixes proto binary to this file",
+ names = {"--out","-o"},
+ converter = FileConverter.class,
+ required = true)
+ File outFile;
+
+ public static void main(String... argv) throws Exception {
+ CombineBackportedFixes main = new CombineBackportedFixes();
+ JCommander.newBuilder().addObject(main).build().parse(argv);
+ main.run();
+ }
+
+ CombineBackportedFixes() {
+ }
+
+ private void run() throws Exception {
+ try (var out = new FileOutputStream(outFile)) {
+ var fixes = Parser.parseBackportedFixFiles(fixFiles);
+ writeBackportedFixes(fixes, out);
+ }
+ }
+
+ static void writeBackportedFixes(BackportedFixes fixes, OutputStream out)
+ throws IOException {
+ fixes.writeTo(out);
+ }
+}
diff --git a/backported_fixes/src/java/com/android/build/backportedfixes/Main.java b/backported_fixes/src/java/com/android/build/backportedfixes/WriteBackportedFixesPropFile.java
similarity index 74%
rename from backported_fixes/src/java/com/android/build/backportedfixes/Main.java
rename to backported_fixes/src/java/com/android/build/backportedfixes/WriteBackportedFixesPropFile.java
index 79148cc..0ffb4ac 100644
--- a/backported_fixes/src/java/com/android/build/backportedfixes/Main.java
+++ b/backported_fixes/src/java/com/android/build/backportedfixes/WriteBackportedFixesPropFile.java
@@ -18,7 +18,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
-import com.android.build.backportedfixes.common.ClosableCollection;
import com.android.build.backportedfixes.common.Parser;
import com.beust.jcommander.JCommander;
@@ -33,27 +32,38 @@
import java.util.List;
import java.util.stream.Collectors;
-public final class Main {
- @Parameter(description = "BackportedFix proto binary files", converter = FileConverter.class,
+
+/**
+ * Creates backported fix properties file.
+ *
+ * <p>Writes BitSet of backported fix aliases from a list of BackportedFix proto binary files and
+ * writes the property {@value PROPERTY_NAME} to a file.
+ */
+public final class WriteBackportedFixesPropFile {
+
+ private static final String PROPERTY_NAME = "ro.build.backported_fixes.alias_bitset.long_list";
+ @Parameter(description = "BackportedFix proto binary files",
+ converter = FileConverter.class,
required = true)
List<File> fixFiles;
@Parameter(description = "The file to write the property value to.",
- names = {"--property_file", "-p"}, converter = FileConverter.class, required = true)
+ names = {"--property_file", "-p"},
+ converter = FileConverter.class,
+ required = true)
File propertyFile;
public static void main(String... argv) throws Exception {
- Main main = new Main();
+ WriteBackportedFixesPropFile main = new WriteBackportedFixesPropFile();
JCommander.newBuilder().addObject(main).build().parse(argv);
main.run();
}
- Main() {
+ WriteBackportedFixesPropFile() {
}
private void run() throws Exception {
- try (var fixStreams = ClosableCollection.wrap(Parser.getFileInputStreams(fixFiles));
- var out = Files.newWriter(propertyFile, UTF_8)) {
- var fixes = Parser.parseBackportedFixes(fixStreams.getCollection());
+ try (var out = Files.newWriter(propertyFile, UTF_8)) {
+ var fixes = Parser.parseBackportedFixFiles(fixFiles);
writeFixesAsAliasBitSet(fixes, out);
}
}
@@ -70,7 +80,7 @@
fixes.getFixesList().stream().mapToInt(BackportedFix::getAlias).toArray());
String bsString = Arrays.stream(bsArray).mapToObj(Long::toString).collect(
Collectors.joining(","));
- printWriter.printf("ro.build.backported_fixes.alias_bitset.long_list=%s", bsString);
+ printWriter.printf("%s=%s", PROPERTY_NAME, bsString);
printWriter.println();
if (printWriter.checkError()) {
throw new RuntimeException("There was an error writing to " + out.toString());
diff --git a/backported_fixes/src/java/com/android/build/backportedfixes/common/ClosableCollection.java b/backported_fixes/src/java/com/android/build/backportedfixes/common/ClosableCollection.java
deleted file mode 100644
index 75b6730..0000000
--- a/backported_fixes/src/java/com/android/build/backportedfixes/common/ClosableCollection.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * 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.android.build.backportedfixes.common;
-
-import com.google.common.collect.ImmutableList;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/** An AutoCloseable holder for a collection of AutoCloseables. */
-public final class ClosableCollection<T extends AutoCloseable, C extends Collection<T>> implements
- AutoCloseable {
- C source;
-
- /** Makes the collection AutoCloseable. */
- public static <T extends AutoCloseable, C extends Collection<T>> ClosableCollection<T, C> wrap(
- C source) {
- return new ClosableCollection<>(source);
- }
-
- private ClosableCollection(C source) {
- this.source = source;
- }
-
- /** Get the source collection. */
- public C getCollection() {
- return source;
- }
-
- /**
- * Closes each item in the collection.
- *
- * @throws Exception if any close throws an an exception, a new exception is thrown with
- * all the exceptions thrown closing the streams added as a suppressed
- * exceptions.
- */
- @Override
- public void close() throws Exception {
- var failures = new ArrayList<Exception>();
- for (T t : source) {
- try {
- t.close();
- } catch (Exception e) {
- failures.add(e);
- }
- }
- if (!failures.isEmpty()) {
- Exception e = new Exception(
- "%d of %d failed while closing".formatted(failures.size(), source.size()));
- failures.forEach(e::addSuppressed);
- throw e;
- }
- }
-}
diff --git a/backported_fixes/src/java/com/android/build/backportedfixes/common/Parser.java b/backported_fixes/src/java/com/android/build/backportedfixes/common/Parser.java
index 6b08b8f..6180fdc 100644
--- a/backported_fixes/src/java/com/android/build/backportedfixes/common/Parser.java
+++ b/backported_fixes/src/java/com/android/build/backportedfixes/common/Parser.java
@@ -15,9 +15,12 @@
*/
package com.android.build.backportedfixes.common;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.android.build.backportedfixes.BackportedFix;
import com.android.build.backportedfixes.BackportedFixes;
+import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import java.io.File;
@@ -26,7 +29,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.BitSet;
+import java.util.Comparator;
import java.util.List;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
/** Static utilities for working with {@link BackportedFixes}. */
@@ -54,16 +60,79 @@
/**
* Creates a {@link BackportedFixes} from a list of {@link BackportedFix} binary proto streams.
*/
- public static BackportedFixes parseBackportedFixes(List<? extends InputStream> fixStreams)
- throws
- IOException {
- var fixes = BackportedFixes.newBuilder();
- for (var s : fixStreams) {
- BackportedFix fix = BackportedFix.parseFrom(s);
- fixes.addFixes(fix);
- s.close();
+ public static BackportedFixes parseBackportedFixFiles(List<File> fixFiles)
+ throws IOException {
+ try {
+ return fixFiles.stream().map(Parser::tunelFileInputStream)
+ .map(Parser::tunnelParse)
+ .sorted(Comparator.comparing(BackportedFix::getKnownIssue))
+ .collect(fixCollector());
+
+ } catch (TunnelException e) {
+ throw e.rethrow(FileNotFoundException.class, IOException.class);
}
- return fixes.build();
+ }
+
+
+ private static Collector<BackportedFix, ?, BackportedFixes> fixCollector() {
+ return Collectors.collectingAndThen(Collectors.toList(), fixList -> {
+ var result = BackportedFixes.newBuilder();
+ result.addAllFixes(fixList);
+ return result.build();
+ });
+ }
+
+ private static FileInputStream tunelFileInputStream(File file) throws TunnelException {
+ try {
+ return new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new TunnelException(e);
+ }
+ }
+
+ private static BackportedFix tunnelParse(InputStream s) throws TunnelException {
+ try {
+ var fix = BackportedFix.parseFrom(s);
+ s.close();
+ return fix;
+ } catch (IOException e) {
+ throw new TunnelException(e);
+ }
+ }
+
+ private static class TunnelException extends RuntimeException {
+ TunnelException(Exception cause) {
+ super("If you see this TunnelException something went wrong. It should always be rethrown as the cause.", cause);
+ }
+
+ <X extends Exception> RuntimeException rethrow(Class<X> exceptionClazz) throws X {
+ checkNotNull(exceptionClazz);
+ Throwables.throwIfInstanceOf(getCause(), exceptionClazz);
+ throw exception(
+ getCause(),
+ "rethrow(%s) doesn't match underlying exception", exceptionClazz);
+ }
+
+ public <X1 extends Exception, X2 extends Exception> RuntimeException rethrow(
+ Class<X1> exceptionClazz1, Class<X2> exceptionClazz2) throws X1, X2 {
+ checkNotNull(exceptionClazz1);
+ checkNotNull(exceptionClazz2);
+ Throwables.throwIfInstanceOf(getCause(), exceptionClazz1);
+ Throwables.throwIfInstanceOf(getCause(), exceptionClazz2);
+ throw exception(
+ getCause(),
+ "rethrow(%s, %s) doesn't match underlying exception",
+ exceptionClazz1,
+ exceptionClazz2);
+ }
+
+ private static ClassCastException exception(
+ Throwable cause, String message, Object... formatArgs) {
+ ClassCastException result = new ClassCastException(String.format(message, formatArgs));
+ result.initCause(cause);
+ return result;
+ }
+
}
private Parser() {
diff --git a/backported_fixes/tests/java/com/android/build/backportedfixes/CombineBackportedFixesTest.java b/backported_fixes/tests/java/com/android/build/backportedfixes/CombineBackportedFixesTest.java
new file mode 100644
index 0000000..21d5f1e
--- /dev/null
+++ b/backported_fixes/tests/java/com/android/build/backportedfixes/CombineBackportedFixesTest.java
@@ -0,0 +1,41 @@
+
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * 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.android.build.backportedfixes;
+
+import com.google.common.truth.Truth;
+
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/** Tests for {@link CombineBackportedFixes}. */
+public class CombineBackportedFixesTest {
+
+
+ @Test
+ public void writeBackportedFixes_default() throws IOException {
+ // Not much of a test, but there is not much to test.
+ BackportedFixes fixes = BackportedFixes.newBuilder()
+ .addFixes(BackportedFix.newBuilder().setKnownIssue(123).build())
+ .build();
+ var result = new ByteArrayOutputStream();
+ CombineBackportedFixes.writeBackportedFixes(fixes, result);
+ Truth.assertThat(BackportedFixes.parseFrom(result.toByteArray()))
+ .isEqualTo(fixes);
+ }
+}
diff --git a/backported_fixes/tests/java/com/android/build/backportedfixes/MainTest.java b/backported_fixes/tests/java/com/android/build/backportedfixes/WriteBackportedFixesPropFileTest.java
similarity index 87%
rename from backported_fixes/tests/java/com/android/build/backportedfixes/MainTest.java
rename to backported_fixes/tests/java/com/android/build/backportedfixes/WriteBackportedFixesPropFileTest.java
index 84061e1..3209c15 100644
--- a/backported_fixes/tests/java/com/android/build/backportedfixes/MainTest.java
+++ b/backported_fixes/tests/java/com/android/build/backportedfixes/WriteBackportedFixesPropFileTest.java
@@ -23,8 +23,8 @@
import java.io.PrintWriter;
import java.io.StringWriter;
-/** Tests for {@link Main}. */
-public class MainTest {
+/** Tests for {@link WriteBackportedFixesPropFile}. */
+public class WriteBackportedFixesPropFileTest {
@Test
@@ -32,7 +32,7 @@
BackportedFixes fixes = BackportedFixes.newBuilder().build();
var result = new StringWriter();
- Main.writeFixesAsAliasBitSet(fixes, new PrintWriter(result));
+ WriteBackportedFixesPropFile.writeFixesAsAliasBitSet(fixes, new PrintWriter(result));
Truth.assertThat(result.toString())
.isEqualTo("""
@@ -50,7 +50,7 @@
.build();
var result = new StringWriter();
- Main.writeFixesAsAliasBitSet(fixes, new PrintWriter(result));
+ WriteBackportedFixesPropFile.writeFixesAsAliasBitSet(fixes, new PrintWriter(result));
Truth.assertThat(result.toString())
.isEqualTo("""
diff --git a/backported_fixes/tests/java/com/android/build/backportedfixes/common/CloseableCollectionTest.java b/backported_fixes/tests/java/com/android/build/backportedfixes/common/CloseableCollectionTest.java
deleted file mode 100644
index d3d84a8..0000000
--- a/backported_fixes/tests/java/com/android/build/backportedfixes/common/CloseableCollectionTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * 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.android.build.backportedfixes.common;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.truth.Correspondence;
-import com.google.common.truth.Truth;
-
-import org.junit.Test;
-
-/** Tests for {@link ClosableCollection}. */
-public class CloseableCollectionTest {
-
- private static class FakeCloseable implements AutoCloseable {
- private final boolean throwOnClose;
- private final String name;
-
-
- private boolean isClosed = false;
-
- private FakeCloseable(String name, boolean throwOnClose) {
- this.name = name;
- this.throwOnClose = throwOnClose;
-
- }
-
- private static FakeCloseable named(String name) {
- return new FakeCloseable(name, false);
- }
-
- private static FakeCloseable failing(String name) {
- return new FakeCloseable(name, true);
- }
-
- public boolean isClosed() {
- return isClosed;
- }
-
- @Override
- public void close() throws Exception {
- if (throwOnClose) {
- throw new Exception(name + " close failed");
- }
- isClosed = true;
- }
- }
-
-
- @Test
- public void bothClosed() throws Exception {
- var c = ImmutableSet.of(FakeCloseable.named("foo"), FakeCloseable.named("bar"));
- try (var cc = ClosableCollection.wrap(c);) {
- Truth.assertThat(cc.getCollection()).isSameInstanceAs(c);
- }
- Truth.assertThat(c)
- .comparingElementsUsing(
- Correspondence.transforming(FakeCloseable::isClosed, "is closed"))
- .containsExactly(true, true);
- }
-
- @Test
- public void bothFailed() {
- var c = ImmutableSet.of(FakeCloseable.failing("foo"), FakeCloseable.failing("bar"));
-
- try {
- try (var cc = ClosableCollection.wrap(c);) {
- Truth.assertThat(cc.getCollection()).isSameInstanceAs(c);
- }
- } catch (Exception e) {
- Truth.assertThat(e).hasMessageThat().isEqualTo("2 of 2 failed while closing");
- Truth.assertThat(e.getSuppressed())
- .asList()
- .comparingElementsUsing(
- Correspondence.transforming(Exception::getMessage, "has a message of "))
- .containsExactly("foo close failed", "bar close failed");
- }
- }
-}
diff --git a/backported_fixes/tests/java/com/android/build/backportedfixes/common/ParserTest.java b/backported_fixes/tests/java/com/android/build/backportedfixes/common/ParserTest.java
index 444e694..57a0a40 100644
--- a/backported_fixes/tests/java/com/android/build/backportedfixes/common/ParserTest.java
+++ b/backported_fixes/tests/java/com/android/build/backportedfixes/common/ParserTest.java
@@ -23,15 +23,21 @@
import com.google.common.collect.ImmutableList;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
-import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
/** Tests for {@link Parser}.*/
public class ParserTest {
+ @Rule
+ public TemporaryFolder mTempFolder = new TemporaryFolder();
+
@Test
public void getFileInputStreams() throws IOException {
var results = Parser.getFileInputStreams(
@@ -53,15 +59,15 @@
}
@Test
- public void parseBackportedFixes_empty() throws IOException {
- var result = Parser.parseBackportedFixes(ImmutableList.of());
+ public void parseBackportedFixFiles_empty() throws IOException {
+ var result = Parser.parseBackportedFixFiles(ImmutableList.of());
assertThat(result).isEqualTo(BackportedFixes.getDefaultInstance());
}
+
@Test
- public void parseBackportedFixes_oneBlank() throws IOException {
- var result = Parser.parseBackportedFixes(
- ImmutableList.of(inputStream(BackportedFix.getDefaultInstance())));
+ public void parseBackportedFixFiles_oneBlank() throws IOException {
+ var result = Parser.parseBackportedFixFiles(ImmutableList.of(mTempFolder.newFile()));
assertThat(result).isEqualTo(
BackportedFixes.newBuilder()
@@ -70,7 +76,7 @@
}
@Test
- public void parseBackportedFixes_two() throws IOException {
+ public void parseBackportedFixFiles_two() throws IOException {
BackportedFix ki123 = BackportedFix.newBuilder()
.setKnownIssue(123)
.setAlias(1)
@@ -79,8 +85,8 @@
.setKnownIssue(456)
.setAlias(2)
.build();
- var result = Parser.parseBackportedFixes(
- ImmutableList.of(inputStream(ki123), inputStream(ki456)));
+ var result = Parser.parseBackportedFixFiles(
+ ImmutableList.of(tempFile(ki456), tempFile(ki123)));
assertThat(result).isEqualTo(
BackportedFixes.newBuilder()
.addFixes(ki123)
@@ -88,7 +94,11 @@
.build());
}
- private static ByteArrayInputStream inputStream(BackportedFix f) {
- return new ByteArrayInputStream(f.toByteArray());
+ private File tempFile(BackportedFix fix) throws IOException {
+ File f = mTempFolder.newFile();
+ try (FileOutputStream out = new FileOutputStream(f)) {
+ fix.writeTo(out);
+ return f;
+ }
}
}