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