Skip to content

Commit

Permalink
Javadocs and tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Oct 31, 2023
1 parent d00ace8 commit c9fe353
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
59 changes: 33 additions & 26 deletions src/main/java/rife/bld/extension/AbstractBootOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void mkDirs(File path) throws IOException {
}

/**
* Retrieves the destination directory in which the JAR will be created.
* Retrieves the destination directory in which the archive will be created.
*
* @return the destination directory
*/
Expand Down Expand Up @@ -247,37 +247,37 @@ protected File executeCreateArchive(File stagingDirectory)
}

/**
* Part of the {@link #execute} operation, create the manifest for the jar archive.
* Part of the {@link #execute} operation, create the manifest for the archive.
*
* @param stagingDirectory the staging directory
*/
protected void executeCreateManifest(File stagingDirectory) throws IOException {
var meta_inf_dir = new File(stagingDirectory, "META-INF");
mkDirs(meta_inf_dir);

var manifest = new File(meta_inf_dir, "MANIFEST.MF");
var manifest = new File(meta_inf_dir, "MANIFEST.MF").toPath();

try (var fileWriter = Files.newBufferedWriter(manifest.toPath())) {
try (var fileWriter = Files.newBufferedWriter(manifest)) {
for (var manifestAttribute : manifestAttributes()) {
fileWriter.write(manifestAttribute.name() + ": " + manifestAttribute.value() + System.lineSeparator());
}
}
}

/**
* Provides JAR libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
* Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
*
* @param jars a list of Java archive files
* @param jars a collection of Java archive files
* @return this operation instance
*/
public T infLibs(List<File> jars) {
public T infLibs(Collection<File> jars) {
infLibs_.addAll(jars);
//noinspection unchecked
return (T) this;
}

/**
* Provides JAR libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
* Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}.
*
* @param jar one or more Java archive file
* @return this operation instance
Expand All @@ -289,7 +289,7 @@ public T infLibs(File... jar) {
}

/**
* Retrieves the JAR libraries in {@code BOOT-INF} or {@code WEB-INF}.
* Retrieves the libraries in {@code BOOT-INF} or {@code WEB-INF}.
*
* @return a list of Java archives
*/
Expand All @@ -298,7 +298,13 @@ public List<File> infLibs() {
}

/**
* Provides the JAR launcher ({@code spring-boot-loader}) fully-qualified class name.
* Provides the launcher ({@code spring-boot-loader}) fully-qualified class name.
* <p>
* For examples:
* <ul>
* <li>{@code org.springframework.boot.loader.WarLauncher}</li>
* <li>{@code org.springframework.boot.loader.JarLauncher}</li>
* </ul>
*
* @param className the launcher class name
* @return this operation instance
Expand All @@ -310,7 +316,7 @@ public T launcherClass(String className) {
}

/**
* Retrieves the JAR launcher ({@code spring-boot-loader}) fully-qualified class name.
* Retrieves the launcher ({@code spring-boot-loader}) fully-qualified class name.
*
* @return the launcher class name
*/
Expand All @@ -323,7 +329,7 @@ protected String launcherClass() {
}

/**
* Retrieves the launcher ({@code spring-boot-loader}) JAR libraries.
* Retrieves the launcher ({@code spring-boot-loader}) libraries.
*
* @return a list of Java archives
*/
Expand All @@ -332,16 +338,16 @@ public List<File> launcherLibs() {
}

/**
* Provides the JAR libraries for the launcher ({@code spring-boot-loader}).
* Provides the libraries for the launcher ({@code spring-boot-loader}).
*
* @param jars a list of a Java archives
* @param jars a collection of a Java archives
* @return this operation instance
*/
public T launcherLibs(List<File> jars) throws IOException {
public T launcherLibs(Collection<File> jars) throws IOException {
if (!jars.isEmpty()) {
for (var j : jars) {
if (!j.exists()) {
throw new IOException("ERROR: launcher (spring-boot-loader) JAR(s) not found: " + j);
throw new IOException("ERROR: launcher (spring-boot-loader) library not found: " + j);
}
}
launcherLibs_.addAll(jars);
Expand Down Expand Up @@ -372,10 +378,10 @@ public String mainClass() {
}

/**
* Provides an attribute to put in the JAR manifest.
* Provides an attribute to put in the archive manifest.
*
* @param name the attribute name to put in the manifest
* @param value the attribute value to put in the manifest
* @param name the attribute name
* @param value the attribute value
* @return this operation instance
*/
public T manifestAttribute(String name, String value) {
Expand All @@ -385,7 +391,7 @@ public T manifestAttribute(String name, String value) {
}

/**
* Retrieves the list of attributes that will be put in the jar manifest.
* Retrieves the list of attributes that will be put in the archive manifest.
*
* @return a list of manifest attributes
*/
Expand All @@ -394,9 +400,9 @@ public List<BootManifestAttribute> manifestAttributes() {
}

/**
* Provides a map of attributes to put in the jar manifest.
* Provides a map of attributes to put in the archive manifest.
*
* @param attributes the attributes to put in the manifest
* @param attributes the manifest attributes
* @return this operation instance
*/
public T manifestAttributes(Collection<BootManifestAttribute> attributes) {
Expand All @@ -406,7 +412,7 @@ public T manifestAttributes(Collection<BootManifestAttribute> attributes) {
}

/**
* Provides source directories that will be used for the jar archive creation.
* Provides source directories that will be used for the archive creation.
*
* @param directories one or more source directory
* @return this operation instance
Expand All @@ -418,7 +424,7 @@ public T sourceDirectories(File... directories) {
}

/**
* Retrieves the source directories that will be used for the jar archive creation.
* Retrieves the source directories that will be used for the archive creation.
*
* @return a list of directories
*/
Expand All @@ -427,7 +433,8 @@ public List<File> sourceDirectories() {
}

/**
* Verifies that all the elements required to create the archived have been provided, throws an
* Verifies that all the elements ({@link #mainClass() mainClass}, {@link #launcherClass() launcherClass} and
* {@link #launcherLibs() launcherLibs}) required to create the archive have been provided, throws an
* {@link IllegalArgumentException} otherwise.
*
* @return {@code true} or an {@link IllegalArgumentException}
Expand All @@ -439,7 +446,7 @@ protected boolean verifyExecute() throws IllegalArgumentException {
} else if (launcherClass().isEmpty()) {
throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) class required"));
} else if (launcherLibs().isEmpty()) {
throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) JAR(s) required"));
throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) libraries required"));
}
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/extension/BootWarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void execute() throws Exception {
}

/**
* Part of the {@link #execute} operation, copy the {@code WEB-INF/lib-provided} libs.
* Part of the {@link #execute} operation, copy the {@code WEB-INF/lib-provided} libraries.
*
* @param stagingWebInfDirectory the staging {@code WEB-INF/lib-provided} directory
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ public BootWarOperation fromProject(Project project) throws IOException {
}

/**
* Provides JAR libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
* Provides libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jars a collection of Java archive files
* @return this operation instance
Expand All @@ -132,7 +132,7 @@ public BootWarOperation providedLibs(Collection<File> jars) {
}

/**
* Provides the JAR libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
* Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}.
*
* @param jar one or more Java archive file
* @return this operation instance
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/rife/bld/extension/BootJarOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class BootJarOperationTest {
private static final String BLD = "bld-1.7.5.jar";
private static final String EXAMPLES_LIB_COMPILE = "examples/lib/compile/";
private static final String EXAMPLES_LIB_RUNTIME = "examples/lib/runtime/";
private static final String EXAMPLES_LIB_STANDALONE = "examples/lib/standalone/";
private static final String LAUNCHER_JARS = """
org/
Expand Down Expand Up @@ -114,6 +115,7 @@ class BootJarOperationTest {
org/springframework/boot/loader/util/SystemPropertyUtils.class
""";
private static final String MAIN_CLASS = "com.example.Foo";
private static final String PROVIDED_LIB = "LatencyUtils-2.0.3.jar";
private static final String SPRING_BOOT = "spring-boot-3.1.5.jar";
private static final String SPRING_BOOT_ACTUATOR = "spring-boot-actuator-3.1.5.jar";
private static final String SPRING_BOOT_LOADER = "spring-boot-loader-3.1.5.jar";
Expand Down Expand Up @@ -227,7 +229,7 @@ void testJarProjectExecute() throws Exception {

@Test
void testProject() throws IOException {
var tmp_dir = Files.createTempDirectory("bootjartmp").toFile();
var tmp_dir = Files.createTempDirectory("bootprjtmp").toFile();
var project = new CustomProject(tmp_dir);
var bootJar = new BootJarOperation().fromProject(project);

Expand Down Expand Up @@ -255,15 +257,17 @@ void testProject() throws IOException {
@Test
void testWarProjectExecute() throws Exception {
var tmp_dir = Files.createTempDirectory("bootjartmp").toFile();
var project = new CustomProject(new File("."));
new BootWarOperation()
.fromProject(new CustomProject(new File(".")))
.fromProject(project)
.launcherLibs(List.of(new File(EXAMPLES_LIB_STANDALONE + SPRING_BOOT_LOADER)))
.destinationDirectory(tmp_dir)
.infLibs(new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT),
new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT_ACTUATOR))
.providedLibs(new File(EXAMPLES_LIB_RUNTIME + PROVIDED_LIB))
.execute();

var warFile = new File(tmp_dir, "test_project-0.0.1-boot.war");
var warFile = new File(tmp_dir, project.name() + '-' + project.version().toString() + "-boot.war");
assertThat(warFile).exists();

var jarEntries = readJarEntries(warFile);
Expand All @@ -284,7 +288,8 @@ void testWarProjectExecute() throws Exception {
"WEB-INF/lib/dist/\n" +
"WEB-INF/lib/" + SPRING_BOOT + '\n' +
"WEB-INF/lib/" + SPRING_BOOT_ACTUATOR + '\n' +
"WEB-INF/lib-provided/\n" + LAUNCHER_JARS);
"WEB-INF/lib-provided/\n" +
"WEB-INF/lib-provided/" + PROVIDED_LIB + '\n' + LAUNCHER_JARS);

FileUtils.deleteDirectory(tmp_dir);
}
Expand Down

0 comments on commit c9fe353

Please sign in to comment.