Skip to content

Commit e4fab44

Browse files
committed
bug(#4016): fixes
1 parent 2391109 commit e4fab44

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

eo-maven-plugin/src/main/java/org/eolang/maven/EmptyDirectoriesIn.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import com.jcabi.log.Logger;
88
import java.io.File;
9-
import java.nio.file.Files;
109
import java.nio.file.Path;
1110

1211
/**
@@ -18,27 +17,34 @@ final class EmptyDirectoriesIn {
1817
/**
1918
* Root path.
2019
*/
21-
private final Path root;
20+
private final File root;
2221

2322
/**
2423
* Ctor.
2524
* @param root Root directory.
2625
*/
2726
EmptyDirectoriesIn(final Path root) {
27+
this(root.toFile());
28+
}
29+
30+
/**
31+
* Ctor.
32+
* @param root Root directory
33+
*/
34+
EmptyDirectoriesIn(final File root) {
2835
this.root = root;
2936
}
3037

3138
/**
3239
* Clear empty directories in {@code this.root}.
3340
*/
3441
void clear() {
35-
if (Files.isDirectory(this.root)) {
36-
this.delete(this.root.toFile());
37-
} else {
42+
if (!this.root.isDirectory()) {
3843
throw new IllegalStateException(
3944
Logger.format("Provided path %[file]s is not a directory", this.root)
4045
);
4146
}
47+
this.delete(this.root);
4248
}
4349

4450
/**
@@ -47,23 +53,20 @@ void clear() {
4753
* @checkstyle NestedIfDepthCheck (20 lines)
4854
*/
4955
private void delete(final File dir) {
50-
if (dir.isDirectory()) {
51-
final File[] before = dir.listFiles();
52-
if (before != null) {
53-
for (final File file : before) {
54-
if (file.isDirectory()) {
55-
this.delete(file);
56-
}
56+
if (!dir.isDirectory()) {
57+
return;
58+
}
59+
final File[] before = dir.listFiles();
60+
if (before != null) {
61+
for (final File file : before) {
62+
if (file.isDirectory()) {
63+
this.delete(file);
5764
}
5865
}
59-
final File[] after = dir.listFiles();
60-
if (after != null
61-
&& after.length == 0
62-
&& !dir.equals(this.root.toFile())
63-
&& dir.delete()
64-
) {
65-
Logger.debug(EmptyDirectoriesIn.class, "Deleted empty directory %[file]s", dir);
66-
}
66+
}
67+
final File[] after = dir.listFiles();
68+
if (after != null && after.length == 0 && !dir.equals(this.root) && dir.delete()) {
69+
Logger.debug(EmptyDirectoriesIn.class, "Deleted empty directory %[file]s", dir);
6770
}
6871
}
6972
}

eo-maven-plugin/src/main/java/org/eolang/maven/UnspileMojo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void unspile(final Walk classes) {
7878
if (filtered.isEmpty()) {
7979
Logger.info(
8080
this, "No .class files out of %d deleted in %[file]s",
81-
classes.size(), this.classesDir
81+
classes.size(), this.classesDir.toPath()
8282
);
8383
} else {
8484
final int unspiled = new Threaded<>(
@@ -98,7 +98,7 @@ private void unspile(final Walk classes) {
9898
return deleted;
9999
}
100100
).total();
101-
new EmptyDirectoriesIn(this.classesDir.toPath()).clear();
101+
new EmptyDirectoriesIn(this.classesDir).clear();
102102
Logger.info(
103103
this,
104104
"Deleted %d .class files in %[file]s",

0 commit comments

Comments
 (0)