Search in sources :

Example 1 with MavenArtifact

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;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) QName(javax.xml.namespace.QName) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) MavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MavenProjectIdentity) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) MavenNormalizedPublication(org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication) IvyArtifactSet(org.gradle.api.publish.ivy.IvyArtifactSet) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IvyNormalizedPublication(org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) MavenArtifactSet(org.gradle.api.publish.maven.MavenArtifactSet) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) File(java.io.File) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 2 with MavenArtifact

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;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact)

Example 3 with MavenArtifact

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;
}
Also used : DerivedMavenArtifact(org.gradle.api.publish.maven.internal.artifact.DerivedMavenArtifact) SingleOutputTaskMavenArtifact(org.gradle.api.publish.maven.internal.artifact.SingleOutputTaskMavenArtifact) DerivedMavenArtifact(org.gradle.api.publish.maven.internal.artifact.DerivedMavenArtifact) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) AbstractMavenArtifact(org.gradle.api.publish.maven.internal.artifact.AbstractMavenArtifact)

Example 4 with MavenArtifact

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"));
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact)

Example 5 with MavenArtifact

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;
}
Also used : Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact)

Aggregations

MavenArtifact (org.gradle.api.publish.maven.MavenArtifact)9 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)3 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)2 SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)2 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)2 File (java.io.File)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 IvyArtifact (org.gradle.api.publish.ivy.IvyArtifact)1 IvyArtifactSet (org.gradle.api.publish.ivy.IvyArtifactSet)1 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)1 IvyPublicationInternal (org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal)1 IvyNormalizedPublication (org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication)1 IvyPublicationIdentity (org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity)1 MavenArtifactSet (org.gradle.api.publish.maven.MavenArtifactSet)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1 AbstractMavenArtifact (org.gradle.api.publish.maven.internal.artifact.AbstractMavenArtifact)1 DerivedMavenArtifact (org.gradle.api.publish.maven.internal.artifact.DerivedMavenArtifact)1 SingleOutputTaskMavenArtifact (org.gradle.api.publish.maven.internal.artifact.SingleOutputTaskMavenArtifact)1 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)1