use of org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask in project build-info by JFrogDev.
the class GradleBuildInfoExtractor method extract.
@Override
public Build extract(Project rootProject) {
String buildName = clientConf.info.getBuildName();
BuildInfoBuilder bib = new BuildInfoBuilder(buildName);
// backward compat
bib.type(BuildType.GRADLE);
String buildNumber = clientConf.info.getBuildNumber();
bib.number(buildNumber);
String buildStartedIso = clientConf.info.getBuildStarted();
Date buildStartDate = null;
try {
buildStartDate = new SimpleDateFormat(Build.STARTED_FORMAT).parse(buildStartedIso);
} catch (ParseException e) {
log.error("Build start date format error: " + buildStartedIso, e);
}
bib.started(buildStartedIso);
BuildAgent buildAgent = new BuildAgent(clientConf.info.getBuildAgentName(), clientConf.info.getBuildAgentVersion());
bib.buildAgent(buildAgent);
// CI agent
String agentName = clientConf.info.getAgentName();
String agentVersion = clientConf.info.getAgentVersion();
if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
bib.agent(new Agent(agentName, agentVersion));
} else {
// Fallback for standalone builds
bib.agent(new Agent(buildAgent.getName(), buildAgent.getVersion()));
}
long durationMillis = buildStartDate != null ? System.currentTimeMillis() - buildStartDate.getTime() : 0;
bib.durationMillis(durationMillis);
Set<Project> allProjects = rootProject.getAllprojects();
for (Project project : allProjects) {
if (project.getState().getExecuted()) {
ArtifactoryTask buildInfoTask = getBuildInfoTask(project);
if (buildInfoTask != null && buildInfoTask.hasModules()) {
bib.addModule(extractModule(project));
}
}
}
String parentName = clientConf.info.getParentBuildName();
String parentNumber = clientConf.info.getParentBuildNumber();
if (parentName != null && parentNumber != null) {
bib.parentName(parentName);
bib.parentNumber(parentNumber);
}
String principal = clientConf.info.getPrincipal();
if (StringUtils.isBlank(principal)) {
principal = System.getProperty("user.name");
}
bib.principal(principal);
String artifactoryPrincipal = clientConf.publisher.getUsername();
if (StringUtils.isBlank(artifactoryPrincipal)) {
artifactoryPrincipal = System.getProperty("user.name");
}
bib.artifactoryPrincipal(artifactoryPrincipal);
String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
if (StringUtils.isBlank(artifactoryPluginVersion)) {
artifactoryPluginVersion = "Unknown";
}
bib.artifactoryPluginVersion(artifactoryPluginVersion);
String buildUrl = clientConf.info.getBuildUrl();
if (StringUtils.isNotBlank(buildUrl)) {
bib.url(buildUrl);
}
String vcsRevision = clientConf.info.getVcsRevision();
Vcs vcs = new Vcs();
if (StringUtils.isNotBlank(vcsRevision)) {
vcs.setRevision(vcsRevision);
bib.vcsRevision(vcsRevision);
}
String vcsUrl = clientConf.info.getVcsUrl();
if (StringUtils.isNotBlank(vcsUrl)) {
vcs.setUrl(vcsUrl);
bib.vcsUrl(vcsUrl);
}
if (!vcs.isEmpty()) {
bib.vcs(Arrays.asList(vcs));
}
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());
bib.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);
bib.governance(governance);
if (clientConf.info.isReleaseEnabled()) {
String stagingRepository = clientConf.publisher.getRepoKey();
String comment = clientConf.info.getReleaseComment();
if (comment == null) {
comment = "";
}
bib.addStatus(new PromotionStatusBuilder(Promotion.STAGED).timestampDate(buildStartDate).comment(comment).repository(stagingRepository).ciUser(principal).user(artifactoryPrincipal).build());
}
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);
}
bib.issues(issues);
}
for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
bib.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()) {
bib.addProperty(envProp.getKey(), envProp.getValue());
}
}
log.debug("buildInfoBuilder = " + bib);
// for backward compatibility for Artifactory 2.2.3
Build build = bib.build();
if (parentName != null && parentNumber != null) {
build.setParentBuildId(parentName);
}
return build;
}
use of org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask in project build-info by JFrogDev.
the class GradleBuildInfoExtractor method getBuildInfoTask.
private ArtifactoryTask getBuildInfoTask(Project project) {
Set<Task> tasks = project.getTasksByName(ArtifactoryTask.ARTIFACTORY_PUBLISH_TASK_NAME, false);
if (tasks.isEmpty()) {
return null;
}
ArtifactoryTask artifactoryTask = (ArtifactoryTask) tasks.iterator().next();
if (taskDidWork(artifactoryTask)) {
return artifactoryTask;
}
return null;
}
use of org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask in project build-info by JFrogDev.
the class GradleBuildInfoExtractor method extractModule.
public Module extractModule(Project project) {
String artifactName = project.getName();
ArtifactoryTask task = getBuildInfoTask(project);
if (task != null) {
artifactName = project.getName();
}
ModuleBuilder builder = new ModuleBuilder().id(getModuleIdString(project.getGroup().toString(), artifactName, project.getVersion().toString()));
try {
ArtifactoryClientConfiguration.PublisherHandler publisher = ArtifactoryPluginUtil.getPublisherHandler(project);
if (publisher != null) {
boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
Iterable<GradleDeployDetails> deployExcludeDetails = null;
Iterable<GradleDeployDetails> deployIncludeDetails = null;
if (excludeArtifactsFromBuild) {
deployIncludeDetails = Iterables.filter(gradleDeployDetails, new IncludeExcludePredicate(project, patterns, true));
deployExcludeDetails = Iterables.filter(gradleDeployDetails, new IncludeExcludePredicate(project, patterns, false));
} else {
deployIncludeDetails = Iterables.filter(gradleDeployDetails, new ProjectPredicate(project));
deployExcludeDetails = new ArrayList<GradleDeployDetails>();
}
builder.artifacts(calculateArtifacts(deployIncludeDetails)).excludedArtifacts(calculateArtifacts(deployExcludeDetails)).dependencies(calculateDependencies(project));
} else {
log.warn("No publisher config found for project: " + project.getName());
}
} catch (Exception e) {
log.error("Error during extraction: ", e);
}
return builder.build();
}
Aggregations