Remove use of execute method inherited from internal class

Closes gh-15484
This commit is contained in:
Andy Wilkinson 2018-12-17 17:32:34 +00:00
parent 317c4c2c38
commit 4edc32844a
3 changed files with 41 additions and 29 deletions

View File

@ -95,7 +95,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Test
public void basicArchiveCreation() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
@ -109,7 +109,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void classpathJarsArePackagedBeneathLibPath() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
@ -125,7 +125,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
this.task.classpath(classpathFolder);
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(
jarFile.getEntry(this.classesPath + "/com/example/Application.class"))
@ -139,7 +139,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.classpath(this.temp.newFile("one.jar"));
this.task
.setClasspath(this.task.getProject().files(this.temp.newFile("two.jar")));
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
@ -151,7 +151,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("one.jar"));
this.task.setClasspath(this.temp.newFile("two.jar"));
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
@ -161,7 +161,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
@Test
public void loaderIsWrittenToTheRootOfTheJar() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
@ -174,7 +174,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher()
throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.execute();
executeTask();
this.task.getManifest().getAttributes().put("Main-Class",
"org.springframework.boot.loader.PropertiesLauncher");
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
@ -190,7 +190,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
this.task.requiresUnpack("**/one.jar");
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar").getComment())
.startsWith("UNPACK:");
@ -203,7 +203,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("one.jar"), this.temp.newFile("two.jar"));
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
this.task.execute();
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/two.jar").getComment())
.startsWith("UNPACK:");
@ -215,7 +215,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void launchScriptCanBePrepended() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.launchScript();
this.task.execute();
executeTask();
Map<String, String> properties = new HashMap<>();
properties.put("initInfoProvides", this.task.getBaseName());
properties.put("initInfoShortDescription", this.project.getDescription());
@ -239,7 +239,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
Files.write(customScript.toPath(), Arrays.asList("custom script"),
StandardOpenOption.CREATE);
this.task.launchScript((configuration) -> configuration.setScript(customScript));
this.task.execute();
executeTask();
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
.startsWith("custom script".getBytes());
}
@ -253,7 +253,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
"short description");
configuration.getProperties().put("initInfoDescription", "description");
});
this.task.execute();
executeTask();
byte[] bytes = Files.readAllBytes(this.task.getArchivePath().toPath());
assertThat(bytes).containsSequence("Provides: provides".getBytes());
assertThat(bytes)
@ -266,7 +266,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Main-Class",
"com.example.CustomLauncher");
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
@ -284,7 +284,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.getManifest().getAttributes().put("Start-Class",
"com.example.CustomMain");
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
@ -298,7 +298,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void fileTimestampPreservationCanBeDisabled() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.setPreserveFileTimestamps(false);
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
Enumeration<JarEntry> entries = jarFile.entries();
@ -316,7 +316,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.from(this.temp.newFile("bravo.txt"), this.temp.newFile("alpha.txt"),
this.temp.newFile("charlie.txt"));
this.task.setReproducibleFileOrder(true);
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
List<String> textFiles = new ArrayList<>();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
@ -335,7 +335,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
public void devtoolsJarIsExcludedByDefault() throws IOException {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
@ -348,7 +348,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setMainClassName("com.example.Main");
this.task.classpath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
this.task.setExcludeDevtools(false);
this.task.execute();
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
@ -365,7 +365,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
resource.getParentFile().mkdirs();
resource.createNewFile();
this.task.classpath(classpathFolder);
this.task.execute();
executeTask();
File archivePath = this.task.getArchivePath();
try (ZipFile zip = new ZipFile(archivePath)) {
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
@ -390,7 +390,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.temp.newFile("second-library.jar"),
this.temp.newFile("third-library.jar"));
this.task.requiresUnpack("second-library.jar");
this.task.execute();
executeTask();
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence(
"org/springframework/boot/loader/",
this.classesPath + "/com/example/Application.class",
@ -405,6 +405,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
return task;
}
protected abstract void executeTask();
protected T getTask() {
return this.task;
}

View File

@ -42,7 +42,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
bootJar.setMainClassName("com.example.Application");
bootJar.getBootInf().into("test")
.from(new File("build.gradle").getAbsolutePath());
bootJar.execute();
bootJar.copy();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
}
@ -54,10 +54,15 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
bootJar.setMainClassName("com.example.Application");
bootJar.bootInf((copySpec) -> copySpec.into("test")
.from(new File("build.gradle").getAbsolutePath()));
bootJar.execute();
bootJar.copy();
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
}
}
@Override
protected void executeTask() {
getTask().copy();
}
}

View File

@ -41,7 +41,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(this.temp.newFile("one.jar"),
this.temp.newFile("two.jar"));
getTask().execute();
executeTask();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNotNull();
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
@ -54,7 +54,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().providedClasspath(this.temp.newFile("one.jar"));
getTask().setProvidedClasspath(
getTask().getProject().files(this.temp.newFile("two.jar")));
getTask().execute();
executeTask();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNull();
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
@ -66,7 +66,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(this.temp.newFile("one.jar"));
getTask().setProvidedClasspath(this.temp.newFile("two.jar"));
getTask().execute();
executeTask();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNull();
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
@ -78,7 +78,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
throws IOException {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
getTask().execute();
executeTask();
assertThat(getTask().getArchivePath()).exists();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile
@ -93,7 +93,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().setMainClassName("com.example.Main");
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
getTask().setExcludeDevtools(false);
getTask().execute();
executeTask();
assertThat(getTask().getArchivePath()).exists();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile
@ -111,7 +111,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
new File(orgFolder, "foo.txt").createNewFile();
getTask().from(webappFolder);
getTask().setMainClassName("com.example.Main");
getTask().execute();
executeTask();
assertThat(getTask().getArchivePath()).exists();
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
assertThat(jarFile.getEntry("org/")).isNotNull();
@ -124,9 +124,14 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
getTask().setMainClassName("com.example.Main");
getTask().classpath(this.temp.newFile("library.jar"));
getTask().providedClasspath(this.temp.newFile("provided-library.jar"));
getTask().execute();
executeTask();
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence(
"WEB-INF/lib/library.jar", "WEB-INF/lib-provided/provided-library.jar");
}
@Override
protected void executeTask() {
getTask().copy();
}
}