Search in sources :

Example 11 with Dependency

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

the class DependenciesDownloaderHelper method downloadDependencies.

/**
 * Download dependencies by the provided spec using the provided in the constructor client.
 * returns a distinct list of downloaded artifacts
 *
 * @param downloadSpec the download spec
 * @return list of downloaded artifacts
 * @throws IOException in case of IO error
 */
public List<Dependency> downloadDependencies(FileSpec downloadSpec) throws IOException {
    ArtifactorySearcher searcher = new ArtifactorySearcher(downloader.getArtifactoryManager(), log);
    Set<DownloadableArtifact> downloadableArtifacts;
    List<AqlSearchResult.SearchEntry> searchResults;
    HashSet<Dependency> resolvedDependencies = new HashSet<>();
    for (FilesGroup file : downloadSpec.getFiles()) {
        log.debug("Downloading dependencies using spec: \n" + file.toString());
        this.downloader.setFlatDownload(BooleanUtils.toBoolean(file.getFlat()));
        searchResults = searcher.SearchByFileSpec(file);
        downloadableArtifacts = fetchDownloadableArtifactsFromResult(searchResults, Boolean.valueOf(file.getExplode()), file.getTarget());
        if (file.getSpecType() == FilesGroup.SpecType.PATTERN) {
            replaceTargetPlaceholders(file.getPattern(), downloadableArtifacts, file.getTarget());
        }
        resolvedDependencies.addAll(downloadDependencies(downloadableArtifacts));
    }
    return new ArrayList<>(resolvedDependencies);
}
Also used : DownloadableArtifact(org.jfrog.build.api.dependency.DownloadableArtifact) Dependency(org.jfrog.build.extractor.ci.Dependency) FilesGroup(org.jfrog.filespecs.entities.FilesGroup)

Example 12 with Dependency

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

the class Utils method assertRequestedBy.

private static void assertRequestedBy(BuildInfo buildInfo) {
    List<Dependency> apiDependencies = buildInfo.getModule("org.jfrog.test.gradle.publish:api:1.0-SNAPSHOT").getDependencies();
    assertEquals(apiDependencies.size(), 5);
    for (Dependency dependency : apiDependencies) {
        if (dependency.getId().equals("commons-io:commons-io:1.2")) {
            String[][] requestedBy = dependency.getRequestedBy();
            assertNotNull(requestedBy);
            assertEquals(requestedBy.length, 1);
            assertEquals(requestedBy[0].length, 2);
            assertEquals(requestedBy[0][0], "org.apache.commons:commons-lang3:3.12.0");
            assertEquals(requestedBy[0][1], "org.jfrog.test.gradle.publish:api:1.0-SNAPSHOT");
        }
    }
}
Also used : Dependency(org.jfrog.build.extractor.ci.Dependency)

Example 13 with Dependency

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

the class GradleBuildInfoExtractor method extract.

@Override
public BuildInfo extract(Project rootProject) {
    String buildName = clientConf.info.getBuildName();
    BuildInfoBuilder bib = new BuildInfoBuilder(buildName);
    String buildNumber = clientConf.info.getBuildNumber();
    bib.number(buildNumber);
    String buildStartedIso = clientConf.info.getBuildStarted();
    Date buildStartDate = null;
    try {
        buildStartDate = new SimpleDateFormat(BuildInfo.STARTED_FORMAT).parse(buildStartedIso);
    } catch (ParseException e) {
        log.error("Build start date format error: " + buildStartedIso, e);
    }
    bib.started(buildStartedIso);
    BuildAgent buildAgent = new BuildAgent(clientConf.info.getBuildAgentName(), clientConf.info.getBuildAgentVersion());
    bib.buildAgent(buildAgent);
    // CI agent
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        bib.agent(new Agent(agentName, agentVersion));
    } else {
        // Fallback for standalone builds
        bib.agent(new Agent(buildAgent.getName(), buildAgent.getVersion()));
    }
    long durationMillis = buildStartDate != null ? System.currentTimeMillis() - buildStartDate.getTime() : 0;
    bib.durationMillis(durationMillis);
    Set<File> moduleFilesWithModules = moduleInfoFileProducers.stream().filter(ModuleInfoFileProducer::hasModules).flatMap(moduleInfoFileProducer -> moduleInfoFileProducer.getModuleInfoFiles().getFiles().stream()).collect(Collectors.toSet());
    moduleFilesWithModules.forEach(moduleFile -> {
        try {
            Module module = ModuleExtractorUtils.readModuleFromFile(moduleFile);
            List<Artifact> artifacts = module.getArtifacts();
            List<Dependency> dependencies = module.getDependencies();
            if ((artifacts != null && !artifacts.isEmpty()) || (dependencies != null && !dependencies.isEmpty())) {
                bib.addModule(module);
            }
        } catch (IOException e) {
            throw new RuntimeException("Cannot load module info from file: " + moduleFile.getAbsolutePath(), e);
        }
    });
    String parentName = clientConf.info.getParentBuildName();
    String parentNumber = clientConf.info.getParentBuildNumber();
    if (parentName != null && parentNumber != null) {
        bib.parentName(parentName);
        bib.parentNumber(parentNumber);
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isBlank(principal)) {
        principal = System.getProperty("user.name");
    }
    bib.principal(principal);
    String artifactoryPrincipal = clientConf.publisher.getUsername();
    if (StringUtils.isBlank(artifactoryPrincipal)) {
        artifactoryPrincipal = System.getProperty("user.name");
    }
    bib.artifactoryPrincipal(artifactoryPrincipal);
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isBlank(artifactoryPluginVersion)) {
        artifactoryPluginVersion = "Unknown";
    }
    bib.artifactoryPluginVersion(artifactoryPluginVersion);
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        bib.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        bib.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        bib.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        bib.vcs(Arrays.asList(vcs));
    }
    if (clientConf.info.isReleaseEnabled()) {
        String stagingRepository = clientConf.publisher.getRepoKey();
        String comment = clientConf.info.getReleaseComment();
        if (comment == null) {
            comment = "";
        }
        bib.addStatus(new PromotionStatusBuilder(Promotion.STAGED).timestampDate(buildStartDate).comment(comment).repository(stagingRepository).ciUser(principal).user(artifactoryPrincipal).build());
    }
    String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
    if (StringUtils.isNotBlank(issueTrackerName)) {
        Issues issues = new Issues();
        issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
        issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
        issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
        Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
        if (!affectedIssuesSet.isEmpty()) {
            issues.setAffectedIssues(affectedIssuesSet);
        }
        bib.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        bib.addRunParameters(matrixParameter);
    }
    log.debug("buildInfoBuilder = " + bib);
    // for backward compatibility for Artifactory 2.2.3
    BuildInfo buildInfo = bib.build();
    if (parentName != null && parentNumber != null) {
        buildInfo.setParentBuildId(parentName);
    }
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    return buildInfo;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) Agent(org.jfrog.build.extractor.ci.Agent) StringUtils(org.apache.commons.lang3.StringUtils) Logger(org.gradle.api.logging.Logger) Issues(org.jfrog.build.extractor.ci.Issues) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Artifact(org.jfrog.build.extractor.ci.Artifact) BuildInfoExtractor(org.jfrog.build.extractor.BuildInfoExtractor) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) Module(org.jfrog.build.extractor.ci.Module) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Map(java.util.Map) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) ParseException(java.text.ParseException) Dependency(org.jfrog.build.extractor.ci.Dependency) PackageManagerUtils(org.jfrog.build.extractor.packageManager.PackageManagerUtils) Project(org.gradle.api.Project) PromotionStatusBuilder(org.jfrog.build.api.builder.PromotionStatusBuilder) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Logging(org.gradle.api.logging.Logging) Issue(org.jfrog.build.extractor.ci.Issue) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) Promotion(org.jfrog.build.api.release.Promotion) Vcs(org.jfrog.build.extractor.ci.Vcs) ModuleExtractorUtils(org.jfrog.build.extractor.ModuleExtractorUtils) ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) Vcs(org.jfrog.build.extractor.ci.Vcs) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Dependency(org.jfrog.build.extractor.ci.Dependency) IOException(java.io.IOException) Date(java.util.Date) Artifact(org.jfrog.build.extractor.ci.Artifact) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) PromotionStatusBuilder(org.jfrog.build.api.builder.PromotionStatusBuilder) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) ParseException(java.text.ParseException) Module(org.jfrog.build.extractor.ci.Module) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Map(java.util.Map)

Example 14 with Dependency

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

the class GoExtractorTest method goRunPublishTest.

/*
     * 1. Build project1 locally (with default Go proxy)
     * 2. Publish project1 package to Artifactory. (Project1 is a dependency for project2)
     * 3. Build project2 with Artifactory for resolution.
     */
@Test
public void goRunPublishTest() {
    Path projectDir = null;
    ArrayListMultimap<String, String> properties = ArrayListMultimap.create();
    try {
        // Run Go build on project1 locally
        Project project = Project.PROJECT_1;
        projectDir = createProjectDir(project.targetDir, project.projectOrigin);
        GoRun goRun = new GoRun(GO_BUILD_CMD, projectDir, null, null, StringUtils.EMPTY, getUsername(), getAdminToken(), getLog(), env);
        BuildInfo project1BuildInfo = goRun.execute();
        // Check successful execution
        assertNotNull(project1BuildInfo);
        // Publish project1 to Artifactory
        GoPublish goPublish = new GoPublish(artifactoryManagerBuilder, properties, localRepo1, projectDir, project.getVersion(), null, getLog());
        BuildInfo publishBuildInfo = goPublish.execute();
        // Check successful execution
        assertNotNull(publishBuildInfo);
        project1BuildInfo.append(publishBuildInfo);
        // Check correctness of the module, dependencies and artifacts
        assertEquals(project1BuildInfo.getModules().size(), 1);
        Module module = project1BuildInfo.getModules().get(0);
        assertEquals(module.getType(), "go");
        assertEquals(module.getId(), project.getModuleId());
        assertEquals(module.getRepository(), localRepo1);
        Set<String> moduleDependencies = module.getDependencies().stream().map(Dependency::getId).collect(Collectors.toSet());
        assertEquals(moduleDependencies, project.dependencies);
        Set<String> moduleArtifacts = module.getArtifacts().stream().map(Artifact::getName).collect(Collectors.toSet());
        assertEquals(moduleArtifacts, project.getArtifactSet());
        String expectedRemotePath = project.getRemotePath();
        module.getArtifacts().stream().map(BaseBuildFileBean::getRemotePath).forEach(remotePath -> assertEquals(remotePath, expectedRemotePath));
        // Run Go build on project2 using Artifactory for resolution
        project = Project.PROJECT_2;
        projectDir = createProjectDir(project.targetDir, project.projectOrigin);
        goRun = new GoRun(GO_BUILD_CMD, projectDir, null, artifactoryManagerBuilder, virtualRepo, getUsername(), getAdminToken(), getLog(), env);
        BuildInfo project2BuildInfo = goRun.execute();
        // Check successful execution and correctness of the module, dependencies and artifacts
        assertNotNull(project2BuildInfo);
        assertEquals(project2BuildInfo.getModules().size(), 1);
        module = project2BuildInfo.getModules().get(0);
        assertEquals(module.getId(), project.getModuleId());
        moduleDependencies = module.getDependencies().stream().map(Dependency::getId).collect(Collectors.toSet());
        assertEquals(moduleDependencies, project.dependencies);
    } 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) Dependency(org.jfrog.build.extractor.ci.Dependency) Module(org.jfrog.build.extractor.ci.Module) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 15 with Dependency

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

the class DockerImage method setDependencies.

private void setDependencies(ModuleBuilder moduleBuilder) throws IOException {
    LinkedHashSet<Dependency> dependencies = new LinkedHashSet<>();
    // Docker manifest may hold 'empty layers', as a result, docker promote will fail to promote the same layer more than once.
    for (String digest : DockerUtils.getLayersDigests(manifest)) {
        DockerLayer layer = layers.getByDigest(digest);
        Dependency dependency = new DependencyBuilder().id(layer.getFileName()).sha1(layer.getSha1()).build();
        dependencies.add(dependency);
    }
    moduleBuilder.dependencies(new ArrayList<>(dependencies));
}
Also used : DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) Dependency(org.jfrog.build.extractor.ci.Dependency)

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