Skip to content

Commit 75a901c

Browse files
committed
Remove BootUtils.mkDirs; use IOTools.createDris instead
1 parent 079bc9f commit 75a901c

5 files changed

Lines changed: 15 additions & 58 deletions

File tree

src/main/java/rife/bld/extension/AbstractBootOperation.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
public abstract class AbstractBootOperation<T extends AbstractBootOperation<T>>
5959
extends AbstractOperation<AbstractBootOperation<T>> {
6060

61-
protected final Logger logger = Logger.getLogger(getClass().getName());
6261
private static final String INF_LIBS = "infLibs";
6362
private static final String LAUNCHER_LIBS = "launcherLibs";
6463
private static final String SOURCE_DIRECTORIES = "sourceDirectories";
64+
protected final Logger logger = Logger.getLogger(getClass().getName());
6565
private final List<File> infLibs_ = new ArrayList<>();
6666
private final List<File> launcherLibs_ = new ArrayList<>();
6767
private final Map<String, String> manifestAttributes_ = new HashMap<>();
@@ -580,7 +580,7 @@ protected void executeCopyBootLoader(File stagingDirectory) throws FileUtilsErro
580580
*/
581581
protected void executeCopyInfClassesFiles(File stagingInfDirectory) throws IOException {
582582
var infClassesDir = new File(stagingInfDirectory, "classes");
583-
BootUtils.mkDirs(infClassesDir);
583+
IOTools.createDirs(infClassesDir);
584584

585585
for (var dir : sourceDirectories_) {
586586
if (dir.exists()) {
@@ -599,7 +599,7 @@ protected void executeCopyInfClassesFiles(File stagingInfDirectory) throws IOExc
599599
*/
600600
protected void executeCopyInfLibs(File stagingInfDirectory) throws IOException {
601601
var infLibDir = stagingInfDirectory.toPath().resolve("lib");
602-
BootUtils.mkDirs(infLibDir.toFile());
602+
IOTools.createDirs(infLibDir.toFile());
603603

604604
for (var jar : infLibs_) {
605605
if (jar.exists()) {
@@ -674,7 +674,7 @@ protected File executeCreateArchive(File stagingDirectory) throws IOException {
674674
*/
675675
protected void executeCreateManifest(File stagingDirectory) throws IOException {
676676
var metaInfDir = stagingDirectory.toPath().resolve("META-INF");
677-
BootUtils.mkDirs(metaInfDir.toFile());
677+
IOTools.createDirs(metaInfDir.toFile());
678678

679679
var manifestFile = metaInfDir.resolve("MANIFEST.MF");
680680

@@ -722,10 +722,11 @@ protected T mainClass(String className) {
722722
* {@link #launcherLibs() launcherLibs}) required to create the archive have been provided, throws an
723723
* {@link IllegalArgumentException} otherwise.
724724
*
725+
* @throws IOException if the {@link #destinationDirectory() destination directory} could not be created
725726
* @throws IllegalArgumentException if a required element is missing or invalid
726727
*/
727-
@SuppressFBWarnings({"DRE_DECLARED_RUNTIME_EXCEPTION", "EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"})
728-
protected void verifyExecute() throws IllegalArgumentException {
728+
@SuppressFBWarnings("DRE_DECLARED_RUNTIME_EXCEPTION")
729+
protected void verifyExecute() throws IllegalArgumentException, IOException {
729730
if (TextTools.isBlank(mainClass_)) {
730731
throw new IllegalArgumentException("Project mainClass required.");
731732
} else if (TextTools.isBlank(launcherClass_)) {
@@ -737,10 +738,9 @@ protected void verifyExecute() throws IllegalArgumentException {
737738
throw new IllegalArgumentException("Destination directory required.");
738739
}
739740
try {
740-
BootUtils.mkDirs(destinationDirectory_);
741+
IOTools.createDirs(destinationDirectory_);
741742
} catch (IOException e) {
742-
throw new IllegalArgumentException(
743-
MessageFormat.format("Cannot create directory {0}.", destinationDirectory_), e);
743+
throw new IOException("Cannot create destination directory: " + destinationDirectory_, e);
744744
}
745745
}
746746
for (var jar : launcherLibs_) {

src/main/java/rife/bld/extension/BootJarOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import edu.umd.cs.findbugs.annotations.NonNull;
2020
import rife.bld.Project;
21+
import rife.bld.extension.tools.IOTools;
2122
import rife.bld.extension.tools.ObjectTools;
2223
import rife.tools.FileUtils;
2324

@@ -58,7 +59,7 @@ public void execute() throws Exception {
5859

5960
try {
6061
var bootInfDir = new File(stagingDir, "BOOT-INF");
61-
BootUtils.mkDirs(bootInfDir);
62+
IOTools.createDirs(bootInfDir);
6263

6364
executeCopyInfClassesFiles(bootInfDir);
6465
executeCopyInfLibs(bootInfDir);

src/main/java/rife/bld/extension/BootUtils.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
package rife.bld.extension;
1818

1919
import rife.bld.Project;
20-
import rife.bld.extension.tools.IOTools;
2120

2221
import java.io.File;
23-
import java.io.IOException;
2422
import java.text.DecimalFormat;
2523
import java.util.regex.Pattern;
2624

@@ -78,18 +76,6 @@ public static String launcherClass(Project project, String name) {
7876
return resolveLauncherPrefix(project) + name;
7977
}
8078

81-
/**
82-
* Makes a directory for the given path, including any necessary but nonexistent parent directories.
83-
*
84-
* @param path the directory path
85-
* @throws IOException if an error occurs
86-
*/
87-
public static void mkDirs(File path) throws IOException {
88-
if (!IOTools.mkdirs(path)) {
89-
throw new IOException("Unable to create: " + path.getAbsolutePath());
90-
}
91-
}
92-
9379
private static String resolveLauncherPrefix(Project project) {
9480
for (var jar : project.standaloneClasspathJars()) {
9581
var matcher = LOADER_JAR.matcher(jar.getName());

src/main/java/rife/bld/extension/BootWarOperation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2121
import rife.bld.Project;
2222
import rife.bld.extension.tools.CollectionTools;
23+
import rife.bld.extension.tools.IOTools;
2324
import rife.bld.extension.tools.ObjectTools;
2425
import rife.tools.FileUtils;
2526

@@ -67,7 +68,7 @@ public void execute() throws Exception {
6768

6869
try {
6970
var webInfDir = new File(stagingDir, "WEB-INF");
70-
BootUtils.mkDirs(webInfDir);
71+
IOTools.createDirs(webInfDir);
7172

7273
executeCopyInfClassesFiles(webInfDir);
7374
executeCopyInfLibs(webInfDir);
@@ -260,7 +261,7 @@ public final BootWarOperation providedLibsStrings(@NonNull Collection<String> ja
260261
*/
261262
protected void executeCopyWebInfProvidedLib(File stagingWebInfDirectory) throws IOException {
262263
var libProvidedPath = stagingWebInfDirectory.toPath().resolve("lib-provided");
263-
BootUtils.mkDirs(libProvidedPath.toFile());
264+
IOTools.createDirs(libProvidedPath.toFile());
264265

265266
for (var lib : providedLibs_) {
266267
if (lib.exists()) {

src/test/java/rife/bld/extension/BootUtilsTests.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@
1919
import org.junit.jupiter.api.DisplayName;
2020
import org.junit.jupiter.api.Nested;
2121
import org.junit.jupiter.api.Test;
22-
import org.junit.jupiter.api.condition.DisabledOnOs;
23-
import org.junit.jupiter.api.condition.OS;
24-
import org.junit.jupiter.api.io.TempDir;
2522
import rife.bld.Project;
2623
import rife.bld.blueprints.BaseProjectBlueprint;
27-
import rife.tools.FileUtils;
2824

2925
import java.io.File;
3026
import java.io.IOException;
3127
import java.nio.file.Files;
3228
import java.util.List;
3329

34-
import static org.junit.jupiter.api.Assertions.*;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
3531

3632
@SuppressWarnings({"PMD.AvoidDuplicateLiterals"})
3733
class BootUtilsTests {
@@ -171,31 +167,4 @@ public List<File> standaloneClasspathJars() {
171167
BootUtils.launcherClass(project, "JarLauncher"));
172168
}
173169
}
174-
175-
@Nested
176-
@DisplayName("MkDirs Tests")
177-
class MkDirsTests {
178-
179-
@TempDir
180-
private File tmpDir;
181-
182-
@Test
183-
void mkDirsCreatesDirectories() throws IOException {
184-
FileUtils.deleteDirectory(tmpDir);
185-
assertFalse(tmpDir.exists());
186-
187-
BootUtils.mkDirs(tmpDir);
188-
assertTrue(tmpDir.exists());
189-
}
190-
191-
@Test
192-
@DisabledOnOs(OS.WINDOWS)
193-
void mkDirsThrowsIOException() {
194-
var tmpFile = new File("/foo/bar.txt");
195-
tmpFile.deleteOnExit();
196-
197-
var exception = assertThrows(IOException.class, () -> BootUtils.mkDirs(tmpFile));
198-
assertEquals("Unable to create: " + tmpFile.getAbsolutePath(), exception.getMessage());
199-
}
200-
}
201170
}

0 commit comments

Comments
 (0)