pshevche commented on code in PR #3179:
URL: https://github.com/apache/maven-surefire/pull/3179#discussion_r2911406075


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleOutputFileReporter.java:
##########
@@ -72,83 +68,103 @@ public ConsoleOutputFileReporter(
     }
 
     @Override
-    public synchronized void testSetStarting(TestSetReportEntry reportEntry) {
-        closeNullReportFile(reportEntry);
+    public void testSetStarting(TestSetReportEntry reportEntry) {
+        String className = usePhrasedFileName ? reportEntry.getSourceText() : 
reportEntry.getSourceName();
+        try {
+            File file = getReportFile(reportsDirectory, className, 
reportNameSuffix, "-output.txt");
+            if (!reportsDirectory.exists()) {
+                Files.createDirectories(reportsDirectory.toPath());
+            }
+            if (!Files.exists(file.toPath())) {
+                Files.createFile(file.toPath());
+            }
+            outputStreams.put(
+                    className, new 
BufferedOutputStream(Files.newOutputStream(file.toPath()), STREAM_BUFFER_SIZE));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     @Override
     public void testSetCompleted(TestSetReportEntry report) {}
 
     @Override
-    public synchronized void close() {
-        // The close() method is called in main Thread T2.
-        closeReportFile();
+    public void close() {
+        // Close all output streams in the map
+        for (FilterOutputStream stream : outputStreams.values()) {
+            try {
+                stream.close();
+            } catch (IOException e) {
+                dumpException(e);
+            }
+        }
     }
 
     @Override
     public synchronized void writeTestOutput(TestOutputReportEntry 
reportEntry) {
         try {
-            // This method is called in single thread T1 per fork JVM (see 
ThreadedStreamConsumer).
-            // The close() method is called in main Thread T2.
-            int[] status = new int[1];
-            FilterOutputStream os = fileOutputStream.get(status);
-            if (status[0] != CLOSED) {
-                if (os == null) {
+            // Determine the target class name based on stack trace or 
reportEntryName
+            String targetClassName = 
extractTestClassFromStack(reportEntry.getStack());
+            if (targetClassName == null) {
+                targetClassName = reportEntryName;

Review Comment:
   @olamy , we have tested the Develocity Maven extension against the latest 
surefire 3.6.0 snapshot that includes your changes. This piece of code causes 
some trouble for Test Distribution and Predictive Test Selection. Unless I am 
missing something, the `reportEntryName` is accessed but never set. So, the 
output without stack traces is not attributed to the correct output file. You 
probably need to set it in the `testSetStarting` and reset it in the 
`testSetCompleted`.



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