From b02789735b986fec3efcfb1a8708222c10636676 Mon Sep 17 00:00:00 2001 From: Henning Schmiedehausen Date: Sat, 31 Oct 2015 21:17:37 -0700 Subject: [PATCH] Add a flag to turn edge labels on and off. For some graphs, labeling the edges is not really important. Make it possible to turn the labels off. --- .../maven/plugins/graph/dot/EdgeGenerator.java | 12 +++++++++++- .../maven/plugins/graph/mojo/BaseGraphMojo.java | 16 ++++++++++++++++ .../maven/plugins/graph/mojo/MojoHelper.java | 4 ++-- .../plugins/graph/pojo/GraphDescriptor.java | 8 ++++++++ .../graph/processor/FlatEdgeProcessor.java | 7 ++++++- .../graph/processor/HideConflictsProcessor.java | 7 ++----- .../graph/processor/LinkedEdgeProcessor.java | 7 ++++++- 7 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/kuali/maven/plugins/graph/dot/EdgeGenerator.java b/src/main/java/org/kuali/maven/plugins/graph/dot/EdgeGenerator.java index 34fd633..afa18fd 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/dot/EdgeGenerator.java +++ b/src/main/java/org/kuali/maven/plugins/graph/dot/EdgeGenerator.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import org.kuali.maven.plugins.graph.pojo.Edge; +import org.kuali.maven.plugins.graph.pojo.GraphDescriptor; import org.kuali.maven.plugins.graph.pojo.GraphNode; import org.kuali.maven.plugins.graph.pojo.MavenContext; import org.kuali.maven.plugins.graph.pojo.Scope; @@ -36,6 +37,11 @@ public class EdgeGenerator { StyleProcessor sp = new StyleProcessor(); Counter counter = new Counter(1); + Boolean showEdgeLabels; + + public EdgeGenerator(GraphDescriptor gd) { + this.showEdgeLabels = gd.getShowEdgeLabels(); + } /** *

@@ -103,7 +109,11 @@ public Edge getStyledEdge(GraphNode parent, GraphNode child, boolean optional, S Edge edge = new Edge(parent, child); edge.setId(id); sp.copyStyleProperties(edge, style); - edge.setLabel(label); + + if (!Boolean.FALSE.equals(showEdgeLabels)) { + edge.setLabel(label); + } + return edge; } } diff --git a/src/main/java/org/kuali/maven/plugins/graph/mojo/BaseGraphMojo.java b/src/main/java/org/kuali/maven/plugins/graph/mojo/BaseGraphMojo.java index 04ec30a..afdba0c 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/mojo/BaseGraphMojo.java +++ b/src/main/java/org/kuali/maven/plugins/graph/mojo/BaseGraphMojo.java @@ -143,6 +143,15 @@ public abstract class BaseGraphMojo extends BaseMavenMojo { */ private boolean showDuplicates; + /** + *

+ * Show labels on the graph edges. + *

+ * + * @parameter expression="${graph.showEdgeLabels}" default-value="true" + */ + private boolean showEdgeLabels = true; + /** *

* Determines how conflicts in the dependency tree are displayed. Valid options are IGNORE, @@ -363,4 +372,11 @@ public void setShowTypes(boolean showTypes) { this.showTypes = showTypes; } + public boolean isShowEdgeLabels() { + return showEdgeLabels; + } + + public void setShowEdgeLabels(boolean showEdgeLabels) { + this.showEdgeLabels = showEdgeLabels; + } } \ No newline at end of file diff --git a/src/main/java/org/kuali/maven/plugins/graph/mojo/MojoHelper.java b/src/main/java/org/kuali/maven/plugins/graph/mojo/MojoHelper.java index f6e82da..a18fc71 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/mojo/MojoHelper.java +++ b/src/main/java/org/kuali/maven/plugins/graph/mojo/MojoHelper.java @@ -473,7 +473,7 @@ protected List getEdgeProcessors(GraphDescriptor gd) { Processor conflictsProcessor = new HideConflictsProcessor(gd); switch (gd.getLayout()) { case LINKED: - processors.add(new LinkedEdgeProcessor()); + processors.add(new LinkedEdgeProcessor(gd)); if (conflicts == Conflicts.LABEL) { logger.debug("labeling conflicts"); processors.add(new ReduceClutterProcessor()); @@ -488,7 +488,7 @@ protected List getEdgeProcessors(GraphDescriptor gd) { } return processors; case FLAT: - processors.add(new FlatEdgeProcessor()); + processors.add(new FlatEdgeProcessor(gd)); if (conflicts == Conflicts.LABEL) { logger.debug("labeling conflicts"); processors.add(conflictsProcessor); diff --git a/src/main/java/org/kuali/maven/plugins/graph/pojo/GraphDescriptor.java b/src/main/java/org/kuali/maven/plugins/graph/pojo/GraphDescriptor.java index 0466674..c5ea6b4 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/pojo/GraphDescriptor.java +++ b/src/main/java/org/kuali/maven/plugins/graph/pojo/GraphDescriptor.java @@ -36,6 +36,7 @@ public class GraphDescriptor { Boolean showTypes; Boolean showClassifiers; Boolean showDuplicates; + Boolean showEdgeLabels; Conflicts conflicts; Boolean cascadeOptional; Boolean showLegend; @@ -328,4 +329,11 @@ public void setShowClassifiers(Boolean showClassifiers) { this.showClassifiers = showClassifiers; } + public Boolean getShowEdgeLabels() { + return showEdgeLabels; + } + + public void setShowEdgeLabels(Boolean showEdgeLabels) { + this.showEdgeLabels = showEdgeLabels; + } } \ No newline at end of file diff --git a/src/main/java/org/kuali/maven/plugins/graph/processor/FlatEdgeProcessor.java b/src/main/java/org/kuali/maven/plugins/graph/processor/FlatEdgeProcessor.java index 1021e3d..3399cb0 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/processor/FlatEdgeProcessor.java +++ b/src/main/java/org/kuali/maven/plugins/graph/processor/FlatEdgeProcessor.java @@ -17,11 +17,16 @@ import org.kuali.maven.plugins.graph.dot.EdgeGenerator; import org.kuali.maven.plugins.graph.pojo.Edge; +import org.kuali.maven.plugins.graph.pojo.GraphDescriptor; import org.kuali.maven.plugins.graph.pojo.MavenContext; import org.kuali.maven.plugins.graph.tree.Node; public class FlatEdgeProcessor implements Processor { - EdgeGenerator generator = new EdgeGenerator(); + EdgeGenerator generator; + + public FlatEdgeProcessor(GraphDescriptor gd) { + generator = new EdgeGenerator(gd); + } @Override public void process(Node node) { diff --git a/src/main/java/org/kuali/maven/plugins/graph/processor/HideConflictsProcessor.java b/src/main/java/org/kuali/maven/plugins/graph/processor/HideConflictsProcessor.java index 01c3781..50bd02e 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/processor/HideConflictsProcessor.java +++ b/src/main/java/org/kuali/maven/plugins/graph/processor/HideConflictsProcessor.java @@ -28,16 +28,13 @@ public class HideConflictsProcessor implements Processor { TreeHelper helper = new TreeHelper(); - EdgeGenerator generator = new EdgeGenerator(); + EdgeGenerator generator; GraphDescriptor descriptor; - public HideConflictsProcessor() { - this(null); - } - public HideConflictsProcessor(GraphDescriptor descriptor) { super(); this.descriptor = descriptor; + this.generator = new EdgeGenerator(descriptor); } @Override diff --git a/src/main/java/org/kuali/maven/plugins/graph/processor/LinkedEdgeProcessor.java b/src/main/java/org/kuali/maven/plugins/graph/processor/LinkedEdgeProcessor.java index 6af6d09..c4b900a 100644 --- a/src/main/java/org/kuali/maven/plugins/graph/processor/LinkedEdgeProcessor.java +++ b/src/main/java/org/kuali/maven/plugins/graph/processor/LinkedEdgeProcessor.java @@ -17,6 +17,7 @@ import org.kuali.maven.plugins.graph.dot.EdgeGenerator; import org.kuali.maven.plugins.graph.pojo.Edge; +import org.kuali.maven.plugins.graph.pojo.GraphDescriptor; import org.kuali.maven.plugins.graph.pojo.GraphNode; import org.kuali.maven.plugins.graph.pojo.MavenContext; import org.kuali.maven.plugins.graph.pojo.Scope; @@ -29,7 +30,11 @@ public class LinkedEdgeProcessor implements Processor { private static final Logger logger = LoggerFactory.getLogger(LinkedEdgeProcessor.class); public static final String REPLACEMENT_LABEL = "replacement"; - EdgeGenerator generator = new EdgeGenerator(); + EdgeGenerator generator; + + public LinkedEdgeProcessor(GraphDescriptor gd) { + generator = new EdgeGenerator(gd); + } @Override public void process(Node node) {