Search in sources :

Example 1 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class TaskHelperPublications method getArtifactDeployDetails.

public Set<GradleDeployDetails> getArtifactDeployDetails() {
    Set<GradleDeployDetails> deployDetails = new LinkedHashSet<>();
    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):
        File ivyFile = getIvyDescriptorFile(ivyNormalizedPublication);
        if (isPublishIvy()) {
            DeployDetails.Builder builder = createBuilder(ivyFile, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getModule(), "xml", "ivy", null, extraInfo, ivyFile);
                addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
            }
        }
        // Second adding all artifacts, skipping the ivy file
        Set<IvyArtifact> artifacts = ivyNormalizedPublication.getAllArtifacts();
        for (IvyArtifact artifact : artifacts) {
            File file = artifact.getFile();
            // Skip the ivy file
            if (file.equals(ivyFile))
                continue;
            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();
        // First adding the Maven descriptor (if the build is configured to add it):
        File pomFile = mavenNormalizedPublication.getPomArtifact().getFile();
        if (isPublishMaven()) {
            DeployDetails.Builder builder = createBuilder(pomFile, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(mavenPublication.getArtifactId(), "pom", "pom", null, pomFile);
                addMavenArtifactToDeployDetails(deployDetails, publicationName, builder, artifactInfo, mavenPublication);
            }
        }
        boolean legacy = false;
        Set<MavenArtifact> artifacts = new HashSet<>();
        try {
            // Gradle 5.0 and above:
            artifacts = mavenNormalizedPublication.getAdditionalArtifacts();
            // Second adding the main artifact of the publication, if present
            if (mavenNormalizedPublication.getMainArtifact() != null) {
                createPublishArtifactInfoAndAddToDeployDetails(mavenNormalizedPublication.getMainArtifact(), deployDetails, mavenPublication, publicationName);
            }
        } catch (IllegalStateException exception) {
            // The Jar task is disabled, and therefore getMainArtifact() threw an exception:
            // "Artifact api.jar wasn't produced by this build."
            log.warn("Illegal state detected at Maven publication '{}', {}: {}", publicationName, getProject(), exception.getMessage());
        } catch (NoSuchMethodError error) {
            // Compatibility with older versions of Gradle:
            artifacts = mavenNormalizedPublication.getAllArtifacts();
            legacy = true;
        }
        // Third adding all additional artifacts - includes Gradle Module Metadata when produced
        for (MavenArtifact artifact : artifacts) {
            if (legacy && artifact.getFile().equals(pomFile)) {
                // Need to skip the POM file for Gradle < 5.0
                continue;
            }
            createPublishArtifactInfoAndAddToDeployDetails(artifact, deployDetails, mavenPublication, publicationName);
        }
    }
    return deployDetails;
}
Also used : MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) MavenNormalizedPublication(org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IvyNormalizedPublication(org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.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) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) 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 DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class ArtifactoryBuildListener method doDeploy.

private void doDeploy(BuildEvent event) {
    IvyBuildInfoLog log = getBuildInfoLog(event);
    log.info("[buildinfo:ant] Starting deployment");
    Project project = event.getProject();
    Set<DeployDetails> deployDetails = ctx.getDeployDetails();
    BuildInfoBuilder builder = new BuildInfoBuilder(project.getName()).modules(ctx.getModules()).number("0").durationMillis(System.currentTimeMillis() - ctx.getBuildStartTime()).startedDate(new Date(ctx.getBuildStartTime())).buildAgent(new BuildAgent("Ivy", Ivy.getIvyVersion())).agent(new Agent("Ivy", Ivy.getIvyVersion()));
    ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
    String agentName = clientConf.info.getAgentName();
    String agentVersion = clientConf.info.getAgentVersion();
    if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
        builder.agent(new Agent(agentName, agentVersion));
    }
    String buildAgentName = clientConf.info.getBuildAgentName();
    String buildAgentVersion = clientConf.info.getBuildAgentVersion();
    if (StringUtils.isNotBlank(buildAgentName) && StringUtils.isNotBlank(buildAgentVersion)) {
        builder.buildAgent(new BuildAgent(buildAgentName, buildAgentVersion));
    }
    String buildName = clientConf.info.getBuildName();
    if (StringUtils.isNotBlank(buildName)) {
        builder.name(buildName);
    }
    String buildNumber = clientConf.info.getBuildNumber();
    if (StringUtils.isNotBlank(buildNumber)) {
        builder.number(buildNumber);
    }
    String buildUrl = clientConf.info.getBuildUrl();
    if (StringUtils.isNotBlank(buildUrl)) {
        builder.url(buildUrl);
    }
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        builder.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        builder.vcsUrl(vcsUrl);
    }
    Vcs vcs = new Vcs(vcsUrl, vcsRevision, clientConf.info.getVcsBranch(), clientConf.info.getVcsMessage());
    if (!vcs.isEmpty()) {
        builder.vcs(Arrays.asList(vcs));
    }
    String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
    if (StringUtils.isNotBlank(artifactoryPluginVersion)) {
        builder.artifactoryPluginVersion(artifactoryPluginVersion);
    } else {
        builder.artifactoryPluginVersion("Unknown");
    }
    String principal = clientConf.info.getPrincipal();
    if (StringUtils.isNotBlank(principal)) {
        builder.principal(principal);
    }
    String parentBuildName = clientConf.info.getParentBuildName();
    if (StringUtils.isNotBlank(parentBuildName)) {
        builder.parentName(parentBuildName);
    }
    String parentBuildNumber = clientConf.info.getParentBuildNumber();
    if (StringUtils.isNotBlank(parentBuildNumber)) {
        builder.parentNumber(parentBuildNumber);
    }
    String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
    if (StringUtils.isNotBlank(issueTrackerName)) {
        Issues issues = new Issues();
        issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
        issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
        issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
        Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
        if (!affectedIssuesSet.isEmpty()) {
            issues.setAffectedIssues(affectedIssuesSet);
        }
        builder.issues(issues);
    }
    for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
        MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
        builder.addRunParameters(matrixParameter);
    }
    BuildInfo buildInfo = builder.build();
    PackageManagerUtils.collectEnvIfNeeded(clientConf, buildInfo);
    String contextUrl = clientConf.publisher.getContextUrl();
    String username = clientConf.publisher.getUsername();
    String password = clientConf.publisher.getPassword();
    try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, log)) {
        configureProxy(clientConf, artifactoryManager);
        configConnectionTimeout(clientConf, artifactoryManager);
        configRetriesParams(clientConf, artifactoryManager);
        if (clientConf.publisher.isPublishArtifacts()) {
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
            deployArtifacts(project, artifactoryManager, deployDetails, patterns);
        }
        if (clientConf.publisher.isPublishBuildInfo()) {
            Utils.sendBuildAndBuildRetention(artifactoryManager, buildInfo, clientConf);
        }
        isDidDeploy = true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Agent(org.jfrog.build.extractor.ci.Agent) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) Issue(org.jfrog.build.extractor.ci.Issue) Issues(org.jfrog.build.extractor.ci.Issues) IssueTracker(org.jfrog.build.extractor.ci.IssueTracker) MatrixParameter(org.jfrog.build.extractor.ci.MatrixParameter) Vcs(org.jfrog.build.extractor.ci.Vcs) IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) IOException(java.io.IOException) BuildAgent(org.jfrog.build.extractor.ci.BuildAgent) Date(java.util.Date) Project(org.apache.tools.ant.Project) BuildInfoBuilder(org.jfrog.build.extractor.builder.BuildInfoBuilder) ArtifactoryManager(org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager) BuildInfo(org.jfrog.build.extractor.ci.BuildInfo) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog) Map(java.util.Map)

Example 3 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class ArtifactoryBuildInfoTrigger method buildDeployDetails.

private DeployDetails buildDeployDetails(File artifactFile, Artifact artifact, BuildContext ctx, Map<String, String> map, Map<String, String> extraAttributes) {
    ArtifactoryClientConfiguration clientConf = ctx.getClientConf();
    DeployDetails.Builder builder = new DeployDetails.Builder().file(artifactFile).sha1(artifact.getSha1()).md5(artifact.getMd5()).packageType(DeployDetails.PackageType.IVY);
    builder.artifactPath(IvyResolverHelper.calculateArtifactPath(clientConf.publisher, map, extraAttributes));
    builder.targetRepository(clientConf.publisher.getRepoKey());
    if (StringUtils.isNotBlank(clientConf.info.getVcsRevision())) {
        builder.addProperty(BuildInfoFields.VCS_REVISION, clientConf.info.getVcsRevision());
    }
    if (StringUtils.isNotBlank(clientConf.info.getVcsUrl())) {
        builder.addProperty(BuildInfoFields.VCS_URL, clientConf.info.getVcsUrl());
    }
    if (StringUtils.isNotBlank(clientConf.info.getBuildName())) {
        builder.addProperty(BuildInfoFields.BUILD_NAME, clientConf.info.getBuildName());
    }
    if (StringUtils.isNotBlank(clientConf.info.getBuildNumber())) {
        builder.addProperty(BuildInfoFields.BUILD_NUMBER, clientConf.info.getBuildNumber());
    }
    String buildTimestamp = clientConf.info.getBuildTimestamp();
    if (StringUtils.isBlank(buildTimestamp)) {
        buildTimestamp = ctx.getBuildStartTime() + "";
    }
    builder.addProperty(BuildInfoFields.BUILD_TIMESTAMP, buildTimestamp);
    if (StringUtils.isNotBlank(clientConf.info.getParentBuildName())) {
        builder.addProperty(BuildInfoFields.BUILD_PARENT_NAME, clientConf.info.getParentBuildName());
    }
    if (StringUtils.isNotBlank(clientConf.info.getParentBuildNumber())) {
        builder.addProperty(BuildInfoFields.BUILD_PARENT_NUMBER, clientConf.info.getParentBuildNumber());
    }
    builder.addProperties(clientConf.publisher.getMatrixParams());
    return builder.build();
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)

Example 4 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class BuildInfoRecorder method addDeployableArtifact.

private void addDeployableArtifact(org.jfrog.build.extractor.ci.Artifact artifact, File artifactFile, boolean pathConflicts, String groupId, String artifactId, String version, String classifier, String fileExtension) {
    if (pathConflicts) {
        logger.info("'" + artifact.getName() + "' will not be deployed due to the defined include-exclude patterns.");
        return;
    }
    String deploymentPath = getDeploymentPath(groupId, artifactId, version, classifier, fileExtension);
    // deploy to snapshots or releases repository based on the deploy version
    String targetRepository = getTargetRepository(deploymentPath);
    DeployDetails deployable = new DeployDetails.Builder().artifactPath(deploymentPath).file(artifactFile).targetRepository(targetRepository).addProperties(conf.publisher.getMatrixParams()).packageType(DeployDetails.PackageType.MAVEN).build();
    String myArtifactId = BuildInfoExtractorUtils.getArtifactId(currentModule.get().build().getId(), artifact.getName());
    deployableArtifactBuilderMap.put(myArtifactId, deployable);
}
Also used : DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) BuildInfoMavenBuilder(org.jfrog.build.extractor.builder.BuildInfoMavenBuilder) ModuleBuilder(org.jfrog.build.extractor.builder.ModuleBuilder) DependencyBuilder(org.jfrog.build.extractor.builder.DependencyBuilder) ArtifactBuilder(org.jfrog.build.extractor.builder.ArtifactBuilder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)

Example 5 with DeployDetails

use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.

the class DistributionManagerTest method uploadFile.

String uploadFile() throws IOException {
    String fileName = RandomStringUtils.randomAlphabetic(10);
    Path tmpFile = tempWorkspace.toPath().resolve(fileName).toAbsolutePath();
    Files.createFile(tmpFile);
    Files.write(tmpFile, RandomStringUtils.randomAlphabetic(10).getBytes(StandardCharsets.UTF_8));
    DeployDetails deployDetails = new DeployDetails.Builder().file(tmpFile.toFile()).artifactPath("data/" + fileName).targetRepository(localRepo1).build();
    ArtifactoryUploadResponse response = artifactoryManager.upload(deployDetails);
    assertFalse(CollectionUtils.hasElements(response.getErrors()));
    return fileName;
}
Also used : Path(java.nio.file.Path) DeployDetails(org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails) ArtifactoryUploadResponse(org.jfrog.build.client.ArtifactoryUploadResponse)

Aggregations

DeployDetails (org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails)24 File (java.io.File)8 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)7 IOException (java.io.IOException)6 ArtifactBuilder (org.jfrog.build.extractor.builder.ArtifactBuilder)6 ArtifactoryUploadResponse (org.jfrog.build.client.ArtifactoryUploadResponse)4 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)4 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)4 ModuleBuilder (org.jfrog.build.extractor.builder.ModuleBuilder)4 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)4 Artifact (org.jfrog.build.extractor.ci.Artifact)3 ArtifactoryManager (org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager)3 GradleDeployDetails (org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails)3 RandomAccessFile (java.io.RandomAccessFile)2 Map (java.util.Map)2 Project (org.apache.tools.ant.Project)2 DependencyBuilder (org.jfrog.build.extractor.builder.DependencyBuilder)2 Module (org.jfrog.build.extractor.ci.Module)2 PublishArtifactInfo (org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo)2 Path (java.nio.file.Path)1