Search in sources :

Example 1 with PublishArtifactInfo

use of org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo 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());
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)

Example 2 with PublishArtifactInfo

use of org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo 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 3 with PublishArtifactInfo

use of org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo in project build-info by JFrogDev.

the class TaskHelperConfigurations method getMavenDeployDetails.

private GradleDeployDetails getMavenDeployDetails() {
    ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(getProject());
    DeployDetails.Builder artifactBuilder = new DeployDetails.Builder().file(artifactoryTask.mavenDescriptor);
    try {
        Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(artifactoryTask.mavenDescriptor, "MD5", "SHA1");
        artifactBuilder.md5(checksums.get("MD5")).sha1(checksums.get("SHA1"));
    } catch (Exception e) {
        throw new GradleException("Failed to calculate checksums for artifact: " + artifactoryTask.mavenDescriptor.getAbsolutePath(), e);
    }
    // for pom files always enforce the M2 pattern
    artifactBuilder.artifactPath(IvyPatternHelper.substitute(LayoutPatterns.M2_PATTERN, getProject().getGroup().toString().replace(".", "/"), getModuleName(), getProject().getVersion().toString(), null, "pom", "pom"));
    artifactBuilder.targetRepository(publisher.getRepoKey());
    PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifactoryTask.mavenDescriptor.getName(), "pom", "pom", null, artifactoryTask.mavenDescriptor);
    Map<String, String> propsToAdd = getPropsToAdd(artifactInfo, null);
    artifactBuilder.addProperties(propsToAdd);
    return new GradleDeployDetails(artifactInfo, artifactBuilder.build(), getProject());
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)

Example 4 with PublishArtifactInfo

use of org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo in project build-info by JFrogDev.

the class TaskHelperConfigurations method gradleDeployDetails.

private GradleDeployDetails gradleDeployDetails(PublishArtifact artifact, String configuration, @Nullable String artifactPath, @Nullable Set<String> processedFiles) {
    ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(getProject());
    if (publisher == null) {
        return null;
    }
    File file = artifact.getFile();
    if (processedFiles != null && processedFiles.contains(file.getAbsolutePath())) {
        return null;
    }
    if (!file.exists()) {
        throw new GradleException("File '" + file.getAbsolutePath() + "'" + " does not exists, and need to be published!");
    }
    if (processedFiles != null) {
        processedFiles.add(file.getAbsolutePath());
    }
    String revision = getProject().getVersion().toString();
    Map<String, String> extraTokens = Maps.newHashMap();
    if (StringUtils.isNotBlank(artifact.getClassifier())) {
        extraTokens.put("classifier", artifact.getClassifier());
    }
    String pattern = publisher.getIvyArtifactPattern();
    String gid = getProject().getGroup().toString();
    if (publisher.isM2Compatible()) {
        gid = gid.replace(".", "/");
    }
    DeployDetails.Builder deployDetailsBuilder = new DeployDetails.Builder().file(file);
    try {
        Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(file, "MD5", "SHA1");
        deployDetailsBuilder.md5(checksums.get("MD5")).sha1(checksums.get("SHA1"));
    } catch (Exception e) {
        throw new GradleException("Failed to calculate checksums for artifact: " + file.getAbsolutePath(), e);
    }
    if (artifactPath != null) {
        deployDetailsBuilder.artifactPath(artifactPath);
    } else {
        deployDetailsBuilder.artifactPath(IvyPatternHelper.substitute(pattern, gid, getModuleName(), revision, artifact.getName(), artifact.getType(), artifact.getExtension(), configuration, extraTokens, null));
    }
    deployDetailsBuilder.targetRepository(publisher.getRepoKey());
    PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifact);
    Map<String, String> propsToAdd = getPropsToAdd(artifactInfo, configuration);
    deployDetailsBuilder.addProperties(propsToAdd);
    DeployDetails details = deployDetailsBuilder.build();
    return new GradleDeployDetails(artifactInfo, details, getProject());
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) GradleException(org.gradle.api.GradleException) File(java.io.File) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)

Aggregations

DeployDetails (org.jfrog.build.client.DeployDetails)4 GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)4 PublishArtifactInfo (org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo)4 IOException (java.io.IOException)3 GradleException (org.gradle.api.GradleException)3 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)3 File (java.io.File)2 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 MavenArtifact (org.gradle.api.publish.maven.MavenArtifact)1 MavenArtifactSet (org.gradle.api.publish.maven.MavenArtifactSet)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)1 MavenNormalizedPublication (org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication)1 MavenProjectIdentity (org.gradle.api.publish.maven.internal.publisher.MavenProjectIdentity)1