use of org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails in project build-info by JFrogDev.
the class TaskHelperConfigurations method getArtifactDeployDetails.
protected Set<GradleDeployDetails> getArtifactDeployDetails() {
Set<GradleDeployDetails> deployDetails = Sets.newLinkedHashSet();
if (!hasConfigurations()) {
log.info("No configurations to publish for project '{}'.", getProject().getPath());
return deployDetails;
}
Set<String> processedFiles = Sets.newHashSet();
for (Configuration configuration : publishConfigurations) {
PublishArtifactSet artifacts = configuration.getAllArtifacts();
for (PublishArtifact artifact : artifacts) {
GradleDeployDetails gdd = gradleDeployDetails(artifact, configuration.getName(), processedFiles);
if (gdd != null) {
deployDetails.add(gdd);
}
}
}
return deployDetails;
}
use of org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails in project build-info by JFrogDev.
the class TaskHelperConfigurations method getIvyDescriptorDeployDetails.
private GradleDeployDetails getIvyDescriptorDeployDetails() {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(getProject());
DeployDetails.Builder artifactBuilder = new DeployDetails.Builder().file(artifactoryTask.ivyDescriptor);
try {
Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(artifactoryTask.ivyDescriptor, "MD5", "SHA1");
artifactBuilder.md5(checksums.get("MD5")).sha1(checksums.get("SHA1"));
} catch (Exception e) {
throw new GradleException("Failed to calculate checksums for artifact: " + artifactoryTask.ivyDescriptor.getAbsolutePath(), e);
}
String gid = getProject().getGroup().toString();
if (publisher.isM2Compatible()) {
gid = gid.replace(".", "/");
}
artifactBuilder.artifactPath(IvyPatternHelper.substitute(publisher.getIvyPattern(), gid, getModuleName(), getProject().getVersion().toString(), null, "ivy", "xml"));
artifactBuilder.targetRepository(publisher.getRepoKey());
PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifactoryTask.ivyDescriptor.getName(), "xml", "ivy", null, artifactoryTask.ivyDescriptor);
Map<String, String> propsToAdd = getPropsToAdd(artifactInfo, null);
artifactBuilder.addProperties(propsToAdd);
return new GradleDeployDetails(artifactInfo, artifactBuilder.build(), getProject());
}
use of org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails 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.gradle.plugin.artifactory.extractor.GradleDeployDetails in project build-info by JFrogDev.
the class DeployTask method prepareAndDeploy.
/**
* This method will be activated only at the "end" of the build, when we reached the root project.
*
* @throws java.io.IOException In case the deployment fails.
*/
private void prepareAndDeploy() throws IOException {
ArtifactoryClientConfiguration accRoot = ArtifactoryPluginUtil.getArtifactoryConvention(getProject()).getClientConfig();
Map<String, String> propsRoot = accRoot.publisher.getProps();
// Reset the default properties, they may have changed
GradleArtifactoryClientConfigUpdater.setMissingBuildAttributes(accRoot, getProject().getRootProject());
Set<GradleDeployDetails> allDeployDetails = Sets.newTreeSet();
List<ArtifactoryTask> orderedTasks = findArtifactoryPublishTasks(getProject().getGradle().getTaskGraph());
for (ArtifactoryTask artifactoryTask : orderedTasks) {
if (artifactoryTask.getDidWork()) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(artifactoryTask.getProject());
if (publisher != null && publisher.getContextUrl() != null) {
Map<String, String> moduleProps = new HashMap<String, String>(propsRoot);
moduleProps.putAll(publisher.getProps());
publisher.getProps().putAll(moduleProps);
String contextUrl = publisher.getContextUrl();
String username = publisher.getUsername();
String password = publisher.getPassword();
if (StringUtils.isBlank(username)) {
username = "";
}
if (StringUtils.isBlank(password)) {
password = "";
}
artifactoryTask.collectDescriptorsAndArtifactsForUpload();
if (publisher.isPublishArtifacts()) {
ArtifactoryBuildInfoClient client = null;
try {
client = new ArtifactoryBuildInfoClient(contextUrl, username, password, new GradleClientLogger(log));
log.debug("Uploading artifacts to Artifactory at '{}'", contextUrl);
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
configureProxy(accRoot, client);
configConnectionTimeout(accRoot, client);
configRetriesParams(accRoot, client);
deployArtifacts(artifactoryTask.deployDetails, client, patterns);
} finally {
if (client != null) {
client.close();
}
}
}
allDeployDetails.addAll(artifactoryTask.deployDetails);
}
} else {
log.debug("Task '{}' did no work", artifactoryTask.getPath());
}
}
ArtifactoryBuildInfoClient client = null;
String contextUrl = accRoot.publisher.getContextUrl();
String username = accRoot.publisher.getUsername();
String password = accRoot.publisher.getPassword();
if (contextUrl != null) {
if (StringUtils.isBlank(username)) {
username = "";
}
if (StringUtils.isBlank(password)) {
password = "";
}
try {
client = new ArtifactoryBuildInfoClient(accRoot.publisher.getContextUrl(), accRoot.publisher.getUsername(), accRoot.publisher.getPassword(), new GradleClientLogger(log));
configureProxy(accRoot, client);
configConnectionTimeout(accRoot, client);
configRetriesParams(accRoot, client);
GradleBuildInfoExtractor gbie = new GradleBuildInfoExtractor(accRoot, allDeployDetails);
Build build = gbie.extract(getProject().getRootProject());
exportBuildInfo(build, getExportFile(accRoot));
if (isPublishBuildInfo(accRoot)) {
// If export property set always save the file before sending it to artifactory
exportBuildInfo(build, getExportFile(accRoot));
if (accRoot.info.isIncremental()) {
log.debug("Publishing build info modules to artifactory at: '{}'", contextUrl);
client.sendModuleInfo(build);
} else {
log.debug("Publishing build info to artifactory at: '{}'", contextUrl);
Utils.sendBuildAndBuildRetention(client, build, accRoot);
}
}
if (isGenerateBuildInfoToFile(accRoot)) {
try {
exportBuildInfo(build, new File(accRoot.info.getGeneratedBuildInfoFilePath()));
} catch (Exception e) {
log.error("Failed writing build info to file: ", e);
throw new IOException("Failed writing build info to file", e);
}
}
if (isGenerateDeployableArtifactsToFile(accRoot)) {
try {
exportDeployableArtifacts(allDeployDetails, new File(accRoot.info.getDeployableArtifactsFilePath()));
} catch (Exception e) {
log.error("Failed writing deployable artifacts to file: ", e);
throw new RuntimeException("Failed writing deployable artifacts to file", e);
}
}
} finally {
if (client != null) {
client.close();
}
}
}
}
use of org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails 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