Search in sources :

Example 6 with Application

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;
    }
}
Also used : CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) EventingApplication(classloader.applications.EventingApplication) SleepingApplication(classloader.applications.SleepingApplication) ParentApplication(classloader.applications.ParentApplication) Application(com.oracle.bedrock.runtime.Application)

Example 7 with Application

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;
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PipedApplicationConsole(com.oracle.bedrock.runtime.console.PipedApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Example 8 with Application

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;
    }
}
Also used : CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Example 9 with Application

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());
        }
    }
}
Also used : CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application) File(java.io.File)

Example 10 with Application

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");
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) RemotePlatform(com.oracle.bedrock.runtime.remote.RemotePlatform) Platform(com.oracle.bedrock.runtime.Platform) CapturingApplicationConsole(com.oracle.bedrock.runtime.console.CapturingApplicationConsole) Application(com.oracle.bedrock.runtime.Application)

Aggregations

Application (com.oracle.bedrock.runtime.Application)57 Test (org.junit.Test)23 CapturingApplicationConsole (com.oracle.bedrock.runtime.console.CapturingApplicationConsole)22 Platform (com.oracle.bedrock.runtime.Platform)16 Arguments (com.oracle.bedrock.runtime.options.Arguments)13 OptionsByType (com.oracle.bedrock.OptionsByType)12 File (java.io.File)12 JavaApplication (com.oracle.bedrock.runtime.java.JavaApplication)11 Timeout (com.oracle.bedrock.options.Timeout)9 MetaClass (com.oracle.bedrock.runtime.MetaClass)9 List (java.util.List)7 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)6 Remove (com.oracle.bedrock.runtime.docker.commands.Remove)5 RemotePlatform (com.oracle.bedrock.runtime.remote.RemotePlatform)5 InetAddress (java.net.InetAddress)5 SleepingApplication (applications.SleepingApplication)4 ContainerCloseBehaviour (com.oracle.bedrock.runtime.docker.options.ContainerCloseBehaviour)4 TimeUnit (java.util.concurrent.TimeUnit)4 Collectors (java.util.stream.Collectors)4 EventingApplication (classloader.applications.EventingApplication)3