Search in sources :

Example 1 with Log

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);
    }
}
Also used : Log(org.jfrog.build.api.util.Log) TestingLog(org.jfrog.build.extractor.util.TestingLog) Vcs(org.jfrog.build.extractor.ci.Vcs) TestingLog(org.jfrog.build.extractor.util.TestingLog) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with Log

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;
}
Also used : Arrays(java.util.Arrays) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) Collectors(java.util.stream.Collectors) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ModuleType(org.jfrog.build.api.builder.ModuleType) ArrayList(java.util.ArrayList) Log(org.jfrog.build.api.util.Log) List(java.util.List) Module(org.jfrog.build.extractor.ci.Module) Map(java.util.Map) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) AqlSearchResult(org.jfrog.build.api.search.AqlSearchResult) Path(java.nio.file.Path) Collections(java.util.Collections) Dependency(org.jfrog.build.extractor.ci.Dependency) AqlSearchResult(org.jfrog.build.api.search.AqlSearchResult) HashMap(java.util.HashMap) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 3 with Log

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);
    }
}
Also used : Log(org.jfrog.build.api.util.Log)

Example 4 with Log

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

Example 5 with Log

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);
    }
}
Also used : Log(org.jfrog.build.api.util.Log) TestingLog(org.jfrog.build.extractor.util.TestingLog) Vcs(org.jfrog.build.extractor.ci.Vcs) TestingLog(org.jfrog.build.extractor.util.TestingLog) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Log (org.jfrog.build.api.util.Log)5 File (java.io.File)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Vcs (org.jfrog.build.extractor.ci.Vcs)2 TestingLog (org.jfrog.build.extractor.util.TestingLog)2 Test (org.testng.annotations.Test)2 Path (java.nio.file.Path)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1 ModuleType (org.jfrog.build.api.builder.ModuleType)1 AqlSearchResult (org.jfrog.build.api.search.AqlSearchResult)1