Search in sources :

Example 1 with IvyBuildInfoLog

use of org.jfrog.build.util.IvyBuildInfoLog 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 IvyBuildInfoLog

use of org.jfrog.build.util.IvyBuildInfoLog in project build-info by JFrogDev.

the class ArtifactoryBuildListener method assertInitialized.

private void assertInitialized(BuildEvent event) {
    if (buildInfoLog != null) {
        buildInfoLog.setProject(event.getProject());
        return;
    }
    try {
        buildInfoLog = new IvyBuildInfoLog(event.getProject());
        ArtifactoryClientConfiguration clientConf = new ArtifactoryClientConfiguration(buildInfoLog);
        Properties props = getMergedEnvAndSystemProps();
        clientConf.fillFromProperties(props);
        ctx = new BuildContext(clientConf);
        DEPENDENCY_TRIGGER.setIvyBuildContext(ctx);
        PUBLISH_TRIGGER.setIvyBuildContext(ctx);
        buildInfoLog.info("[buildinfo:ant] Artifactory Build Info Listener Initialized");
    } catch (Exception e) {
        RuntimeException re = new RuntimeException("Fail to initialize the Ivy listeners for the Artifactory Ivy plugin, due to: " + e.getMessage(), e);
        if (buildInfoLog != null && buildInfoLog.getProject() != null) {
            buildInfoLog.error(re.getMessage(), e);
        }
        throw re;
    }
}
Also used : ArtifactoryClientConfiguration(org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration) BuildContext(org.jfrog.build.context.BuildContext) IvyBuildInfoLog(org.jfrog.build.util.IvyBuildInfoLog) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ArtifactoryClientConfiguration (org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration)2 IvyBuildInfoLog (org.jfrog.build.util.IvyBuildInfoLog)2 BuildInfoBuilder (org.jfrog.build.api.builder.BuildInfoBuilder)1 DeployDetails (org.jfrog.build.client.DeployDetails)1 BuildContext (org.jfrog.build.context.BuildContext)1 IncludeExcludePatterns (org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns)1 ArtifactoryBuildInfoClient (org.jfrog.build.extractor.clientConfiguration.client.ArtifactoryBuildInfoClient)1