3
3
* Compi Core
4
4
* %%
5
5
* Copyright (C) 2016 - 2018 Daniel Glez-Peña, Osvaldo Graña-Castro, Hugo
6
- * López-Fernández, Jesús Álvarez Casanova
6
+ * López-Fernández, Jesús Álvarez Casanova
7
7
* %%
8
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
9
* you may not use this file except in compliance with the License.
33
33
import java .io .File ;
34
34
import java .io .IOException ;
35
35
import java .util .HashMap ;
36
+ import java .util .HashSet ;
36
37
import java .util .List ;
37
38
import java .util .Map ;
39
+ import java .util .Set ;
38
40
39
41
import org .sing_group .compi .core .pipeline .Foreach ;
40
42
import org .sing_group .compi .core .pipeline .Pipeline ;
@@ -153,10 +155,12 @@ public void export() throws IOException {
153
155
pipelineGraph = pipelineGraph .nodeAttr ().with (config ("Arial" , this .fontSize ));
154
156
155
157
Map <String , Node > idToNode = new HashMap <>();
158
+ Map <String , Task > idToTask = new HashMap <>();
156
159
157
- for (Task task : pipelineObject .getTasks ()) {
158
- Node node = node (task .getId ());
160
+ List <Task > tasks = pipelineObject .getTasks ();
159
161
162
+ for (Task task : tasks ) {
163
+ Node node = node (task .getId ());
160
164
if (Foreach .class .isAssignableFrom (task .getClass ())) {
161
165
node = node .with (Shape .RECTANGLE , getTaskStyle (task .getId (), true ));
162
166
} else {
@@ -166,44 +170,17 @@ public void export() throws IOException {
166
170
node = node .with (Color .rgb (taskToRgbColor .get (task .getId ())));
167
171
}
168
172
idToNode .putIfAbsent (task .getId (), node );
173
+ idToTask .putIfAbsent (task .getId (), task );
169
174
}
170
175
171
- for (Task task : pipelineObject .getTasks ()) {
172
- Node node = idToNode .get (task .getId ());
173
- for (String afterId : task .getAfterList ()) {
174
- if (afterId .startsWith ("*" )) {
175
- afterId = afterId .substring (1 );
176
- idToNode .put (afterId , idToNode .get (afterId ).link (to (node ).with (Style .DASHED )));
177
- } else {
178
- idToNode .put (afterId , idToNode .get (afterId ).link (node ));
179
- }
180
- }
176
+ Set <String > connectedTasks = new HashSet <>();
181
177
182
- if (isDrawParameters (task ) && !task .getParameters ().isEmpty ()) {
183
- if (this .drawParams .equals (DrawParams .TASK )) {
184
- String paramsNodeName = task .getId () + "_params" ;
185
- Node params =
186
- node (paramsNodeName ).with (
187
- html (task .getParameters ().stream ().collect (joining ("<br/>" )))
188
- ).with (getParamsNodeStyle ());
189
- idToNode .put (paramsNodeName , params .link (to (node ).with (Style .DOTTED )));
190
- } else {
191
- for (String p : task .getParameters ()) {
192
- String paramsNodeName = p ;
193
- Node paramsNode = null ;
194
- if (idToNode .containsKey (paramsNodeName )) {
195
- paramsNode = idToNode .get (paramsNodeName );
196
- } else {
197
- paramsNode = node (paramsNodeName ).with (Label .of (p )).with (getParamsNodeStyle ());
198
- }
199
- idToNode .put (paramsNodeName , paramsNode .link (to (node ).with (Style .DOTTED )));
200
- }
201
- }
202
- }
178
+ for (Task task : tasks ) {
179
+ connectTask (task , connectedTasks , idToNode , idToTask );
203
180
}
204
181
205
- for (Node n : idToNode . values () ) {
206
- pipelineGraph = pipelineGraph .with (n );
182
+ for (Task task : tasks ) {
183
+ pipelineGraph = pipelineGraph .with (idToNode . get ( task . getId ()) );
207
184
}
208
185
209
186
Graphviz graphviz = fromGraph (pipelineGraph );
@@ -219,6 +196,50 @@ public void export() throws IOException {
219
196
graphviz .render (this .outputFormat .getFormat ()).toFile (this .output );
220
197
}
221
198
199
+ private void connectTask (
200
+ Task task , Set <String > connectedTasks , Map <String , Node > idToNode , Map <String , Task > idToTask
201
+ ) {
202
+ if (connectedTasks .contains (task .getId ())) {
203
+ return ;
204
+ }
205
+
206
+ Node node = idToNode .get (task .getId ());
207
+ for (String afterId : task .getAfterList ()) {
208
+ if (afterId .startsWith ("*" )) {
209
+ afterId = afterId .substring (1 );
210
+ connectTask (idToTask .get (afterId ), connectedTasks , idToNode , idToTask );
211
+ idToNode .put (afterId , idToNode .get (afterId ).link (to (node ).with (Style .DASHED )));
212
+ } else {
213
+ connectTask (idToTask .get (afterId ), connectedTasks , idToNode , idToTask );
214
+ idToNode .put (afterId , idToNode .get (afterId ).link (node ));
215
+ }
216
+ }
217
+
218
+ connectedTasks .add (task .getId ());
219
+
220
+ if (isDrawParameters (task ) && !task .getParameters ().isEmpty ()) {
221
+ if (this .drawParams .equals (DrawParams .TASK )) {
222
+ String paramsNodeName = task .getId () + "_params" ;
223
+ Node params =
224
+ node (paramsNodeName ).with (
225
+ html (task .getParameters ().stream ().collect (joining ("<br/>" )))
226
+ ).with (getParamsNodeStyle ());
227
+ idToNode .put (paramsNodeName , params .link (to (node ).with (Style .DOTTED )));
228
+ } else {
229
+ for (String p : task .getParameters ()) {
230
+ String paramsNodeName = p ;
231
+ Node paramsNode = null ;
232
+ if (idToNode .containsKey (paramsNodeName )) {
233
+ paramsNode = idToNode .get (paramsNodeName );
234
+ } else {
235
+ paramsNode = node (paramsNodeName ).with (Label .of (p )).with (getParamsNodeStyle ());
236
+ }
237
+ idToNode .put (paramsNodeName , paramsNode .link (to (node ).with (Style .DOTTED )));
238
+ }
239
+ }
240
+ }
241
+ }
242
+
222
243
private boolean isDrawParameters (Task task ) {
223
244
if (drawParams .equals (DrawParams .NO )) {
224
245
return false ;
0 commit comments