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);
}
}
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;
}
Aggregations