Search in sources :

Example 1 with AppLauncherCallback

use of org.robovm.libimobiledevice.util.AppLauncherCallback 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

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