use of org.gradle.api.publish.maven.MavenArtifact 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.gradle.api.publish.maven.MavenArtifact in project gradle by gradle.
the class MavenRemotePublisher method createSnapshotMetadata.
@Override
protected Metadata createSnapshotMetadata(MavenNormalizedPublication publication, String groupId, String artifactId, String version, ExternalResourceRepository repository, ExternalResourceName metadataResource) {
Metadata metadata = new Metadata();
metadata.setModelVersion("1.1.0");
metadata.setGroupId(groupId);
metadata.setArtifactId(artifactId);
metadata.setVersion(version);
String timestamp = createSnapshotTimestamp();
Snapshot snapshot = new Snapshot();
snapshot.setBuildNumber(getNextBuildNumber(repository, metadataResource));
snapshot.setTimestamp(timestamp);
Versioning versioning = new Versioning();
versioning.setSnapshot(snapshot);
versioning.setLastUpdated(snapshot.getTimestamp().replace(".", ""));
String timestampVersion = version.replace("SNAPSHOT", snapshot.getTimestamp() + "-" + snapshot.getBuildNumber());
for (MavenArtifact artifact : publication.getAllArtifacts()) {
SnapshotVersion sv = new SnapshotVersion();
sv.setClassifier(artifact.getClassifier());
sv.setExtension(artifact.getExtension());
sv.setVersion(timestampVersion);
sv.setUpdated(versioning.getLastUpdated());
versioning.getSnapshotVersions().add(sv);
}
metadata.setVersioning(versioning);
return metadata;
}
use of org.gradle.api.publish.maven.MavenArtifact in project gradle by gradle.
the class DefaultMavenPublication method addDerivedArtifact.
@Override
public MavenArtifact addDerivedArtifact(MavenArtifact originalArtifact, DerivedArtifact file) {
MavenArtifact artifact = new DerivedMavenArtifact((AbstractMavenArtifact) originalArtifact, file);
derivedArtifacts.add(artifact);
return artifact;
}
use of org.gradle.api.publish.maven.MavenArtifact in project gradle by gradle.
the class AbstractMavenPublisher method publish.
protected void publish(MavenNormalizedPublication publication, ExternalResourceRepository repository, URI rootUri, boolean localRepo) {
String groupId = publication.getGroupId();
String artifactId = publication.getArtifactId();
String version = publication.getVersion();
ModuleArtifactPublisher artifactPublisher = new ModuleArtifactPublisher(repository, localRepo, rootUri, groupId, artifactId, version);
if (isSnapshot(version)) {
ExternalResourceName snapshotMetadataPath = artifactPublisher.getSnapshotMetadataLocation();
Metadata snapshotMetadata = createSnapshotMetadata(publication, groupId, artifactId, version, repository, snapshotMetadataPath);
artifactPublisher.publish(snapshotMetadataPath, writeMetadataToTmpFile(snapshotMetadata, "snapshot-maven-metadata.xml"));
if (!localRepo) {
// Use the timestamped version for all published artifacts:
// The timestamped version is hidden deep in `Metadata.versioning.snapshotVersions`
artifactPublisher.artifactVersion = snapshotMetadata.getVersioning().getSnapshotVersions().get(0).getVersion();
}
}
if (publication.getMainArtifact() != null) {
artifactPublisher.publish(null, publication.getMainArtifact().getExtension(), publication.getMainArtifact().getFile());
}
artifactPublisher.publish(null, "pom", publication.getPomArtifact().getFile());
for (MavenArtifact artifact : publication.getAdditionalArtifacts()) {
artifactPublisher.publish(artifact.getClassifier(), artifact.getExtension(), artifact.getFile());
}
ExternalResourceName externalResource = artifactPublisher.getMetadataLocation();
Metadata metadata = createMetadata(groupId, artifactId, version, repository, externalResource);
artifactPublisher.publish(externalResource, writeMetadataToTmpFile(metadata, "module-maven-metadata.xml"));
}
use of org.gradle.api.publish.maven.MavenArtifact in project gradle by gradle.
the class MavenLocalPublisher method createSnapshotMetadata.
@Override
protected Metadata createSnapshotMetadata(MavenNormalizedPublication publication, String groupId, String artifactId, String version, ExternalResourceRepository repository, ExternalResourceName metadataResource) {
Metadata metadata = new Metadata();
metadata.setModelVersion("1.1.0");
metadata.setGroupId(groupId);
metadata.setArtifactId(artifactId);
metadata.setVersion(version);
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy(true);
Versioning versioning = new Versioning();
versioning.updateTimestamp();
versioning.setSnapshot(snapshot);
for (MavenArtifact artifact : publication.getAllArtifacts()) {
SnapshotVersion sv = new SnapshotVersion();
sv.setClassifier(artifact.getClassifier());
sv.setExtension(artifact.getExtension());
sv.setVersion(version);
sv.setUpdated(versioning.getLastUpdated());
versioning.getSnapshotVersions().add(sv);
}
metadata.setVersioning(versioning);
return metadata;
}
Aggregations