use of org.jfrog.build.api.util.Log in project build-info by JFrogDev.
the class GitUtilsTest method testExtractVcsWithSubmodule.
@Test
private void testExtractVcsWithSubmodule() throws IOException, URISyntaxException {
String parentDotGitResource = "git_submodule_parent_.git_suffix";
String submoduleDotGitResource = "git_submodule_.git_suffix";
File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
File parentDotGitFile = new File(testResourcesPath, ".git");
String submoduleDotGitFilePath = testResourcesPath.toString() + File.separator + "subDir" + File.separator + "subModule" + File.separator + ".git";
File submoduleDotGitFile = new File(submoduleDotGitFilePath);
try {
// Copy the parent folder and create .git.
FileUtils.copyDirectory(new File(testResourcesPath, parentDotGitResource), parentDotGitFile);
// Copy the submodule .git file to the correct path.
FileUtils.copyFile(new File(testResourcesPath, submoduleDotGitResource), submoduleDotGitFile);
// Get VCS info.
Log testLog = new TestingLog();
Vcs vcs = GitUtils.extractVcs((new File(submoduleDotGitFilePath)).getAbsoluteFile(), testLog);
// Validate.
Assert.assertNotNull(vcs);
Assert.assertEquals(vcs.getUrl(), "https://github.com/jfrog/subModule.git");
Assert.assertEquals(vcs.getRevision(), "thisIsADummyRevision");
} finally {
// Cleanup.
FileUtils.forceDelete(submoduleDotGitFile);
FileUtils.deleteDirectory(parentDotGitFile);
}
}
use of org.jfrog.build.api.util.Log in project build-info by JFrogDev.
the class PipBuildInfoExtractor method createDependenciesFromAqlResult.
private Map<String, Dependency> createDependenciesFromAqlResult(AqlSearchResult searchResult, Map<String, String> fileToPackage, Log logger) {
if (searchResult.getResults().isEmpty()) {
return Collections.emptyMap();
}
Map<String, Dependency> dependenciesMap = new HashMap<>();
for (AqlSearchResult.SearchEntry searchEntry : searchResult.getResults()) {
if (!isResultComplete(searchEntry)) {
continue;
}
// Avoid adding duplicated dependencies.
if (dependenciesMap.containsKey(fileToPackage.get(searchEntry.getName()))) {
continue;
}
// Add a new dependency only if searchEntry represents a package downloaded in this build execution.
if (fileToPackage.containsKey(searchEntry.getName())) {
Dependency curDep = new DependencyBuilder().id(searchEntry.getName()).md5(searchEntry.getActualMd5()).sha1(searchEntry.getActualSha1()).build();
dependenciesMap.put(fileToPackage.get(searchEntry.getName()), curDep);
}
}
Set<String> missingFiles = fileToPackage.keySet().stream().filter(x -> !dependenciesMap.containsKey(fileToPackage.get(x))).collect(Collectors.toSet());
promptMissingChecksumFromArtifactory(missingFiles, logger);
return dependenciesMap;
}
use of org.jfrog.build.api.util.Log in project build-info by JFrogDev.
the class ToolchainDriverBase method runCmd.
public void runCmd(String args, List<String> extraArgs, List<String> credentials, boolean prompt) throws IOException, InterruptedException {
Log logger = prompt ? this.logger : null;
String cmdOutput = runCommand(args.split(" "), extraArgs, credentials, logger);
if (prompt) {
logger.info(cmdOutput);
}
}
use of org.jfrog.build.api.util.Log 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;
}
use of org.jfrog.build.api.util.Log in project build-info by JFrogDev.
the class GitUtilsTest method testReadGitConfig.
/**
* Tests extracting Vcs details manually by comparing results to those received from the git executable
*/
@Test
private void testReadGitConfig() throws IOException, InterruptedException, URISyntaxException {
String gitResource = "git_simple_.git_suffix";
File testResourcesPath = new File(this.getClass().getResource("/gitutils").toURI()).getCanonicalFile();
File dotGitDir = new File(testResourcesPath, ".git").getAbsoluteFile();
try {
FileUtils.copyDirectory(new File(testResourcesPath, gitResource), dotGitDir);
Log testLog = new TestingLog();
Vcs vcs = GitUtils.extractVcs(dotGitDir, testLog);
Assert.assertNotNull(vcs);
Assert.assertEquals(vcs.getUrl(), getGitUrlWithExecutor(dotGitDir, testLog));
Assert.assertEquals(vcs.getRevision(), getGitRevisionWithExecutor(dotGitDir, testLog));
Assert.assertEquals(vcs.getBranch(), getGitBranchWithExecutor(dotGitDir, testLog));
Assert.assertEquals(vcs.getMessage(), getGitMessageWithExecutor(dotGitDir, testLog));
} finally {
// Cleanup.
FileUtils.deleteDirectory(dotGitDir);
}
}
Aggregations