36
36
import java .nio .file .Path ;
37
37
import java .nio .file .Paths ;
38
38
import java .util .ArrayList ;
39
+ import java .util .Arrays ;
39
40
import java .util .HashMap ;
40
41
import java .util .HashSet ;
41
42
import java .util .List ;
@@ -115,102 +116,112 @@ public static void main(String[] args) throws Exception {
115
116
/**
116
117
* Custom dot file attributes.
117
118
*/
118
- static class ModuleGraphAttributes implements ModuleDotGraph .Attributes {
119
- static Map <String , String > DEFAULT_ATTRIBUTES = Map .of (
120
- "ranksep" , "0.6" ,
121
- "fontsize" , "12" ,
122
- "fontcolor" , BLACK ,
123
- "fontname" , "DejaVuSans" ,
124
- "arrowsize" , "1" ,
125
- "arrowwidth" , "2" ,
126
- "arrowcolor" , DARK_GRAY ,
127
- // custom
128
- "requiresMandatedColor" , LIGHT_GRAY ,
129
- "javaSubgraphColor" , ORANGE ,
130
- "jdkSubgraphColor" , BLUE
131
- );
132
-
133
- final Map <String , Integer > weights = new HashMap <>();
134
- final List <Set <String >> ranks = new ArrayList <>();
135
- final Map <String , String > attrs ;
136
- ModuleGraphAttributes (Map <String , String > attrs ) {
137
- int h = 1000 ;
138
- weight ("java.se" , "java.sql.rowset" , h * 10 );
139
- weight ("java.sql.rowset" , "java.sql" , h * 10 );
140
- weight ("java.sql" , "java.xml" , h * 10 );
141
- weight ("java.xml" , "java.base" , h * 10 );
142
-
143
- ranks .add (Set .of ("java.logging" , "java.scripting" , "java.xml" ));
144
- ranks .add (Set .of ("java.sql" ));
145
- ranks .add (Set .of ("java.transaction.xa" ));
146
- ranks .add (Set .of ("java.compiler" , "java.instrument" ));
147
- ranks .add (Set .of ("java.desktop" , "java.management" ));
148
-
149
- this .attrs = attrs ;
150
- }
119
+ static class ModuleGraphAttributes extends ModuleDotGraph .DotGraphAttributes {
120
+ final Properties attrs ;
121
+ final Map <String , Integer > weights ;
151
122
152
123
ModuleGraphAttributes () {
153
- this (DEFAULT_ATTRIBUTES );
154
- }
124
+ this (new Properties () );
125
+ };
155
126
ModuleGraphAttributes (Properties props ) {
156
- this (toAttributes (props ));
127
+ this .attrs = props ;
128
+ this .weights = initWeights (props );
129
+ }
130
+
131
+ @ Override
132
+ public double nodeSep () {
133
+ String v = attrs .getProperty ("nodesep" );
134
+ return v != null ? Double .valueOf (v ) : super .nodeSep ();
157
135
}
158
136
159
137
@ Override
160
138
public double rankSep () {
161
- return Double .valueOf (attrs .get ("ranksep" ));
139
+ String v = attrs .getProperty ("ranksep" );
140
+ return v != null ? Double .valueOf (v ) : super .rankSep ();
162
141
}
163
142
164
143
@ Override
165
144
public int fontSize () {
166
- return Integer .valueOf (attrs .get ("fontsize" ));
145
+ String v = attrs .getProperty ("fontsize" );
146
+ return v != null ? Integer .valueOf (v ) : super .fontSize ();
167
147
}
168
148
169
149
@ Override
170
150
public String fontName () {
171
- return attrs .get ("fontname" );
151
+ String v = attrs .getProperty ("fontname" );
152
+ return v != null ? v : super .fontName ();
172
153
}
173
154
174
155
@ Override
175
156
public String fontColor () {
176
- return attrs .get ("fontcolor" );
157
+ String v = attrs .getProperty ("fontcolor" );
158
+ return v != null ? v : super .fontColor ();
177
159
}
178
160
179
161
@ Override
180
162
public int arrowSize () {
181
- return Integer .valueOf (attrs .get ("arrowsize" ));
163
+ String v = attrs .getProperty ("arrowsize" );
164
+ return v != null ? Integer .valueOf (v ) : super .arrowSize ();
182
165
}
183
166
184
167
@ Override
185
168
public int arrowWidth () {
186
- return Integer .valueOf (attrs .get ("arrowwidth" ));
169
+ String v = attrs .getProperty ("arrowwidth" );
170
+ return v != null ? Integer .valueOf (v ) : super .arrowWidth ();
187
171
}
188
172
189
173
@ Override
190
174
public String arrowColor () {
191
- return attrs .get ("arrowcolor" );
175
+ String v = attrs .getProperty ("arrowcolor" );
176
+ return v != null ? v : super .arrowColor ();
192
177
}
193
178
194
179
@ Override
195
180
public List <Set <String >> ranks () {
196
- return ranks ;
181
+ return attrs .stringPropertyNames ().stream ()
182
+ .filter (k -> k .startsWith ("ranks." ))
183
+ .sorted ()
184
+ .map (k -> Arrays .stream (attrs .getProperty (k ).split ("," ))
185
+ .collect (Collectors .toSet ()))
186
+ .toList ();
197
187
}
198
188
199
189
@ Override
200
190
public String requiresMandatedColor () {
201
- return attrs .get ("requiresMandatedColor" );
191
+ String v = attrs .getProperty ("requiresMandatedColor" );
192
+ return v != null ? v : super .requiresMandatedColor ();
202
193
}
203
194
204
195
@ Override
205
196
public String javaSubgraphColor () {
206
- return attrs .get ("javaSubgraphColor" );
197
+ String v = attrs .getProperty ("javaSubgraphColor" );
198
+ return v != null ? v : super .javaSubgraphColor ();
207
199
}
208
200
209
201
@ Override
210
202
public String jdkSubgraphColor () {
211
- return attrs .get ("jdkSubgraphColor" );
203
+ String v = attrs .getProperty ("jdkSubgraphColor" );
204
+ return v != null ? v : super .jdkSubgraphColor ();
205
+ }
206
+
207
+ @ Override
208
+ public String nodeMargin () {
209
+ String v = attrs .getProperty ("node-margin" );
210
+ return v != null ? v : super .nodeMargin ();
212
211
}
213
212
213
+ @ Override
214
+ public String requiresStyle () {
215
+ String v = attrs .getProperty ("requiresStyle" );
216
+ return v != null ? v : super .requiresStyle ();
217
+ };
218
+
219
+ @ Override
220
+ public String requiresTransitiveStyle () {
221
+ String v = attrs .getProperty ("requiresTransitiveStyle" );
222
+ return v != null ? v : super .requiresTransitiveStyle ();
223
+ };
224
+
214
225
@ Override
215
226
public int weightOf (String s , String t ) {
216
227
int w = weights .getOrDefault (s + ":" + t , 1 );
@@ -221,14 +232,25 @@ public int weightOf(String s, String t) {
221
232
return 1 ;
222
233
}
223
234
224
- public void weight (String s , String t , int w ) {
225
- weights .put (s + ":" + t , w );
226
- }
227
-
228
- static Map <String , String > toAttributes (Properties props ) {
229
- return DEFAULT_ATTRIBUTES .keySet ().stream ()
230
- .collect (Collectors .toMap (Function .identity (),
231
- k -> props .getProperty (k , DEFAULT_ATTRIBUTES .get (k ))));
235
+ /*
236
+ * Create a map of <mn>:<dep> with a weight trying to line up
237
+ * the modules in the weights property in the specified order.
238
+ */
239
+ public static Map <String , Integer > initWeights (Properties props ) {
240
+ String [] modules = props .getProperty ("weights" , "" ).split ("," );
241
+ int len = modules .length ;
242
+ if (len == 0 ) return Map .of ();
243
+
244
+ Map <String , Integer > weights = new HashMap <>();
245
+ String mn = modules [0 ];
246
+ int w = 10000 ;
247
+ for (int i = 1 ; i < len ; i ++) {
248
+ String dep = modules [i ];
249
+ weights .put (mn + ":" + dep , w );
250
+ mn = dep ;
251
+ }
252
+ weights .put (mn + ":java.base" , w );
253
+ return weights ;
232
254
}
233
255
}
234
256
0 commit comments