SapiensAnatis commented on issue #1452:
URL: https://github.com/apache/maven-mvnd/issues/1452#issuecomment-3394945697

   In an attempt to be helpful I thought I would look at the code and see what 
I could find, I could be completely wrong but I suspect the cause may be 
sending an EOF before sending the text in 
`TerminalInputHandler::handleProjectInput`. I made this change to add some 
debug logging and move the EOF to after the response:
   
   ```patch
   index c4071cbe..74f0aa62 100644
   --- 
a/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalInputHandler.java
   +++ 
b/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalInputHandler.java
   @@ -127,6 +127,8 @@ public class TerminalInputHandler implements 
AutoCloseable {
        }
    
        private void handleProjectInput(String projectId, int bytesToRead) 
throws IOException {
   +        System.err.println("Project " + projectId + " requests to read " + 
bytesToRead + " bytes.");
   +
            if (daemonReceive == null) {
                return;
            }
   @@ -138,17 +140,22 @@ public class TerminalInputHandler implements 
AutoCloseable {
                int c = terminal.reader().read(timeout);
                if (c < 0) {
                    // End of stream reached
   -                daemonReceive.accept(Message.inputEof());
   +                System.out.println("Reached end of stream");
                    break;
                }
   +
   +            System.out.println("Read character: " + (char)c);
                buf[idx++] = (char) c;
                timeout = idx > 0 ? 1 : 10; // Shorter timeout after first char
            }
    
            if (idx > 0) {
                String data = String.valueOf(buf, 0, idx);
   +            System.out.println("Sending response: " + data);
                daemonReceive.accept(Message.inputResponse(data));
            }
   +
   +        daemonReceive.accept(Message.inputEof());
        }
    
        private void handleControlKeys() throws IOException {
   ```
   
   then my example sort of works, but I have to remove my call to 
`System.in.available()`. It comes through like this:
   
   ```
   [INFO] --- hello:1.0-SNAPSHOT:sayhi (default-cli) @ hello-maven-plugin ---
   Project hello-maven-plugin requests to read 16384 bytes.
   Read character: H
   Read character: e
   Read character: l
   Read character: l
   Read character: o
   Reached end of stream
   Sending response: Hello
   Project hello-maven-plugin requests to read 16379 bytes.
   Reached end of stream
   [INFO] [stdout] Read 5 bytes from stdin.
   [INFO] [stdout] Stdin content: "Hello"
   ```
   
   If I keep the `System.in.available()` it seems like that comes through as a 
request to read 1 byte, which breaks under both master and my change:
   
   ```
   [INFO] --- hello:1.0-SNAPSHOT:sayhi (default-cli) @ hello-maven-plugin ---
   Project hello-maven-plugin requests to read 1 bytes.
   Read character: H
   Sending response: H
   [INFO] [stdout] Available bytes: 0
   Project hello-maven-plugin requests to read 16383 bytes.
   [INFO] [stdout] Read 1 bytes from stdin.
   [INFO] [stdout] Stdin content: "H"
   [INFO] 
----------------------------------------------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] 
----------------------------------------------------------------------------------------------------------------
   [INFO] Total time:  0.044 s (Wall Clock)
   [INFO] Finished at: 2025-10-12T18:05:50+01:00
   [INFO] 
----------------------------------------------------------------------------------------------------------------
   Read character: e
   Read character: l
   Read character: l
   Read character: o
   Reached end of stream
   Sending response: ello
   ```


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