Skip to content

Commit

Permalink
Remove use of execute method inherited from internal class
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Dec 17, 2018
1 parent 317c4c2 commit 4edc328
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void createTask() {
@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"))
Expand All @@ -109,7 +109,7 @@ public void basicArchiveCreation() throws IOException {
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();
Expand All @@ -125,7 +125,7 @@ public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
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"))
Expand All @@ -139,7 +139,7 @@ public void classpathCanBeSetUsingAFileCollection() throws IOException {
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();
Expand All @@ -151,7 +151,7 @@ public void classpathCanBeSetUsingAnObject() throws IOException {
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();
Expand All @@ -161,7 +161,7 @@ public void classpathCanBeSetUsingAnObject() throws IOException {
@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"))
Expand All @@ -174,7 +174,7 @@ public void loaderIsWrittenToTheRootOfTheJar() throws IOException {
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())) {
Expand All @@ -190,7 +190,7 @@ public void unpackCommentIsAddedToEntryIdentifiedByAPattern() throws IOException
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:");
Expand All @@ -203,7 +203,7 @@ public void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
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:");
Expand All @@ -215,7 +215,7 @@ public void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
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());
Expand All @@ -239,7 +239,7 @@ public void customLaunchScriptCanBePrepended() throws IOException {
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());
}
Expand All @@ -253,7 +253,7 @@ public void launchScriptInitInfoPropertiesCanBeCustomized() throws IOException {
"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)
Expand All @@ -266,7 +266,7 @@ public void customMainClassInTheManifestIsHonored() throws IOException {
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"))
Expand All @@ -284,7 +284,7 @@ public void customStartClassInTheManifestIsHonored() throws IOException {
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"))
Expand All @@ -298,7 +298,7 @@ public void customStartClassInTheManifestIsHonored() throws IOException {
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();
Expand All @@ -316,7 +316,7 @@ public void reproducibleOrderingCanBeEnabled() throws IOException {
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())) {
Expand All @@ -335,7 +335,7 @@ public void reproducibleOrderingCanBeEnabled() throws IOException {
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"))
Expand All @@ -348,7 +348,7 @@ public void devtoolsJarCanBeIncluded() throws IOException {
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"))
Expand All @@ -365,7 +365,7 @@ public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
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();
Expand All @@ -390,7 +390,7 @@ public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
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",
Expand All @@ -405,6 +405,8 @@ private T configure(T task) throws IOException {
return task;
}

protected abstract void executeTask();

protected T getTask() {
return this.task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOExcepti
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();
}
Expand All @@ -54,10 +54,15 @@ public void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void providedClasspathJarsArePackagedInWebInfLibProvided() throws IOExcep
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();
Expand All @@ -54,7 +54,7 @@ public void providedClasspathCanBeSetUsingAFileCollection() throws IOException {
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();
Expand All @@ -66,7 +66,7 @@ public void providedClasspathCanBeSetUsingAnObject() throws IOException {
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();
Expand All @@ -78,7 +78,7 @@ public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
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
Expand All @@ -93,7 +93,7 @@ public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath()
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
Expand All @@ -111,7 +111,7 @@ public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged()
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();
Expand All @@ -124,9 +124,14 @@ public void libProvidedEntriesAreWrittenAfterLibEntries() throws IOException {
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();
}

}

0 comments on commit 4edc328

Please sign in to comment.