diff --git a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/ClusterLabelMapper.java b/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/ClusterLabelMapper.java deleted file mode 100644 index 3da9bec2311a0b03440692ba735f83b9de7d6929..0000000000000000000000000000000000000000 --- a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/ClusterLabelMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -package kieker.analysis.softwaresystem.dependencygraphs.dot; - -import java.util.function.Function; - -import kieker.analysis.util.graph.Vertex; - -class ClusterLabelMapper implements Function<Vertex, String> { - - private final boolean useShortNamesIfExists; - - public ClusterLabelMapper(final boolean useShortNamesIfExists) { - this.useShortNamesIfExists = useShortNamesIfExists; - } - - @Override - public String apply(final Vertex vertex) { - final StringBuilder label = new StringBuilder(); - if (vertex.getProperty("Type") != null) { - label.append(vertex.getProperty("Type").toString()); - label.append("\\n"); - } - if (this.useShortNamesIfExists && vertex.getProperty("ShortName") != null) { - label.append(vertex.getProperty("ShortName").toString()); - } else { - label.append(vertex.getProperty("Name").toString()); - } - return label.toString(); - } - -} diff --git a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/DotDependencyGraphExporterFactory.java b/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/DotDependencyGraphExporterFactory.java index cd21e3195f7ae782805d7fe1eb42ce04f3653bd7..3f0a45cf14ead0fb89d09df43a9890923002de89 100644 --- a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/DotDependencyGraphExporterFactory.java +++ b/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/DotDependencyGraphExporterFactory.java @@ -1,75 +1,82 @@ -package kieker.analysis.softwaresystem.dependencygraphs.dot; - -import kieker.analysis.util.graph.export.dot.DotExportConfiguration; -import kieker.analysis.util.graph.export.dot.DotFileWriterStage; -import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute; -import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute; -import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute; -import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute; - -public class DotDependencyGraphExporterFactory { - - private final boolean useShortNames = true; // TODO Temp - - private final VertexLabelMapper vertexLabelMapper = new VertexLabelMapper(useShortNames); - private final ClusterLabelMapper clusterLabelMapper = new ClusterLabelMapper(useShortNames); - - public DotFileWriterStage getAssemblyComponentExporter(final String outputDirectory) { - DotExportConfiguration configuration = getNewBaseConfiguration(); - - configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box"); - configuration.addNodeAttribute(DotNodeAttribute.LABEL, this.vertexLabelMapper); - - return createStage(outputDirectory, configuration); - } - - public DotFileWriterStage getAssemblyOperationExporter(final String outputDirectory) { - DotExportConfiguration configuration = getNewBaseConfiguration(); - - configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "oval"); - configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); - - return createStage(outputDirectory, configuration); - } - - public DotFileWriterStage getDeploymentContainerExporter(final String outputDirectory) { - DotExportConfiguration configuration = getNewBaseConfiguration(); - - configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box3d"); - - return createStage(outputDirectory, configuration); - } - - public DotFileWriterStage getDeploymentComponentExporter(final String outputDirectory) { - DotExportConfiguration configuration = getNewBaseConfiguration(); - - configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box"); - configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); - - return createStage(outputDirectory, configuration); - } - - public DotFileWriterStage getDeploymentOperationExporter(final String outputDirectory) { - DotExportConfiguration configuration = getNewBaseConfiguration(); - - configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "oval"); - configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); - - return createStage(outputDirectory, configuration); - } - - private DotExportConfiguration getNewBaseConfiguration() { - DotExportConfiguration configuration = new DotExportConfiguration(); - - configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); - configuration.addNodeAttribute(DotNodeAttribute.LABEL, this.vertexLabelMapper); - configuration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString())); - - return configuration; - } - - private DotFileWriterStage createStage(final String outputDirectory, final DotExportConfiguration configuration) { - return new DotFileWriterStage(outputDirectory, configuration); - } - -} +package kieker.analysis.softwaresystem.dependencygraphs.dot; + +import kieker.analysis.util.graph.export.dot.DotExportConfiguration; +import kieker.analysis.util.graph.export.dot.DotFileWriterStage; +import kieker.analysis.util.graph.util.dot.attributes.DotClusterAttribute; +import kieker.analysis.util.graph.util.dot.attributes.DotEdgeAttribute; +import kieker.analysis.util.graph.util.dot.attributes.DotGraphAttribute; +import kieker.analysis.util.graph.util.dot.attributes.DotNodeAttribute; + +/** + * This class provides factory methods for creating {@link DotFileWriterStage}s + * with given {@link DotExportConfiguration}s. + * + * @author Sören Henning + * + */ +public class DotDependencyGraphExporterFactory { + + private final boolean useShortNames = true; // TODO Temp + + private final VertexLabelMapper vertexLabelMapper = new VertexLabelMapper(useShortNames, true); + private final VertexLabelMapper clusterLabelMapper = new VertexLabelMapper(useShortNames, false); + + public DotFileWriterStage getAssemblyComponentExporter(final String outputDirectory) { + DotExportConfiguration configuration = getNewBaseConfiguration(); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box"); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, this.vertexLabelMapper); + + return createStage(outputDirectory, configuration); + } + + public DotFileWriterStage getAssemblyOperationExporter(final String outputDirectory) { + DotExportConfiguration configuration = getNewBaseConfiguration(); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "oval"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); + + return createStage(outputDirectory, configuration); + } + + public DotFileWriterStage getDeploymentContainerExporter(final String outputDirectory) { + DotExportConfiguration configuration = getNewBaseConfiguration(); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box3d"); + + return createStage(outputDirectory, configuration); + } + + public DotFileWriterStage getDeploymentComponentExporter(final String outputDirectory) { + DotExportConfiguration configuration = getNewBaseConfiguration(); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "box"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); + + return createStage(outputDirectory, configuration); + } + + public DotFileWriterStage getDeploymentOperationExporter(final String outputDirectory) { + DotExportConfiguration configuration = getNewBaseConfiguration(); + + configuration.addDefaultNodeAttribute(DotNodeAttribute.SHAPE, g -> "oval"); + configuration.addClusterAttribute(DotClusterAttribute.LABEL, this.clusterLabelMapper); + + return createStage(outputDirectory, configuration); + } + + private DotExportConfiguration getNewBaseConfiguration() { + DotExportConfiguration configuration = new DotExportConfiguration(); + + configuration.addGraphAttribute(DotGraphAttribute.RANKDIR, g -> "LR"); + configuration.addNodeAttribute(DotNodeAttribute.LABEL, this.vertexLabelMapper); + configuration.addEdgeAttribute(DotEdgeAttribute.LABEL, (e -> e.getProperty("calls").toString())); + + return configuration; + } + + private DotFileWriterStage createStage(final String outputDirectory, final DotExportConfiguration configuration) { + return new DotFileWriterStage(outputDirectory, configuration); + } + +} diff --git a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/VertexLabelMapper.java b/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/VertexLabelMapper.java index 276af9de9279f080162a7fc203b24ec6776c0e1a..3260b251b8a7b059885ee712d23d860d575b4faa 100644 --- a/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/VertexLabelMapper.java +++ b/src/main/java/kieker/analysis/softwaresystem/dependencygraphs/dot/VertexLabelMapper.java @@ -1,64 +1,78 @@ -package kieker.analysis.softwaresystem.dependencygraphs.dot; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import kieker.analysis.util.graph.Vertex; - -class VertexLabelMapper implements Function<Vertex, String> { - - private final boolean useShortNamesIfExists; - - public VertexLabelMapper(final boolean useShortNamesIfExists) { - this.useShortNamesIfExists = useShortNamesIfExists; - } - - @Override - public String apply(final Vertex vertex) { - final StringBuilder statistics = new StringBuilder(); - if (vertex.getProperty("Type") != null) { - statistics.append(vertex.getProperty("Type").toString()); - statistics.append("\\n"); - } - if (this.useShortNamesIfExists && vertex.getProperty("ShortName") != null) { - statistics.append(vertex.getProperty("ShortName").toString()); - } else { - statistics.append(vertex.getProperty("Name").toString()); - } - statistics.append("\\n"); - statistics.append(generateStatistics(vertex)); - return statistics.toString(); - } - - private String generateStatistics(final Vertex vertex) { - final String temporalUnit = vertex.getProperty("DurationTimeUnit").toString(); - - final List<String> statisticStrings = new ArrayList<>(5); - if (vertex.getProperty("MinDuration") != null) { - statisticStrings.add("min: " + vertex.getProperty("MinDuration").toString() + temporalUnit); - } - if (vertex.getProperty("MaxDuration") != null) { - statisticStrings.add("max: " + vertex.getProperty("MaxDuration").toString() + temporalUnit); - } - if (vertex.getProperty("TotalDuration") != null) { - statisticStrings.add("total: " + vertex.getProperty("TotalDuration").toString() + temporalUnit); - } - if (vertex.getProperty("MeanDuration") != null) { - statisticStrings.add("avg: " + vertex.getProperty("MeanDuration").toString() + temporalUnit); - } - if (vertex.getProperty("MedianDuration") != null) { - statisticStrings.add("med: " + vertex.getProperty("MedianDuration").toString() + temporalUnit); - } - - // If there are more than 3 statistics elements add a line break before the 2nd last - if (statisticStrings.size() > 3) { - final int secondLast = statisticStrings.size() - 2; - statisticStrings.set(secondLast, "\\n" + statisticStrings.get(secondLast)); - } - - return statisticStrings.stream().collect(Collectors.joining(", ")); - } - -} +package kieker.analysis.softwaresystem.dependencygraphs.dot; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import kieker.analysis.util.graph.Graph; +import kieker.analysis.util.graph.Vertex; +import kieker.analysis.util.graph.export.dot.DotExportConfiguration; + +/** + * This function maps Vertices ({@code Vertex}) to label strings. It can be + * used with a {@link DotExportConfiguration} when creating Dot files from + * {@link Graph}s. + * + * @author Sören Henning + * + */ +class VertexLabelMapper implements Function<Vertex, String> { + + private final boolean useShortNamesIfExists; + private final boolean setStatistics; + + public VertexLabelMapper(final boolean useShortNamesIfExists, final boolean setStatistics) { + this.useShortNamesIfExists = useShortNamesIfExists; + this.setStatistics = setStatistics; + } + + @Override + public String apply(final Vertex vertex) { + final StringBuilder label = new StringBuilder(); + if (vertex.getProperty("Type") != null) { + label.append(vertex.getProperty("Type").toString()); + label.append("\\n"); + } + if (this.useShortNamesIfExists && vertex.getProperty("ShortName") != null) { + label.append(vertex.getProperty("ShortName").toString()); + } else { + label.append(vertex.getProperty("Name").toString()); + } + if (this.setStatistics) { + label.append("\\n"); + label.append(generateStatistics(vertex)); + } + return label.toString(); + } + + private String generateStatistics(final Vertex vertex) { + final String temporalUnit = vertex.getProperty("DurationTimeUnit").toString(); + + final List<String> statisticStrings = new ArrayList<>(5); + if (vertex.getProperty("MinDuration") != null) { + statisticStrings.add("min: " + vertex.getProperty("MinDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MaxDuration") != null) { + statisticStrings.add("max: " + vertex.getProperty("MaxDuration").toString() + temporalUnit); + } + if (vertex.getProperty("TotalDuration") != null) { + statisticStrings.add("total: " + vertex.getProperty("TotalDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MeanDuration") != null) { + statisticStrings.add("avg: " + vertex.getProperty("MeanDuration").toString() + temporalUnit); + } + if (vertex.getProperty("MedianDuration") != null) { + statisticStrings.add("med: " + vertex.getProperty("MedianDuration").toString() + temporalUnit); + } + + // If there are more than 3 statistics elements add a line break before the 2nd last + if (statisticStrings.size() > 3) { + final int secondLast = statisticStrings.size() - 2; + statisticStrings.set(secondLast, "\\n" + statisticStrings.get(secondLast)); + } + + return statisticStrings.stream().collect(Collectors.joining(", ")); + } + +} diff --git a/src/main/java/kieker/analysis/util/blueprintsgraph/NamedGraph.java b/src/main/java/kieker/analysis/util/blueprintsgraph/NamedGraph.java deleted file mode 100644 index f922975fe94a2f9d262c10b42274bb8677fb7316..0000000000000000000000000000000000000000 --- a/src/main/java/kieker/analysis/util/blueprintsgraph/NamedGraph.java +++ /dev/null @@ -1,34 +0,0 @@ -package kieker.analysis.util.blueprintsgraph; - -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.util.wrappers.wrapped.WrappedGraph; - -public class NamedGraph<T extends Graph> extends WrappedGraph<T> { - - private String name; - - private String fileName; - - public NamedGraph(final String name, final String fileName, final T baseGraph) { - super(baseGraph); - this.name = name; - this.fileName = fileName; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(final String fileName) { - this.fileName = fileName; - } - -}