1 /* 2 * Copyright (C) 2011 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 vogar.tasks; 18 19 import java.io.File; 20 import java.io.FileFilter; 21 import java.io.FileNotFoundException; 22 import vogar.Result; 23 import vogar.Run; 24 25 public final class RetrieveFilesTask extends Task { 26 private final Run run; 27 private final File deviceFile; 28 29 public RetrieveFilesTask(Run run, File deviceFile) { 30 super("retrieve files " + deviceFile); 31 this.run = run; 32 this.deviceFile = deviceFile; 33 } 34 35 @Override protected Result execute() throws Exception { 36 retrieveFiles(new File("./vogar-results"), deviceFile, run.retrievedFiles); 37 return Result.SUCCESS; 38 } 39 40 /** 41 * Scans {@code dir} for files to grab. 42 */ 43 private void retrieveFiles(File destination, File source, FileFilter filenameFilter) 44 throws FileNotFoundException { 45 for (File file : run.target.ls(source)) { 46 if (filenameFilter.accept(file)) { 47 run.log.info("Moving " + file + " to " + destination); 48 run.mkdir.mkdirs(destination); 49 run.target.pull(file, destination); 50 } 51 } 52 } 53 } 54