SeleniumServerExecution execute(Command command) throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(1); log.info("Running Selenium server process: " + command.toString()); server = Spacelift .task(CommandTool.class) .command(command) .interaction(new BinaryInteraction() .outputPrefix("[Selenium server] ") .printToOut(".*") .when(".+Selenium.+is up and running$") .thenCountDown(countDownLatch) .build()) .execute(); server.registerShutdownHook(); countDownLatch.await(10, TimeUnit.SECONDS); return this; }
SeleniumServerExecution execute(Command command) throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(1); log.info("Running Selenium server process: " + command.toString()); server = Spacelift .task(CommandTool.class) .command(command) .interaction(new BinaryInteraction() .outputPrefix("[Selenium server] ") .printToOut(".*") .when(".+Selenium.+is up and running$") .thenCountDown(countDownLatch) .build()) .execute(); server.registerShutdownHook(); countDownLatch.await(10, TimeUnit.SECONDS); return this; }
private void loadProcessMap() { try { processMap.clear(); Command command = new CommandBuilder(androidSDK.getAdbPath()) .parameter("-s") .parameter(androidDevice.getSerialNumber()) .parameter("shell") .parameter("ps") .build(); List<String> runningProcesses = Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command).execute().await().output(); Pattern pattern = Pattern .compile(".*?\\s+([0-9]+)\\s+[0-9]+\\s+[0-9]+\\s+[0-9]+\\s+[0-9a-f]+\\s+[0-9a-f]+\\s.?\\s(.*)"); for(String line: runningProcesses) { Matcher matcher = pattern.matcher(line); if (!matcher.matches()) { continue; } Integer processId = Integer.valueOf(matcher.group(1)); String processName = matcher.group(2); processMap.put(processId, processName); } } catch (ExecutionException e) { logger.log(Level.SEVERE, "Couldn't load process map!", e); } } }
private List<String> execCommandAsArray(String... arguments) { Command allowExecCmd = new CommandBuilder(arguments).build(); ProcessResult processResult = Spacelift.task(CommandTool.class) .command(allowExecCmd) .execute() .await(); return processResult.output(); } }
public List<String> execCommandAsArray(String... arguments) { Command allowExecCmd = new CommandBuilder(arguments).build(); ProcessResult processResult = Spacelift.task(CommandTool.class) .command(allowExecCmd) .execute() .await(); return processResult.output(); } }
@Override public void startRecording(String remoteFilePath, ScreenrecordOptions options) throws Exception { if (isRecording()) { throw new IllegalStateException("Android device is already recording the video."); } Validate.notNullOrEmpty(remoteFilePath, "remoteFilePath for taken video is a null object"); recordedVideoRemote = remoteFilePath; Validate.notNull(options, "options for recording of a video is a null object"); CommandTool screenRecorderTool = new ScreenRecordToolBuilder() .androidSdk(androidSdk) .options(options) .remoteFilePath(recordedVideoRemote) .build(); screenrecorderExecution = screenRecorderTool.execute(); }
@Override protected ProcessResult process(Integer pid) throws Exception { Validate.notNull(pid, "PID for process to kill is a null object!"); Validate.notNull(androidSdk, "Android SDK is a null object!"); if (pid <= 0) { throw new IllegalStateException("PID to kill is lower then 0."); } ProcessResult processResult = Spacelift.task(CommandTool.class) .programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameters("shell", "kill", "-" + signum, pid.toString()) .execute().await(); return processResult; } }
private List<String> execCommandAsArray(String... arguments) { Command allowExecCmd = new CommandBuilder(arguments).build(); ProcessResult processResult = Spacelift.task(CommandTool.class) .command(allowExecCmd) .execute() .await(); return processResult.output(); } }
public List<String> execCommandAsArray(String... arguments) { Command allowExecCmd = new CommandBuilder(arguments).build(); ProcessResult processResult = Spacelift.task(CommandTool.class) .command(allowExecCmd) .execute() .await(); return processResult.output(); } }
public List<Target> parse() { List<String> output = Spacelift.task(CommandTool.class) .addEnvironment(platformConfiguration.getAndroidSystemEnvironmentProperties()) .programName(androidSdk.getAndroidPath()) .parameters("list", "target") .execute().await() .output(); return parseAndroidListTargetOutput(new LinkedList<String>(output)); }
@Override protected Void process(Object input) throws Exception { try { CommandTool ct = Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()); ct.command(new CommandBuilder(sdk.getAdbPath()) .parameters("-s", serialNumber, "shell", "input", "keyevent", "82")) .execute() .await(); ct.command(new CommandBuilder(sdk.getAdbPath()) .parameters("-s", serialNumber, "shell", "input", "keyevent", "4")) .execute() .await(); } catch (ExecutionException ex) { logger.log(Level.WARNING, "Unlocking device failed", ex); } return null; }
@Override protected Integer process(String androidProcessName) throws Exception { Validate.notNullOrEmpty(androidProcessName, "Android process name to get PID of is a null object or an empty string."); Validate.notNull(androidSdk, "Android SDK is a null object!"); ProcessResult psResult = Spacelift.task(CommandTool.class).programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameter("shell") .parameter("ps") .execute().await(); int pid = -1; for (String psLine : psResult.output()) { if (psLine != null && psLine.trim().endsWith(androidProcessName)) { pid = parsePid(psLine.trim(), androidProcessName); break; } } return pid; }
@Override protected Boolean process(String processName) throws Exception { Validate.notNullOrEmpty(processName, "Process name to get running status of is a null object or it is an empty string!"); Validate.notNull(androidSdk, "AndroidSDK is null object!"); List<String> psOutput = Spacelift.task(CommandTool.class) .programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameter("shell") .parameter("ps") .execute().await() .output(); boolean running = false; for (String outputLine : psOutput) { if (outputLine != null) { if (outputLine.trim().endsWith(processName)) { running = true; break; } } } return running; }
private List<String> getAAPTXmlTreeOutput(File apkFile) { final Command command = new CommandBuilder(sdk.getAaptPath()) .parameter("dump") .parameter("xmltree") .parameter(apkFile.getAbsolutePath()) .parameter("AndroidManifest.xml") .build(); return Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command) .execute() .await() .output(); }
private BadgingOutput getAAPTBadgingOutput(File apk) { final Command command = new CommandBuilder(sdk.getAaptPath()) .parameter("dump") .parameter("badging") .parameter(apk.getAbsolutePath()) .build(); return new BadgingOutput(Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command) .execute() .await() .output()); }
@Override protected File process(File toSign) throws Exception { if (toSign == null || !toSign.exists()) { throw new IllegalStateException("File to be signed is either null or it does not exists"); } Spacelift.task(CheckKeyStoreTask.class).sdk(androidSDK).execute().await(); File signed = new File(androidSDK.getPlatformConfiguration().getTmpDir(), DroidiumFileUtils.getRandomAPKFileName()); Command jarSignerCommand = new CommandBuilder(androidSDK.getPathForJavaTool("jarsigner")) .parameter("-sigalg").parameter("MD5withRSA") .parameter("-digestalg").parameter("SHA1") .parameter("-signedjar").parameter(signed.getAbsolutePath()) .parameter("-storepass").parameter(androidSDK.getPlatformConfiguration().getStorepass()) .parameter("-keystore").parameter(new File(androidSDK.getPlatformConfiguration().getKeystore()).getAbsolutePath()) .parameter(toSign.getAbsolutePath()) .parameter(androidSDK.getPlatformConfiguration().getAlias()) .build(); Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(jarSignerCommand).execute().await(); return signed; } }
private List<String> getAndroidListAVDOutput(boolean compact) { try { CommandBuilder cb = new CommandBuilder(androidSDK.get().getAndroidPath()) .parameter("list") .parameter("avd"); if (compact) { cb.parameter("-c"); } Command command = cb.build(); return Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.get().getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command).execute().await().output(); } catch (ExecutionException ex) { throw new AndroidExecutionException(ex, "Unable to get list of AVDs"); } }
@Override public void createSDCard(SDCard sdCard) throws AndroidExecutionException { AndroidSDCard androidSDCard = (AndroidSDCard) sdCard; AndroidSDK sdk = androidSDK.get(); Command command = new CommandBuilder(sdk.getMakeSdCardPath()) .parameter("-l") .parameter(androidSDCard.getLabel()) .parameter(androidSDCard.getSize()) .parameter(androidSDCard.getFileName()) .build(); try { Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.get().getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command).execute().await(); } catch (ExecutionException ex) { throw new AndroidExecutionException("Unable to create SD card", ex); } logger.log(Level.INFO, "Android SD card labelled {0} located at {1} with size of {2} was created.", new Object[] { androidSDCard.getLabel(), androidSDCard.getFileName(), androidSDCard.getSize() }); } }
public void deleteAndroidVirtualDevice(@Observes AndroidVirtualDeviceDelete event) { AndroidContainerConfiguration configuration = this.configuration.get(); AndroidSDK sdk = androidSDK.get(); String avdName = configuration.getAvdName(); try { Command deleteAvdCommand = new CommandBuilder(sdk.getAndroidPath()) .parameter("delete") .parameter("avd") .parameter("-n") .parameter(avdName) .build(); Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(deleteAvdCommand).execute().await(); logger.log(Level.INFO, "Android Virtual Device {0} deleted.", avdName); } catch (AndroidExecutionException ex) { throw new AndroidExecutionException("Unable to delete Android Virtual device " + avdName, ex); } androidSDCardDelete.fire(new AndroidSDCardDelete()); androidVirtualDeviceDeleted.fire(new AndroidVirtualDeviceDeleted(configuration.getAvdName())); }
@Override protected File process(File input) throws Exception { if (input == null && keyStoreToCreate != null) { input = keyStoreToCreate; } Command createKeyStoreCommand = new CommandBuilder(androidSDK.getPathForJavaTool("keytool")) .parameter("-genkey") .parameter("-v") .parameter("-keystore") .parameter(input.getAbsolutePath()) .parameter("-storepass") .parameter(androidSDK.getPlatformConfiguration().getStorepass()) .parameter("-alias") .parameter(androidSDK.getPlatformConfiguration().getAlias()) .parameter("-keypass") .parameter(androidSDK.getPlatformConfiguration().getKeypass()) .parameter("-dname") .parameter("CN=Android,O=Android,C=US") .parameter("-storetype") .parameter("JKS") .parameter("-sigalg") .parameter(androidSDK.getPlatformConfiguration().getSigalg()) .parameter("-keyalg") .parameter(androidSDK.getPlatformConfiguration().getKeyalg()) .build(); Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(createKeyStoreCommand).execute().await(); return keyStoreToCreate; }