test/langtools/tools/lib/toolbox/JavadocTask.java
author vromero
Wed, 18 Apr 2018 16:02:53 -0400
changeset 49822 53aae0c219e6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196433: use the new error diagnostic approach at javac.Main Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     1
/*
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     4
 *
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     8
 *
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    13
 * accompanied this code).
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    14
 *
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    18
 *
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    21
 * questions.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    22
 */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    23
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    24
package toolbox;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    25
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    26
import java.io.File;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    27
import java.io.IOException;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    28
import java.io.PrintWriter;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    29
import java.nio.file.Path;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    30
import java.nio.file.Paths;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    31
import java.util.ArrayList;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    32
import java.util.Arrays;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    33
import java.util.Collections;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    34
import java.util.HashMap;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    35
import java.util.List;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    36
import java.util.Map;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    37
import java.util.stream.Collectors;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    38
import java.util.stream.Stream;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    39
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    40
import javax.tools.DocumentationTool.DocumentationTask;
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 39105
diff changeset
    41
import javax.tools.DocumentationTool;
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    42
import javax.tools.JavaFileManager;
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 39105
diff changeset
    43
import javax.tools.JavaFileManager.Location;
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    44
import javax.tools.JavaFileObject;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    45
import javax.tools.StandardJavaFileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    46
import javax.tools.StandardLocation;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    47
import javax.tools.ToolProvider;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    48
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    49
import jdk.javadoc.internal.api.JavadocTool;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    50
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    51
/**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    52
 * A task to configure and run the documentation tool, javadoc.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    53
 */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    54
public class JavadocTask extends AbstractTask<JavadocTask> {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    55
    private boolean includeStandardOptions;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    56
    private List<Path> classpath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    57
    private List<Path> sourcepath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    58
    private Path outdir;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    59
    private List<String> options;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    60
    private List<String> classes;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    61
    private List<String> files;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    62
    private List<JavaFileObject> fileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    63
    private JavaFileManager fileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    64
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    65
    private JavadocTool jdtool;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    66
    private StandardJavaFileManager internalFileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    67
    private Class<?> docletClass = null; // use the standard doclet by default
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    68
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    69
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    70
     * Creates a task to execute {@code javadoc} using API mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    71
     * @param toolBox the {@code ToolBox} to use
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    72
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    73
    public JavadocTask(ToolBox toolBox) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    74
        super(toolBox, Task.Mode.API);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    75
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    76
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    77
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    78
     * Creates a task to execute {@code javadoc} in a specified mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    79
     * @param toolBox the {@code ToolBox} to use
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    80
     * @param mode the mode to be used
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    81
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    82
    public JavadocTask(ToolBox toolBox, Task.Mode mode) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    83
        super(toolBox, mode);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    84
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    85
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    86
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    87
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    88
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    89
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    90
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    91
    public JavadocTask classpath(String classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    92
        this.classpath = Stream.of(classpath.split(File.pathSeparator))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    93
                .filter(s -> !s.isEmpty())
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    94
                .map(s -> Paths.get(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    95
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    96
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    97
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    98
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    99
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   100
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   101
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   102
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   103
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   104
    public JavadocTask classpath(Path... classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   105
        this.classpath = Arrays.asList(classpath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   106
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   107
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   108
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   109
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   110
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   111
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   112
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   113
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   114
    public JavadocTask classpath(List<Path> classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   115
        this.classpath = classpath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   116
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   117
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   118
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   119
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   120
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   121
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   122
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   123
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   124
    public JavadocTask sourcepath(String sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   125
        this.sourcepath = Stream.of(sourcepath.split(File.pathSeparator))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   126
                .filter(s -> !s.isEmpty())
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   127
                .map(s -> Paths.get(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   128
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   129
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   130
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   131
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   132
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   133
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   134
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   135
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   136
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   137
    public JavadocTask sourcepath(Path... sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   138
        this.sourcepath = Arrays.asList(sourcepath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   139
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   140
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   141
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   142
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   143
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   144
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   145
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   146
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   147
    public JavadocTask sourcepath(List<Path> sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   148
        this.sourcepath = sourcepath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   149
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   150
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   151
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   152
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   153
     * Sets the output directory.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   154
     * @param outdir the output directory
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   155
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   156
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   157
    public JavadocTask outdir(String outdir) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   158
        this.outdir = Paths.get(outdir);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   159
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   160
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   161
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   162
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   163
     * Sets the output directory.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   164
     * @param outdir the output directory
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   165
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   166
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   167
    public JavadocTask outdir(Path outdir) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   168
        this.outdir = outdir;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   169
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   170
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   171
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   172
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   173
     * Sets the options.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   174
     * @param options the options
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   175
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   176
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   177
    public JavadocTask options(String... options) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   178
        this.options = Arrays.asList(options);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   179
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   180
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   181
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   182
    /**
42277
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   183
     * Sets the options.
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   184
     * @param options the options
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   185
     * @return this task object
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   186
     */
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   187
    public JavadocTask options(List<String> options) {
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   188
        this.options = options;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   189
        return this;
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   190
    }
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   191
2668b0bc7ad7 8164316: Refine the Doclet APIs
ksrini
parents: 41633
diff changeset
   192
    /**
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   193
     * Sets the files to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   194
     * @param files the files
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   195
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   196
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   197
    public JavadocTask files(String... files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   198
        this.files = Arrays.asList(files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   199
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   200
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   201
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   202
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   203
     * Sets the files to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   204
     * @param files the files
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   205
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   206
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   207
    public JavadocTask files(Path... files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   208
        this.files = Stream.of(files)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   209
                .map(Path::toString)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   210
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   211
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   212
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   213
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   214
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   215
     * Sets the files to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   216
     * @param files the files
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   217
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   218
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   219
    public JavadocTask files(List<Path> files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   220
        this.files = files.stream()
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   221
                .map(Path::toString)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   222
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   223
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   224
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   225
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   226
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   227
     * Sets the sources to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   228
     * Each source string is converted into an in-memory object that
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   229
     * can be passed directly to the tool.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   230
     * @param sources the sources
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   231
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   232
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   233
    public JavadocTask sources(String... sources) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   234
        fileObjects = Stream.of(sources)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   235
                .map(s -> new ToolBox.JavaSource(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   236
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   237
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   238
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   239
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   240
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   241
     * Sets the file manager to be used by this task.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   242
     * @param fileManager the file manager
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   243
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   244
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   245
    public JavadocTask fileManager(JavaFileManager fileManager) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   246
        this.fileManager = fileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   247
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   248
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   249
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   250
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   251
     * Sets the doclet class to be invoked by javadoc.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   252
     * Note: this is applicable only in API mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   253
     * @param docletClass the user specified doclet
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   254
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   255
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   256
    public JavadocTask docletClass(Class<?> docletClass) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   257
        this.docletClass = docletClass;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   258
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   259
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   260
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   261
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   262
     * {@inheritDoc}
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   263
     * @return the name "javadoc"
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   264
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   265
    @Override
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   266
    public String name() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   267
        return "javadoc";
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   268
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   269
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   270
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   271
     * Calls the javadoc tool with the arguments as currently configured.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   272
     * @return a Result object indicating the outcome of the execution
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   273
     * and the content of any output written to stdout, stderr, or the
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   274
     * main stream by the tool.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   275
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   276
    @Override
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   277
    public Task.Result run() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   278
        if (mode == Task.Mode.EXEC)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   279
            return runExec();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   280
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   281
        AbstractTask.WriterOutput direct = new AbstractTask.WriterOutput();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   282
        // The following are to catch output to System.out and System.err,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   283
        // in case these are used instead of the primary (main) stream
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   284
        AbstractTask.StreamOutput sysOut = new AbstractTask.StreamOutput(System.out, System::setOut);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   285
        AbstractTask.StreamOutput sysErr = new AbstractTask.StreamOutput(System.err, System::setErr);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   286
        int rc;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   287
        Map<Task.OutputKind, String> outputMap = new HashMap<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   288
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   289
            switch (mode == null ? Task.Mode.API : mode) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   290
                case API:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   291
                    rc = runAPI(direct.pw);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   292
                    break;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   293
                case CMDLINE:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   294
                    rc = runCommand(direct.pw);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   295
                    break;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   296
                default:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   297
                    throw new IllegalStateException();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   298
            }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   299
        } catch (IOException e) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   300
            toolBox.out.println("Exception occurred: " + e);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   301
            rc = 99;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   302
        } finally {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   303
            outputMap.put(Task.OutputKind.STDOUT, sysOut.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   304
            outputMap.put(Task.OutputKind.STDERR, sysErr.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   305
            outputMap.put(Task.OutputKind.DIRECT, direct.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   306
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   307
        return checkExit(new Task.Result(toolBox, this, rc, outputMap));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   308
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   309
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   310
    private int runAPI(PrintWriter pw) throws IOException {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   311
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   312
            jdtool = (JavadocTool) ToolProvider.getSystemDocumentationTool();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   313
            jdtool = new JavadocTool();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   314
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   315
            if (fileManager == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   316
                fileManager = internalFileManager = jdtool.getStandardFileManager(null, null, null);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   317
            if (outdir != null)
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 39105
diff changeset
   318
                setLocationFromPaths(DocumentationTool.Location.DOCUMENTATION_OUTPUT,
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 39105
diff changeset
   319
                        Collections.singletonList(outdir));
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   320
            if (classpath != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   321
                setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   322
            if (sourcepath != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   323
                setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   324
            List<String> allOpts = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   325
            if (options != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   326
                allOpts.addAll(options);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   327
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   328
            Iterable<? extends JavaFileObject> allFiles = joinFiles(files, fileObjects);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   329
            DocumentationTask task = jdtool.getTask(pw,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   330
                    fileManager,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   331
                    null,  // diagnostic listener; should optionally collect diags
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   332
                    docletClass,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   333
                    allOpts,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   334
                    allFiles);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   335
            return ((DocumentationTask) task).call() ? 0 : 1;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   336
        } finally {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   337
            if (internalFileManager != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   338
                internalFileManager.close();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   339
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   340
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   341
41633
eec0f5b0465f 8167383: Javadoc does not handle packages correctly when used with module option.
ksrini
parents: 39105
diff changeset
   342
    private void setLocationFromPaths(Location location, List<Path> files) throws IOException {
39105
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   343
        if (!(fileManager instanceof StandardJavaFileManager))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   344
            throw new IllegalStateException("not a StandardJavaFileManager");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   345
        ((StandardJavaFileManager) fileManager).setLocationFromPaths(location, files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   346
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   347
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   348
    private int runCommand(PrintWriter pw) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   349
        List<String> args = getAllArgs();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   350
        String[] argsArray = args.toArray(new String[args.size()]);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   351
        return jdk.javadoc.internal.tool.Main.execute(argsArray, pw);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   352
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   353
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   354
    private Task.Result runExec() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   355
        List<String> args = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   356
        Path javadoc = toolBox.getJDKTool("javadoc");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   357
        args.add(javadoc.toString());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   358
        if (includeStandardOptions) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   359
            args.addAll(toolBox.split(System.getProperty("test.tool.vm.opts"), " +"));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   360
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   361
        args.addAll(getAllArgs());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   362
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   363
        String[] argsArray = args.toArray(new String[args.size()]);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   364
        ProcessBuilder pb = getProcessBuilder();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   365
        pb.command(argsArray);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   366
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   367
            return runProcess(toolBox, this, pb.start());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   368
        } catch (IOException | InterruptedException e) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   369
            throw new Error(e);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   370
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   371
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   372
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   373
    private List<String> getAllArgs() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   374
        List<String> args = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   375
        if (options != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   376
            args.addAll(options);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   377
        if (outdir != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   378
            args.add("-d");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   379
            args.add(outdir.toString());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   380
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   381
        if (classpath != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   382
            args.add("-classpath");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   383
            args.add(toSearchPath(classpath));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   384
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   385
        if (sourcepath != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   386
            args.add("-sourcepath");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   387
            args.add(toSearchPath(sourcepath));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   388
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   389
        if (classes != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   390
            args.addAll(classes);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   391
        if (files != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   392
            args.addAll(files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   393
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   394
        return args;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   395
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   396
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   397
    private String toSearchPath(List<Path> files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   398
        return files.stream()
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   399
            .map(Path::toString)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   400
            .collect(Collectors.joining(File.pathSeparator));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   401
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   402
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   403
    private Iterable<? extends JavaFileObject> joinFiles(
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   404
            List<String> files, List<JavaFileObject> fileObjects) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   405
        if (files == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   406
            return fileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   407
        if (internalFileManager == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   408
            internalFileManager = jdtool.getStandardFileManager(null, null, null);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   409
        Iterable<? extends JavaFileObject> filesAsFileObjects =
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   410
                internalFileManager.getJavaFileObjectsFromStrings(files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   411
        if (fileObjects == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   412
            return filesAsFileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   413
        List<JavaFileObject> combinedList = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   414
        for (JavaFileObject o : filesAsFileObjects)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   415
            combinedList.add(o);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   416
        combinedList.addAll(fileObjects);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   417
        return combinedList;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   418
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   419
}