Search in sources :

Example 1 with GoDriver

use of org.jfrog.build.extractor.go.GoDriver in project build-info by JFrogDev.

the class GoRun method execute.

public BuildInfo execute() {
    try (ArtifactoryManager artifactoryClient = (artifactoryManagerBuilder != null ? artifactoryManagerBuilder.build() : null)) {
        if (artifactoryClient != null) {
            preparePrerequisites(resolutionRepository, artifactoryClient);
            setResolverAsGoProxy(artifactoryClient);
        }
        // We create the GoDriver here as env might had changed.
        this.goDriver = new GoDriver(GO_CLIENT_CMD, env, path.toFile(), logger);
        // First try to run 'go version' to make sure go is in PATH, and write the output to logger.
        goDriver.version(true);
        goDriver.runCmd(goCmdArgs, true);
        populateModuleAndDeps();
        return createBuild();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) GoDriver(org.jfrog.build.extractor.go.GoDriver) IOException(java.io.IOException)

Example 2 with GoDriver

use of org.jfrog.build.extractor.go.GoDriver in project build-info by JFrogDev.

the class GoDependencyTree method createDependencyTree.

/**
 * Create Go dependency tree of actually used dependencies.
 *
 * @param goDriver - Go driver
 * @param logger   - The logger
 * @param verbose  - verbose logging
 * @return Go dependency tree
 * @throws IOException in case of any I/O error.
 */
public static DependencyTree createDependencyTree(GoDriver goDriver, Log logger, boolean verbose) throws IOException {
    // Run go mod graph.
    CommandResults goGraphResult = goDriver.modGraph(verbose);
    String[] dependenciesGraph = goGraphResult.getRes().split("\\r?\\n");
    // Run go list -f "{{with .Module}}{{.Path}} {{.Version}}{{end}}" all
    CommandResults usedModulesResults;
    try {
        usedModulesResults = goDriver.getUsedModules(false, false);
    } catch (IOException e) {
        // Errors occurred during running "go list". Run again and this time ignore errors.
        usedModulesResults = goDriver.getUsedModules(false, true);
        logger.warn("Errors occurred during building the Go dependency tree. The dependency tree may be incomplete:" + System.lineSeparator() + ExceptionUtils.getRootCauseMessage(e));
    }
    Set<String> usedDependencies = Arrays.stream(usedModulesResults.getRes().split("\\r?\\n")).map(String::trim).map(usedModule -> usedModule.replace(" ", "@")).collect(Collectors.toSet());
    // Create root node.
    String rootPackageName = goDriver.getModuleName();
    DependencyTree rootNode = new DependencyTree(rootPackageName);
    rootNode.setMetadata(true);
    // Build dependency tree.
    Map<String, List<String>> dependenciesMap = new HashMap<>();
    populateDependenciesMap(dependenciesGraph, usedDependencies, dependenciesMap);
    populateDependencyTree(rootNode, rootPackageName, dependenciesMap, logger);
    return rootNode;
}
Also used : Log(org.jfrog.build.api.util.Log) java.util(java.util) DependencyTree(org.jfrog.build.extractor.scan.DependencyTree) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) CommandResults(org.jfrog.build.extractor.executor.CommandResults) Collectors(java.util.stream.Collectors) GoDriver(org.jfrog.build.extractor.go.GoDriver) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) DependencyTree(org.jfrog.build.extractor.scan.DependencyTree) IOException(java.io.IOException) CommandResults(org.jfrog.build.extractor.executor.CommandResults)

Aggregations

IOException (java.io.IOException)2 GoDriver (org.jfrog.build.extractor.go.GoDriver)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1 Log (org.jfrog.build.api.util.Log)1 ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)1 CommandResults (org.jfrog.build.extractor.executor.CommandResults)1 DependencyTree (org.jfrog.build.extractor.scan.DependencyTree)1