Search in sources :

Example 1 with JavaExecutable

use of org.springframework.boot.loader.tools.JavaExecutable in project spring-boot by spring-projects.

the class JarCommandIT method jarCreationWithGrabResolver.

@Test
public void jarCreationWithGrabResolver() throws Exception {
    File jar = new File("target/test-app.jar");
    Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(), "bad.groovy");
    invocation.await();
    assertThat(invocation.getErrorOutput(), equalTo(""));
    invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy");
    invocation.await();
    assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
    assertTrue(jar.exists());
    Process process = new JavaExecutable().processBuilder("-jar", jar.getAbsolutePath()).start();
    invocation = new Invocation(process);
    invocation.await();
    assertThat(invocation.getErrorOutput(), equalTo(""));
}
Also used : Invocation(org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 2 with JavaExecutable

use of org.springframework.boot.loader.tools.JavaExecutable in project spring-boot by spring-projects.

the class JarCommandIT method jarCreation.

@Test
public void jarCreation() throws Exception {
    File jar = new File("target/test-app.jar");
    Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "jar.groovy");
    invocation.await();
    assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
    assertTrue(jar.exists());
    Process process = new JavaExecutable().processBuilder("-jar", jar.getAbsolutePath()).start();
    invocation = new Invocation(process);
    invocation.await();
    assertThat(invocation.getErrorOutput(), equalTo(""));
    assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
    assertThat(invocation.getStandardOutput(), containsString("/BOOT-INF/classes!/public/public.txt"));
    assertThat(invocation.getStandardOutput(), containsString("/BOOT-INF/classes!/resources/resource.txt"));
    assertThat(invocation.getStandardOutput(), containsString("/BOOT-INF/classes!/static/static.txt"));
    assertThat(invocation.getStandardOutput(), containsString("/BOOT-INF/classes!/templates/template.txt"));
    assertThat(invocation.getStandardOutput(), containsString("/BOOT-INF/classes!/root.properties"));
    assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
}
Also used : Invocation(org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 3 with JavaExecutable

use of org.springframework.boot.loader.tools.JavaExecutable in project spring-boot by spring-projects.

the class JarCommandIT method jarCreationWithIncludes.

@Test
public void jarCreationWithIncludes() throws Exception {
    File jar = new File("target/test-app.jar");
    Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include", "-public/**,-resources/**", "jar.groovy");
    invocation.await();
    assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
    assertTrue(jar.exists());
    Process process = new JavaExecutable().processBuilder("-jar", jar.getAbsolutePath()).start();
    invocation = new Invocation(process);
    invocation.await();
    assertThat(invocation.getErrorOutput(), equalTo(""));
    assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
    assertThat(invocation.getStandardOutput(), not(containsString("/public/public.txt")));
    assertThat(invocation.getStandardOutput(), not(containsString("/resources/resource.txt")));
    assertThat(invocation.getStandardOutput(), containsString("/static/static.txt"));
    assertThat(invocation.getStandardOutput(), containsString("/templates/template.txt"));
    assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
}
Also used : Invocation(org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 4 with JavaExecutable

use of org.springframework.boot.loader.tools.JavaExecutable in project spring-boot by spring-projects.

the class SampleAntApplicationIT method runJar.

@Test
public void runJar() throws Exception {
    File target = new File("target");
    File[] jarFiles = target.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.getName().endsWith(".jar");
        }
    });
    assertThat(jarFiles).hasSize(1);
    Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
    process.waitFor(5, TimeUnit.MINUTES);
    assertThat(process.exitValue()).isEqualTo(0);
    String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
    assertThat(output).contains("Spring Boot Ant Example");
}
Also used : InputStreamReader(java.io.InputStreamReader) FileFilter(java.io.FileFilter) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 5 with JavaExecutable

use of org.springframework.boot.loader.tools.JavaExecutable in project spring-boot by spring-projects.

the class StartMojo method runProcess.

private RunProcess runProcess(File workingDirectory, List<String> args) throws MojoExecutionException {
    try {
        RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
        runProcess.run(false, args.toArray(new String[args.size()]));
        return runProcess;
    } catch (Exception ex) {
        throw new MojoExecutionException("Could not exec java", ex);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RunProcess(org.springframework.boot.loader.tools.RunProcess) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectException(java.net.ConnectException) ReflectionException(javax.management.ReflectionException)

Aggregations

JavaExecutable (org.springframework.boot.loader.tools.JavaExecutable)7 File (java.io.File)5 Test (org.junit.Test)5 Invocation (org.springframework.boot.cli.infrastructure.CommandLineInvoker.Invocation)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 RunProcess (org.springframework.boot.loader.tools.RunProcess)2 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ConnectException (java.net.ConnectException)1 ReflectionException (javax.management.ReflectionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1