SapiensAnatis opened a new issue, #1452:
URL: https://github.com/apache/maven-mvnd/issues/1452

   ### Affected version
   
   6734804eedc68f0f30aca315e842f3ec015def73
   
   ### Bug description
   
   I am looking to use mvnd as a way to run an auto-formatter in an IDE plugin, 
so far it looks much faster than mvn so I'm very keen to get it working.
   
   The auto-formatter mojo tries to read the document from stdin. I have 
noticed this works fine in mvn but on mvnd it is only able to read 1 byte. I 
made the following mojo to demonstrate the issue:
   
   ```java
   package sample.plugin;
   
   import org.apache.maven.plugin.AbstractMojo;
   import org.apache.maven.plugin.MojoExecutionException;
   import org.apache.maven.plugins.annotations.Mojo;
   import java.nio.charset.StandardCharsets;
   
   @Mojo(name = "sayhi")
   public class GreetingMojo extends AbstractMojo {
       @Override
       public void execute() throws MojoExecutionException {
           byte[] bytes = new byte[] {};
   
           try {
               System.out.println("Available bytes: " + System.in.available());
               bytes = System.in.readAllBytes();
           } catch (Exception ex) {
               getLog().error("Failed to read from stdin", ex);
           }
   
           System.out.println("Read " + bytes.length + " bytes from stdin.");
           System.out.println("Stdin content: \"" + new String(bytes, 
StandardCharsets.UTF_8) + "\"");
       }
   }
   ```
   
   If I run this with `mvn` as follows:
   
   ```
   $ echo -n "Hello" | mvn sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi
   ```
   
   then I get the expected output:
   
   ```
   [INFO] --- hello:1.0-SNAPSHOT:sayhi (default-cli) @ hello-maven-plugin ---
   [INFO] [stdout] Available bytes: 5
   [INFO] [stdout] Read 5 bytes from stdin.
   [INFO] [stdout] Stdin content: "Hello"
   ```
   
   However if I use `mvnd`:
   
   ```
   $ echo -n "Hello" | mvnd sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi
   ```
   
   then I get this output:
   
   ```
   [INFO] --- hello:1.0-SNAPSHOT:sayhi (default-cli) @ hello-maven-plugin ---
   [INFO] [stdout] Available bytes: 0
   [INFO] [stdout] Read 1 bytes from stdin.
   [INFO] [stdout] Stdin content: "H"
   ```
   
   or sometimes I get `[INFO] [stdout] Stdin content: ""`. I have found if I 
ignore `System.in.available()` and keep trying to read 1 character at a time I 
can eventually get the whole stdin content, but it would be nice if 
`readAllBytes` just worked.
   
   Could this be a delay in the daemon receiving the standard input from the 
terminal interface? I did try adding a sleep for 1s at the start of my mojo but 
this didn't change the behaviour at all.


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