如何使用Ant'输入'任务读取多行值?

Don*_*kby 3 ant

有人知道如何在Ant脚本中输入多行值吗?我正在使用输入任务提示用户进行Subversion提交注释,我希望能够支持多行文本.

我在Windows命令提示符下运行Ant的独立版本.

我以为我可能能够进行搜索并替换\n,但我看不到任何简单的方法来从Ant中的属性值替换属性值.看起来我必须写一个文件,替换文件,然后将文件加载到另一个属性.我不是那么想要它.

Mat*_*nit 5

我不是100%肯定这个,但我看了一下Ant源代码,它只是做了一个readLine():

来自/org/apache/tools/ant/input/DefaultInputHandler.java:

/**
 * Prompts and requests input.  May loop until a valid input has
 * been entered.
 * @param request the request to handle
 * @throws BuildException if not possible to read from console
 */
public void handleInput(InputRequest request) throws BuildException {
    String prompt = getPrompt(request);
    BufferedReader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(getInputStream()));
        do {
            System.err.println(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);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我是你,我会怎么做:

  • 如果您使用的是Ant 1.7,那么请尝试实现您自己的InputHandler,如文档中所述.Apache许可证允许您基本上复制并粘贴上述代码作为起点.
  • 如果您使用的是Ant 1.6或更早版本,那么只需创建自己的MultiLineInput任务即可.您可以扩展现有的Input类,只读取多行.

在任何一种情况下,您都需要决定用户如何表明"我已经完成了".您可以使用空行或句号等.

祝好运!

PS当我在谷歌搜索"蚂蚁多行输入"时,这个页面是第一个命中:-).对于一个不到一小时前提出的问题,令人印象深刻.