elharo commented on code in PR #3589:
URL: https://github.com/apache/maven-surefire/pull/3589#discussion_r4573692144


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java:
##########
@@ -30,7 +30,7 @@
 import org.apache.maven.surefire.api.report.ReporterException;
 import 
org.apache.maven.surefire.extensions.StatelessTestsetInfoFileReportEventListener;
 
-import static 
org.apache.maven.plugin.surefire.report.FileReporterUtils.stripIllegalFilenameChars;
+import static 
org.apache.maven.plugin.surefire.report.FileReporterUtils.makeFileName;

Review Comment:
   This is not a well-known method so don't static import it. Just use 
FileReporterUtils.makeFileName



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java:
##########
@@ -26,11 +26,29 @@
  * @author Andreas Gudian
  */
 public final class FileReporterUtils {
+    // well under the 255-byte limit most filesystems enforce per path 
component,
+    // leaving room for encodings that use more than one byte per character.
+    // Does not cover unusually restrictive encrypted-filename overlays such as
+    // eCryptfs (143 bytes with filename encryption enabled) - handling every
+    // such filesystem is out of scope here.
+    private static final int MAX_FILE_NAME_LENGTH = 200;
+
     private FileReporterUtils() {
         throw new IllegalStateException("non instantiable constructor");
     }
 
-    public static String stripIllegalFilenameChars(String original) {
+    /**
+     * Builds a safe report file name: illegal characters replaced, and 
truncated with a
+     * unique suffix if it would otherwise exceed common filesystem limits.
+     *
+     * @param fileName the file name, including its extension
+     * @return a file name safe to pass to {@link 
java.io.File#File(java.io.File, String)}
+     */
+    public static String makeFileName(String fileName) {

Review Comment:
   non-public



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java:
##########
@@ -43,6 +61,27 @@ public static String stripIllegalFilenameChars(String 
original) {
         return result.toString();
     }
 
+    /**
+     * Shortens a report file name that would otherwise exceed common 
filesystem limits
+     * (e.g. a deeply nested, long test class name), keeping it unique by 
appending a hash
+     * of the untruncated name.
+     *
+     * @param fileName the file name, including its extension
+     * @return {@code fileName} unchanged if it already fits, otherwise a 
truncated name of

Review Comment:
   of the same --> with the same



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java:
##########
@@ -26,11 +26,27 @@
  * @author Andreas Gudian
  */
 public final class FileReporterUtils {
+    // well under the 255-byte limit most filesystems enforce per path 
component,
+    // leaving room for encodings that use more than one byte per character and
+    // for filesystems with a lower limit still (e.g. eCryptfs)
+    private static final int MAX_FILE_NAME_LENGTH = 200;

Review Comment:
   so it doesn't work with eCRyptFS? (which I never heard of before this PR so 
maybe OK) but what does it work with? Why do we still need this PR?



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java:
##########
@@ -26,11 +26,29 @@
  * @author Andreas Gudian
  */
 public final class FileReporterUtils {
+    // well under the 255-byte limit most filesystems enforce per path 
component,
+    // leaving room for encodings that use more than one byte per character.
+    // Does not cover unusually restrictive encrypted-filename overlays such as
+    // eCryptfs (143 bytes with filename encryption enabled) - handling every
+    // such filesystem is out of scope here.
+    private static final int MAX_FILE_NAME_LENGTH = 200;
+
     private FileReporterUtils() {
         throw new IllegalStateException("non instantiable constructor");
     }
 
-    public static String stripIllegalFilenameChars(String original) {
+    /**
+     * Builds a safe report file name: illegal characters replaced, and 
truncated with a
+     * unique suffix if it would otherwise exceed common filesystem limits.
+     *
+     * @param fileName the file name, including its extension
+     * @return a file name safe to pass to {@link 
java.io.File#File(java.io.File, String)}
+     */
+    public static String makeFileName(String fileName) {
+        return truncateFileName(stripIllegalFilenameChars(fileName));
+    }
+
+    static String stripIllegalFilenameChars(String original) {
         StringBuilder result = new StringBuilder(original);
         String illegalChars = getOSSpecificIllegalChars();

Review Comment:
   Not new in this PR, but I really don't like OS specific code or outputs. IN 
this case files might be copied from the current system to a different one. 
Keep in mind that later we might want to fix it so output is platform 
independent. Does this make tests platform dependent?



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