desruisseaux commented on code in PR #286:
URL: 
https://github.com/apache/maven-clean-plugin/pull/286#discussion_r2564334026


##########
src/main/java/org/apache/maven/plugins/clean/BackgroundCleaner.java:
##########
@@ -0,0 +1,342 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.clean;
+
+import java.io.IOException;
+import java.nio.file.DirectoryNotEmptyException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.maven.api.Event;
+import org.apache.maven.api.EventType;
+import org.apache.maven.api.Listener;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.annotations.Nonnull;
+import org.apache.maven.api.plugin.Log;
+import org.apache.maven.api.services.PathMatcherFactory;
+
+/**
+ * A cleaner potentially executed by background threads.
+ *
+ * <h4>Limitations</h4>
+ * This class can be used for deleting {@link Path} only, not {@link Fileset}, 
because this class cannot handle
+ * the case where only a subset of the files should be deleted. It cannot 
handle following symbolic links neither.
+ *
+ * @author Benjamin Bentmann
+ * @author Martin Desruisseaux
+ */
+final class BackgroundCleaner extends Cleaner implements Listener, Runnable {
+    /**
+     * The maven session.
+     */
+    @Nonnull
+    private final Session session;
+
+    /**
+     * The directory where to temporarily move the files to delete.
+     */
+    @Nonnull
+    private final Path fastDir;
+
+    /**
+     * Mode to use when using fast clean. Values are:
+     * {@code background} to start deletion immediately and waiting for all 
files to be deleted when the session ends,
+     * {@code at-end} to indicate that the actual deletion should be performed 
synchronously when the session ends, or
+     * {@code defer} to specify that the actual file deletion should be 
started in the background when the session ends.
+     */
+    @Nonnull
+    private final FastMode fastMode;
+
+    /**
+     * The executor to use for deleting files in background threads.
+     */
+    @Nonnull
+    private final ExecutorService executor;
+
+    /**
+     * Files to delete at the end of the session instead of in background 
thread.
+     * This is unused ({@code null}) for {@link FastMode#BACKGROUND}.
+     */
+    private final List<Path> filesToDeleteAtEnd;
+
+    /**
+     * Directories to delete last, after the executor has been shutdown, and 
only if they are empty.
+     * This is the directory that contains the temporary directories where the 
files to delete have been moved.
+     * We can obviously not delete that directory before all deletion tasks in 
the background thread finished.
+     * The directory is deleted only if empty because other plugins (e.g. 
compiler plugin) may have wrote new
+     * files after the clean.
+     */
+    @Nonnull
+    private final Set<Path> directoriesToDeleteIfEmpty;
+
+    /**
+     * Errors that occurred during the deletion.
+     */
+    private IOException errors;

Review Comment:
   It can contain many exceptions as suppressed exceptions. I will clarify the 
documentation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to