live.document.mavenplugin.sql.TablePlSqlStatementMojo Maven / Gradle / Ivy
package live.document.mavenplugin.sql;
import live.document.generator.utils.FileUtils;
import live.document.mavenplugin.common.AnalyzeAssistant;
import live.document.mavenplugin.common.ProjectAnalyzeResult;
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.nio.file.Path;
import java.nio.file.Paths;
/**
* 导出指定数据库表的所有SQL语句
*/
@Mojo(name = "export-table-sql")
public class TablePlSqlStatementMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.basedir}", required = true)
private File projectRoot;
@Parameter(required = true)
private String[] plsqlPaths;
@Parameter(required = true)
private String[] sqlExecuteFullMethodNames;
@Parameter(required = true)
private String[] tablesToExportSql;
@Parameter(defaultValue = "", required = true)
private String analysisResultOutputDir;
@Override
public void execute() throws MojoExecutionException {
try {
FileUtils fileUtils = new FileUtils();
ProjectAnalyzeResult projectResult = AnalyzeAssistant.analyze(projectRoot,
sqlExecuteFullMethodNames,
plsqlPaths,
analysisResultOutputDir,
null);
TableWriteStatementExporter exporter = new TableWriteStatementExporter(tablesToExportSql,
projectResult.getPlSqlExplained(),
projectResult.getCallGraph());
Path fileName = Paths.get(analysisResultOutputDir, "sql-statements.sql");
fileUtils.writeFile(fileName, exporter.export());
getLog().info("File created: file://" + fileName);
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException(e.getMessage());
}
}
}