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 package com.android.tradefed.result.proto; 17 18 import com.android.tradefed.config.Option; 19 import com.android.tradefed.log.LogUtil.CLog; 20 import com.android.tradefed.result.proto.TestRecordProto.TestRecord; 21 22 import java.io.File; 23 import java.io.FileOutputStream; 24 import java.io.IOException; 25 26 /** Proto reporter that dumps the {@link TestRecord} into a file. */ 27 public class FileProtoResultReporter extends ProtoResultReporter { 28 29 @Option( 30 name = "proto-output-file", 31 description = "File where the proto output will be saved", 32 mandatory = true 33 ) 34 private File mOutputFile; 35 36 @Override processFinalProto(TestRecord finalRecord)37 public void processFinalProto(TestRecord finalRecord) { 38 try { 39 finalRecord.writeDelimitedTo(new FileOutputStream(mOutputFile)); 40 } catch (IOException e) { 41 CLog.e(e); 42 throw new RuntimeException(e); 43 } 44 } 45 46 /** Sets the file where to output the result. */ setFileOutput(File output)47 public void setFileOutput(File output) { 48 mOutputFile = output; 49 } 50 } 51