1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.cts.releaseparser; 18 19 import com.android.cts.releaseparser.ReleaseProto.*; 20 import com.google.protobuf.TextFormat; 21 22 import java.io.FileOutputStream; 23 import java.nio.charset.Charset; 24 import java.nio.file.Paths; 25 import java.util.logging.Logger; 26 27 /** Main of release parser */ 28 public class Main { Main()29 private Main() {} 30 31 private static final String USAGE_MESSAGE = 32 "Usage: java -jar releaseparser.jar [-options <parameter>]...\n" 33 + "\tto prase a release, such as device build, test suite or app distribution package\n" 34 + "Options:\n" 35 + "\t-i PATH\t path to a release folder\n" 36 + "\t-o PATH\t path to output files\n"; 37 main(final String[] args)38 public static void main(final String[] args) { 39 try { 40 ArgumentParser argParser = new ArgumentParser(args); 41 String relFolder = argParser.getParameterElement("i", 0); 42 String outputPath = argParser.getParameterElement("o", 0); 43 44 // parse a release folder 45 ReleaseParser relParser = new ReleaseParser(relFolder); 46 String relNameVer = relParser.getReleaseId(); 47 relParser.writeRelesaeContentCsvFile( 48 relNameVer, getPathString(outputPath, "%s-ReleaseContent.csv", relNameVer)); 49 50 // write release content JSON file 51 JsonPrinter jPrinter = 52 new JsonPrinter( 53 relParser.getReleaseContent(), 54 getPathString(outputPath, "%s", relNameVer)); 55 jPrinter.write(); 56 57 // Write release content message to disk. 58 ReleaseContent relContent = relParser.getReleaseContent(); 59 FileOutputStream output = 60 new FileOutputStream( 61 getPathString(outputPath, "%s-ReleaseContent.pb", relNameVer)); 62 relContent.writeTo(output); 63 output.flush(); 64 output.close(); 65 66 FileOutputStream txtOutput = 67 new FileOutputStream( 68 getPathString(outputPath, "%s-ReleaseContent.txt", relNameVer)); 69 txtOutput.write( 70 TextFormat.printToString(relContent).getBytes(Charset.forName("UTF-8"))); 71 txtOutput.flush(); 72 txtOutput.close(); 73 74 // parse Test Suite 75 TestSuiteParser tsParser = new TestSuiteParser(relContent, relFolder); 76 if (tsParser.getTestSuite().getModulesList().size() == 0) { 77 // skip if no test module 78 return; 79 } 80 81 // write Known Failus & etc. CSV files 82 relParser.writeKnownFailureCsvFile( 83 relNameVer, getPathString(outputPath, "%s-KnownFailure.csv", relNameVer)); 84 tsParser.writeCsvFile( 85 relNameVer, getPathString(outputPath, "%s-TestCase.csv", relNameVer)); 86 tsParser.writeModuleCsvFile( 87 relNameVer, getPathString(outputPath, "%s-TestModule.csv", relNameVer)); 88 89 // Write test suite content message to disk. 90 TestSuite testSuite = tsParser.getTestSuite(); 91 FileOutputStream tsOutput = 92 new FileOutputStream(getPathString(outputPath, "%s-TestSuite.pb", relNameVer)); 93 testSuite.writeTo(tsOutput); 94 tsOutput.flush(); 95 tsOutput.close(); 96 } catch (Exception ex) { 97 System.out.println(USAGE_MESSAGE); 98 ex.printStackTrace(); 99 } 100 } 101 getPathString(String outputPath, String format, String id)102 public static String getPathString(String outputPath, String format, String id) { 103 return Paths.get(outputPath, String.format(format, id)).toString(); 104 } 105 getLogger()106 private static Logger getLogger() { 107 return Logger.getLogger(Main.class.getSimpleName()); 108 } 109 }