I am using the maven-antrun-plugin 1.6 with the <input> task and the default input handler. When I enter input, it throws a BuildException, "Failed to read input from Console". The root exception is: java.io.IOException: Stream closed at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145) at java.io.BufferedInputStream.read(BufferedInputStream.java:308) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) at java.io.InputStreamReader.read(InputStreamReader.java:167) at java.io.BufferedReader.fill(BufferedReader.java:136) at java.io.BufferedReader.readLine(BufferedReader.java:299) at java.io.BufferedReader.readLine(BufferedReader.java:362) I was able to fix this issue by wrapping the input stream in KeepAliveInputStream as follows: public void handleInput(InputRequest request) throws BuildException { String prompt = getPrompt(request); BufferedReader r = null; try { r = new BufferedReader(new InputStreamReader(new KeepAliveInputStream(getInputStream()))); do { System.err.print(prompt + ": "); System.err.flush(); try { String input = r.readLine(); request.setInput(input); } catch (IOException e) { throw new BuildException("Failed to read input from" + " Console.", e); } } while (!request.isInputValid()); } finally { if (r != null) { try { r.close(); } catch (IOException e) { throw new BuildException("Failed to close input.", e); } } } }
I am not that used to write pom.xml file. Could you provide a piece of pom.xml which reproduce the bug please ?
The following pom will generate the error: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.help</groupId> <artifactId>Test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Test</name> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>configure-resources</id> <phase>generate-resources</phase> <configuration> <target> <input message="Enter Foo Property" addproperty="foo.property" defaultvalue="FOO"/> <input message="Enter Bar Property" addproperty="bar.property" defaultvalue="BAR"/> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> execute 'mvn generate-sources'
Sorry for the late follow up, but I cannot reproduce the error. I tried with both maven 2 and maven 3. Here is what I got: hibou@hibpro ~/dev/ant/svn/core/trunk/tmp $ mvn generate-sources [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Test 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.135s [INFO] Finished at: Sun Jul 24 13:52:29 CEST 2011 [INFO] Final Memory: 2M/81M [INFO] ------------------------------------------------------------------------ hibou@hibpro ~/dev/ant/svn/core/trunk/tmp $ mvn2 generate-sources [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Test [INFO] task-segment: [generate-sources] [INFO] ------------------------------------------------------------------------ [INFO] No goals needed for project - skipping [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Sun Jul 24 13:52:36 CEST 2011 [INFO] Final Memory: 2M/81M [INFO] ------------------------------------------------------------------------
Ok, sorry about that. If you run 'mvn generate-sources' it doesn't run the ant plugin. Please run it with 'mvn compile'. That should trigger the problem.
reproduced and fixed. Thanks for your report.