-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a new maven plugin to visualize class hierarchy
- Loading branch information
gaopeng71
committed
Aug 22, 2023
1 parent
2373bb8
commit dc46936
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
dddplus-maven-plugin/src/main/java/io/github/dddplus/maven/ClassHierarchyMojo.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,70 @@ | ||
/* | ||
* Copyright DDDplus Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.github.dddplus.maven; | ||
|
||
import io.github.dddplus.ast.DomainModelAnalyzer; | ||
import io.github.dddplus.ast.model.ReverseEngineeringModel; | ||
import io.github.dddplus.ast.view.ClassHierarchyRenderer; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 无需标注,类的层级结构可视化. | ||
*/ | ||
@Mojo(name = "clazz", aggregator = true) | ||
public class ClassHierarchyMojo extends AbstractMojo { | ||
|
||
/** | ||
* Colon separated directories. | ||
*/ | ||
@Parameter(property = "rootDir", required = true) | ||
String rootDir; | ||
|
||
@Parameter(property = "targetFile", required = true) | ||
String targetFile; | ||
|
||
/** | ||
* Comma separated ignored parent classes. | ||
*/ | ||
@Parameter(property = "ignoreParents") | ||
String ignoreParents; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
getLog().info("Reverse modeling starting ..."); | ||
try { | ||
String[] dirPaths = rootDir.split(":"); | ||
File[] dirs = new File[dirPaths.length]; | ||
for (int i = 0; i < dirPaths.length; i++) { | ||
dirs[i] = new File(dirPaths[i]); | ||
} | ||
|
||
ReverseEngineeringModel model = new DomainModelAnalyzer() | ||
.scan(dirs) | ||
.classHierarchyOnly() | ||
.analyze(); | ||
getLog().info("Rendering ..."); | ||
if (ignoreParents == null) { | ||
ignoreParents = ""; | ||
} | ||
new ClassHierarchyRenderer() | ||
.withModel(model) | ||
.ignores(ignoreParents.split(",")) | ||
.targetDotFile(targetFile) | ||
.render(); | ||
|
||
getLog().info("Reverse Modeling Executed OK"); | ||
} catch (Exception e) { | ||
throw new MojoExecutionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
} |
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