All Downloads are FREE. Search and download functionalities are using the official Maven repository.

live.document.mavenplugin.common.AnalyzeAssistant Maven / Gradle / Ivy

package live.document.mavenplugin.common;

import live.document.generator.launcher.ProjectScanner;
import live.document.generator.launcher.model.JarFileOrModule;
import live.document.generator.plsql.CachedSqlStatementParser;
import live.document.generator.plsql.PlSqlExplainedFactory;
import live.document.mavenplugin.method.AnalysePlSqlExt;
import live.document.plsqlscanner.PlSqlExplained;
import live.document.plsqlscanner.PlSqlReader;
import live.document.scanner.CallGraph;
import live.document.scanner.asm.VisitConfig;

import java.io.File;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class AnalyzeAssistant {
    public static ProjectAnalyzeResult analyze(File projectRoot,
                                               String[] sqlExecuteFullMethodNames,
                                               String[] plsqlPaths,
                                               String analysisResultOutputDir,
                                               String[] excludeFolders) {
        String projectRootDir = projectRoot.getAbsolutePath();
        PlSqlExplained plSqlExplained = analyzeSqls(projectRootDir, plsqlPaths, analysisResultOutputDir);
        CallGraph callGraph = analyzeCode(projectRootDir, excludeFolders, sqlExecuteFullMethodNames, analysisResultOutputDir);

        return new ProjectAnalyzeResult(plSqlExplained, callGraph);
    }

    public static PlSqlExplained analyzeSqls(String projectRootDir, String[] plsqlPaths, String analysisResultOutputDir) {
        List sqlPaths = plsqlPaths == null || plsqlPaths.length == 0
                ? Collections.EMPTY_LIST
                : Arrays.asList(plsqlPaths);
        PlSqlExplained plSqlExplained = PlSqlExplainedFactory.builder()
                .coreSqlParser(new PlSqlReader())
                .sqlFileEnumerator(AnalysePlSqlExt::findSqlFiles)
                .cacheDir(analysisResultOutputDir)
                .build()
                .buildByDirs(sqlPaths.stream()
                        .map(plsqlPath -> Paths.get(projectRootDir, plsqlPath)
                                .toAbsolutePath().toString()));
        return plSqlExplained;
    }

    public static CallGraph analyzeCode(String projectRootDir, String[] excludeFolders, String[] sqlExecuteFullMethodNames, String analysisResultOutputDir) {
        List modules = JarFileOrModule.searchProjectModules(projectRootDir);
        CachedSqlStatementParser sqlStatementParser = CachedSqlStatementParser.parserFromProjectRoot(
                new PlSqlReader(),
                analysisResultOutputDir,
                projectRootDir);
        ProjectScanner scanner = new ProjectScanner(sqlStatementParser);
        if (excludeFolders != null && excludeFolders.length > 0) {
            scanner.assignExcludeFolders(Arrays.asList(excludeFolders), projectRootDir);
        }

        Set executeSqlMethodNames = sqlExecuteFullMethodNames == null || sqlExecuteFullMethodNames.length == 0
                ? Collections.EMPTY_SET
                : new HashSet<>(Arrays.asList(sqlExecuteFullMethodNames));
        CallGraph callGraph = scanner.scanProject(modules, true,
                VisitConfig.builder()
                        .sqlExecuteMethodNames(executeSqlMethodNames)
                        .build());
        sqlStatementParser.save();
        return callGraph;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy