Search in sources :

Example 1 with ArtifactoryClientConfiguration

use of org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration 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()));
    // This is here for backwards compatibility.
    builder.type(BuildType.IVY);
    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);
    }
    Vcs vcs = new Vcs();
    String vcsRevision = clientConf.info.getVcsRevision();
    if (StringUtils.isNotBlank(vcsRevision)) {
        vcs.setRevision(vcsRevision);
        builder.vcsRevision(vcsRevision);
    }
    String vcsUrl = clientConf.info.getVcsUrl();
    if (StringUtils.isNotBlank(vcsUrl)) {
        vcs.setUrl(vcsUrl);
        builder.vcsUrl(vcsUrl);
    }
    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);
    }
    LicenseControl licenseControl = new LicenseControl(clientConf.info.licenseControl.isRunChecks());
    String notificationRecipients = clientConf.info.licenseControl.getViolationRecipients();
    if (StringUtils.isNotBlank(notificationRecipients)) {
        licenseControl.setLicenseViolationsRecipientsList(notificationRecipients);
    }
    licenseControl.setIncludePublishedArtifacts(clientConf.info.licenseControl.isIncludePublishedArtifacts());
    String scopes = clientConf.info.licenseControl.getScopes();
    if (StringUtils.isNotBlank(scopes)) {
        licenseControl.setScopesList(scopes);
    }
    licenseControl.setAutoDiscover(clientConf.info.licenseControl.isAutoDiscover());
    builder.licenseControl(licenseControl);
    final BlackDuckProperties blackDuckProperties;
    if (clientConf.info.blackDuckProperties.isRunChecks()) {
        blackDuckProperties = clientConf.info.blackDuckProperties.copyBlackDuckProperties();
    } else {
        blackDuckProperties = new BlackDuckProperties();
    }
    Governance governance = new Governance();
    governance.setBlackDuckProperties(blackDuckProperties);
    builder.governance(governance);
    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);
    }
    if (clientConf.isIncludeEnvVars()) {
        Properties envProperties = new Properties();
        envProperties.putAll(clientConf.getAllProperties());
        envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, clientConf.getLog());
        for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
            builder.addProperty(envProp.getKey(), envProp.getValue());
        }
    }
    Build build = builder.build();
    String contextUrl = clientConf.publisher.getContextUrl();
    String username = clientConf.publisher.getUsername();
    String password = clientConf.publisher.getPassword();
    ArtifactoryBuildInfoClient client = new ArtifactoryBuildInfoClient(contextUrl, username, password, log);
    try {
        configureProxy(clientConf, client);
        configConnectionTimeout(clientConf, client);
        configRetriesParams(clientConf, client);
        if (clientConf.publisher.isPublishArtifacts()) {
            IncludeExcludePatterns patterns = new IncludeExcludePatterns(clientConf.publisher.getIncludePatterns(), clientConf.publisher.getExcludePatterns());
            deployArtifacts(project, client, deployDetails, patterns);
        }
        if (clientConf.publisher.isPublishBuildInfo()) {
            Utils.sendBuildAndBuildRetention(client, build, clientConf);
        }
        isDidDeploy = true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
Also used : IncludeExcludePatterns(org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns) ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) DeployDetails(org.jfrog.build.client.DeployDetails) IOException(java.io.IOException) ArtifactoryBuildInfoClient(org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient) BuildInfoBuilder(org.jfrog.build.api.builder.BuildInfoBuilder) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog)

Example 2 with ArtifactoryClientConfiguration

use of org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration 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());
    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.client.DeployDetails) BuildInfoExtractorUtils.getModuleIdString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString) BuildInfoExtractorUtils.getTypeString(org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)

Example 3 with ArtifactoryClientConfiguration

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

the class ArtifactoryTask method projectEvaluated.

public void projectEvaluated() {
    Project project = getProject();
    if (isSkip()) {
        log.debug("artifactoryPublish task '{}' skipped for project '{}'.", this.getPath(), project.getName());
    } else {
        ArtifactoryPluginConvention convention = ArtifactoryPluginUtil.getPublisherConvention(project);
        if (convention != null) {
            ArtifactoryClientConfiguration acc = convention.getClientConfig();
            artifactSpecs.clear();
            artifactSpecs.addAll(acc.publisher.getArtifactSpecs());
            // Configure the task using the "defaults" closure (delegate to the task)
            PublisherConfig config = convention.getPublisherConfig();
            if (config != null) {
                Closure defaultsClosure = config.getDefaultsClosure();
                ConfigureUtil.configure(defaultsClosure, this);
            }
        }
        Task deployTask = project.getRootProject().getTasks().findByName(DEPLOY_TASK_NAME);
        if (deployTask == null) {
            throw new IllegalStateException(String.format("Could not find %s in the root project", DEPLOY_TASK_NAME));
        }
        finalizedBy(deployTask);
        // Depend on buildInfo task in sub-projects
        for (Project sub : project.getSubprojects()) {
            Task subArtifactoryTask = sub.getTasks().findByName(ARTIFACTORY_PUBLISH_TASK_NAME);
            if (subArtifactoryTask != null) {
                dependsOn(subArtifactoryTask);
            }
        }
        checkDependsOnArtifactsToPublish();
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) Project(org.gradle.api.Project) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Closure(groovy.lang.Closure) ArtifactoryPluginConvention(org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention) PublisherConfig(org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig)

Example 4 with ArtifactoryClientConfiguration

use of org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration 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 ArtifactoryClientConfiguration

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

the class BuildInfoRecorderLifecycleParticipant method afterProjectsRead.

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
    ArtifactoryClientConfiguration configuration = getConfiguration(session);
    Object activateRecorderObject = configuration.isActivateRecorder();
    if (activateRecorderObject == null) {
        logger.debug("Disabling Artifactory Maven3 Build-Info Recorder: activation property (" + BuildInfoConfigProperties.ACTIVATE_RECORDER + ") not found.");
        return;
    }
    if (!Boolean.valueOf(activateRecorderObject.toString())) {
        logger.debug("Disabling Artifactory Maven3 Build-Info Recorder: activation property (" + BuildInfoConfigProperties.ACTIVATE_RECORDER + ") value is either false or invalid.");
        return;
    }
    logger.debug("Activating Artifactory Maven3 Build-Info Recorder: activation property (" + BuildInfoConfigProperties.ACTIVATE_RECORDER + ") value is true.");
    configuration.info.setBuildStarted(System.currentTimeMillis());
    ExecutionListener existingExecutionListener = session.getRequest().getExecutionListener();
    recorder.setListenerToWrap(existingExecutionListener);
    recorder.setConfiguration(configuration);
    session.getRequest().setExecutionListener(recorder);
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) ExecutionListener(org.apache.maven.execution.ExecutionListener)

Aggregations

ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)8 IOException (java.io.IOException)3 Properties (java.util.Properties)2 DeployDetails (org.jfrog.build.client.DeployDetails)2 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)2 ArtifactoryBuildInfoClient (org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient)2 IvyBuildInfoLog (org.jfrog.build.util.IvyBuildInfoLog)2 Closure (groovy.lang.Closure)1 File (java.io.File)1 ExecutionListener (org.apache.maven.execution.ExecutionListener)1 DefaultTask (org.gradle.api.DefaultTask)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 Build (org.jfrog.build.api.Build)1 BuildInfoConfigProperties (org.jfrog.build.api.BuildInfoConfigProperties)1 BuildInfoBuilder (org.jfrog.build.api.builder.BuildInfoBuilder)1 BuildContext (org.jfrog.build.context.BuildContext)1 BuildInfoExtractorUtils.getModuleIdString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getModuleIdString)1 BuildInfoExtractorUtils.getTypeString (org.jfrog.build.extractor.BuildInfoExtractorUtils.getTypeString)1 Maven3BuildInfoLogger (org.jfrog.build.extractor.maven.Maven3BuildInfoLogger)1