use of org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns 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();
}
}
use of org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns 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();
}
}
}
}
use of org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns in project build-info by JFrogDev.
the class BuildInfoRecorder method addArtifactsToCurrentModule.
private void addArtifactsToCurrentModule(MavenProject project, ModuleBuilder module) {
Set<Artifact> moduleArtifacts = currentModuleArtifacts.get();
if (moduleArtifacts == null) {
logger.warn("Skipping Artifactory Build-Info module artifact addition: Null current module artifact list.");
return;
}
ArtifactoryClientConfiguration.PublisherHandler publisher = conf.publisher;
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
boolean pomFileAdded = false;
Artifact nonPomArtifact = null;
String pomFileName = null;
for (Artifact moduleArtifact : moduleArtifacts) {
String artifactId = moduleArtifact.getArtifactId();
String artifactVersion = moduleArtifact.getVersion();
String artifactClassifier = moduleArtifact.getClassifier();
String artifactExtension = moduleArtifact.getArtifactHandler().getExtension();
String type = getTypeString(moduleArtifact.getType(), artifactClassifier, artifactExtension);
String artifactName = getArtifactName(artifactId, artifactVersion, artifactClassifier, artifactExtension);
ArtifactBuilder artifactBuilder = new ArtifactBuilder(artifactName).type(type);
File artifactFile = moduleArtifact.getFile();
if ("pom".equals(type)) {
pomFileAdded = true;
// For pom projects take the file from the project if the artifact file is null.
if (moduleArtifact.equals(project.getArtifact())) {
// project.getFile() returns the project pom file
artifactFile = project.getFile();
}
} else if (moduleArtifact.getMetadataList().size() > 0) {
nonPomArtifact = moduleArtifact;
pomFileName = StringUtils.removeEnd(artifactName, artifactExtension) + "pom";
}
org.jfrog.build.api.Artifact artifact = artifactBuilder.build();
String groupId = moduleArtifact.getGroupId();
String deploymentPath = getDeploymentPath(groupId, artifactId, artifactVersion, artifactClassifier, artifactExtension);
if (artifactFile != null && artifactFile.isFile()) {
// If excludeArtifactsFromBuild and the PatternMatcher found conflict, add the excluded artifact to the excluded artifact set.
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(deploymentPath, patterns)) {
module.addExcludedArtifact(artifact);
} else {
module.addArtifact(artifact);
}
addDeployableArtifact(artifact, artifactFile, moduleArtifact.getGroupId(), artifactId, artifactVersion, artifactClassifier, artifactExtension);
}
}
/*
* In case of non packaging Pom project module, we need to create the pom file from the ProjectArtifactMetadata on the Artifact
*/
if (!pomFileAdded && nonPomArtifact != null) {
String deploymentPath = getDeploymentPath(nonPomArtifact.getGroupId(), nonPomArtifact.getArtifactId(), nonPomArtifact.getVersion(), nonPomArtifact.getClassifier(), "pom");
addPomArtifact(nonPomArtifact, module, patterns, deploymentPath, pomFileName, excludeArtifactsFromBuild);
}
}
use of org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns in project build-info by JFrogDev.
the class ArtifactoryBuildInfoTrigger method collectModuleInformation.
/**
* Collect module information for each module.
*
* @param event the Ivy publish event
*/
private void collectModuleInformation(IvyEvent event) {
ArtifactoryClientConfiguration.PublisherHandler publisher = ctx.getClientConf().publisher;
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
boolean excludeArtifactsFromBuild = publisher.isFilterExcludedArtifactsFromBuild();
Project project = (Project) IvyContext.peekInContextStack(IvyTask.ANT_PROJECT_CONTEXT_KEY);
// Finding module object from context
@SuppressWarnings("unchecked") final Map<String, String> map = event.getAttributes();
Module module = getOrCreateModule(map);
List<Artifact> artifacts = module.getArtifacts();
if (artifacts == null) {
module.setArtifacts(Lists.<Artifact>newArrayList());
}
List<Artifact> excludedArtifacts = module.getExcludedArtifacts();
if (excludedArtifacts == null) {
module.setExcludedArtifacts(Lists.<Artifact>newArrayList());
}
final org.apache.ivy.core.module.descriptor.Artifact pubArtifact = ((PublishEvent) event).getArtifact();
@SuppressWarnings("unchecked") Map<String, String> extraAttributes = pubArtifact.getExtraAttributes();
// Using the original file, not the published one that can be far away (network wise)
String file = map.get("file");
// But all other attributes are taken from the actual published artifact
final ModuleRevisionId mrid = pubArtifact.getModuleRevisionId();
String moduleName = mrid.getName();
String type = getType(pubArtifact);
// By default simple name
String name = pubArtifact.getName() + "-" + mrid.getRevision() + "." + pubArtifact.getExt();
// Set name from name of published file
String fullPath = IvyResolverHelper.calculateArtifactPath(publisher, map, extraAttributes);
int lastSlash = fullPath.lastIndexOf('/');
if (lastSlash > 0 && lastSlash + 1 < fullPath.length()) {
name = fullPath.substring(lastSlash + 1);
}
project.log("[buildinfo:collect] Collecting artifact " + name + " for module " + moduleName + " using file " + file, Project.MSG_INFO);
if (isArtifactExist(module.getArtifacts(), name) || isArtifactExist(module.getExcludedArtifacts(), name)) {
return;
}
ArtifactBuilder artifactBuilder = new ArtifactBuilder(name);
artifactBuilder.type(type);
File artifactFile = new File(file);
Map<String, String> checksums = calculateFileChecksum(artifactFile);
String md5 = checksums.get(MD5);
String sha1 = checksums.get(SHA1);
artifactBuilder.md5(md5).sha1(sha1);
Artifact artifact = artifactBuilder.build();
if (excludeArtifactsFromBuild && PatternMatcher.pathConflicts(fullPath, patterns)) {
module.getExcludedArtifacts().add(artifact);
} else {
module.getArtifacts().add(artifact);
}
@SuppressWarnings("unchecked") DeployDetails deployDetails = buildDeployDetails(artifactFile, artifact, ctx, map, extraAttributes);
ctx.addDeployDetailsForModule(deployDetails);
List<Module> contextModules = ctx.getModules();
if (contextModules.indexOf(module) == -1) {
ctx.addModule(module);
}
}
use of org.jfrog.build.extractor.clientConfiguration.IncludeExcludePatterns in project build-info by JFrogDev.
the class BuildInfoExtractorUtils method getEnvProperties.
public static Properties getEnvProperties(Properties startProps, Log log) {
IncludeExcludePatterns patterns = new IncludeExcludePatterns(startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_INCLUDE_PATTERNS), startProps.getProperty(BuildInfoConfigProperties.PROP_ENV_VARS_EXCLUDE_PATTERNS));
Properties props = new Properties();
// Add all the startProps that starts with BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX
for (Map.Entry<Object, Object> startEntry : startProps.entrySet()) {
if (StringUtils.startsWith((String) startEntry.getKey(), BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX)) {
props.put(startEntry.getKey(), startEntry.getValue());
}
}
// Add all system environment that match the patterns
Map<String, String> envMap = System.getenv();
for (Map.Entry<String, String> entry : envMap.entrySet()) {
String varKey = entry.getKey();
if (PatternMatcher.pathConflicts(varKey, patterns)) {
continue;
}
props.put(BuildInfoProperties.BUILD_INFO_ENVIRONMENT_PREFIX + varKey, entry.getValue());
}
Map<String, String> sysProps = new HashMap(System.getProperties());
Map<String, String> filteredSysProps = Maps.difference(sysProps, System.getenv()).entriesOnlyOnLeft();
for (Map.Entry<String, String> entry : filteredSysProps.entrySet()) {
String varKey = entry.getKey();
if (PatternMatcher.pathConflicts(varKey, patterns)) {
continue;
}
props.put(varKey, entry.getValue());
}
// TODO: [by FSI] Test if this is needed! Since start props are used now
String propsFilePath = getAdditionalPropertiesFile(startProps, log);
if (StringUtils.isNotBlank(propsFilePath)) {
File propertiesFile = new File(propsFilePath);
InputStream inputStream = null;
try {
inputStream = new FileInputStream(propertiesFile);
Properties propertiesFromFile = new Properties();
propertiesFromFile.load(inputStream);
props.putAll(filterDynamicProperties(propertiesFromFile, ENV_PREDICATE));
} catch (IOException e) {
throw new RuntimeException("Unable to load build info properties from file: " + propertiesFile.getAbsolutePath(), e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
return props;
}
Aggregations