apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.6k stars 836 forks source link

Test results window does not work with colored Maven output #7441

Open maffe opened 1 month ago

maffe commented 1 month ago

Apache NetBeans version

Apache NetBeans 22

What happened

The test results window does not show up automatically when selecting “Test” in a project’s context menu. After opening it via Window → IDE Tools → Test Results, it stays empty even when running the tests again.

Language / Project Type / NetBeans Component

Java Maven Project

How to reproduce

Without --color always:


BUILD SUCCESS

Total time: 3.984 s Finished at: 2024-06-06T10:36:19+02:00


With `--color always`:
- Output does contain prefixes like `[INFO]` (with the letters colored blue, or yellow in case of warnings)
- Some messages like `Tests run: 18, Failures: 0, Errors: 0, Skipped: 0` and `BUILD SUCCESS` appear in green
- `NETBEANS-ExecEvent` entries are visible
- Example output:

[INFO] Tests run: 18, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] NETBEANS-ExecEvent:{"mojo":{"phase":"test","loc":{"col":-1,"ln":-1,"id":"org.apache.maven:maven-core:3.9.3:default-lifecycle-bindings"},"impl":"org.apache.maven.plugin.surefire.SurefirePlugin","urls":["file:\/C:\/…\/org\/apache\/maven\/plugins\/maven-surefire-plugin\/3.2.5\/maven-surefire-plugin-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/maven-surefire-common\/3.2.5\/maven-surefire-common-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-api\/3.2.5\/surefire-api-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-logger-api\/3.2.5\/surefire-logger-api-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-extensions-api\/3.2.5\/surefire-extensions-api-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-booter\/3.2.5\/surefire-booter-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-extensions-spi\/3.2.5\/surefire-extensions-spi-3.2.5.jar","file:\/C:\/…\/org\/apache\/maven\/shared\/maven-common-artifact-filters\/3.1.1\/maven-common-artifact-filters-3.1.1.jar","file:\/C:\/…\/commons-io\/commons-io\/2.15.1\/commons-io-2.15.1.jar","file:\/C:\/…\/org\/codehaus\/plexus\/plexus-java\/1.2.0\/plexus-java-1.2.0.jar","file:\/C:\/…\/org\/ow2\/asm\/asm\/9.6\/asm-9.6.jar","file:\/C:\/…\/com\/thoughtworks\/qdox\/qdox\/2.0.3\/qdox-2.0.3.jar","file:\/C:\/…\/org\/apache\/maven\/surefire\/surefire-shared-utils\/3.2.5\/surefire-shared-utils-3.2.5.jar"],"goal":"test","id":"org.apache.maven.plugins:maven-surefire-plugin:3.2.5","source":"LIFECYCLE","execId":"default-test"},"type":"MojoSucceeded"} [INFO] NETBEANS-ExecEvent:{"prj":{"file":"C:\…","id":"…"},"type":"ProjectSucceeded"} [INFO] NETBEANS-ExecEvent:{"prjcount":1,"type":"SessionEnded"} [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.011 s [INFO] Finished at: 2024-06-06T10:34:59+02:00 [INFO] ------------------------------------------------------------------------



### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows 10 64 Bit

### JDK

OpenJDK 22

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

Full Maven Global execution options are `--batch-mode --errors --color always --show-version --strict-checksums -Djavax.net.ssl.trustStore=foo.jks -Daether.remoteRepositoryFilter.prefixes=true`

Previously reported as #4734

`--color always` also breaks other things like links to source code in Javadoc warnings and stack traces

### Are you willing to submit a pull request?

No
mbien commented 1 month ago

the output window is not a fully featured terminal, it doesn't support meta information in the text. If it would be a terminal, you wouldn't have to force color output, it would automatically activate.

matthiasblaesing commented 1 month ago

I think we are seeing an issue that is caused by ansi escape sequences in the output of maven. Without having looked deeper into the problem, the integration code basicly parses the output of maven and reacts accordingly. #7113 adjusted the matching pattern to fix one problem. Coloring adds sequences to the output, that are not displayed text, but code colors/behavior.

Either the matches need to be adjusted to support ansi escape sequences. Or they need to be stripped out before the existing matchers are processed.

mbien commented 1 month ago

forcing coloring and then stripping text decorations again while adding more custom coloring will lead to other issues most likely. This sounds also like a bit too much patchwork and might not be something we should sink time into.

Maven is smart enough to detect not fully featured terminals and turn coloring off. The forward looking fix would be to switch the output to a proper terminal. This is more work though and windows is missing a good impl atm https://github.com/apache/netbeans/issues/3959.

btw: the issue goes deeper, mvnd for example really likes fully featured terminals since it outputs log in parallel which rewrites terminal lines. To work within NB it switches to a simple impl which serializes the output again.

related: https://github.com/apache/netbeans/issues/5552

duplicate: https://github.com/apache/netbeans/issues/6210

matthiasblaesing commented 1 month ago

I think you are wrong. The author works around #6210 by forcing maven to output color codes and This works:

Normal output:

image

Output with "--color always":

image

So the output window of NetBeans happily parses the escape sequences and outputs them.

What I see is this:

  1. Maven process is executed and NetBeans receives its output
  2. A set of handlers process the output line-by-line and react to that
  3. The output might contain ansi escape sequences if maven either thinks it is talking to a real terminal or is forced to to so (the color flag)
  4. The processors are not prepared to get output with ansi escape sequences
  5. Because the processors are not prepared to get ansi escape sequences the JUnitOutputListenerProvider will not match the lines it should match

All referenced issues may be related, but don't match.

3959 is from my POV totally different, as it just requests to be able to use cmd/powershell as shell. I ran cmd inside a the NetBeans terminal emulator at least once, so the terminal emulator of NetBeans is enough to support the output of cmd, powershell needs another test. I suspect the hard part is to see, that the features the NB Terminal emulator provides with bash also work with cmd (launching with a working directory, receiving title updates).

5552 just says, that it is not consistent across OutputWindow users and sometimes ansi escape sequences don't work, but my screenshot shows, that it works. My take on that is, that the problem is the sending side, that might detect, that it is not talking to a tty and thus falls back to not sending ansi sequences.

6210 is not a duplicate, but asks for color support by default, different problem and using color parameter explicitly overruled by author.

mbien commented 1 month ago

I know that the current output can render some decorations, this causes several problems. NB is coloring the output too without anticipating it to be in color already, and none of the output line handlers expect decorated text at the moment. You see that in your output that nothing is filtered, code folding is off and mojo specific handlers will likely also not work.