Code and Javadocs cleanup

This commit is contained in:
Erik C. Thauvin 2023-11-01 00:15:42 -07:00
parent b81fff3d19
commit 2b58bef262
5 changed files with 53 additions and 49 deletions

2
.idea/misc.xml generated
View file

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<pattern value="rife.bld.extension.SpringBootBuild" method="pmd" /> <pattern value="rife.bld.extension.SpringBootBuild" method="pmd" />
<pattern value="rife.bld.extension.SpringBootBuild" /> <pattern value="rife.bld.extension.SpringBootBuild" />
<pattern value="rife.bld.extension.AbstractBootOperation" method="fromProject" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -51,8 +51,7 @@ public class SpringBootBuild extends Project {
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()
.docLint(NO_MISSING) .docLint(NO_MISSING)
.link("https://rife2.github.io/bld/") .link("https://rife2.github.io/bld/");
.link("https://rife2.github.io/rife2/");
publishOperation() publishOperation()
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2")) .repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))

View file

@ -68,7 +68,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Return the given file size in bytes, kilobytes, megabytes, gigabytes or terabytes. * Calculates the given file size in bytes, kilobytes, megabytes, gigabytes or terabytes.
* *
* @param file the file * @param file the file
* @return the file size in B, KB, MB, GB, or TB. * @return the file size in B, KB, MB, GB, or TB.
@ -91,7 +91,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
*/ */
public static void mkDirs(File path) throws IOException { public static void mkDirs(File path) throws IOException {
if (!path.exists() && !path.mkdirs()) { if (!path.exists() && !path.mkdirs()) {
throw new IOException("ERROR: unable to create: " + path.getAbsolutePath()); throw new IOException("Unable to create: " + path.getAbsolutePath());
} }
} }
@ -139,14 +139,14 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Part of the {@link #execute execute} operation, copy the {@code spring-boot-loader} archive content to the staging * Part of the {@link #execute execute} operation, copies the Spring Boot loader launcher archive content to the
* directory. * staging directory.
* *
* @param stagingDirectory the staging directory * @param stagingDirectory the staging directory
*/ */
protected void executeCopyBootLoader(File stagingDirectory) throws FileUtilsErrorException { protected void executeCopyBootLoader(File stagingDirectory) throws FileUtilsErrorException {
if (launcherLibs_.isEmpty()) { if (launcherLibs_.isEmpty()) {
throw new IllegalArgumentException("ERROR: Spring Boot Loader required."); throw new IllegalArgumentException("Spring Boot loader launcher required.");
} else { } else {
var meta_inf_dir = new File(stagingDirectory, "META-INF"); var meta_inf_dir = new File(stagingDirectory, "META-INF");
for (var jar : launcherLibs()) { for (var jar : launcherLibs()) {
@ -156,14 +156,14 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
FileUtils.deleteDirectory(meta_inf_dir); FileUtils.deleteDirectory(meta_inf_dir);
} }
} else if (LOGGER.isLoggable(Level.WARNING)) { } else if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("ERROR: file not found: " + jar.getAbsolutePath()); LOGGER.warning("File not found: " + jar.getAbsolutePath());
} }
} }
} }
} }
/** /**
* Part of the {@link #execute execute} operation, copy the {@code BOOT-INF} or {@code WEB-INF} classes. * Part of the {@link #execute execute} operation, copies the {@code BOOT-INF} or {@code WEB-INF} classes.
* *
* @param stagingInfDirectory Tte staging {@code INF} directory * @param stagingInfDirectory Tte staging {@code INF} directory
*/ */
@ -175,7 +175,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
if (dir.exists()) { if (dir.exists()) {
FileUtils.copyDirectory(dir, inf_classes_dir); FileUtils.copyDirectory(dir, inf_classes_dir);
} else if (LOGGER.isLoggable(Level.WARNING)) { } else if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("ERROR: directory not found: " + dir.getAbsolutePath()); LOGGER.warning("Directory not found: " + dir.getAbsolutePath());
} }
} }
@ -183,7 +183,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Part of the {@link #execute execute} operation, copy the {@code BOOT-INF} or (@code WEB-INF) libs. * Part of the {@link #execute execute} operation, copies the {@code BOOT-INF} or (@code WEB-INF) libs.
* *
* @param stagingInfDirectory the staging {@code INF} directory * @param stagingInfDirectory the staging {@code INF} directory
*/ */
@ -195,26 +195,30 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
if (jar.exists()) { if (jar.exists()) {
Files.copy(jar.toPath(), inf_lib_dir.toPath().resolve(jar.getName())); Files.copy(jar.toPath(), inf_lib_dir.toPath().resolve(jar.getName()));
} else if (LOGGER.isLoggable(Level.WARNING)) { } else if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("ERROR: file not found: " + jar.getAbsolutePath()); LOGGER.warning("File not found: " + jar.getAbsolutePath());
} }
} }
} }
/** /**
* Part of the {@link #execute execute} operation, create the archive from the staging directory. * Part of the {@link #execute execute} operation, creates the archive from the staging directory.
* *
* @param stagingDirectory the staging directory * @param stagingDirectory the staging directory
* @return the archive * @return the archive
*/ */
protected File executeCreateArchive(File stagingDirectory) protected File executeCreateArchive(File stagingDirectory) throws IOException {
throws IOException {
executeCreateManifest(stagingDirectory); executeCreateManifest(stagingDirectory);
if (LOGGER.isLoggable(Level.FINE) && (!silent())) { if (LOGGER.isLoggable(Level.FINE) && (!silent())) {
LOGGER.fine(MessageFormat.format("Staging Directory: {0} (exists:{1})", stagingDirectory, LOGGER.fine(MessageFormat.format("""
stagingDirectory.exists())); \tStaging -> {0} [exists={1}]
LOGGER.fine(MessageFormat.format("Destination Directory: {0} (exists:{1})", destinationDirectory(), \tDestination -> {2} [exists={3}]
destinationDirectory().exists())); \tArchive -> {4}
LOGGER.fine(MessageFormat.format("Destination Archive: {0}", destinationFileName())); \tLauncher -> {5}""",
stagingDirectory, stagingDirectory.exists(),
destinationDirectory(), destinationDirectory().exists(),
destinationFileName(),
launcherClass()));
} }
var out = new StringWriter(); var out = new StringWriter();
@ -248,7 +252,7 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Part of the {@link #execute execute} operation, create the manifest for the archive. * Part of the {@link #execute execute} operation, creates the manifest for the archive.
* *
* @param stagingDirectory the staging directory * @param stagingDirectory the staging directory
*/ */
@ -307,12 +311,13 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Provides the launcher ({@code spring-boot-loader}) fully-qualified class name. * Provides the Spring Boot loader launcher fully-qualified class name.
* <p> * <p>
* For examples: * For examples:
* <ul> * <ul>
* <li>{@code org.springframework.boot.loader.WarLauncher}</li>
* <li>{@code org.springframework.boot.loader.JarLauncher}</li> * <li>{@code org.springframework.boot.loader.JarLauncher}</li>
* <li>{@code org.springframework.boot.loader.PropertiesLauncher}</li>
* <li>{@code org.springframework.boot.loader.WarLauncher}</li>
* </ul> * </ul>
* *
* @param className the launcher class name * @param className the launcher class name
@ -325,20 +330,19 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Retrieves the launcher ({@code spring-boot-loader}) fully-qualified class name. * Retrieves the Spring Boot loader launcher fully-qualified class name.
* *
* @return the launcher class name * @return the launcher class name
*/ */
protected String launcherClass() { protected String launcherClass() {
if (launcherClass_ == null) { if (launcherClass_ == null) {
throw new IllegalArgumentException("ERROR: Spring boot launcher (spring-boot-loader) class " + throw new IllegalArgumentException("Spring boot loader launcher class required.");
"required.");
} }
return launcherClass_; return launcherClass_;
} }
/** /**
* Retrieves the launcher ({@code spring-boot-loader}) libraries. * Retrieves the Spring Boot loader launcher libraries.
* *
* @return a list of Java archives * @return a list of Java archives
*/ */
@ -347,19 +351,20 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
} }
/** /**
* Provides the libraries for the launcher ({@code spring-boot-loader}). * Provides the libraries for the Spring Boot loader launcher.
* *
* @param jars a collection of a Java archives * @param jars a collection of Java archives
* @return this operation instance * @return this operation instance
*/ */
public T launcherLibs(Collection<File> jars) throws IOException { public T launcherLibs(Collection<File> jars) throws IOException {
if (!jars.isEmpty()) { if (!jars.isEmpty()) {
for (var j : jars) { for (var j : jars) {
if (!j.exists()) { if (j.exists()) {
throw new IOException("ERROR: launcher (spring-boot-loader) library not found: " + j); launcherLibs_.add(j);
} else {
throw new IOException("Spring Boot loader launcher library not found: " + j);
} }
} }
launcherLibs_.addAll(jars);
} }
//noinspection unchecked //noinspection unchecked
return (T) this; return (T) this;
@ -451,11 +456,11 @@ public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
@SuppressWarnings("SameReturnValue") @SuppressWarnings("SameReturnValue")
protected boolean verifyExecute() throws IllegalArgumentException { protected boolean verifyExecute() throws IllegalArgumentException {
if (mainClass() == null) { if (mainClass() == null) {
throw new IllegalArgumentException("ERROR: project mainClass required."); throw new IllegalArgumentException("Project mainClass required.");
} else if (launcherClass().isEmpty()) { } else if (launcherClass().isEmpty()) {
throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) class required")); throw new IllegalArgumentException(("Spring Boot loader launcher class required."));
} else if (launcherLibs().isEmpty()) { } else if (launcherLibs().isEmpty()) {
throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) libraries required")); throw new IllegalArgumentException(("Spring Boot loader launcher libraries required."));
} }
return true; return true;
} }

View file

@ -88,12 +88,11 @@ public class BootJarOperation extends AbstractBootOperation<BootJarOperation> {
.launcherClass("org.springframework.boot.loader.JarLauncher") .launcherClass("org.springframework.boot.loader.JarLauncher")
.launcherLibs(project.standaloneClasspathJars()) .launcherLibs(project.standaloneClasspathJars())
.mainClass(project.mainClass()) .mainClass(project.mainClass())
.manifestAttributes( .manifestAttributes(List.of(
List.of( new BootManifestAttribute("Manifest-Version", "1.0"),
new BootManifestAttribute("Manifest-Version", "1.0"), new BootManifestAttribute("Main-Class", launcherClass()),
new BootManifestAttribute("Main-Class", launcherClass()), new BootManifestAttribute("Start-Class", mainClass())
new BootManifestAttribute("Start-Class", mainClass())) ))
)
.sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory()); .sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory());
} }
} }

View file

@ -66,7 +66,7 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
} }
/** /**
* Part of the {@link #execute execute} operation, copy the {@code WEB-INF/lib-provided} libraries. * Part of the {@link #execute execute} operation, copies the {@code WEB-INF/lib-provided} libraries.
* *
* @param stagingWebInfDirectory the staging {@code WEB-INF/lib-provided} directory * @param stagingWebInfDirectory the staging {@code WEB-INF/lib-provided} directory
*/ */
@ -78,7 +78,7 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
if (jar.exists()) { if (jar.exists()) {
Files.copy(jar.toPath(), lib_provided_dir.toPath().resolve(jar.getName())); Files.copy(jar.toPath(), lib_provided_dir.toPath().resolve(jar.getName()));
} else if (LOGGER.isLoggable(Level.WARNING)) { } else if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("ERROR: file not found: " + jar); LOGGER.warning("File not found: " + jar);
} }
} }
} }
@ -111,12 +111,11 @@ public class BootWarOperation extends AbstractBootOperation<BootWarOperation> {
.launcherClass("org.springframework.boot.loader.WarLauncher") .launcherClass("org.springframework.boot.loader.WarLauncher")
.launcherLibs(project.standaloneClasspathJars()) .launcherLibs(project.standaloneClasspathJars())
.mainClass(project.mainClass()) .mainClass(project.mainClass())
.manifestAttributes( .manifestAttributes(List.of(
List.of( new BootManifestAttribute("Manifest-Version", "1.0"),
new BootManifestAttribute("Manifest-Version", "1.0"), new BootManifestAttribute("Main-Class", launcherClass()),
new BootManifestAttribute("Main-Class", launcherClass()), new BootManifestAttribute("Start-Class", mainClass())
new BootManifestAttribute("Start-Class", mainClass()) ))
))
.sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory()); .sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory());
} }