Skip to content

Commit 3b73d60

Browse files
committed
Fix graph creation to avoid duplicated node links
1 parent 6042fd0 commit 3b73d60

File tree

6 files changed

+62
-41
lines changed

6 files changed

+62
-41
lines changed

cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.3</version>
12+
<version>1.3.4</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>org.sing_group</groupId>
1212
<artifactId>compi</artifactId>
13-
<version>1.3.3</version>
13+
<version>1.3.4</version>
1414
<!--
1515
WARNING: change version using (in the parent project):
1616
mvn versions:set -DnewVersion=[new_version]

core/src/main/java/org/sing_group/compi/io/graph/PipelineGraphExporter.java

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Compi Core
44
* %%
55
* 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
77
* %%
88
* Licensed under the Apache License, Version 2.0 (the "License");
99
* you may not use this file except in compliance with the License.
@@ -33,8 +33,10 @@
3333
import java.io.File;
3434
import java.io.IOException;
3535
import java.util.HashMap;
36+
import java.util.HashSet;
3637
import java.util.List;
3738
import java.util.Map;
39+
import java.util.Set;
3840

3941
import org.sing_group.compi.core.pipeline.Foreach;
4042
import org.sing_group.compi.core.pipeline.Pipeline;
@@ -153,10 +155,12 @@ public void export() throws IOException {
153155
pipelineGraph = pipelineGraph.nodeAttr().with(config("Arial", this.fontSize));
154156

155157
Map<String, Node> idToNode = new HashMap<>();
158+
Map<String, Task> idToTask = new HashMap<>();
156159

157-
for (Task task : pipelineObject.getTasks()) {
158-
Node node = node(task.getId());
160+
List<Task> tasks = pipelineObject.getTasks();
159161

162+
for (Task task : tasks) {
163+
Node node = node(task.getId());
160164
if (Foreach.class.isAssignableFrom(task.getClass())) {
161165
node = node.with(Shape.RECTANGLE, getTaskStyle(task.getId(), true));
162166
} else {
@@ -166,44 +170,17 @@ public void export() throws IOException {
166170
node = node.with(Color.rgb(taskToRgbColor.get(task.getId())));
167171
}
168172
idToNode.putIfAbsent(task.getId(), node);
173+
idToTask.putIfAbsent(task.getId(), task);
169174
}
170175

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<>();
181177

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);
203180
}
204181

205-
for (Node n : idToNode.values()) {
206-
pipelineGraph = pipelineGraph.with(n);
182+
for (Task task : tasks) {
183+
pipelineGraph = pipelineGraph.with(idToNode.get(task.getId()));
207184
}
208185

209186
Graphviz graphviz = fromGraph(pipelineGraph);
@@ -219,6 +196,50 @@ public void export() throws IOException {
219196
graphviz.render(this.outputFormat.getFormat()).toFile(this.output);
220197
}
221198

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+
222243
private boolean isDrawParameters(Task task) {
223244
if (drawParams.equals(DrawParams.NO)) {
224245
return false;

dk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.3</version>
12+
<version>1.3.4</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

e2e-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.3</version>
12+
<version>1.3.4</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>org.sing_group</groupId>
77
<artifactId>compi</artifactId>
88
<packaging>pom</packaging>
9-
<version>1.3.3</version>
9+
<version>1.3.4</version>
1010
<!-- WARNING: change version using (in the parent project): mvn versions:set -DnewVersion=[new_version] mvn versions:commit This will change the version
1111
in all modules at-once -->
1212

0 commit comments

Comments
 (0)