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);
}
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");
}
}
}
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;
}
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());
}
}
}
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));
}
Aggregations