use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class TaskHelperPublications method getArtifactDeployDetails.
public Set<GradleDeployDetails> getArtifactDeployDetails() {
Set<GradleDeployDetails> deployDetails = Sets.newLinkedHashSet();
if (!hasPublications()) {
log.info("No publications to publish for project '{}'.", getProject().getPath());
return deployDetails;
}
for (IvyPublication ivyPublication : ivyPublications) {
String publicationName = ivyPublication.getName();
if (!(ivyPublication instanceof IvyPublicationInternal)) {
// TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
log.warn("Ivy publication name '{}' is of unsupported type '{}'!", publicationName, ivyPublication.getClass());
continue;
}
IvyPublicationInternal ivyPublicationInternal = (IvyPublicationInternal) ivyPublication;
IvyNormalizedPublication ivyNormalizedPublication = ivyPublicationInternal.asNormalisedPublication();
IvyPublicationIdentity projectIdentity = ivyNormalizedPublication.getProjectIdentity();
Map<QName, String> extraInfo = ivyPublication.getDescriptor().getExtraInfo().asMap();
// First adding the Ivy descriptor (if the build is configured to add it):
if (isPublishIvy()) {
File file = getIvyDescriptorFile(ivyNormalizedPublication);
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder != null) {
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getModule(), "xml", "ivy", null, extraInfo, file);
addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
}
}
IvyArtifactSet artifacts = ivyPublication.getArtifacts();
for (IvyArtifact artifact : artifacts) {
File file = artifact.getFile();
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder == null)
continue;
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifact.getName(), artifact.getExtension(), artifact.getType(), artifact.getClassifier(), extraInfo, file);
addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
}
}
for (MavenPublication mavenPublication : mavenPublications) {
String publicationName = mavenPublication.getName();
if (!(mavenPublication instanceof MavenPublicationInternal)) {
// TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
log.warn("Maven publication name '{}' is of unsupported type '{}'!", publicationName, mavenPublication.getClass());
continue;
}
MavenPublicationInternal mavenPublicationInternal = (MavenPublicationInternal) mavenPublication;
MavenNormalizedPublication mavenNormalizedPublication = mavenPublicationInternal.asNormalisedPublication();
MavenProjectIdentity projectIdentity = mavenNormalizedPublication.getProjectIdentity();
// First adding the Maven descriptor (if the build is configured to add it):
if (isPublishMaven()) {
File file = mavenNormalizedPublication.getPomFile();
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder != null) {
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), "pom", "pom", null, file);
addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
}
}
MavenArtifactSet artifacts = mavenPublication.getArtifacts();
for (MavenArtifact artifact : artifacts) {
File file = artifact.getFile();
DeployDetails.Builder builder = createBuilder(file, publicationName);
if (builder == null)
continue;
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), artifact.getExtension(), artifact.getExtension(), artifact.getClassifier(), file);
addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
}
}
return deployDetails;
}
use of org.jfrog.build.client.DeployDetails 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()));
// This is here for backwards compatibility.
builder.type(BuildType.IVY);
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);
}
Vcs vcs = new Vcs();
String vcsRevision = clientConf.info.getVcsRevision();
if (StringUtils.isNotBlank(vcsRevision)) {
vcs.setRevision(vcsRevision);
builder.vcsRevision(vcsRevision);
}
String vcsUrl = clientConf.info.getVcsUrl();
if (StringUtils.isNotBlank(vcsUrl)) {
vcs.setUrl(vcsUrl);
builder.vcsUrl(vcsUrl);
}
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);
}
LicenseControl licenseControl = new LicenseControl(clientConf.info.licenseControl.isRunChecks());
String notificationRecipients = clientConf.info.licenseControl.getViolationRecipients();
if (StringUtils.isNotBlank(notificationRecipients)) {
licenseControl.setLicenseViolationsRecipientsList(notificationRecipients);
}
licenseControl.setIncludePublishedArtifacts(clientConf.info.licenseControl.isIncludePublishedArtifacts());
String scopes = clientConf.info.licenseControl.getScopes();
if (StringUtils.isNotBlank(scopes)) {
licenseControl.setScopesList(scopes);
}
licenseControl.setAutoDiscover(clientConf.info.licenseControl.isAutoDiscover());
builder.licenseControl(licenseControl);
final BlackDuckProperties blackDuckProperties;
if (clientConf.info.blackDuckProperties.isRunChecks()) {
blackDuckProperties = clientConf.info.blackDuckProperties.copyBlackDuckProperties();
} else {
blackDuckProperties = new BlackDuckProperties();
}
Governance governance = new Governance();
governance.setBlackDuckProperties(blackDuckProperties);
builder.governance(governance);
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);
}
if (clientConf.isIncludeEnvVars()) {
Properties envProperties = new Properties();
envProperties.putAll(clientConf.getAllProperties());
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, clientConf.getLog());
for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
builder.addProperty(envProp.getKey(), envProp.getValue());
}
}
Build build = builder.build();
String contextUrl = clientConf.publisher.getContextUrl();
String username = clientConf.publisher.getUsername();
String password = clientConf.publisher.getPassword();
ArtifactoryBuildInfoClient client = new ArtifactoryBuildInfoClient(contextUrl, username, password, log);
try {
configureProxy(clientConf, client);
configConnectionTimeout(clientConf, client);
configRetriesParams(clientConf, client);
if (clientConf.publisher.isPublishArtifacts()) {
IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
deployArtifacts(project, client, deployDetails, patterns);
}
if (clientConf.publisher.isPublishBuildInfo()) {
Utils.sendBuildAndBuildRetention(client, build, clientConf);
}
isDidDeploy = true;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
client.close();
}
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class ArtifactoryBuildListener method deployArtifacts.
private void deployArtifacts(Project project, ArtifactoryBuildInfoClient client, Set<DeployDetails> deployDetails, IncludeExcludePatterns patterns) throws IOException {
for (DeployDetails deployDetail : deployDetails) {
String artifactPath = deployDetail.getArtifactPath();
if (PatternMatcher.pathConflicts(artifactPath, patterns)) {
project.log("[buildinfo:deploy] Skipping the deployment of '" + artifactPath + "' due to the defined include-exclude patterns.", Project.MSG_INFO);
continue;
}
client.deployArtifact(deployDetail);
}
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class ArtifactoryBuildInfoTrigger method buildDeployDetails.
private DeployDetails buildDeployDetails(File artifactFile, Artifact artifact, BuildContext ctx, Map<String, String> map, Map<String, String> extraAttributes) {
ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
DeployDetails.Builder builder = new DeployDetails.Builder().file(artifactFile).sha1(artifact.getSha1()).md5(artifact.getMd5());
builder.artifactPath(IvyResolverHelper.calculateArtifactPath(clientConf.publisher, map, extraAttributes));
builder.targetRepository(clientConf.publisher.getRepoKey());
if (StringUtils.isNotBlank(clientConf.info.getVcsRevision())) {
builder.addProperty(BuildInfoFields.VCS_REVISION, clientConf.info.getVcsRevision());
}
if (StringUtils.isNotBlank(clientConf.info.getVcsUrl())) {
builder.addProperty(BuildInfoFields.VCS_URL, clientConf.info.getVcsUrl());
}
if (StringUtils.isNotBlank(clientConf.info.getBuildName())) {
builder.addProperty(BuildInfoFields.BUILD_NAME, clientConf.info.getBuildName());
}
if (StringUtils.isNotBlank(clientConf.info.getBuildNumber())) {
builder.addProperty(BuildInfoFields.BUILD_NUMBER, clientConf.info.getBuildNumber());
}
String buildTimestamp = clientConf.info.getBuildTimestamp();
if (StringUtils.isBlank(buildTimestamp)) {
buildTimestamp = ctx.getBuildStartTime() + "";
}
builder.addProperty(BuildInfoFields.BUILD_TIMESTAMP, buildTimestamp);
if (StringUtils.isNotBlank(clientConf.info.getParentBuildName())) {
builder.addProperty(BuildInfoFields.BUILD_PARENT_NAME, clientConf.info.getParentBuildName());
}
if (StringUtils.isNotBlank(clientConf.info.getParentBuildNumber())) {
builder.addProperty(BuildInfoFields.BUILD_PARENT_NUMBER, clientConf.info.getParentBuildNumber());
}
builder.addProperties(clientConf.publisher.getMatrixParams());
return builder.build();
}
use of org.jfrog.build.client.DeployDetails in project build-info by JFrogDev.
the class DeployTask method exportDeployableArtifacts.
private void exportDeployableArtifacts(Set<GradleDeployDetails> allDeployDetails, File toFile) throws IOException {
log.debug("Exporting deployable artifacts to '{}'", toFile.getAbsolutePath());
Set<DeployDetails> deploySet = Sets.newLinkedHashSet();
for (GradleDeployDetails details : allDeployDetails) {
deploySet.add(details.getDeployDetails());
}
DeployableArtifactsUtils.saveDeployableArtifactsToFile(deploySet, toFile);
}
Aggregations