use of org.jfrog.gradle.plugin.artifactory.extractor.GradleBuildInfoExtractor 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();
}
}
}
}
Aggregations