use of org.jfrog.build.extractor.builder.BuildInfoBuilder in project build-info by JFrogDev.
the class ArtifactoryBuildListener method doDeploy.
private void doDeploy(BuildEvent event) {
IvyBuildInfoLog log = getBuildInfoLog(event);
log.info("[buildinfo:ant] Starting deployment");
Project project = event.getProject();
Set<DeployDetails> deployDetails = ctx.getDeployDetails();
BuildInfoBuilder builder = new BuildInfoBuilder(project.getName()).modules(ctx.getModules()).number("0").durationMillis(System.currentTimeMillis() - ctx.getBuildStartTime()).startedDate(new Date(ctx.getBuildStartTime())).buildAgent(new BuildAgent("Ivy", Ivy.getIvyVersion())).agent(new Agent("Ivy", Ivy.getIvyVersion()));
ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
String agentName = clientConf.info.getAgentName();
String agentVersion = clientConf.info.getAgentVersion();
if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
builder.agent(new Agent(agentName, agentVersion));
}
String buildAgentName = clientConf.info.getBuildAgentName();
String buildAgentVersion = clientConf.info.getBuildAgentVersion();
if (StringUtils.isNotBlank(buildAgentName) && StringUtils.isNotBlank(buildAgentVersion)) {
builder.buildAgent(new BuildAgent(buildAgentName, buildAgentVersion));
}
String buildName = clientConf.info.getBuildName();
if (StringUtils.isNotBlank(buildName)) {
builder.name(buildName);
}
String buildNumber = clientConf.info.getBuildNumber();
if (StringUtils.isNotBlank(buildNumber)) {
builder.number(buildNumber);
}
String buildUrl = clientConf.info.getBuildUrl();
if (StringUtils.isNotBlank(buildUrl)) {
builder.url(buildUrl);
}
String vcsRevision = clientConf.info.getVcsRevision();
if (StringUtils.isNotBlank(vcsRevision)) {
builder.vcsRevision(vcsRevision);
}
String vcsUrl = clientConf.info.getVcsUrl();
if (StringUtils.isNotBlank(vcsUrl)) {
builder.vcsUrl(vcsUrl);
}
Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
if (!vcs.isEmpty()) {
builder.vcs(Arrays.asList(vcs));
}
String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
if (StringUtils.isNotBlank(artifactoryPluginVersion)) {
builder.artifactoryPluginVersion(artifactoryPluginVersion);
} else {
builder.artifactoryPluginVersion("Unknown");
}
String principal = clientConf.info.getPrincipal();
if (StringUtils.isNotBlank(principal)) {
builder.principal(principal);
}
String parentBuildName = clientConf.info.getParentBuildName();
if (StringUtils.isNotBlank(parentBuildName)) {
builder.parentName(parentBuildName);
}
String parentBuildNumber = clientConf.info.getParentBuildNumber();
if (StringUtils.isNotBlank(parentBuildNumber)) {
builder.parentNumber(parentBuildNumber);
}
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);
}
builder.issues(issues);
}
for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
builder.addRunParameters(matrixParameter);
}
BuildInfo buildInfo = builder.build();
PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
String contextUrl = clientConf.publisher.getContextUrl();
String username = clientConf.publisher.getUsername();
String password = clientConf.publisher.getPassword();
try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, log)) {
configureProxy(clientConf, artifactoryManager);
configConnectionTimeout(clientConf, artifactoryManager);
configRetriesParams(clientConf, artifactoryManager);
if (clientConf.publisher.isPublishArtifacts()) {
IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
deployArtifacts(project, artifactoryManager, deployDetails, patterns);
}
if (clientConf.publisher.isPublishBuildInfo()) {
Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
}
isDidDeploy = true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.builder.BuildInfoBuilder in project build-info by JFrogDev.
the class ArtifactoryManagerTest method publishAndCheckBuildInfo.
private void publishAndCheckBuildInfo(String project) throws IOException {
final Date STARTED = new Date();
final List<Vcs> VCS = Arrays.asList(new Vcs("foo", "1"), new Vcs("bar", "2"), new Vcs("baz", "3"));
final List<MatrixParameter> RUN_PARAMETERS = Arrays.asList(new MatrixParameter("a", "b"), new MatrixParameter("c", "d"));
final Module module = new Module();
module.setId("foo");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BuildInfo.STARTED_FORMAT);
final List<PromotionStatus> STATUSES = Collections.singletonList(new PromotionStatus("a", "b", "c", simpleDateFormat.format(STARTED), "e", "f"));
BuildInfoBuilder buildInfoBuilder = new BuildInfoBuilder(BUILD_NAME).number(BUILD_NUMBER).setProject(project).buildAgent(new BuildAgent("agent11", "11")).agent(new Agent("agent22", "22")).startedDate(STARTED).durationMillis(100).principal("foo").artifactoryPrincipal(getUsername()).artifactoryPluginVersion("2.3.1").url(getArtifactoryUrl()).parentName("baz").parentNumber("10").vcs(VCS).buildRetention(new BuildRetention(true)).buildRunParameters(RUN_PARAMETERS).modules(Collections.singletonList(module)).statuses(STATUSES).issues(new Issues());
BuildInfo buildInfoToSend = buildInfoBuilder.build();
// Publish build info
artifactoryManager.publishBuildInfo(buildInfoToSend, project);
// Get build info
BuildInfo receivedBuildInfo = artifactoryManager.getBuildInfo(BUILD_NAME, BUILD_NUMBER, project);
// Compare
Assert.assertEquals(toJsonString(buildInfoToSend), toJsonString(receivedBuildInfo));
}
use of org.jfrog.build.extractor.builder.BuildInfoBuilder in project build-info by JFrogDev.
the class BuildInfo method ToBuildInfo.
public static BuildInfo ToBuildInfo(org.jfrog.build.api.Build build) {
BuildInfoBuilder builder = new BuildInfoBuilder(build.getName());
builder.number(build.getNumber()).setProject(build.getProject()).agent(build.getAgent() == null ? null : new Agent(build.getAgent().getName(), build.getAgent().getVersion())).buildAgent(build.getBuildAgent() == null ? null : new BuildAgent(build.getBuildAgent().getName(), build.getBuildAgent().getVersion())).started(build.getStarted()).startedMillis(build.getStartedMillis()).durationMillis(build.getDurationMillis()).principal(build.getPrincipal()).artifactoryPrincipal(build.getArtifactoryPrincipal()).artifactoryPluginVersion(build.getArtifactoryPluginVersion()).url(build.getUrl()).parentName(build.getParentName()).parentNumber(build.getParentNumber()).buildRunParameters(build.getRunParameters() == null ? null : build.getRunParameters().stream().map(rp -> new MatrixParameter(rp.getKey(), rp.getValue())).collect(Collectors.toList())).statuses(build.getStatuses()).properties(build.getProperties()).vcs(build.getVcs() == null ? null : build.getVcs().stream().map(Vcs::ToBuildInfoVcs).collect(Collectors.toList())).buildRetention(build.getBuildRetention() == null ? null : BuildRetention.ToBuildInfoRetention(build.getBuildRetention())).issues(build.getIssues() == null ? null : Issues.ToBuildInfoIssues(build.getIssues()));
if (build.getModules() != null) {
builder.modules(build.getModules().stream().map(m -> new ModuleBuilder().type(m.getType()).id(m.getId()).repository(m.getRepository()).sha1(m.getSha1()).md5(m.getMd5()).artifacts(m.getArtifacts() == null ? null : m.getArtifacts().stream().map(Artifact::ToBuildInfoArtifact).collect(Collectors.toList())).dependencies(m.getDependencies() == null ? null : m.getDependencies().stream().map(Dependency::ToBuildDependency).collect(Collectors.toList())).properties(m.getProperties()).excludedArtifacts(m.getExcludedArtifacts() == null ? null : m.getExcludedArtifacts().stream().map(Artifact::ToBuildInfoArtifact).collect(Collectors.toList())).build()).collect(Collectors.toList()));
}
return builder.build();
}
use of org.jfrog.build.extractor.builder.BuildInfoBuilder in project build-info by JFrogDev.
the class BuildInfoMavenBuilderTest method testBuilderSetters.
/**
* Validates the build values after using the builder setters
*/
public void testBuilderSetters() {
String version = "1.2.0";
String name = "moo";
String number = "15";
Agent agent = new Agent("pop", "1.6");
BuildAgent buildAgent = new BuildAgent("rock", "2.6");
long durationMillis = 6L;
String principal = "bob";
String artifactoryPrincipal = "too";
String artifactoryPluginVersion = "2.3.1";
String url = "mitz";
String parentName = "pooh";
String parentNumber = "5";
List<Module> modules = new ArrayList<>();
Properties properties = new Properties();
BuildInfo buildInfo = new BuildInfoBuilder(name).started("test").version(version).number(number).agent(agent).durationMillis(durationMillis).principal(principal).artifactoryPrincipal(artifactoryPrincipal).url(url).parentName(parentName).parentNumber(parentNumber).modules(modules).properties(properties).buildAgent(buildAgent).artifactoryPluginVersion(artifactoryPluginVersion).build();
assertEquals(buildInfo.getVersion(), version, "Unexpected buildInfo version.");
assertEquals(buildInfo.getName(), name, "Unexpected buildInfo name.");
assertEquals(buildInfo.getNumber(), number, "Unexpected buildInfo number.");
assertEquals(buildInfo.getAgent(), agent, "Unexpected buildInfo agent.");
assertEquals(buildInfo.getBuildAgent(), buildAgent, "Unexpected buildInfo agent.");
assertEquals(buildInfo.getDurationMillis(), durationMillis, "Unexpected buildInfo duration millis.");
assertEquals(buildInfo.getPrincipal(), principal, "Unexpected buildInfo principal.");
assertEquals(buildInfo.getArtifactoryPrincipal(), artifactoryPrincipal, "Unexpected buildInfo artifactory principal.");
assertEquals(buildInfo.getArtifactoryPluginVersion(), artifactoryPluginVersion, "Unexpected buildInfo artifactory Plugin Version.");
assertEquals(buildInfo.getUrl(), url, "Unexpected buildInfo URL.");
assertEquals(buildInfo.getParentName(), parentName, "Unexpected buildInfo parent name.");
assertEquals(buildInfo.getParentNumber(), parentNumber, "Unexpected buildInfo parent buildInfo number.");
assertEquals(buildInfo.getModules(), modules, "Unexpected buildInfo modules.");
assertTrue(buildInfo.getModules().isEmpty(), "BuildInfo modules list should not have been populated.");
assertEquals(buildInfo.getProperties(), properties, "Unexpected buildInfo properties.");
assertTrue(buildInfo.getProperties().isEmpty(), "BuildInfo properties list should not have been populated.");
}
use of org.jfrog.build.extractor.builder.BuildInfoBuilder 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;
}
Aggregations