Search in sources :

Example 1 with GradleDeployDetails

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;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) PublishArtifactSet(org.gradle.api.artifacts.PublishArtifactSet) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)

Example 2 with GradleDeployDetails

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());
}
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 3 with GradleDeployDetails

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;
}
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 4 with GradleDeployDetails

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();
            }
        }
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) GradleClientLogger(org.jfrog.gradle.plugin.artifactory.extractor.GradleClientLogger) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IOException(java.io.IOException) ArtifactoryBuildInfoClient(org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient) GradleBuildInfoExtractor(org.jfrog.gradle.plugin.artifactory.extractor.GradleBuildInfoExtractor) Build(org.jfrog.build.api.Build) File(java.io.File)

Example 5 with GradleDeployDetails

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);
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)

Aggregations

GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)9 DeployDetails (org.jfrog.build.client.DeployDetails)7 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)6 IOException (java.io.IOException)4 PublishArtifactInfo (org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo)4 File (java.io.File)3 GradleException (org.gradle.api.GradleException)3 QName (javax.xml.namespace.QName)1 Configuration (org.gradle.api.artifacts.Configuration)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 PublishArtifactSet (org.gradle.api.artifacts.PublishArtifactSet)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