Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 24, 2024
1 parent 2255d49 commit 76dbe50
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
52 changes: 17 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,48 @@ under the License.

<properties>
<mavenVersion>4.0.0-beta-3</mavenVersion>
<project.build.outputTimestamp>2023-06-14T18:50:52Z</project.build.outputTimestamp>
<javaVersion>17</javaVersion>
<version.maven-invoker-plugin>3.7.0</version.maven-invoker-plugin>
<version.maven-plugin-testing>4.0.0-alpha-3-SNAPSHOT</version.maven-plugin-testing>
<version.maven-plugin-tools>4.0.0-SNAPSHOT</version.maven-plugin-tools>
<project.build.outputTimestamp>2024-06-16T10:25:11Z</project.build.outputTimestamp>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-di</artifactId>
<version>${mavenVersion}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-core</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-di</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-meta</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>4.0.0</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>4.0.0-alpha-3-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>4.0.2</version>
<version>${version.maven-plugin-testing}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -132,28 +128,14 @@ under the License.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.apache.maven</groupId>
<artifactId>maven-di</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>${version.maven-plugin-tools}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
Expand Down
50 changes: 32 additions & 18 deletions src/main/java/org/apache/maven/plugins/clean/Cleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Stream;

import org.apache.maven.api.Event;
Expand Down Expand Up @@ -79,11 +81,11 @@ class Cleaner {
* @param fastMode The fast deletion mode.
*/
Cleaner(Session session, Log log, boolean verbose, Path fastDir, String fastMode) {
logDebug = (log == null || !log.isDebugEnabled()) ? null : log::debug;
logDebug = (log == null || !log.isDebugEnabled()) ? null : logger(log::debug, log::debug);

logInfo = (log == null || !log.isInfoEnabled()) ? null : log::info;
logInfo = (log == null || !log.isInfoEnabled()) ? null : logger(log::info, log::info);

logWarn = (log == null || !log.isWarnEnabled()) ? null : log::warn;
logWarn = (log == null || !log.isWarnEnabled()) ? null : logger(log::warn, log::warn);

logVerbose = verbose ? logInfo : logDebug;

Expand All @@ -92,6 +94,20 @@ class Cleaner {
this.fastMode = fastMode;
}

private Logger logger(Consumer<CharSequence> l1, BiConsumer<CharSequence, Throwable> l2) {
return new Logger() {
@Override
public void log(CharSequence message) {
l1.accept(message);
}

@Override
public void log(CharSequence message, Throwable t) {
l2.accept(message, t);
}
};
}

/**
* Deletes the specified directories and its contents.
*
Expand Down Expand Up @@ -152,8 +168,7 @@ private boolean fastDelete(Path baseDir) {
}
} catch (IOException e) {
if (logDebug != null) {
// TODO: this Logger interface cannot log exceptions and needs refactoring
logDebug.log("Unable to fast delete directory: " + e);
logDebug.log("Unable to fast delete directory", e);
}
return false;
}
Expand All @@ -165,9 +180,10 @@ private boolean fastDelete(Path baseDir) {
}
} catch (IOException e) {
if (logDebug != null) {
// TODO: this Logger interface cannot log exceptions and needs refactoring
logDebug.log("Unable to fast delete directory as the path " + fastDir
+ " does not point to a directory or cannot be created: " + e);
logDebug.log(
"Unable to fast delete directory as the path " + fastDir
+ " does not point to a directory or cannot be created",
e);
}
return false;
}
Expand All @@ -184,8 +200,7 @@ private boolean fastDelete(Path baseDir) {
return true;
} catch (IOException e) {
if (logDebug != null) {
// TODO: this Logger interface cannot log exceptions and needs refactoring
logDebug.log("Unable to fast delete directory: " + e);
logDebug.log("Unable to fast delete directory", e);
}
return false;
}
Expand Down Expand Up @@ -281,7 +296,6 @@ private int delete(Path file, boolean failOnError, boolean retryOnError) throws
Files.deleteIfExists(file);
return 0;
} catch (IOException e) {
boolean deleted = false;
IOException exception = new IOException("Failed to delete " + file);
exception.addSuppressed(e);

Expand All @@ -292,9 +306,9 @@ private int delete(Path file, boolean failOnError, boolean retryOnError) throws
}

final int[] delays = {50, 250, 750};
for (int i = 0; !deleted && i < delays.length; i++) {
for (int delay : delays) {
try {
Thread.sleep(delays[i]);
Thread.sleep(delay);
} catch (InterruptedException e2) {
exception.addSuppressed(e2);
}
Expand All @@ -305,16 +319,14 @@ private int delete(Path file, boolean failOnError, boolean retryOnError) throws
exception.addSuppressed(e2);
}
}
} else {
deleted = !Files.exists(file);
}

if (!deleted) {
if (Files.exists(file)) {
if (failOnError) {
throw new IOException("Failed to delete " + file);
throw new IOException("Failed to delete " + file, exception);
} else {
if (logWarn != null) {
logWarn.log("Failed to delete " + file);
logWarn.log("Failed to delete " + file, exception);
}
return 1;
}
Expand All @@ -339,6 +351,8 @@ public void update(Result result) {
private interface Logger {

void log(CharSequence message);

void log(CharSequence message, Throwable t);
}

private static class BackgroundCleaner extends Thread {
Expand Down

0 comments on commit 76dbe50

Please sign in to comment.