代码之家  ›  专栏  ›  技术社区  ›  Nick Veys

捕获Ant<javadoc>任务输出

  •  4
  • Nick Veys  · 技术社区  · 17 年前

    javadoc 蚂蚁任务?我没有看到像任务中那样的输出属性。似乎有警告说Checkstyle无法捕获,最好在文件中捕获该输出。

    ~*~*~*~ (答案如下)~*~*~*~

    the Ant docs .

    <target name="generate.docs">
        <record name="javadoc.log" action="start"/>
        <javadoc ... />
        <record name="javadoc.log" action="stop"/>
    <target/>
    
    4 回复  |  直到 15 年前
        1
  •  1
  •   Roboprog    17 年前

    <exec> reference here )...这可能会很痛苦,但可能可以执行javadoc可执行文件并重建生成javadoc所需的命令参数。不过,作为一个巨大的打击,它似乎只使用你的自然shell重定向,因此在Win32和Linux上构建需要一些特殊的方法。

    write your own task 做这项工作;要么 <redirect>

        2
  •  1
  •   Art Doler    17 年前

    <redirect file='foo.txt' append='true'>
      <anytag you='want' />
    </redirect>
    
        3
  •  1
  •   Yishai    17 年前

    您可以使用com.sun.tools.javadoc将javadoc作为Java类执行。Main类,调用execute方法(它位于JDK中包含的tools.jar中),因此您可以包装从Ant java任务调用的java类,这允许重定向输出。您必须自己重建javadoc命令行参数,而不是像Ant任务那样精确,但它应该可以工作。

        4
  •  1
  •   haui    6 年前

    javadoc outputFile

    public class MyJavaDoc extends org.apache.tools.ant.taskdefs.Javadoc{
    
        private File _outFile;
    
        private Writer _writer;
    
        /**
         * The file to write error output to.
         */
        public void setOutputFile(File outFile) {
            _outFile = outFile;
        }
    
        @Override
        public void execute() throws BuildException {
            if (_outFile == null) {
                throw new BuildException("Missing 'outputFile' parameter.");
            }
            try (OutputStream out = new FileOutputStream(_outFile)) {
                _writer = new OutputStreamWriter(out);
                try {
                    super.execute();
                } finally {
                    _writer.close();
                }
            } catch (IOException ex) {
                throw new BuildException("Cannot write error output: " + ex.getMessage(), ex);
            }
        }
    
        @Override
        public void log(String msg, int msgLevel) {
            if (msgLevel <= Project.MSG_WARN) {
                try {
                    _writer.write(msg);
                    _writer.write("\n");
                } catch (IOException ex) {
                    throw new IOError(ex);
                }
            }
            super.log(msg, msgLevel);
        }
    
    }
    
    推荐文章