use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class LocalPlatformJavaApplicationTest method hasJDB.
/**
* Determine if Java Debugging is available by attempting to launch the Java Debugger.
*
* @return <code>true</code> if "jdb" is available, <code>false</code> otherwise
*
* @throws Exception
*/
protected boolean hasJDB() throws Exception {
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (Application jdb = LocalPlatform.get().launch(Application.class, Executable.named("jdb"), Argument.of("-version"), DisplayName.of("JDB"), Console.of(console))) {
Eventually.assertThat(invoking(console).getCapturedOutputLines(), hasItem(startsWith("This is jdb version")));
console.getInputWriter().println("quit");
jdb.waitFor();
return true;
} catch (Throwable t) {
return false;
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class VagrantChecker method vagrantExists.
/**
* Attempt to run the Vagrant --version command and
* parse the expected output. If this succeeds then
* Vagrant is present on the system.
*
* @return true if Vagrant is installed
*/
public static synchronized boolean vagrantExists() {
boolean noVagrantProperty = Boolean.getBoolean("no.vagrant");
if (noVagrantProperty) {
return false;
}
String command = VagrantPlatform.getDefaultVagrantCommand();
try (PipedApplicationConsole console = new PipedApplicationConsole();
Application application = LocalPlatform.get().launch(Application.class, Executable.named(command), Argument.of("--version"), DisplayName.of("Vagrant"), Console.of(console))) {
int exitCode = application.waitFor();
if (exitCode != 0) {
return false;
}
String line = console.getOutputReader().readLine();
application.close();
Pattern pattern = Pattern.compile(VAGRANT_REGEX);
Matcher matcher = pattern.matcher(line);
return matcher.matches();
} catch (Throwable e) {
System.err.println("Error checking for Vagrant - assume not present. " + e.getMessage());
return false;
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class VagrantChecker method vagrantExistsWithBox.
public static synchronized boolean vagrantExistsWithBox(String boxName) {
if (!vagrantExists()) {
return false;
}
String command = VagrantPlatform.getDefaultVagrantCommand();
try (CapturingApplicationConsole console = new CapturingApplicationConsole();
Application application = LocalPlatform.get().launch(Application.class, Executable.named(command), Argument.of("box"), Argument.of("list"), DisplayName.of("Vagrant"), Console.of(console))) {
int exitCode = application.waitFor();
if (exitCode != 0) {
return false;
}
application.close();
for (String line : console.getCapturedOutputLines()) {
String[] parts = line.split(" ");
if (parts[0].equals(boxName)) {
return true;
}
}
return false;
} catch (Throwable e) {
System.err.println("Error checking for Vagrant box " + boxName + " - assume not present. " + e.getMessage());
return false;
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class PowerShellHttpDeployer method deployArtifact.
@Override
protected void deployArtifact(final URL sourceURL, final String targetFileName, final Platform platform) {
int index = targetFileName.lastIndexOf('\\');
String parentFolder = index > 0 ? targetFileName.substring(0, index) : "C:\\";
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (Application application = platform.launch(Application.class, Executable.named("powershell"), Argument.of("-Command"), Argument.of("Invoke-WebRequest"), Argument.of("-Uri"), Argument.of(sourceURL.toExternalForm()), Argument.of("-OutFile"), Argument.of(StringHelper.doubleQuoteIfNecessary(targetFileName)), WorkingDirectory.at(new File(parentFolder)), DisplayName.of("Deploy"), Console.of(console))) {
int exitCode = application.waitFor();
if (exitCode != 0) {
StringBuilder message = new StringBuilder("Error deploying ").append(targetFileName).append(" - PowerShell returned ").append(application.exitValue()).append("\n").append("Invoke-WebRequest output:");
for (String line : console.getCapturedOutputLines()) {
message.append('\n').append(line);
}
for (String line : console.getCapturedErrorLines()) {
message.append('\n').append(line);
}
throw new RuntimeException(message.toString());
}
}
}
use of com.oracle.bedrock.runtime.Application in project oracle-bedrock by coherence-community.
the class AbstractWindowsTest method hasWinRM.
/**
* Determine whether WinRM is running on the local platform.
*
* @return true if WinRM is running, otherwise false.
*/
public static boolean hasWinRM() {
if (!isWindows()) {
return false;
}
int exitCode = -1;
Platform platform = LocalPlatform.get();
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (Application application = platform.launch(Application.class, Executable.named("cmd.exe"), Argument.of("/C"), Argument.of("winrm"), Argument.of("enumerate"), Argument.of("winrm/config/listener"), DisplayName.of("WinRMCheck"), Console.of(console))) {
try {
exitCode = application.waitFor();
} catch (AssertionError assertionError) {
// ignored
}
}
Queue<String> lines = console.getCapturedOutputLines();
return exitCode == 0 && lines.size() > 0 && lines.poll().startsWith("Listener");
}
Aggregations