Search in sources :

Example 26 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class Utils method checkWebserviceDependency.

/**
 * Check commons-collections:commons-collections:3.2 dependency under webservice module.
 *
 * @param webservice - The webservice module
 */
private static void checkWebserviceDependency(Module webservice) {
    Dependency commonsCollections = webservice.getDependencies().stream().filter(dependency -> StringUtils.equals(dependency.getId(), "commons-collections:commons-collections:3.2")).findAny().orElse(null);
    assertNotNull(commonsCollections);
    assertEquals(commonsCollections.getType(), "jar");
    assertEquals(commonsCollections.getMd5(), "7b9216b608d550787bdf43a63d88bf3b");
    assertEquals(commonsCollections.getSha1(), "f951934aa5ae5a88d7e6dfaa6d32307d834a88be");
    assertEquals(commonsCollections.getSha256(), "093fea360752de55afcb80cf713403eb1a66cb7dc0d529955b6f4a96f975df5c");
    assertEquals(commonsCollections.getRequestedBy(), new String[][] { { "org.jfrog.test.gradle.publish:webservice:1.0-SNAPSHOT" } });
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 27 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class DockerImage method setDependenciesAndArtifacts.

/**
 * Search the docker image in Artifactory and add all artifacts & dependencies into Module.
 */
private void setDependenciesAndArtifacts(ModuleBuilder moduleBuilder, ArtifactoryManager artifactoryManager) throws IOException {
    DockerLayer historyLayer = layers.getByDigest(imageId);
    if (historyLayer == null) {
        throw new IllegalStateException("Could not find the history docker layer: " + imageId + " for image: " + imageTag + " in Artifactory.");
    }
    int dependencyLayerNum = DockerUtils.getNumberOfDependentLayers(artifactoryManager.download(historyLayer.getFullPath()).getContent());
    LinkedHashSet<Dependency> dependencies = new LinkedHashSet<>();
    LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
    // Filter out duplicate layers from manifest by using HashSet.
    // Docker manifest may hold 'empty layers', as a result, docker promote will fail to promote the same layer more than once.
    Iterator<String> it = DockerUtils.getLayersDigests(manifest).iterator();
    for (int i = 0; i < dependencyLayerNum; i++) {
        String digest = it.next();
        DockerLayer layer = layers.getByDigest(digest);
        Dependency dependency = new DependencyBuilder().id(layer.getFileName()).sha1(layer.getSha1()).build();
        dependencies.add(dependency);
        Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
        artifacts.add(artifact);
    }
    moduleBuilder.dependencies(new ArrayList<>(dependencies));
    while (it.hasNext()) {
        String digest = it.next();
        DockerLayer layer = layers.getByDigest(digest);
        if (layer == null) {
            continue;
        }
        Artifact artifact = new ArtifactBuilder(layer.getFileName()).sha1(layer.getSha1()).remotePath(layer.getPath()).build();
        artifacts.add(artifact);
    }
    moduleBuilder.artifacts(new ArrayList<>(artifacts));
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) Artifact(org.jfrog.build.extractor.ci.Artifact) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder)

Example 28 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class DockerExtractorTest method validatePulledDockerImage.

private void validatePulledDockerImage(BuildInfo buildInfo, String image) {
    assertEquals(buildInfo.getModules().size(), 1);
    Module module = buildInfo.getModules().get(0);
    assertEquals(module.getType(), "docker");
    List<Dependency> dependencies = module.getDependencies();
    validateImageDependencies(dependencies, image);
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) Module(org.jfrog.build.extractor.ci.Module)

Example 29 with Dependency

use of org.jfrog.build.extractor.ci.Dependency in project build-info by JFrogDev.

the class NpmBuildInfoExtractor method collectDependencies.

/**
 * For each scope ('development' or 'production'):
 * 1. Run 'npm ls' command.
 * 2. From 'npm ls' command results - Create a tree of 'NpmPackageInfo's.
 * 3. Collect the dependencies from the tree.
 *
 * @param workingDir - Project's directory
 * @return List of dependencies
 * @see NpmPackageInfo
 */
private List<Dependency> collectDependencies(Path workingDir) throws Exception {
    Map<String, Dependency> dependencies = new ConcurrentHashMap<>();
    List<NpmScope> scopes = getNpmScopes();
    if (scopes.isEmpty()) {
        return new ArrayList<>();
    }
    for (NpmScope scope : scopes) {
        List<String> extraListArgs = new ArrayList<>();
        extraListArgs.add("--" + scope);
        JsonNode jsonNode = npmDriver.list(workingDir.toFile(), extraListArgs);
        populateDependenciesMap(dependencies, getDependenciesMapFromLatestBuild(), jsonNode, scope, workingDir);
    }
    return new ArrayList<>(dependencies.values());
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) Dependency(org.jfrog.build.extractor.ci.Dependency) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NpmScope(org.jfrog.build.extractor.npm.types.NpmScope)

Aggregations

Dependency (org.jfrog.build.extractor.ci.Dependency)29 File (java.io.File)12 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)9 Module (org.jfrog.build.extractor.ci.Module)7 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 Path (java.nio.file.Path)4 DownloadableArtifact (org.jfrog.build.api.dependency.DownloadableArtifact)4 RandomAccessFile (java.io.RandomAccessFile)3 ArrayList (java.util.ArrayList)3 Artifact (org.jfrog.build.extractor.ci.Artifact)3 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2