Javadocs and tests cleanup
This commit is contained in:
parent
d00ace8b8c
commit
c9fe353ce1
3 changed files with 45 additions and 33 deletions
|
@ -95,7 +95,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -247,7 +247,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -255,9 +255,9 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
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());
|
||||
}
|
||||
|
@ -265,19 +265,19 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -289,7 +289,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -298,7 +298,13 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -310,7 +316,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -323,7 +329,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves the launcher ({@code spring-boot-loader}) JAR libraries.
|
||||
* Retrieves the launcher ({@code spring-boot-loader}) libraries.
|
||||
*
|
||||
* @return a list of Java archives
|
||||
*/
|
||||
|
@ -332,16 +338,16 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -372,10 +378,10 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -385,7 +391,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -394,9 +400,9 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -406,7 +412,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -418,7 +424,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -427,7 +433,8 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
|
@ -439,7 +446,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
|
|||
} 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;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -121,7 +121,7 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -132,7 +132,7 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
|||
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/
|
||||
|
@ -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";
|
||||
|
@ -227,7 +229,7 @@ class BootJarOperationTest {
|
|||
|
||||
@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);
|
||||
|
||||
|
@ -255,15 +257,17 @@ class BootJarOperationTest {
|
|||
@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);
|
||||
|
@ -284,7 +288,8 @@ class BootJarOperationTest {
|
|||
"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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue