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 2020/12/23 17:13:56 UTC

[GitHub] [maven] bmarwell opened a new pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

bmarwell opened a new pull request #415:
URL: https://github.com/apache/maven/pull/415


   This PR will fix MNG-7032: ANSI will not be used when using both `--batch-mode` and `--version`.
   This is a bug because with batch mode, ANSI colours should not be used.
   
   The tests works on a char level: By comparing the stripped and the non-stripped version, the test would fail if they differed. Or put in another way: If the sysout-version contained ANSI colour information, it would not match the stripped version.
   ---
   
   Following this checklist to help us incorporate your 
   contribution quickly and easily:
   
    - [X] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MNG) 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 `[MNG-XXX] - Fixes bug in ApproximateQuantiles`,
          where you replace `MNG-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.
    - [ ] Run `mvn clean verify` to make sure basic checks pass. A more thorough check will 
          be performed on your pull request automatically.
    - [X] You have run the [Core IT][core-its] successfully.
   
   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.
   
    - [ ] 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).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   


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

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



[GitHub] [maven] bmarwell commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549097062



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode

Review comment:
       Hi @michael-o – are you sure it is "unwanted"? There are numerous similar comments…
   
   Also, I think it is helpful for readability. You do not always have all commits on your second screen. Blame might not help if there was a slight change in a later version, as blame only shows the LATEST commit of a line.
   
   ![2020-12-27T11:46:22_0001_screenshot](https://user-images.githubusercontent.com/1413391/103169106-47362a80-4839-11eb-9a62-ee0ec7f35be9.png)
   




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

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



[GitHub] [maven] michael-o commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-869067524


   Can this be closed? MNG-7032 has been addressed with another PR.


-- 
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] rfscholte commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
rfscholte commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549106876



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode

Review comment:
       Only if there's a huge comment required to explain what's happening based on a ticket, it might be worth adding the issue number for easy access to the discussion. In this case it is quite clear what's happing, especially if the comment is almost the same as the methodname.




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

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



[GitHub] [maven] rfscholte commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
rfscholte commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549107198



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -569,6 +570,20 @@ else if ( cliRequest.commandLine.hasOption( CLIManager.BATCH_MODE )
         }
     }
 
+    /**
+     * Disables the colour output in the case that the {@link CLIManager#BATCH_MODE} option
+     * or {@link CLIManager#LOG_FILE} option was given (or both). In those cases, ANSI output is never feasible.
+     * @param cliRequest the arguments as request pojo.
+     */
+    private void disableColorsInLogfileOrBatch( CliRequest cliRequest )

Review comment:
       I'd prefer a more general method name: applyColorMode. This way we can add more logic when necessary




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

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



[GitHub] [maven] asfgit closed pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #415:
URL: https://github.com/apache/maven/pull/415


   


-- 
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] michael-o commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549103918



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode

Review comment:
       I now that there are, I think this really belongs to an SCM unless you are describing the behavior of the code. Getting "MNG-7032" git be done with 'git blame', so this information is redundant for me. Like people adding dates to their comments.




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

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



[GitHub] [maven] bmarwell commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-750395178


   Huh, I need some help with the tests.
   I do not think any IT should fail because of my change, but they did fail: https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven/job/MNG-7032_versioncolours/2/testReport/
   
   On the other hand, I get an NPE locally – in `MavenCliTest.testStyleColors:340`. I really cannot explain what is going on here. Is `cli` being nulled? If so, why?


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

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



[GitHub] [maven] bmarwell commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-751812135


   > My bad, I did not notice that you have moved the code. But still, The property needs to be in the new method now for consistency reasons.
   
   I see. I could just move that block into the new method `applyColorMode( CliRequest cliRequest )` and update its Javadoc.


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

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



[GitHub] [maven] michael-o commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r548254291



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode

Review comment:
       This comment is redundant because we have commit messages and blames.




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

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



[GitHub] [maven] rfscholte commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
rfscholte commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549321675



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -518,10 +520,9 @@ else if ( !"auto".equals( styleColor ) )
             throw new IllegalArgumentException( "Invalid color configuration option [" + styleColor
                 + "]. Supported values are (auto|always|never)." );
         }
-        else if ( cliRequest.commandLine.hasOption( CLIManager.BATCH_MODE )
-            || cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) )
+        else

Review comment:
       this else-statement can now be removed, because the color mode has already been applied




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

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



[GitHub] [maven] bmarwell commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549316323



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode

Review comment:
       Thanks, that is helpful insight. I now see why the comment is redundant.




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

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



[GitHub] [maven] bmarwell edited a comment on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell edited a comment on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-751754398


   > This looks OK, but incomplete. When if you at `org.apache.maven.cli.MavenCli.logging(CliRequest)` in the block marked with `// LOG COLOR` you see duplicate code now. It is probably time to move that code out of `logging()` into `cli()`.
   
   Which one? This? 
   https://github.com/apache/maven/blob/496b9bd65d0ddd0fb19c8c9f89058555f458790e/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L508-L522
   
   I do not see this code duplicated somewhere else. There are other duplicated parts, however.
   
   ![2020-12-28T16:35:36_0001_screenshot](https://user-images.githubusercontent.com/1413391/103225713-dcfdb280-492a-11eb-8544-fced0e35043a.png)
   


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

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



[GitHub] [maven] bmarwell commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
bmarwell commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-751754398


   > This looks OK, but incomplete. When if you at `org.apache.maven.cli.MavenCli.logging(CliRequest)` in the block marked with `// LOG COLOR` you see duplicate code now. It is probably time to move that code out of `logging()` into `cli()`.
   > 
   > I wonder what will happen when one does the following:
   > 
   > ```
   > mvn -v -Dstyle.color=always | less -R
   > ```
   > 
   > I would expect to see colors here also stdout is not attached to a tty. I think we need to move the use property to a CLI option to make it more obvious.
   > 
   > I am quite used to: `grep --color=always ... | less -R`
   
   Which one? This? 
   https://github.com/apache/maven/blob/496b9bd65d0ddd0fb19c8c9f89058555f458790e/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L508-L522
   
   I do not see this code duplicated somewhere else. There are other duplicated parts, however.
   
   ![2020-12-28T16:35:36_0001_screenshot](https://user-images.githubusercontent.com/1413391/103225713-dcfdb280-492a-11eb-8544-fced0e35043a.png)
   


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

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



[GitHub] [maven] michael-o commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-751684726


   I will happily go through. I was never really happy that Jansi is installed by default even if batch or file mode were activated.


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

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



[GitHub] [maven] rfscholte commented on a change in pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
rfscholte commented on a change in pull request #415:
URL: https://github.com/apache/maven/pull/415#discussion_r549106686



##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -433,6 +433,8 @@ void cli( CliRequest cliRequest )
 
         if ( cliRequest.commandLine.hasOption( CLIManager.VERSION ) )
         {
+            // MNG-7032: Also disable colours if in batch mode
+            disableColorsInLogfileOrBatch( cliRequest );

Review comment:
       Please move this line to line 427. I can imagine we're going to add colors to the help output too. And maybe there will be more options in the future. This disabling a global thing, should not be restricted to `version`.




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

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



[GitHub] [maven] michael-o commented on pull request #415: [MNG-7032] do not print colours for --version when in batch mode.

Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #415:
URL: https://github.com/apache/maven/pull/415#issuecomment-751758529


   My bad, I did not notice that you have moved the code. But still, The property needs to be in the new method now for consistency reasons.


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

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