Add methods to BootJar for adding content to BOOT-INF

Closes gh-13000
This commit is contained in:
Andy Wilkinson
2018-05-11 11:14:14 +01:00
parent d9d7499ae6
commit 7913d9b599
2 changed files with 65 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,14 @@
package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link BootJar}.
*
@@ -28,4 +36,28 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
"BOOT-INF/lib", "BOOT-INF/classes");
}
@Test
public void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.getBootInf().into("test")
.from(new File("build.gradle").getAbsolutePath());
bootJar.execute();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
}
}
@Test
public void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
BootJar bootJar = getTask();
bootJar.setMainClassName("com.example.Application");
bootJar.bootInf((copySpec) -> copySpec.into("test")
.from(new File("build.gradle").getAbsolutePath()));
bootJar.execute();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
}
}
}