Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2014 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.tradefed.targetprep;
     18 
     19 import com.android.tradefed.build.IBuildInfo;
     20 import com.android.tradefed.config.Option;
     21 import com.android.tradefed.config.Option.Importance;
     22 import com.android.tradefed.config.OptionClass;
     23 import com.android.tradefed.device.DeviceNotAvailableException;
     24 import com.android.tradefed.device.ITestDevice;
     25 import com.android.tradefed.util.FileUtil;
     26 
     27 import java.io.File;
     28 import java.util.ArrayList;
     29 import java.util.Collection;
     30 
     31 /** A {@link ITargetCleaner} that removes filesystem files on teardown */
     32 @OptionClass(alias = "file-cleaner")
     33 public class FileCleaner extends BaseTargetPreparer implements ITargetCleaner {
     34 
     35     @Option(name = "apk-path", description =
     36         "the filesystem path of the apk to cleanup. Can be repeated.",
     37         importance = Importance.IF_UNSET)
     38     private Collection<File> mApkPaths = new ArrayList<File>();
     39 
     40     @Override
     41     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
     42             BuildError, DeviceNotAvailableException {
     43         // ignore
     44 
     45     }
     46 
     47     @Override
     48     public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
     49             throws DeviceNotAvailableException {
     50         for (File file : mApkPaths) {
     51             FileUtil.deleteFile(file);
     52         }
     53     }
     54 }
     55