Search in sources :

Example 1 with DefaultLaunchScript

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

the class BootZipCopyAction method writeLaunchScriptIfNecessary.

private void writeLaunchScriptIfNecessary(ZipArchiveOutputStream outputStream) {
    if (this.launchScript == null) {
        return;
    }
    try {
        File file = this.launchScript.getScript();
        Map<String, String> properties = this.launchScript.getProperties();
        outputStream.writePreamble(new DefaultLaunchScript(file, properties).toByteArray());
        this.output.setExecutable(true);
    } catch (IOException ex) {
        throw new GradleException("Failed to write launch script to " + this.output, ex);
    }
}
Also used : DefaultLaunchScript(org.springframework.boot.loader.tools.DefaultLaunchScript) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) File(java.io.File)

Example 2 with DefaultLaunchScript

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

the class AbstractBootArchiveTests method launchScriptCanBePrepended.

@Test
void launchScriptCanBePrepended() throws IOException {
    this.task.getMainClass().set("com.example.Main");
    this.task.launchScript();
    executeTask();
    Map<String, String> properties = new HashMap<>();
    properties.put("initInfoProvides", this.task.getArchiveBaseName().get());
    properties.put("initInfoShortDescription", this.project.getDescription());
    properties.put("initInfoDescription", this.project.getDescription());
    File archiveFile = this.task.getArchiveFile().get().getAsFile();
    assertThat(Files.readAllBytes(archiveFile.toPath())).startsWith(new DefaultLaunchScript(null, properties).toByteArray());
    try (ZipFile zipFile = new ZipFile(archiveFile)) {
        assertThat(zipFile.getEntries().hasMoreElements()).isTrue();
    }
    try {
        Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(archiveFile.toPath());
        assertThat(permissions).contains(PosixFilePermission.OWNER_EXECUTE);
    } catch (UnsupportedOperationException ex) {
    // Windows, presumably. Continue
    }
}
Also used : DefaultLaunchScript(org.springframework.boot.loader.tools.DefaultLaunchScript) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) HashMap(java.util.HashMap) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) JarFile(java.util.jar.JarFile) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

File (java.io.File)2 DefaultLaunchScript (org.springframework.boot.loader.tools.DefaultLaunchScript)2 IOException (java.io.IOException)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 HashMap (java.util.HashMap)1 JarFile (java.util.jar.JarFile)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1 GradleException (org.gradle.api.GradleException)1 Test (org.junit.jupiter.api.Test)1