live.document.mavenplugin.docify.MyMojo Maven / Gradle / Ivy
package live.document.mavenplugin.docify;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* 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.
*/
import live.document.generator.BaseDocumentGenerator;
import live.document.generator.ModuleDependencyGenerator;
import live.document.generator.launcher.ProjectScanner;
import live.document.generator.model.Markdown4CallTree;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* 生成业务活文档
*/
@Mojo(name = "generate")
public class MyMojo extends AbstractMojo {
/**
* Location of the file.
*/
@Parameter(defaultValue = "${project.basedir}", required = true)
private File projectRoot;
/**
* 排除某些文件夹不扫描class文件
*/
@Parameter
private String[] excludeFolders;
@Parameter(required = true)
private String documentOutputDir;
@Parameter(required = true)
private String gitRepositoryUri;
@Parameter(defaultValue = "", required = true)
private String docSectionName;
@Parameter(defaultValue = "false", required = true)
private String displayClassAndMethodName;
@Parameter
private String[] resourceLayerPattern;
@Parameter
private String[] controllerPattern;
@Parameter
private String[] applicationLayerPattern;
@Parameter
private String[] applicationServicePattern;
@Parameter
private String[] domainLayerPattern;
@Parameter
private String[] domainServicePattern;
@Parameter
private String[] entityPattern;
@Parameter
private String[] infrastructureLayerPattern;
@Parameter
private String[] repositoryPattern;
@Parameter
private String[] aclLayerPattern;
@Parameter
private String[] aclPattern;
@Parameter
private String[] transactionPattern;
public void execute() throws MojoExecutionException {
try {
getLog().info("scan: " + projectRoot.getAbsolutePath());
CustomMindMap4CallTree mindmap4CallTree = new CustomMindMap4CallTree();
ProjectScanner projectScanner = new ProjectScanner(null);
BaseDocumentGenerator generator = new BaseDocumentGenerator(
new ModuleDependencyGenerator(),
new Markdown4CallTree(),
mindmap4CallTree,
projectScanner
);
Map colorMap = new HashMap<>();
colorMap.put("resourceLayer", resourceLayerPattern);
colorMap.put("controller", controllerPattern);
colorMap.put("applicationLayer", applicationLayerPattern);
colorMap.put("applicationService", applicationServicePattern);
colorMap.put("domainLayer", domainLayerPattern);
colorMap.put("domainService", domainServicePattern);
colorMap.put("entity", entityPattern);
colorMap.put("infrastructureLayer", infrastructureLayerPattern);
colorMap.put("repository", repositoryPattern);
colorMap.put("aclLayer", aclLayerPattern);
colorMap.put("acl", aclPattern);
mindmap4CallTree.setColors(colorMap);
mindmap4CallTree.setDisplayClassAndMethodName("true".equalsIgnoreCase(displayClassAndMethodName));
mindmap4CallTree.setLogger(getLog());
mindmap4CallTree.setTransactionPattern(transactionPattern);
if (excludeFolders == null || excludeFolders.length == 0) {
excludeFolders = new String[]{};
}
generator.generateDocuments(projectRoot.getAbsolutePath(),
Arrays.asList(excludeFolders),
documentOutputDir,
gitRepositoryUri,
docSectionName);
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage());
}
}
}