forked from lxm_tools/screw
🎉 初始化提交
This commit is contained in:
54
screw-maven-plugin/pom.xml
Normal file
54
screw-maven-plugin/pom.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>cn.smallbun.screw</groupId>
|
||||
<artifactId>screw</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>screw-maven-plugin</artifactId>
|
||||
|
||||
<packaging>maven-plugin</packaging>
|
||||
<dependencies>
|
||||
<!--项目核心包-->
|
||||
<dependency>
|
||||
<groupId>cn.smallbun.screw</groupId>
|
||||
<artifactId>screw-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--lombok-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- HikariCP -->
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>${HikariCP.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>${maven-plugin-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* screw-maven-plugin - 简洁好用的数据库文档生成器
|
||||
* Copyright © 2020 SanLi (qinggang.zuo@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cn.smallbun.screw.maven.plugin.mojo;
|
||||
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
import cn.smallbun.screw.core.engine.EngineFileType;
|
||||
import cn.smallbun.screw.core.engine.EngineTemplateType;
|
||||
import cn.smallbun.screw.core.execute.DocumentationExecute;
|
||||
import cn.smallbun.screw.core.process.ProcessConfig;
|
||||
import cn.smallbun.screw.core.query.DatabaseType;
|
||||
import cn.smallbun.screw.core.util.FileUtils;
|
||||
import cn.smallbun.screw.core.util.JdbcUtils;
|
||||
import cn.smallbun.screw.core.util.StringUtils;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.smallbun.screw.core.constant.DefaultConstants.*;
|
||||
import static cn.smallbun.screw.core.util.FileUtils.getRealFilePath;
|
||||
|
||||
/**
|
||||
* Database document generation mojo
|
||||
*
|
||||
* @author SanLi
|
||||
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/1
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Mojo(name = "run", threadSafe = true, defaultPhase = LifecyclePhase.COMPILE)
|
||||
public class RunDocMojo extends AbstractMojo {
|
||||
|
||||
//====================基本配置====================//
|
||||
/**
|
||||
* 组织
|
||||
*/
|
||||
@Parameter(property = "organization")
|
||||
private String organization;
|
||||
/**
|
||||
* url
|
||||
*/
|
||||
@Parameter(property = "organizationUrl")
|
||||
private String organizationUrl;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Parameter(property = "title")
|
||||
private String title;
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
@Parameter(property = "version")
|
||||
private String version;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@Parameter(property = "description")
|
||||
private String description;
|
||||
|
||||
//====================连接配置====================//
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Parameter
|
||||
private volatile String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Parameter
|
||||
private volatile String password;
|
||||
|
||||
/**
|
||||
* 驱动类名称
|
||||
*/
|
||||
@Parameter
|
||||
private String driverClassName;
|
||||
/**
|
||||
* JDBC URL
|
||||
*/
|
||||
@Parameter
|
||||
private String jdbcUrl;
|
||||
|
||||
//====================数据处理配置====================//
|
||||
/**
|
||||
* 忽略表名
|
||||
*/
|
||||
@Parameter
|
||||
private List<String> tableName;
|
||||
/**
|
||||
* 忽略表前缀
|
||||
*/
|
||||
@Parameter
|
||||
private List<String> tablePrefix;
|
||||
/**
|
||||
* 忽略表后缀
|
||||
*/
|
||||
@Parameter
|
||||
private List<String> tableSuffix;
|
||||
|
||||
//====================生成引擎配置====================//
|
||||
/**
|
||||
* 是否打开输出目录
|
||||
*/
|
||||
@Parameter(defaultValue = "true")
|
||||
private boolean openOutputDir;
|
||||
/**
|
||||
* 文件产生位置
|
||||
*/
|
||||
@Parameter
|
||||
private String fileOutputDir;
|
||||
/**
|
||||
* 生成文件类型
|
||||
*/
|
||||
@Parameter(defaultValue = "HTML")
|
||||
private EngineFileType fileType;
|
||||
/**
|
||||
* 生成实现
|
||||
*/
|
||||
@Parameter(defaultValue = "freemarker")
|
||||
private EngineTemplateType produceType;
|
||||
/**
|
||||
* 自定义模板,模板需要和文件类型和使用模板的语法进行编写和处理,否则将会生成错误
|
||||
*/
|
||||
@Parameter
|
||||
private String template;
|
||||
|
||||
/**
|
||||
* 文档生成
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws MojoFailureException {
|
||||
getLog().info(LOGGER_BEGINS);
|
||||
//参数为空
|
||||
long start = System.currentTimeMillis();
|
||||
validator();
|
||||
//总配置
|
||||
Configuration config = Configuration.builder()
|
||||
//组织
|
||||
.organization(getOrganization())
|
||||
//url
|
||||
.organizationUrl(getOrganizationUrl())
|
||||
//标题
|
||||
.title(getTitle())
|
||||
//版本
|
||||
.version(getVersion())
|
||||
//描述
|
||||
.description(getDescription())
|
||||
//数据源
|
||||
.dataSource(getDataSource())
|
||||
//引擎模板配置
|
||||
.engineConfig(getEngineConfig())
|
||||
//数据处理配置
|
||||
.produceConfig(getProcessConfig()).build();
|
||||
//生成文档
|
||||
new DocumentationExecute(config).execute();
|
||||
getLog().info(String.format(LOGGER_COMPLETE, (System.currentTimeMillis() - start) / 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* 引擎模板配置
|
||||
*
|
||||
* @return {@link EngineConfig}
|
||||
*/
|
||||
private EngineConfig getEngineConfig() {
|
||||
return EngineConfig.builder()
|
||||
//是否打开目录
|
||||
.openOutputDir(isOpenOutputDir())
|
||||
//生成文件路径
|
||||
.fileOutputDir(getFileOutputDir())
|
||||
//文件类型
|
||||
.fileType(getFileType())
|
||||
//生成模板实现
|
||||
.produceType(getProduceType())
|
||||
//自定义模板位置
|
||||
.customTemplate(getTemplate()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据处理配置
|
||||
*
|
||||
* @return {@link ProcessConfig}
|
||||
*/
|
||||
private ProcessConfig getProcessConfig() {
|
||||
return ProcessConfig.builder()
|
||||
//忽略表名
|
||||
.ignoreTableName(getTableName())
|
||||
//忽略表前缀
|
||||
.ignoreTablePrefix(getTablePrefix())
|
||||
//忽略表后缀
|
||||
.ignoreTableSuffix(getTableSuffix()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源
|
||||
*
|
||||
* @return {@link DataSource}
|
||||
*/
|
||||
private DataSource getDataSource() {
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setPoolName(NAME);
|
||||
//驱动名称
|
||||
hikariConfig.setDriverClassName(getDriverClassName().trim());
|
||||
//url
|
||||
hikariConfig.setJdbcUrl(getJdbcUrl());
|
||||
//用户名
|
||||
hikariConfig.setUsername(getUsername());
|
||||
//密码
|
||||
hikariConfig.setPassword(getPassword());
|
||||
//mysql oracle
|
||||
if (JdbcUtils.getDbType(getJdbcUrl()).equals(DatabaseType.MYSQL)
|
||||
|| JdbcUtils.getDbType(getJdbcUrl()).equals(DatabaseType.MARIADB)) {
|
||||
hikariConfig.addDataSourceProperty(USE_INFORMATION_SCHEMA, "true");
|
||||
}
|
||||
//oracle
|
||||
if (JdbcUtils.getDbType(getJdbcUrl()).equals(DatabaseType.ORACLE)) {
|
||||
hikariConfig.addDataSourceProperty(ORACLE_REMARKS, "true");
|
||||
}
|
||||
return new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数验证
|
||||
*
|
||||
* @throws MojoFailureException MojoFailureException
|
||||
*/
|
||||
private void validator() throws MojoFailureException {
|
||||
//基础配置验证
|
||||
if (StringUtils.isBlank(getUsername())) {
|
||||
throw new MojoFailureException("请配置数据库用户名");
|
||||
}
|
||||
if (StringUtils.isBlank(getPassword())) {
|
||||
throw new MojoFailureException("请配置数据库密码");
|
||||
}
|
||||
if (StringUtils.isBlank(getDriverClassName())) {
|
||||
throw new MojoFailureException("请配置数据库驱动名称");
|
||||
}
|
||||
if (StringUtils.isBlank(getJdbcUrl())) {
|
||||
throw new MojoFailureException("请配置数据库URL地址");
|
||||
}
|
||||
//验证模板是否存在
|
||||
if (StringUtils.isNotBlank(getTemplate())) {
|
||||
String path = getRealFilePath(getTemplate());
|
||||
boolean exists = FileUtils.isFileExists(path);
|
||||
if (!exists) {
|
||||
throw new MojoFailureException("未检索到模板文件[" + path + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* screw-maven-plugin - 简洁好用的数据库文档生成器
|
||||
* Copyright © 2020 SanLi (qinggang.zuo@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* Mojo
|
||||
* @author SanLi
|
||||
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/3 12:09
|
||||
*/
|
||||
package cn.smallbun.screw.maven.plugin.mojo;
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* screw-maven-plugin - 简洁好用的数据库文档生成器
|
||||
* Copyright © 2020 SanLi (qinggang.zuo@gmail.com)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @author SanLi
|
||||
* Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2020/4/3 12:09
|
||||
*/
|
||||
package cn.smallbun.screw.maven.plugin;
|
||||
Reference in New Issue
Block a user