michael-o commented on a change in pull request #6:
URL: https://github.com/apache/maven-clean-plugin/pull/6#discussion_r771549758



##########
File path: src/main/java/org/apache/maven/plugins/clean/Cleaner.java
##########
@@ -286,4 +393,189 @@ public void update( Result result )
 
     }
 
+    static class BackgroundCleaner extends Thread
+    {
+
+        private static BackgroundCleaner instance;
+
+        private final Deque<File> filesToDelete = new ArrayDeque<>();
+
+        private final Cleaner cleaner;
+
+        private static final int NEW = 0;
+        private static final int RUNNING = 1;
+        private static final int STOPPED = 2;
+
+        private int status = NEW;
+
+        public static void delete( Cleaner cleaner, File dir )
+        {
+            synchronized ( BackgroundCleaner.class )
+            {
+                if ( instance == null || !instance.doDelete( dir ) )
+                {
+                    instance = new BackgroundCleaner( cleaner, dir );
+                }
+            }
+        }
+
+        static void sessionEnd()
+        {
+            synchronized ( BackgroundCleaner.class )
+            {
+                if ( instance != null )
+                {
+                    instance.doSessionEnd();
+                }
+            }
+        }
+
+        private BackgroundCleaner( Cleaner cleaner, File dir )
+        {
+            this.cleaner = cleaner;
+            init( cleaner.fastDir, dir );
+        }
+
+        public void run()
+        {
+            while ( true )
+            {
+                File basedir = pollNext();
+                if ( basedir == null )
+                {
+                    break;
+                }
+                try
+                {
+                    cleaner.delete( basedir, "", null, false, false, true );
+                }
+                catch ( IOException e )
+                {
+                    // do not display errors
+                }
+            }
+        }
+
+        synchronized void init( File fastDir, File dir )
+        {
+            if ( fastDir.isDirectory() )
+            {
+                File[] children = fastDir.listFiles();
+                if ( children != null && children.length > 0 )
+                {
+                    for ( File child : children )
+                    {
+                        doDelete( child );

Review comment:
       Since this thread will exist once per JVM, can we give it a better name 
than Java assigns to it? E.g, `mvn-background-cleaner`?

##########
File path: src/main/java/org/apache/maven/plugins/clean/Cleaner.java
##########
@@ -115,9 +135,96 @@ public void delete( File basedir, Selector selector, 
boolean followSymlinks, boo
 
         File file = followSymlinks ? basedir : basedir.getCanonicalFile();
 
+        if ( selector == null && !followSymlinks && fastDir != null && session 
!= null )

Review comment:
       Can the session still be null?




-- 
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