You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/05/12 13:57:24 UTC

[GitHub] [maven-surefire] sman-81 opened a new pull request, #535: [SUREFIRE-2086] Management of temporary files

sman-81 opened a new pull request, #535:
URL: https://github.com/apache/maven-surefire/pull/535

   Management of temporary files in surefire into sub directories of the system's directory of temporary files to avoid bloating the temp directory root.
   
    - [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SUREFIRE) filed 
          for the change (usually before you start working on it).  Trivial changes like typos do not 
          require a JIRA issue.  Your pull request should address just this issue, without 
          pulling in other changes.
    - [x] Each commit in the pull request should have a meaningful subject line and body.
    - [x] Format the pull request title like `[SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `SUREFIRE-XXX` with the appropriate JIRA issue. Best practice
          is to use the JIRA issue title in the pull request title and in the first line of the 
          commit message.
    - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
    - [x] Run `mvn clean install` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [ ] You have run the integration tests successfully (`mvn -Prun-its clean install`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under 
   the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
    - [x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] sman-81 commented on pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
sman-81 commented on PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#issuecomment-1141822955

   hi @michael-o I've answered to the requested changes. Anything else that needs to be done before accepting this pull request?


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] michael-o commented on a diff in pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#discussion_r871738015


##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -0,0 +1,242 @@
+package org.apache.maven.surefire.api.util;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Management of temporary files in surefire with support for sub directories of the system's directory
+ * of temporary files.<br>
+ * The {@link File#createTempFile(String, String)} API creates rather meaningless file names and
+ * only in the system's temp directory.<br>
+ * This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix.
+ * It also helps you organize temporary files into sub-directories,
+ * and thus avoid bloating the temp directory root.<br>
+ * Apart from that, this class works in much the same way as {@link File#createTempFile(String, String)}
+ * and {@link File#deleteOnExit()}, and can be used as a drop-in replacement.
+ *
+ * @author Markus Spann
+ */
+public final class TempFileManager
+{
+
+    private static final Map<File, TempFileManager> INSTANCES  = new LinkedHashMap<>();
+    /** An id unique across all file managers used as part of the temporary file's base name. */
+    private static final AtomicInteger              FILE_ID    = new AtomicInteger( 1 );
+    private static final String                     SUFFIX_TMP = ".tmp";
+
+    private static Thread                           shutdownHook;
+
+    /** The temporary directory or sub-directory under which temporary files are created. */
+    private final File                              tempDir;
+    /** The fixed base name used between prefix and suffix of temporary files created by this class. */
+    private final String                            baseName;
+
+    /** List of successfully created temporary files. */
+    private final List<File>                        tempFiles;
+
+    /** Temporary files are delete on JVM exit if true. */
+    private boolean                                 deleteOnExit;
+
+    private TempFileManager( File tempDir )
+    {
+        this.tempDir = tempDir;
+        this.baseName = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSSS" ).format( LocalDateTime.now() );

Review Comment:
   Use basic ISO 8601.



##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -0,0 +1,242 @@
+package org.apache.maven.surefire.api.util;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Management of temporary files in surefire with support for sub directories of the system's directory
+ * of temporary files.<br>
+ * The {@link File#createTempFile(String, String)} API creates rather meaningless file names and
+ * only in the system's temp directory.<br>
+ * This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix.
+ * It also helps you organize temporary files into sub-directories,
+ * and thus avoid bloating the temp directory root.<br>
+ * Apart from that, this class works in much the same way as {@link File#createTempFile(String, String)}
+ * and {@link File#deleteOnExit()}, and can be used as a drop-in replacement.
+ *
+ * @author Markus Spann
+ */
+public final class TempFileManager
+{
+
+    private static final Map<File, TempFileManager> INSTANCES  = new LinkedHashMap<>();
+    /** An id unique across all file managers used as part of the temporary file's base name. */
+    private static final AtomicInteger              FILE_ID    = new AtomicInteger( 1 );
+    private static final String                     SUFFIX_TMP = ".tmp";
+
+    private static Thread                           shutdownHook;
+
+    /** The temporary directory or sub-directory under which temporary files are created. */
+    private final File                              tempDir;
+    /** The fixed base name used between prefix and suffix of temporary files created by this class. */
+    private final String                            baseName;
+
+    /** List of successfully created temporary files. */
+    private final List<File>                        tempFiles;
+
+    /** Temporary files are delete on JVM exit if true. */
+    private boolean                                 deleteOnExit;
+
+    private TempFileManager( File tempDir )
+    {
+        this.tempDir = tempDir;
+        this.baseName = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSSS" ).format( LocalDateTime.now() );
+        this.tempFiles = new ArrayList<>();
+    }
+
+    private static File calcTempDir( String subDirName )
+    {
+        String tempDirName = subDirName == null ? null
+                        : subDirName.trim().isEmpty() ? null : subDirName.trim();
+        File tempDirCandidate = tempDirName == null ? new File( getJavaIoTmpDir() )
+                        : new File( getJavaIoTmpDir(), tempDirName );
+        return tempDirCandidate;
+    }
+
+    public static TempFileManager instance( )
+    {
+        return instance( ( File ) null );
+    }
+
+    /**
+     * Creates an instance using a subdirectory of the system's temporary directory.
+     * @param subDirName name of subdirectory
+     * @return instance
+     */
+    public static TempFileManager instance( String subDirName )
+    {
+        return instance( calcTempDir( subDirName ) );
+    }
+
+    public static synchronized TempFileManager instance( File tempDir )
+    {
+
+        // on creation of the first instance, register a shutdown hook to delete temporary files of all managers
+        if ( shutdownHook == null )
+        {
+            ThreadGroup tg = Thread.currentThread().getThreadGroup();

Review Comment:
   Aren't those dead?



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] olamy merged pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
olamy merged PR #535:
URL: https://github.com/apache/maven-surefire/pull/535


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] sman-81 commented on pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
sman-81 commented on PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#issuecomment-1145594568

   Thanks @olamy!


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] olamy commented on pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
olamy commented on PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#issuecomment-1143133867

   @sman-81 not sure what you have done but this PR include plenty of non needed commits (already in master)
   you should rebase correctly from master thanks


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] sman-81 commented on pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
sman-81 commented on PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#issuecomment-1143166333

   > @sman-81 not sure what you have done but this PR include plenty of non needed commits (already in master) plenty of changes are not from you. maybe you should rebase correctly from master. thanks
   
   @olamy I had done the rebase from master wrongly. Now it should be good. Could you please take another look?


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] sman-81 commented on a diff in pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
sman-81 commented on code in PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#discussion_r872279362


##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -0,0 +1,242 @@
+package org.apache.maven.surefire.api.util;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Management of temporary files in surefire with support for sub directories of the system's directory
+ * of temporary files.<br>
+ * The {@link File#createTempFile(String, String)} API creates rather meaningless file names and
+ * only in the system's temp directory.<br>
+ * This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix.
+ * It also helps you organize temporary files into sub-directories,
+ * and thus avoid bloating the temp directory root.<br>
+ * Apart from that, this class works in much the same way as {@link File#createTempFile(String, String)}
+ * and {@link File#deleteOnExit()}, and can be used as a drop-in replacement.
+ *
+ * @author Markus Spann
+ */
+public final class TempFileManager
+{
+
+    private static final Map<File, TempFileManager> INSTANCES  = new LinkedHashMap<>();
+    /** An id unique across all file managers used as part of the temporary file's base name. */
+    private static final AtomicInteger              FILE_ID    = new AtomicInteger( 1 );
+    private static final String                     SUFFIX_TMP = ".tmp";
+
+    private static Thread                           shutdownHook;
+
+    /** The temporary directory or sub-directory under which temporary files are created. */
+    private final File                              tempDir;
+    /** The fixed base name used between prefix and suffix of temporary files created by this class. */
+    private final String                            baseName;
+
+    /** List of successfully created temporary files. */
+    private final List<File>                        tempFiles;
+
+    /** Temporary files are delete on JVM exit if true. */
+    private boolean                                 deleteOnExit;
+
+    private TempFileManager( File tempDir )
+    {
+        this.tempDir = tempDir;
+        this.baseName = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSSS" ).format( LocalDateTime.now() );
+        this.tempFiles = new ArrayList<>();
+    }
+
+    private static File calcTempDir( String subDirName )
+    {
+        String tempDirName = subDirName == null ? null
+                        : subDirName.trim().isEmpty() ? null : subDirName.trim();
+        File tempDirCandidate = tempDirName == null ? new File( getJavaIoTmpDir() )
+                        : new File( getJavaIoTmpDir(), tempDirName );
+        return tempDirCandidate;
+    }
+
+    public static TempFileManager instance( )
+    {
+        return instance( ( File ) null );
+    }
+
+    /**
+     * Creates an instance using a subdirectory of the system's temporary directory.
+     * @param subDirName name of subdirectory
+     * @return instance
+     */
+    public static TempFileManager instance( String subDirName )
+    {
+        return instance( calcTempDir( subDirName ) );
+    }
+
+    public static synchronized TempFileManager instance( File tempDir )
+    {
+
+        // on creation of the first instance, register a shutdown hook to delete temporary files of all managers
+        if ( shutdownHook == null )
+        {
+            ThreadGroup tg = Thread.currentThread().getThreadGroup();

Review Comment:
   Do you mean `ShutdownHook` or `ThreadGroup`?
   Both are still part of moderns JDKs such as Java 17 (LTS) and neither marked deprecated nor discouraged.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven-surefire] sman-81 commented on a diff in pull request #535: [SUREFIRE-2086] Management of temporary files

Posted by GitBox <gi...@apache.org>.
sman-81 commented on code in PR #535:
URL: https://github.com/apache/maven-surefire/pull/535#discussion_r872275968


##########
surefire-api/src/main/java/org/apache/maven/surefire/api/util/TempFileManager.java:
##########
@@ -0,0 +1,242 @@
+package org.apache.maven.surefire.api.util;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Management of temporary files in surefire with support for sub directories of the system's directory
+ * of temporary files.<br>
+ * The {@link File#createTempFile(String, String)} API creates rather meaningless file names and
+ * only in the system's temp directory.<br>
+ * This class creates temp files from a prefix, a unique date/timestamp, a short file id and suffix.
+ * It also helps you organize temporary files into sub-directories,
+ * and thus avoid bloating the temp directory root.<br>
+ * Apart from that, this class works in much the same way as {@link File#createTempFile(String, String)}
+ * and {@link File#deleteOnExit()}, and can be used as a drop-in replacement.
+ *
+ * @author Markus Spann
+ */
+public final class TempFileManager
+{
+
+    private static final Map<File, TempFileManager> INSTANCES  = new LinkedHashMap<>();
+    /** An id unique across all file managers used as part of the temporary file's base name. */
+    private static final AtomicInteger              FILE_ID    = new AtomicInteger( 1 );
+    private static final String                     SUFFIX_TMP = ".tmp";
+
+    private static Thread                           shutdownHook;
+
+    /** The temporary directory or sub-directory under which temporary files are created. */
+    private final File                              tempDir;
+    /** The fixed base name used between prefix and suffix of temporary files created by this class. */
+    private final String                            baseName;
+
+    /** List of successfully created temporary files. */
+    private final List<File>                        tempFiles;
+
+    /** Temporary files are delete on JVM exit if true. */
+    private boolean                                 deleteOnExit;
+
+    private TempFileManager( File tempDir )
+    {
+        this.tempDir = tempDir;
+        this.baseName = DateTimeFormatter.ofPattern( "yyyyMMddHHmmssSSS" ).format( LocalDateTime.now() );

Review Comment:
   `DateTimeFormatter` has no constant for a date/timestamp with milliseconds.



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org