Home | History | Annotate | Download | only in suite
      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.suite;
     17 
     18 /** Reporter that allows to generate reports in a particular format. TODO: fix logged file */
     19 public abstract class FormattedGeneratorReporter extends SuiteResultReporter {
     20 
     21     /** {@inheritDoc} */
     22     @Override
     23     public final void invocationEnded(long elapsedTime) {
     24         // Let the parent create the results structures
     25         super.invocationEnded(elapsedTime);
     26 
     27         SuiteResultHolder holder = generateResultHolder();
     28 
     29         IFormatterGenerator generator = createFormatter();
     30 
     31         finalizeResults(generator, holder);
     32     }
     33 
     34     /**
     35      * Step that handles using the {@link IFormatterGenerator} and the {@link SuiteResultHolder} in
     36      * order to generate some formatted results.
     37      *
     38      * @param generator
     39      * @param resultHolder
     40      */
     41     public abstract void finalizeResults(
     42             IFormatterGenerator generator, SuiteResultHolder resultHolder);
     43 
     44     /** Returns a new instance of the {@link IFormatterGenerator} to use. */
     45     public abstract IFormatterGenerator createFormatter();
     46 
     47     private SuiteResultHolder generateResultHolder() {
     48         final SuiteResultHolder holder = new SuiteResultHolder();
     49         holder.context = getInvocationContext();
     50 
     51         holder.runResults = getRunResults();
     52         //holder.loggedFiles = mLoggedFiles;
     53         holder.modulesAbi = getModulesAbi();
     54 
     55         holder.completeModules = getCompleteModules();
     56         holder.totalModules = getTotalModules();
     57         holder.passedTests = getPassedTests();
     58         holder.failedTests = getFailedTests();
     59 
     60         holder.startTime = getStartTime();
     61         holder.endTime = getElapsedTime() + getStartTime();
     62 
     63         return holder;
     64     }
     65 }
     66