17850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com/* 27850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * Copyright (C) 2010 The Android Open Source Project 37850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * 47850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * Licensed under the Apache License, Version 2.0 (the "License"); 57850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * you may not use this file except in compliance with the License. 67850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * You may obtain a copy of the License at 77850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * 87850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * http://www.apache.org/licenses/LICENSE-2.0 97850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * 107850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * Unless required by applicable law or agreed to in writing, software 117850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * distributed under the License is distributed on an "AS IS" BASIS, 127850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * See the License for the specific language governing permissions and 147850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com * limitations under the License. 157850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com */ 167850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com 177850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.compackage vogar; 187850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com 1983672b1eeb88b7b8e04126a8656ac4594f676a54Elliott Hughesimport com.google.common.collect.ImmutableList; 207850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.comimport java.io.File; 217029503206e4c89fe167c3389c1062d89cf35c52Paul Duffinimport java.io.FileNotFoundException; 220eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.comimport java.util.Arrays; 230eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.comimport java.util.List; 240eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.comimport vogar.commands.Command; 257029503206e4c89fe167c3389c1062d89cf35c52Paul Duffinimport vogar.commands.Mkdir; 267029503206e4c89fe167c3389c1062d89cf35c52Paul Duffinimport vogar.commands.Rm; 277850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com 28db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com/** 29db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com * Run tests on the host machine. 30db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com */ 310eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.compublic final class LocalTarget extends Target { 32db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com 33411cb1fb67241125203629229600ecbd821eb9c7Paul Duffin private static final ImmutableList<String> TARGET_PROCESS_PREFIX = ImmutableList.of("sh", "-c"); 34411cb1fb67241125203629229600ecbd821eb9c7Paul Duffin 357029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin private final Log log; 367029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin 377029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin private final Mkdir mkdir; 387029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin 397029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin private final Rm rm; 407029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin 417029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin public LocalTarget(Log log, Mkdir mkdir, Rm rm) { 427029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin this.mkdir = mkdir; 437029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin this.rm = rm; 447029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin this.log = log; 45f83be5e4273263df2bb9ef609946b911695b3996jessewilson@google.com } 467850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com 477029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin public static File defaultDeviceDir() { 480eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com return new File("/tmp/vogar"); 497850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com } 50ce1223de05f8d4d34f1607b11043c7f04ce00e12jsharpe@google.com 51411cb1fb67241125203629229600ecbd821eb9c7Paul Duffin @Override protected ImmutableList<String> targetProcessPrefix() { 52411cb1fb67241125203629229600ecbd821eb9c7Paul Duffin return TARGET_PROCESS_PREFIX; 53db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com } 54db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com 550eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public String getDeviceUserName() { 560eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com throw new UnsupportedOperationException(); 57ce1223de05f8d4d34f1607b11043c7f04ce00e12jsharpe@google.com } 58ce1223de05f8d4d34f1607b11043c7f04ce00e12jsharpe@google.com 590eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void await(File nonEmptyDirectory) { 60db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com } 61db82cde9016d812b26b6c79e375fdf60ead1d9fajessewilson@google.com 620eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void rm(File file) { 637029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin rm.file(file); 640eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 650eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com 667029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin @Override public List<File> ls(File directory) throws FileNotFoundException { 677029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin File[] files = directory.listFiles(); 687029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin if (files == null) { 697029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin throw new FileNotFoundException(directory + " not found."); 707029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin } 717029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin return Arrays.asList(files); 720eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 730eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com 740eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void mkdirs(File file) { 757029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin mkdir.mkdirs(file); 760eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 770eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com 780eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void forwardTcp(int port) { 790eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com // do nothing 800eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 810eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com 820eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void push(File local, File remote) { 830eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com if (remote.equals(local)) { 840eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com return; 850eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 860eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com // if the user dir exists, cp would copy the files to the wrong place 870eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com if (remote.exists()) { 880eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com throw new IllegalStateException(); 890eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 907029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin new Command(log, "cp", "-r", local.toString(), remote.toString()).execute(); 910eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com } 920eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com 930eb0936e90bf11463c8ee937ca996d7bd654a098jessewilson@google.com @Override public void pull(File remote, File local) { 947029503206e4c89fe167c3389c1062d89cf35c52Paul Duffin new Command(log, "cp", remote.getPath(), local.getPath()).execute(); 95ce1223de05f8d4d34f1607b11043c7f04ce00e12jsharpe@google.com } 967850f3f3da0099b76f09ed64d23e0a43ba4a5c76jessewilson@google.com} 97