forked from ferstl/depgraph-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mermaid): add a new output format
Add the possibility to use mermaid syntax. See https://mermaid-js.github.io/mermaid/#/flowchart?id=flowcharts-basic-syntax ferstl#150
- Loading branch information
Showing
26 changed files
with
957 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ain/java/com/github/ferstl/depgraph/dependency/mermaid/MermaidDependencyEdgeRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2014 - 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.ferstl.depgraph.dependency.mermaid; | ||
|
||
import com.github.ferstl.depgraph.dependency.DependencyNode; | ||
import com.github.ferstl.depgraph.dependency.NodeResolution; | ||
import com.github.ferstl.depgraph.graph.EdgeRenderer; | ||
|
||
import static com.github.ferstl.depgraph.dependency.VersionAbbreviator.abbreviateVersion; | ||
|
||
|
||
public class MermaidDependencyEdgeRenderer implements EdgeRenderer<DependencyNode> { | ||
|
||
public static final String DUPLICATE_PREFIX = "+"; | ||
public static final String CONFLICT_PREFIX = "*"; | ||
private final boolean renderVersions; | ||
|
||
public MermaidDependencyEdgeRenderer(boolean renderVersions) { | ||
this.renderVersions = renderVersions; | ||
} | ||
|
||
@Override | ||
public String render(DependencyNode from, DependencyNode to) { | ||
NodeResolution toResolution = to.getResolution(); | ||
switch (toResolution) { | ||
case OMITTED_FOR_CONFLICT: | ||
return CONFLICT_PREFIX + (this.renderVersions ? abbreviateVersion(to.getArtifact().getVersion()) : ""); | ||
case OMITTED_FOR_DUPLICATE: | ||
return DUPLICATE_PREFIX; | ||
} | ||
return ""; | ||
} | ||
|
||
} |
119 changes: 119 additions & 0 deletions
119
...java/com/github/ferstl/depgraph/dependency/mermaid/MermaidDependencyNodeNameRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2014 - 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.ferstl.depgraph.dependency.mermaid; | ||
|
||
import com.github.ferstl.depgraph.dependency.DependencyNode; | ||
import com.github.ferstl.depgraph.dependency.dot.style.StyleConfiguration; | ||
import com.github.ferstl.depgraph.dependency.dot.style.StyleKey; | ||
import com.github.ferstl.depgraph.graph.NodeRenderer; | ||
import com.google.common.base.Joiner; | ||
import org.apache.maven.artifact.Artifact; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; | ||
|
||
|
||
public class MermaidDependencyNodeNameRenderer implements NodeRenderer<DependencyNode> { | ||
|
||
private static final Joiner SLASH_JOINER = Joiner.on("/").skipNulls(); | ||
private static final Joiner NEWLINE_JOINER = Joiner.on("<br/>").skipNulls(); | ||
|
||
private final boolean showGroupId; | ||
private final boolean showArtifactId; | ||
private final boolean showTypes; | ||
private final boolean showClassifiers; | ||
private final boolean showVersion; | ||
private final boolean showOptional; | ||
private final boolean showScope; | ||
|
||
public MermaidDependencyNodeNameRenderer(boolean showGroupId, boolean showArtifactId, boolean showTypes, boolean showClassifiers, boolean showVersion, boolean showOptional, boolean showScope) { | ||
this.showGroupId = showGroupId; | ||
this.showArtifactId = showArtifactId; | ||
this.showTypes = showTypes; | ||
this.showClassifiers = showClassifiers; | ||
this.showVersion = showVersion; | ||
this.showOptional = showOptional; | ||
this.showScope = showScope; | ||
} | ||
|
||
@Override | ||
public String render(DependencyNode node) { | ||
|
||
Collection<String> items = new ArrayList<>(); | ||
if (node.getArtifact().isOptional() && showOptional) { | ||
items.add(printWithSmallFont("#lt;optional#gt;")); | ||
} | ||
if (showGroupId) { | ||
items.add(node.getArtifact().getGroupId()); | ||
} | ||
if (showArtifactId) { | ||
items.add(node.getArtifact().getArtifactId()); | ||
} | ||
if (showVersion) { | ||
items.add(node.getEffectiveVersion()); | ||
} | ||
if (showTypes) { | ||
items.add(createTypeString(node.getTypes())); | ||
} | ||
if (showClassifiers) { | ||
items.add(createClassifierString(node.getClassifiers())); | ||
} | ||
if (showScope) { | ||
items.add(createScopeString(node.getScopes())); | ||
} | ||
if (items.isEmpty()) { | ||
return "[\" \"]"; | ||
} | ||
|
||
return "[\"" + NEWLINE_JOINER.join(items) + "\"]"; | ||
} | ||
|
||
private static String createScopeString(Set<String> scopes) { | ||
if (!scopes.isEmpty() && (scopes.size() > 1 || !scopes.contains(SCOPE_COMPILE))) { | ||
return printWithSmallFont("(" + SLASH_JOINER.join(scopes) + ")"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static String createTypeString(Set<String> types) { | ||
if (types.size() > 1 || !types.contains("jar")) { | ||
types.forEach(type -> type = "." + type); | ||
|
||
return SLASH_JOINER.join(types.stream().map(type -> "." + type).collect(Collectors.toList())); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static String createClassifierString(Set<String> classifiers) { | ||
if( classifiers.size() > 1 ) { | ||
return SLASH_JOINER.join(classifiers); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static String printWithSmallFont(String stringToPrint) { | ||
return "<font size=1>" + stringToPrint + "</font>"; | ||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/ferstl/depgraph/dependency/mermaid/MermaidGraphStyleConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2014 - 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.ferstl.depgraph.dependency.mermaid; | ||
|
||
|
||
import com.github.ferstl.depgraph.dependency.AbstractGraphStyleConfigurer; | ||
import com.github.ferstl.depgraph.dependency.DependencyNode; | ||
import com.github.ferstl.depgraph.dependency.dot.style.StyleConfiguration; | ||
import com.github.ferstl.depgraph.graph.GraphBuilder; | ||
import com.github.ferstl.depgraph.graph.mermaid.MermaidGraphFormatter; | ||
|
||
public class MermaidGraphStyleConfigurer extends AbstractGraphStyleConfigurer { | ||
|
||
@Override | ||
public GraphBuilder<DependencyNode> configure(GraphBuilder<DependencyNode> graphBuilder) { | ||
return graphBuilder | ||
.useNodeNameRenderer(new MermaidDependencyNodeNameRenderer(this.showGroupId, this.showArtifactId, this.showTypes, this.showClassifiers, this.showVersionsOnNodes, this.showOptional, this.showScope)) | ||
.useEdgeRenderer(new MermaidDependencyEdgeRenderer(this.showVersionOnEdges)) | ||
.graphFormatter(new MermaidGraphFormatter()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/github/ferstl/depgraph/graph/mermaid/MermaidEdgeStyle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2014 - 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.ferstl.depgraph.graph.mermaid; | ||
|
||
public class MermaidEdgeStyle { | ||
private static final String DUPLICATE_COLOR = "#000000"; // lightGray | ||
private static final String CONFLICT_COLOR = "#FF0000"; // red | ||
|
||
private int index; | ||
private String color; | ||
private int strokeSize; | ||
|
||
private MermaidEdgeStyle() {} | ||
|
||
private MermaidEdgeStyle(int index, String color, int strokeSize) { | ||
this.index = index; | ||
this.color = color; | ||
this.strokeSize = strokeSize; | ||
} | ||
|
||
public static MermaidEdgeStyle createConflictStyle(int index) { | ||
return new MermaidEdgeStyle(index, CONFLICT_COLOR, 10); | ||
} | ||
|
||
public static MermaidEdgeStyle createDuplicateStyle(int index) { | ||
return new MermaidEdgeStyle(index, DUPLICATE_COLOR, 3); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "linkStyle " + index + " color:" + color + ", stroke:" + color + ", stroke-dasharray:" + strokeSize + "px"; | ||
} | ||
} |
Oops, something went wrong.