Search in sources :

Example 1 with DependencyBuilder

use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.

the class BuildInfoRecorder method addDependenciesToCurrentModule.

private void addDependenciesToCurrentModule(ModuleBuilder module) {
    Set<Artifact> moduleDependencies = currentModuleDependencies.get();
    if (moduleDependencies == null) {
        logger.warn("Skipping Artifactory Build-Info module dependency addition: Null current module dependency " + "list.");
        return;
    }
    for (Artifact dependency : moduleDependencies) {
        File depFile = dependency.getFile();
        String gav = getModuleIdString(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
        DependencyBuilder dependencyBuilder = new DependencyBuilder().id(gav).requestedBy(dependencyParentsMaps.get(gav)).type(getTypeString(dependency.getType(), dependency.getClassifier(), getExtension(depFile)));
        String scopes = dependency.getScope();
        if (StringUtils.isNotBlank(scopes)) {
            dependencyBuilder.scopes(CommonUtils.newHashSet(scopes));
        }
        setDependencyChecksums(depFile, dependencyBuilder);
        module.addDependency(dependencyBuilder.build());
    }
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 2 with DependencyBuilder

use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.

the class ArtifactoryBuildInfoTrigger method collectDependencyInformation.

/**
 * Collect dependency information during the build.
 *
 * @param event The end of resolution Ivy event
 */
private void collectDependencyInformation(IvyEvent event) {
    Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
    ResolveReport report = ((EndResolveEvent) event).getReport();
    @SuppressWarnings("unchecked") Map<String, String> attributes = event.getAttributes();
    Module module = getOrCreateModule(attributes);
    project.log("[buildinfo:collect] Collecting dependencies for " + module.getId(), Project.MSG_INFO);
    if (module.getDependencies() == null || module.getDependencies().isEmpty()) {
        String[] configurations = report.getConfigurations();
        List<Dependency> moduleDependencies = new ArrayList<>();
        for (String configuration : configurations) {
            project.log("[buildinfo:collect] Configuration: " + configuration + " Dependencies", Project.MSG_DEBUG);
            ConfigurationResolveReport configurationReport = report.getConfigurationReport(configuration);
            ArtifactDownloadReport[] allArtifactsReports = configurationReport.getAllArtifactsReports();
            for (final ArtifactDownloadReport artifactsReport : allArtifactsReports) {
                project.log("[buildinfo:collect] Artifact Download Report for configuration: " + configuration + " : " + artifactsReport, Project.MSG_DEBUG);
                ModuleRevisionId id = artifactsReport.getArtifact().getModuleRevisionId();
                String type = getType(artifactsReport.getArtifact());
                Dependency dependency = findDependencyInList(id, type, moduleDependencies);
                if (dependency == null) {
                    DependencyBuilder dependencyBuilder = new DependencyBuilder();
                    dependencyBuilder.type(type).scopes(CommonUtils.newHashSet(configuration));
                    String idString = getModuleIdString(id.getOrganisation(), id.getName(), id.getRevision());
                    dependencyBuilder.id(idString);
                    File file = artifactsReport.getLocalFile();
                    Map<String, String> checksums;
                    try {
                        checksums = FileChecksumCalculator.calculateChecksums(file, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    String md5 = checksums.get(MD5_ALGORITHM);
                    String sha1 = checksums.get(SHA1_ALGORITHM);
                    String sha256 = checksums.get(SHA256_ALGORITHM);
                    dependencyBuilder.md5(md5).sha1(sha1).sha256(sha256);
                    dependency = dependencyBuilder.build();
                    moduleDependencies.add(dependency);
                    project.log("[buildinfo:collect] Added dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                } else {
                    if (!dependency.getScopes().contains(configuration)) {
                        dependency.getScopes().add(configuration);
                        project.log("[buildinfo:collect] Added scope " + configuration + " to dependency '" + dependency.getId() + "'", Project.MSG_DEBUG);
                    } else {
                        project.log("[buildinfo:collect] Find same dependency twice in configuration '" + configuration + "' for dependency '" + artifactsReport + "'", Project.MSG_WARN);
                    }
                }
            }
        }
        module.setDependencies(moduleDependencies);
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString) Dependency(org.jfrog.build.extractor.ci.Dependency) EndResolveEvent(org.apache.ivy.core.event.resolve.EndResolveEvent) Project(org.apache.tools.ant.Project) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) Module(org.jfrog.build.extractor.ci.Module) File(java.io.File)

Example 3 with DependencyBuilder

use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.

the class NugetRun method createDependency.

private Dependency createDependency(NugetPackgesConfig.ConfigPackage pkg, String globalCachePath) throws IOException, NoSuchAlgorithmException {
    boolean found = true;
    File nupkg = createNupkgFile(pkg.getId(), pkg.getVersion(), globalCachePath);
    if (!nupkg.exists()) {
        // If the original version can not be found in cache, we will check if one of the alternative version forms do exist.
        found = false;
        for (String v : createAlternativeVersionForms(pkg.getVersion())) {
            nupkg = createNupkgFile(pkg.getId(), v, globalCachePath);
            if (nupkg.exists()) {
                found = true;
                break;
            }
        }
    }
    if (found) {
        Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(nupkg, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
        Dependency dependency = new DependencyBuilder().id(pkg.getId() + ':' + pkg.getVersion()).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).build();
        return dependency;
    }
    return null;
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency) File(java.io.File)

Example 4 with DependencyBuilder

use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.

the class DependenciesDownloaderHelper method validateChecksumsAndBuildDependency.

private Dependency validateChecksumsAndBuildDependency(Map<String, String> checksumsMap, ArtifactMetaData artifactMetaData, String filePath, String fileDestination, String remotePath) throws IOException {
    String md5 = validateMd5Checksum(artifactMetaData.getMd5(), checksumsMap.get(MD5_ALGORITHM));
    String sha1 = validateSha1Checksum(artifactMetaData.getSha1(), checksumsMap.get(SHA1_ALGORITHM));
    return new DependencyBuilder().md5(md5).sha1(sha1).sha256(checksumsMap.get(SHA256_ALGORITHM)).id(filePath.substring(filePath.lastIndexOf(File.separatorChar) + 1)).localPath(fileDestination).remotePath(remotePath).build();
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder)

Example 5 with DependencyBuilder

use of org.jfrog.build.extractor.builder.DependencyBuilder in project build-info by JFrogDev.

the class BuildInfoMavenBuilderTest method testDuplicateModuleDependencies.

/**
 * Validates adding same dependencies with different scopes to different modules
 */
public void testDuplicateModuleDependencies() {
    ModuleBuilder module1 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
    module1.addDependency(new DependencyBuilder().id("dep1").scopes(CommonUtils.newHashSet("compile")).build());
    module1.addDependency(new DependencyBuilder().id("dep2").scopes(CommonUtils.newHashSet("compile")).build());
    ModuleBuilder module2 = new ModuleBuilder().type(ModuleType.MAVEN).id("id");
    module2.addDependency(new DependencyBuilder().id("dep1").scopes(CommonUtils.newHashSet("compile", "test")).build());
    module2.addDependency(new DependencyBuilder().id("dep2").scopes(CommonUtils.newHashSet("compile", "test")).build());
    BuildInfoMavenBuilder builder = new BuildInfoMavenBuilder("test").number("4").started("test");
    builder.addModule(module1.build());
    builder.addModule(module2.build());
    BuildInfo buildInfo = builder.build();
    List<Module> modules = buildInfo.getModules();
    assertFalse(modules.isEmpty(), "A buildInfo module should have been added.");
    assertEquals(modules.size(), 1, "Expected to find only 1 module.");
    assertEquals(modules.get(0).getId(), "id", "Expected to find module with id = 'id'.");
    assertEquals(modules.get(0).getType(), "maven", "Expected to find module with type = 'maven'.");
    List<Dependency> dependencies = modules.get(0).getDependencies();
    assertEquals(dependencies.size(), 2, "Expected to find only 2 dependencies.");
    assertTrue(dependencies.get(0).getScopes().contains("compile"), "Expected to find compile scope");
    assertTrue(dependencies.get(0).getScopes().contains("test"), "Expected to find test scope");
    assertTrue(dependencies.get(1).getScopes().contains("compile"), "Expected to find compile scope");
    assertTrue(dependencies.get(1).getScopes().contains("test"), "Expected to find test scope");
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) BuildInfoMavenBuilder(org.jfrog.build.extractor.builder.BuildInfoMavenBuilder) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder)

Aggregations

DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)14 Dependency (org.jfrog.build.extractor.ci.Dependency)9 File (java.io.File)6 IOException (java.io.IOException)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)3 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)3 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AqlSearchResult (org.jfrog.build.api.search.AqlSearchResult)2 Module (org.jfrog.build.extractor.ci.Module)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1