• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2024 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package com.android.build.backportedfixes;
18 
19 import com.android.build.backportedfixes.common.Parser;
20 
21 import com.beust.jcommander.JCommander;
22 import com.beust.jcommander.Parameter;
23 import com.beust.jcommander.converters.FileConverter;
24 
25 import java.io.File;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.util.List;
30 
31 
32 /** Creates a BackportedFixes binary proto file from a list of BackportedFix proto binary files. */
33 public final class CombineBackportedFixes {
34 
35     @Parameter(description = "BackportedFix proto binary files",
36             converter = FileConverter.class,
37             required = true)
38     List<File> fixFiles;
39     @Parameter(description = "Write the BackportedFixes proto binary to this file",
40             names = {"--out","-o"},
41             converter = FileConverter.class,
42             required = true)
43     File outFile;
44 
main(String... argv)45     public static void main(String... argv) throws Exception {
46         CombineBackportedFixes main = new CombineBackportedFixes();
47         JCommander.newBuilder().addObject(main).build().parse(argv);
48         main.run();
49     }
50 
CombineBackportedFixes()51     CombineBackportedFixes() {
52     }
53 
run()54     private void run() throws Exception {
55         try (var out = new FileOutputStream(outFile)) {
56             var fixes = Parser.parseBackportedFixFiles(fixFiles);
57             writeBackportedFixes(fixes, out);
58         }
59     }
60 
writeBackportedFixes(BackportedFixes fixes, OutputStream out)61     static void writeBackportedFixes(BackportedFixes fixes, OutputStream out)
62             throws IOException {
63         fixes.writeTo(out);
64     }
65 }
66