langtools/test/tools/lib/toolbox/JavadocTask.java
author ksrini
Mon, 20 Jun 2016 07:02:42 -0700
changeset 39105 956490b8da9c
child 41633 eec0f5b0465f
permissions -rw-r--r--
8159756: javadoc tests needs a tool invoker 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;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    41
import javax.tools.JavaFileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    42
import javax.tools.JavaFileObject;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    43
import javax.tools.StandardJavaFileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    44
import javax.tools.StandardLocation;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    45
import javax.tools.ToolProvider;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    46
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    47
import jdk.javadoc.internal.api.JavadocTool;
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
/**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    50
 * A task to configure and run the documentation tool, javadoc.
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
public class JavadocTask extends AbstractTask<JavadocTask> {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    53
    private boolean includeStandardOptions;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    54
    private List<Path> classpath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    55
    private List<Path> sourcepath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    56
    private Path outdir;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    57
    private List<String> options;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    58
    private List<String> classes;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    59
    private List<String> files;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    60
    private List<JavaFileObject> fileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    61
    private JavaFileManager fileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    62
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    63
    private JavadocTool jdtool;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    64
    private StandardJavaFileManager internalFileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    65
    private Class<?> docletClass = null; // use the standard doclet by default
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    66
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    67
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    68
     * Creates a task to execute {@code javadoc} using API mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    69
     * @param toolBox the {@code ToolBox} to use
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    70
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    71
    public JavadocTask(ToolBox toolBox) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    72
        super(toolBox, Task.Mode.API);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    73
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    74
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
     * Creates a task to execute {@code javadoc} in a specified mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    77
     * @param toolBox the {@code ToolBox} to use
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    78
     * @param mode the mode to be used
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    79
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    80
    public JavadocTask(ToolBox toolBox, Task.Mode mode) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    81
        super(toolBox, mode);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    82
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    83
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
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    86
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    87
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    88
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    89
    public JavadocTask classpath(String classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    90
        this.classpath = Stream.of(classpath.split(File.pathSeparator))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    91
                .filter(s -> !s.isEmpty())
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    92
                .map(s -> Paths.get(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    93
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    94
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    95
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    96
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
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
    99
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   100
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   101
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   102
    public JavadocTask classpath(Path... classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   103
        this.classpath = Arrays.asList(classpath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   104
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   105
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   106
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
     * Sets the classpath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   109
     * @param classpath the classpath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   110
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   111
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   112
    public JavadocTask classpath(List<Path> classpath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   113
        this.classpath = classpath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   114
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   115
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   116
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
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   119
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   120
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   121
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   122
    public JavadocTask sourcepath(String sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   123
        this.sourcepath = Stream.of(sourcepath.split(File.pathSeparator))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   124
                .filter(s -> !s.isEmpty())
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   125
                .map(s -> Paths.get(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   126
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   127
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   128
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   129
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
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   132
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   133
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   134
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   135
    public JavadocTask sourcepath(Path... sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   136
        this.sourcepath = Arrays.asList(sourcepath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   137
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   138
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   139
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
     * Sets the sourcepath.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   142
     * @param sourcepath the sourcepath
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   143
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   144
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   145
    public JavadocTask sourcepath(List<Path> sourcepath) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   146
        this.sourcepath = sourcepath;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   147
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   148
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   149
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
     * Sets the output directory.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   152
     * @param outdir the output directory
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   153
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   154
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   155
    public JavadocTask outdir(String outdir) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   156
        this.outdir = Paths.get(outdir);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   157
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   158
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   159
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
     * Sets the output directory.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   162
     * @param outdir the output directory
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   163
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   164
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   165
    public JavadocTask outdir(Path outdir) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   166
        this.outdir = outdir;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   167
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   168
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   169
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
     * Sets the options.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   172
     * @param options the options
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   173
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   174
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   175
    public JavadocTask options(String... options) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   176
        this.options = Arrays.asList(options);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   177
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   178
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   179
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
     * Sets the files to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   182
     * @param files the files
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   183
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   184
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   185
    public JavadocTask files(String... files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   186
        this.files = Arrays.asList(files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   187
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   188
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   189
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   190
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   191
     * Sets the files to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   192
     * @param files the files
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   193
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   194
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   195
    public JavadocTask files(Path... files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   196
        this.files = Stream.of(files)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   197
                .map(Path::toString)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   198
                .collect(Collectors.toList());
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(List<Path> files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   208
        this.files = files.stream()
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 sources to be documented.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   216
     * Each source string is converted into an in-memory object that
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   217
     * can be passed directly to the tool.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   218
     * @param sources the sources
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   219
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   220
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   221
    public JavadocTask sources(String... sources) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   222
        fileObjects = Stream.of(sources)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   223
                .map(s -> new ToolBox.JavaSource(s))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   224
                .collect(Collectors.toList());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   225
        return this;
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
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   228
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   229
     * Sets the file manager to be used by this task.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   230
     * @param fileManager the file manager
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 fileManager(JavaFileManager fileManager) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   234
        this.fileManager = fileManager;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   235
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   236
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   237
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
     * Sets the doclet class to be invoked by javadoc.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   240
     * Note: this is applicable only in API mode.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   241
     * @param docletClass the user specified doclet
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   242
     * @return this task object
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   243
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   244
    public JavadocTask docletClass(Class<?> docletClass) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   245
        this.docletClass = docletClass;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   246
        return this;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   247
    }
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
     * {@inheritDoc}
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   251
     * @return the name "javadoc"
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   252
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   253
    @Override
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   254
    public String name() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   255
        return "javadoc";
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   256
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   257
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   258
    /**
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   259
     * Calls the javadoc tool with the arguments as currently configured.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   260
     * @return a Result object indicating the outcome of the execution
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   261
     * and the content of any output written to stdout, stderr, or the
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   262
     * main stream by the tool.
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   263
     */
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   264
    @Override
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   265
    public Task.Result run() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   266
        if (mode == Task.Mode.EXEC)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   267
            return runExec();
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
        AbstractTask.WriterOutput direct = new AbstractTask.WriterOutput();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   270
        // The following are to catch output to System.out and System.err,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   271
        // in case these are used instead of the primary (main) stream
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   272
        AbstractTask.StreamOutput sysOut = new AbstractTask.StreamOutput(System.out, System::setOut);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   273
        AbstractTask.StreamOutput sysErr = new AbstractTask.StreamOutput(System.err, System::setErr);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   274
        int rc;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   275
        Map<Task.OutputKind, String> outputMap = new HashMap<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   276
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   277
            switch (mode == null ? Task.Mode.API : mode) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   278
                case API:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   279
                    rc = runAPI(direct.pw);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   280
                    break;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   281
                case CMDLINE:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   282
                    rc = runCommand(direct.pw);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   283
                    break;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   284
                default:
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   285
                    throw new IllegalStateException();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   286
            }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   287
        } catch (IOException e) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   288
            toolBox.out.println("Exception occurred: " + e);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   289
            rc = 99;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   290
        } finally {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   291
            outputMap.put(Task.OutputKind.STDOUT, sysOut.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   292
            outputMap.put(Task.OutputKind.STDERR, sysErr.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   293
            outputMap.put(Task.OutputKind.DIRECT, direct.close());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   294
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   295
        return checkExit(new Task.Result(toolBox, this, rc, outputMap));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   296
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   297
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   298
    private int runAPI(PrintWriter pw) throws IOException {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   299
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   300
            jdtool = (JavadocTool) ToolProvider.getSystemDocumentationTool();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   301
            jdtool = new JavadocTool();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   302
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   303
            if (fileManager == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   304
                fileManager = internalFileManager = jdtool.getStandardFileManager(null, null, null);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   305
            if (outdir != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   306
                setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Collections.singletonList(outdir));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   307
            if (classpath != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   308
                setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   309
            if (sourcepath != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   310
                setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   311
            List<String> allOpts = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   312
            if (options != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   313
                allOpts.addAll(options);
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
            Iterable<? extends JavaFileObject> allFiles = joinFiles(files, fileObjects);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   316
            DocumentationTask task = jdtool.getTask(pw,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   317
                    fileManager,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   318
                    null,  // diagnostic listener; should optionally collect diags
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   319
                    docletClass,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   320
                    allOpts,
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   321
                    allFiles);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   322
            return ((DocumentationTask) task).call() ? 0 : 1;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   323
        } finally {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   324
            if (internalFileManager != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   325
                internalFileManager.close();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   326
        }
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
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   329
    private void setLocationFromPaths(StandardLocation location, List<Path> files) throws IOException {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   330
        if (!(fileManager instanceof StandardJavaFileManager))
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   331
            throw new IllegalStateException("not a StandardJavaFileManager");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   332
        ((StandardJavaFileManager) fileManager).setLocationFromPaths(location, files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   333
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   334
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   335
    private int runCommand(PrintWriter pw) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   336
        List<String> args = getAllArgs();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   337
        String[] argsArray = args.toArray(new String[args.size()]);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   338
        return jdk.javadoc.internal.tool.Main.execute(argsArray, pw);
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
    private Task.Result runExec() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   342
        List<String> args = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   343
        Path javadoc = toolBox.getJDKTool("javadoc");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   344
        args.add(javadoc.toString());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   345
        if (includeStandardOptions) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   346
            args.addAll(toolBox.split(System.getProperty("test.tool.vm.opts"), " +"));
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
        args.addAll(getAllArgs());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   349
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
        ProcessBuilder pb = getProcessBuilder();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   352
        pb.command(argsArray);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   353
        try {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   354
            return runProcess(toolBox, this, pb.start());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   355
        } catch (IOException | InterruptedException e) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   356
            throw new Error(e);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   357
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   358
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   359
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   360
    private List<String> getAllArgs() {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   361
        List<String> args = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   362
        if (options != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   363
            args.addAll(options);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   364
        if (outdir != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   365
            args.add("-d");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   366
            args.add(outdir.toString());
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   367
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   368
        if (classpath != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   369
            args.add("-classpath");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   370
            args.add(toSearchPath(classpath));
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
        if (sourcepath != null) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   373
            args.add("-sourcepath");
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   374
            args.add(toSearchPath(sourcepath));
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   375
        }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   376
        if (classes != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   377
            args.addAll(classes);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   378
        if (files != null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   379
            args.addAll(files);
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
        return args;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   382
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   383
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   384
    private String toSearchPath(List<Path> files) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   385
        return files.stream()
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   386
            .map(Path::toString)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   387
            .collect(Collectors.joining(File.pathSeparator));
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
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   390
    private Iterable<? extends JavaFileObject> joinFiles(
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   391
            List<String> files, List<JavaFileObject> fileObjects) {
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   392
        if (files == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   393
            return fileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   394
        if (internalFileManager == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   395
            internalFileManager = jdtool.getStandardFileManager(null, null, null);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   396
        Iterable<? extends JavaFileObject> filesAsFileObjects =
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   397
                internalFileManager.getJavaFileObjectsFromStrings(files);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   398
        if (fileObjects == null)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   399
            return filesAsFileObjects;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   400
        List<JavaFileObject> combinedList = new ArrayList<>();
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   401
        for (JavaFileObject o : filesAsFileObjects)
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   402
            combinedList.add(o);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   403
        combinedList.addAll(fileObjects);
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   404
        return combinedList;
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   405
    }
956490b8da9c 8159756: javadoc tests needs a tool invoker
ksrini
parents:
diff changeset
   406
}