author | ksrini |
Wed, 12 Apr 2017 11:42:50 -0700 | |
changeset 44684 | 6ce4d52084e8 |
parent 42407 | f3702cff2933 |
child 44807 | 47e09e3f1829 |
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 = ""; |
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 | 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 | 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 | 58 |
public ModuleBuilder(ToolBox tb, String name) { |
59 |
this.tb = tb; |
|
60 |
this.name = name; |
|
61 |
} |
|
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 'a;/'. |
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 | 72 |
} |
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 | 124 |
return this; |
125 |
} |
|
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 | 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 | 171 |
} |
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 | 201 |
} |
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 | 210 |
} |
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 | 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 | 224 |
return this; |
225 |
} |
|
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 | 233 |
public ModuleBuilder classes(String... content) { |
234 |
this.content.addAll(Arrays.asList(content)); |
|
235 |
return this; |
|
236 |
} |
|
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 | 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 | 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 | 263 |
tb.writeJavaFiles(moduleSrc, sources.toArray(new String[]{})); |
264 |
return moduleSrc; |
|
265 |
} |
|
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 | 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 | 295 |
.files(tb.findJavaFiles(moduleSrc)) |
296 |
.run() |
|
297 |
.writeAll(); |
|
298 |
} |
|
299 |
} |