langtools/test/tools/lib/toolbox/ModuleBuilder.java
author ksrini
Wed, 12 Apr 2017 11:42:50 -0700
changeset 44684 6ce4d52084e8
parent 42407 f3702cff2933
child 44807 47e09e3f1829
permissions -rw-r--r--
8178067: support for @uses/@provides tags is broken Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     1
/*
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42407
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     4
 *
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     8
 *
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    13
 * accompanied this code).
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    14
 *
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    18
 *
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    21
 * questions.
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    22
 */
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    23
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    24
package toolbox;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    25
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    26
import java.io.File;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    27
import java.io.IOException;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    28
import java.nio.file.Files;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    29
import java.nio.file.Path;
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    30
import java.nio.file.Paths;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    31
import java.util.ArrayList;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    32
import java.util.Arrays;
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    33
import java.util.LinkedHashSet;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    34
import java.util.List;
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    35
import java.util.Set;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    36
import java.util.stream.Collectors;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    37
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    38
/**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    39
 * Builder for module declarations.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    40
 */
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    41
public class ModuleBuilder {
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    42
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    43
    private final ToolBox tb;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    44
    private final String name;
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    45
    private String comment = "";
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    46
    private List<String> requires = new ArrayList<>();
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    47
    private List<String> exports = new ArrayList<>();
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    48
    private List<String> uses = new ArrayList<>();
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    49
    private List<String> provides = new ArrayList<>();
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    50
    private List<String> content = new ArrayList<>();
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    51
    private Set<Path> modulePath = new LinkedHashSet<>();
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    52
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    53
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    54
     * Creates a builder for a module.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    55
     * @param tb a Toolbox that can be used to compile the module declaration.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    56
     * @param name the name of the module to be built
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    57
     */
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    58
    public ModuleBuilder(ToolBox tb, String name) {
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    59
        this.tb = tb;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    60
        this.name = name;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    61
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    62
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    63
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    64
     * Sets the doc comment for the declaration.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    65
     * @param comment the content of the comment, excluding the initial
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    66
     *  '/**', leading whitespace and asterisks, and the final trailing '&#02a;/'.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    67
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    68
     */
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    69
    public ModuleBuilder comment(String comment) {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    70
        this.comment = comment;
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    71
        return this;
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    72
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
    73
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    74
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    75
     * Adds a "requires" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    76
     * @param module the name of the module that is required
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    77
     * @param modulePath a path in while to locate the modules
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    78
     *    if the declaration is compiled
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    79
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    80
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    81
    public ModuleBuilder requires(String module, Path... modulePath) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    82
        addDirective(requires, "requires " + module + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    83
        this.modulePath.addAll(Arrays.asList(modulePath));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    84
        return this;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    85
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    86
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    87
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    88
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    89
     * Adds a "requires static" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    90
     * @param module the name of the module that is required
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    91
     * @param modulePath a path in which to locate the modules
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    92
     *    if the declaration is compiled
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    93
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
    94
     */
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    95
    public ModuleBuilder requiresStatic(String module, Path... modulePath) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    96
        addDirective(requires, "requires static " + module + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    97
        this.modulePath.addAll(Arrays.asList(modulePath));
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    98
        return this;
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
    99
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   100
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   101
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   102
     * Adds a "requires transitive" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   103
     * @param module the name of the module that is required
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   104
     * @param modulePath a path in which to locate the modules
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   105
     *    if the declaration is compiled
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   106
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   107
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   108
    public ModuleBuilder requiresTransitive(String module, Path... modulePath) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   109
        addDirective(requires, "requires transitive " + module + ";");
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   110
        this.modulePath.addAll(Arrays.asList(modulePath));
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   111
        return this;
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   112
    }
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   113
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   114
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   115
     * Adds a "requires static transitive" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   116
     * @param module the name of the module that is required
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   117
     * @param modulePath a path in which to locate the modules
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   118
     *    if the declaration is compiled
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   119
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   120
     */
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   121
    public ModuleBuilder requiresStaticTransitive(String module, Path... modulePath) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   122
        addDirective(requires, "requires static transitive " + module + ";");
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   123
        this.modulePath.addAll(Arrays.asList(modulePath));
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   124
        return this;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   125
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   126
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   127
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   128
     * Adds an unqualified "exports" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   129
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   130
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   131
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   132
    public ModuleBuilder exports(String pkg) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   133
        return addDirective(exports, "exports " + pkg + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   134
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   135
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   136
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   137
     * Adds an unqualified "exports dynamic" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   138
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   139
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   140
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   141
    public ModuleBuilder exportsDynamic(String pkg) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   142
        return addDirective(exports, "exports dynamic " + pkg + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   143
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   144
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   145
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   146
     * Adds an unqualified "exports private" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   147
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   148
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   149
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   150
    public ModuleBuilder exportsPrivate(String pkg) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   151
        return addDirective(exports, "exports private " + pkg + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   152
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   153
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   154
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   155
     * Adds an unqualified "exports dynamic private" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   156
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   157
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   158
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   159
    public ModuleBuilder exportsDynamicPrivate(String pkg) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   160
        return addDirective(exports, "exports dynamic private " + pkg + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   161
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   162
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   163
    /**
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   164
     * Adds a qualified "exports" directive to the declaration.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   165
     * @param pkg the name of the package to be exported
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   166
     * @param module the name of the module to which it is to be exported
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   167
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   168
     */
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   169
    public ModuleBuilder exportsTo(String pkg, String module) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   170
        return addDirective(exports, "exports " + pkg + " to " + module + ";");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   171
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   172
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   173
    /**
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   174
     * Adds a qualified "exports dynamic" directive to the declaration.
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   175
     * @param pkg the name of the package to be exported
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   176
     * @param module the name of the module to which it is to be exported
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   177
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   178
     */
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   179
    public ModuleBuilder exportsDynamicTo(String pkg, String module) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   180
        return addDirective(exports, "exports dynamic " + pkg + " to " + module + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   181
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   182
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   183
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   184
     * Adds a qualified "exports private" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   185
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   186
     * @param module the name of the module to which it is to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   187
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   188
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   189
    public ModuleBuilder exportsPrivateTo(String pkg, String module) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   190
        return addDirective(exports, "exports private " + pkg + " to " + module + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   191
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   192
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   193
    /**
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   194
     * Adds a qualified "exports dynamic private" directive to the declaration.
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   195
     * @param pkg the name of the package to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   196
     * @param module the name of the module to which it is to be exported
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   197
     * @return this builder
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   198
     */
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   199
    public ModuleBuilder exportsDynamicPrivateTo(String pkg, String module) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   200
        return addDirective(exports, "exports dynamic private " + pkg + " to " + module + ";");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   201
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   202
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   203
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   204
     * Adds a "uses" directive to the declaration.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   205
     * @param service the name of the service type
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   206
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   207
     */
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   208
    public ModuleBuilder uses(String service) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   209
        return addDirective(uses, "uses " + service + ";");
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   210
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   211
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   212
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   213
     * Adds a "provides" directive to the declaration.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   214
     * @param service the name of the service type
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   215
     * @param implementation the name of the implementation type
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   216
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   217
     */
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   218
    public ModuleBuilder provides(String service, String implementation) {
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   219
        return addDirective(provides, "provides " + service + " with " + implementation + ";");
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   220
    }
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   221
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   222
    private ModuleBuilder addDirective(List<String> directives, String directive) {
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40763
diff changeset
   223
        directives.add(directive);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   224
        return this;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   225
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   226
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   227
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   228
     * Adds type definitions to the module.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   229
     * @param content a series of strings, each representing the content of
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   230
     *  a compilation unit to be included with the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   231
     * @return this builder
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   232
     */
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   233
    public ModuleBuilder classes(String... content) {
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   234
        this.content.addAll(Arrays.asList(content));
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   235
        return this;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   236
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   237
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   238
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   239
     * Writes the module declaration and associated additional compilation
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   240
     * units to a module directory within a given directory.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   241
     * @param srcDir the directory in which a directory will be created
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   242
     *  to contain the source files for the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   243
     * @return the directory containing the source files for the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   244
     */
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   245
    public Path write(Path srcDir) throws IOException {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   246
        Files.createDirectories(srcDir);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   247
        List<String> sources = new ArrayList<>();
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   248
        StringBuilder sb = new StringBuilder();
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   249
        if (!comment.isEmpty()) {
44684
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42407
diff changeset
   250
            sb.append("/**\n * ")
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42407
diff changeset
   251
                    .append(comment.replace("\n", "\n * "))
6ce4d52084e8 8178067: support for @uses/@provides tags is broken
ksrini
parents: 42407
diff changeset
   252
                    .append("\n */\n");
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   253
        }
40500
f293dbb81a53 8162353: javadoc should provide a way to disable use of frames
jjg
parents: 39103
diff changeset
   254
        sb.append("module ").append(name).append(" {\n");
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   255
        requires.forEach(r -> sb.append("    " + r + "\n"));
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   256
        exports.forEach(e -> sb.append("    " + e + "\n"));
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   257
        uses.forEach(u -> sb.append("    " + u + "\n"));
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   258
        provides.forEach(p -> sb.append("    " + p + "\n"));
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   259
        sb.append("}");
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   260
        sources.add(sb.toString());
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   261
        sources.addAll(content);
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   262
        Path moduleSrc = srcDir.resolve(name);
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   263
        tb.writeJavaFiles(moduleSrc, sources.toArray(new String[]{}));
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   264
        return moduleSrc;
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   265
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   266
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   267
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   268
     * Writes the source files for the module to an interim directory,
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   269
     * and then compiles them to a given directory.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   270
     * @param modules the directory in which a directory will be created
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   271
     *    to contain the compiled class files for the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   272
     * @throws IOException if an error occurs while compiling the files
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   273
     */
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   274
    public void build(Path modules) throws IOException {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   275
        build(Paths.get(modules + "Src"), modules);
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   276
    }
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   277
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   278
    /**
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   279
     * Writes the source files for the module to a specified directory,
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   280
     * and then compiles them to a given directory.
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   281
     * @param srcDir the directory in which a directory will be created
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   282
     *  to contain the source files for the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   283
     * @param modules the directory in which a directory will be created
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   284
     *    to contain the compiled class files for the module
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   285
     * @throws IOException if an error occurs while compiling the files
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   286
     */
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   287
    public void build(Path src, Path modules) throws IOException {
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   288
        Path moduleSrc = write(src);
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   289
        String mp = modulePath.stream()
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   290
                .map(Path::toString)
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   291
                .collect(Collectors.joining(File.pathSeparator));
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   292
        new JavacTask(tb)
39103
91a64ec5b970 8159749: Update toolbox ModuleBuilder for doc comments
jjg
parents: 37758
diff changeset
   293
                .outdir(Files.createDirectories(modules.resolve(name)))
40763
209113892b0d 8165109: langtools/test switches to use new CLI options
mchung
parents: 40500
diff changeset
   294
                .options("--module-path", mp)
37758
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   295
                .files(tb.findJavaFiles(moduleSrc))
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   296
                .run()
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   297
                .writeAll();
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   298
    }
3ecf9b414e05 8155774: move code from ModuleTestBase to toolbox
jjg
parents:
diff changeset
   299
}