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 17package vogar.tasks; 18 19import java.io.File; 20import vogar.Result; 21import vogar.Run; 22import vogar.Target; 23import vogar.Vogar; 24 25public final class PrepareTarget extends Task { 26 private final Run run; 27 private final Target target; 28 29 public PrepareTarget(Run run, Target target) { 30 super("prepare target"); 31 this.run = run; 32 this.target = target; 33 } 34 35 @Override protected Result execute() throws Exception { 36 // Even if runner dir is /vogar/run, the grandparent will be / (and non-null) 37 target.await(run.runnerDir.getParentFile().getParentFile()); 38 if (run.cleanBefore) { 39 target.rm(run.runnerDir); 40 } 41 target.mkdirs(run.runnerDir); 42 target.mkdirs(run.vogarTemp()); 43 target.mkdirs(run.dalvikCache()); 44 for (int i = 0; i < Vogar.NUM_PROCESSORS; i++) { 45 target.forwardTcp(run.firstMonitorPort + i); 46 } 47 // Only forward port if we need to bind to a remote port ourselves. In app debugging DDMS 48 // takes care of opening a port on the device and forwarding it. 49 if (run.debugPort != null) { 50 target.forwardTcp(run.debugPort); 51 } 52 target.mkdirs(run.deviceUserHome); 53 54 // push ~/.caliperrc to device if found 55 File hostCaliperRc = Vogar.dotFile(".caliperrc"); 56 if (hostCaliperRc.exists()) { 57 target.push(hostCaliperRc, new File(run.deviceUserHome, ".caliperrc")); 58 } 59 return Result.SUCCESS; 60 } 61} 62