Search in sources :

Example 1 with Module

use of org.jfrog.build.extractor.ci.Module 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 2 with Module

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

the class NpmBuildInfoExtractor method getDependenciesMapFromBuild.

static Map<String, Dependency> getDependenciesMapFromBuild(BuildInfo buildInfo) {
    Map<String, Dependency> previousBuildDependencies = new ConcurrentHashMap<>();
    // Iterate over all modules and extract dependencies.
    List<Module> modules = buildInfo.getModules();
    for (Module module : modules) {
        List<Dependency> dependencies = module.getDependencies();
        if (dependencies != null) {
            for (Dependency dependency : dependencies) {
                previousBuildDependencies.put(dependency.getId(), dependency);
            }
        }
    }
    return previousBuildDependencies;
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Module(org.jfrog.build.extractor.ci.Module)

Example 3 with Module

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

the class PipExtractorTest method pipInstallTest.

@Test(dataProvider = "pipInstallProvider")
private void pipInstallTest(Project project) {
    try {
        if (!project.allowDirtyEnv) {
            // Copy project files to temp.
            projectDir = TestUtils.createTestProjectTempDir(project.targetDir, project.projectOrigin);
            // Check pip env is clean.
            validateEmptyPipEnv(driver);
        }
        // Run pip-install.
        PipInstall pipInstall = new PipInstall(artifactoryManagerBuilder, virtualRepo, project.args, getLog(), projectDir, env, project.moduleId, getUsername(), getAdminToken(), null);
        BuildInfo buildInfo = pipInstall.execute();
        assertNotNull(buildInfo, "Pip execution returned empty buildInfo.");
        // Validate produced build-info.
        Module module = buildInfo.getModules().get(0);
        assertEquals(module.getType(), "pypi");
        assertEquals(module.getId(), project.moduleId);
        assertEquals(module.getDependencies().size(), project.expectedDependencies);
        if (project.cleanEnvAfterExecution) {
            // Clean environment.
            cleanPipEnv(projectDir);
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    } catch (Exception e) {
        // Clean env in case of exception.
        try {
            cleanPipEnv(projectDir);
        } finally {
            fail(ExceptionUtils.getStackTrace(e));
            if (projectDir != null) {
                FileUtils.deleteQuietly(projectDir.toFile());
            }
        }
    }
}
Also used : BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 4 with Module

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

the class NpmExtractorTest method runNpmTest.

private void runNpmTest(Project project, Dependency[] expectedDependencies, String args, boolean packageJsonPath, boolean isNpmCi) {
    Path projectDir = null;
    try {
        // Prepare.
        projectDir = createProjectDir(project);
        Path path = packageJsonPath ? projectDir.resolve("package.json") : projectDir;
        if (isNpmCi) {
            // Run npm install to generate package-lock.json file.
            new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null).execute();
        }
        // Execute command.
        NpmInstallCi buildExecutor;
        if (isNpmCi) {
            buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, true, null);
        } else {
            buildExecutor = new NpmInstallCi(artifactoryManagerBuilder, localRepo1, args, log, path, null, null, null, false, null);
        }
        BuildInfo buildInfo = buildExecutor.execute();
        // Validate.
        assertEquals(buildInfo.getModules().size(), 1);
        Module module = buildInfo.getModules().get(0);
        assertEquals(module.getType(), "npm");
        assertEquals(module.getId(), project.getModuleId());
        assertEqualsNoOrder(module.getDependencies().toArray(), expectedDependencies);
    } catch (Exception e) {
        fail(ExceptionUtils.getStackTrace(e));
    } finally {
        if (projectDir != null) {
            FileUtils.deleteQuietly(projectDir.toFile());
        }
    }
}
Also used : Path(java.nio.file.Path) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException)

Example 5 with Module

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

the class PipBuildInfoExtractor method createBuild.

private BuildInfo createBuild(List<Dependency> dependenciesList, String moduleName) {
    Module module = new ModuleBuilder().type(ModuleType.PYPI).id(moduleName).dependencies(dependenciesList).build();
    List<Module> modules = new ArrayList<>();
    modules.add(module);
    BuildInfo buildInfo = new BuildInfo();
    buildInfo.setModules(modules);
    return buildInfo;
}
Also used : ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ArrayList(java.util.ArrayList) Module(org.jfrog.build.extractor.ci.Module)

Aggregations

Module (org.jfrog.build.extractor.ci.Module)28 BuildInfo (org.jfrog.build.extractor.ci.BuildInfo)18 IOException (java.io.IOException)9 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)7 Path (java.nio.file.Path)6 Dependency (org.jfrog.build.extractor.ci.Dependency)6 Test (org.testng.annotations.Test)6 File (java.io.File)5 Artifact (org.jfrog.build.extractor.ci.Artifact)5 ArrayList (java.util.ArrayList)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)3 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)3 DockerImage (org.jfrog.build.extractor.docker.types.DockerImage)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 Project (org.apache.tools.ant.Project)2 DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1