Search in sources :

Example 1 with IDevice

use of org.robovm.libimobiledevice.IDevice in project robovm by robovm.

the class AppLauncher method main.

public static void main(String[] args) throws Exception {
    String appId = null;
    File localAppPath = null;
    String[] arguments = new String[0];
    Map<String, String> env = new HashMap<>();
    boolean debug = false;
    String deviceId = null;
    int forwardPort = -1;
    int i = 0;
    loop: while (i < args.length) {
        switch(args[i++]) {
            case "-h":
            case "-help":
                printUsageAndExit();
                break;
            case "-appid":
                appId = args[i++];
                break;
            case "-b":
                localAppPath = new File(args[i++]);
                break;
            case "-f":
                forwardPort = Integer.parseInt(args[i++]);
                break;
            case "-udid":
                deviceId = args[i++];
                break;
            case "-env":
                String[] parts = args[i++].split("=", 2);
                env.put(parts[0], parts[1]);
                break;
            case "-debug":
                debug = true;
                break;
            case "-args":
                arguments = Arrays.copyOfRange(args, i, args.length);
                break loop;
        }
    }
    if (appId == null && localAppPath == null) {
        printUsageAndExit();
    }
    if (deviceId == null) {
        String[] udids = IDevice.listUdids();
        if (udids.length == 0) {
            System.err.println("No device connected");
            return;
        }
        if (udids.length > 1) {
            System.err.println("More than 1 device connected (" + Arrays.asList(udids) + "). Using " + udids[0]);
        }
        deviceId = udids[0];
    }
    IDevice device = new IDevice(deviceId);
    AppLauncher launcher = null;
    if (localAppPath != null) {
        launcher = new AppLauncher(device, localAppPath);
    } else {
        launcher = new AppLauncher(device, appId);
    }
    System.exit(launcher.args(arguments).env(env).debug(debug).forward(forwardPort).launch());
}
Also used : HashMap(java.util.HashMap) IDevice(org.robovm.libimobiledevice.IDevice) NSString(com.dd.plist.NSString) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 2 with IDevice

use of org.robovm.libimobiledevice.IDevice in project robovm by robovm.

the class IOSTarget method createIOSDevLauncher.

private Launcher createIOSDevLauncher(LaunchParameters launchParameters) throws IOException {
    IOSDeviceLaunchParameters deviceLaunchParameters = (IOSDeviceLaunchParameters) launchParameters;
    String deviceId = deviceLaunchParameters.getDeviceId();
    int forwardPort = deviceLaunchParameters.getForwardPort();
    AppLauncherCallback callback = deviceLaunchParameters.getAppPathCallback();
    if (deviceId == null) {
        String[] udids = IDevice.listUdids();
        if (udids.length == 0) {
            throw new RuntimeException("No devices connected");
        }
        if (udids.length > 1) {
            config.getLogger().warn("More than 1 device connected (%s). " + "Using %s.", Arrays.asList(udids), udids[0]);
        }
        deviceId = udids[0];
    }
    device = new IDevice(deviceId);
    OutputStream out = null;
    if (launchParameters.getStdoutFifo() != null) {
        out = new OpenOnWriteFileOutputStream(launchParameters.getStdoutFifo());
    } else {
        out = System.out;
    }
    Map<String, String> env = launchParameters.getEnvironment();
    if (env == null) {
        env = new HashMap<>();
    }
    AppLauncher launcher = new AppLauncher(device, getAppDir()) {

        protected void log(String s, Object... args) {
            config.getLogger().info(s, args);
        }
    }.stdout(out).closeOutOnExit(true).args(launchParameters.getArguments().toArray(new String[0])).env(env).forward(forwardPort).appLauncherCallback(callback).xcodePath(ToolchainUtil.findXcodePath()).uploadProgressCallback(new UploadProgressCallback() {

        boolean first = true;

        public void success() {
            config.getLogger().info("[100%%] Upload complete");
        }

        public void progress(File path, int percentComplete) {
            if (first) {
                config.getLogger().info("[  0%%] Beginning upload...");
            }
            first = false;
            config.getLogger().info("[%3d%%] Uploading %s...", percentComplete, path);
        }

        public void error(String message) {
        }
    }).installStatusCallback(new StatusCallback() {

        boolean first = true;

        public void success() {
            config.getLogger().info("[100%%] Install complete");
        }

        public void progress(String status, int percentComplete) {
            if (first) {
                config.getLogger().info("[  0%%] Beginning installation...");
            }
            first = false;
            config.getLogger().info("[%3d%%] %s", percentComplete, status);
        }

        public void error(String message) {
        }
    });
    return new AppLauncherProcess(config.getLogger(), launcher, launchParameters);
}
Also used : AppLauncherCallback(org.robovm.libimobiledevice.util.AppLauncherCallback) OutputStream(java.io.OutputStream) OpenOnWriteFileOutputStream(org.robovm.compiler.util.io.OpenOnWriteFileOutputStream) IDevice(org.robovm.libimobiledevice.IDevice) StatusCallback(org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback) NSString(com.dd.plist.NSString) NSObject(com.dd.plist.NSObject) UploadProgressCallback(org.robovm.libimobiledevice.AfcClient.UploadProgressCallback) OpenOnWriteFileOutputStream(org.robovm.compiler.util.io.OpenOnWriteFileOutputStream) AppLauncher(org.robovm.libimobiledevice.util.AppLauncher) File(java.io.File)

Aggregations

NSString (com.dd.plist.NSString)2 File (java.io.File)2 IDevice (org.robovm.libimobiledevice.IDevice)2 NSObject (com.dd.plist.NSObject)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 ZipFile (java.util.zip.ZipFile)1 OpenOnWriteFileOutputStream (org.robovm.compiler.util.io.OpenOnWriteFileOutputStream)1 UploadProgressCallback (org.robovm.libimobiledevice.AfcClient.UploadProgressCallback)1 StatusCallback (org.robovm.libimobiledevice.InstallationProxyClient.StatusCallback)1 AppLauncher (org.robovm.libimobiledevice.util.AppLauncher)1 AppLauncherCallback (org.robovm.libimobiledevice.util.AppLauncherCallback)1