use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.
the class SpecsHelper method uploadArtifactsBySpec.
/**
* Upload artifacts according to a given spec, return a list describing the deployed items.
*
* @param uploadSpec The required spec represented as String
* @param numberOfThreads Number of concurrent threads to use for handling uploads
* @param workspace File object that represents the workspace
* @param buildProperties Upload properties
* @param artifactoryManagerBuilder ArtifactoryManagerBuilder which will build the ArtifactoryManager per the number of passed threads number to perform the actual upload
* @return Set of DeployDetails that was calculated from the given params
* @throws IOException Thrown if any error occurs while reading the file, calculating the
* checksums or in case of any file system exception
*/
public List<Artifact> uploadArtifactsBySpec(String uploadSpec, int numberOfThreads, File workspace, Multimap<String, String> buildProperties, ArtifactoryManagerBuilder artifactoryManagerBuilder) throws Exception {
FileSpec fileSpec = FileSpec.fromString(uploadSpec);
FileSpecsValidation.validateUploadFileSpec(fileSpec, this.log);
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
// Create producer Runnable
ProducerRunnableBase[] producerRunnable = new ProducerRunnableBase[] { new SpecDeploymentProducer(fileSpec, workspace, buildProperties) };
// Create consumer Runnables
ConsumerRunnableBase[] consumerRunnables = new ConsumerRunnableBase[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
consumerRunnables[i] = new SpecDeploymentConsumer(artifactoryManager);
}
// Create the deployment executor
ProducerConsumerExecutor deploymentExecutor = new ProducerConsumerExecutor(log, producerRunnable, consumerRunnables, CONNECTION_POOL_SIZE);
deploymentExecutor.start();
Set<DeployDetails> deployedArtifacts = ((SpecDeploymentProducer) producerRunnable[0]).getDeployedArtifacts();
return convertDeployDetailsToArtifacts(deployedArtifacts);
}
}
use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.
the class SpecsHelper method convertDeployDetailsToArtifacts.
private List<Artifact> convertDeployDetailsToArtifacts(Set<DeployDetails> details) {
List<Artifact> result = new ArrayList<>();
for (DeployDetails detail : details) {
String ext = FilenameUtils.getExtension(detail.getFile().getName());
ArtifactBuilder artifactBuilder = new ArtifactBuilder(detail.getFile().getName());
artifactBuilder.md5(detail.getMd5()).sha1(detail.getSha1()).sha256(detail.getSha256()).type(ext).localPath(detail.getFile().getAbsolutePath()).remotePath(detail.getArtifactPath()).build();
result.add(artifactBuilder.build());
}
return result;
}
use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.
the class DeployTask method deployArtifacts.
private void deployArtifacts(ArtifactoryClientConfiguration accRoot, Map<String, String> propsRoot, Map<String, Set<DeployDetails>> allDeployDetails, ArtifactoryTask artifactoryTask, String logPrefix) {
try {
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 = "";
}
if (publisher.isPublishArtifacts()) {
try (ArtifactoryManager artifactoryManager = new ArtifactoryManager(contextUrl, username, password, new GradleClientLogger(log))) {
log.debug("Uploading artifacts to Artifactory at '{}'", contextUrl);
IncludeExcludePatterns patterns = new IncludeExcludePatterns(publisher.getIncludePatterns(), publisher.getExcludePatterns());
configureProxy(accRoot, artifactoryManager);
configConnectionTimeout(accRoot, artifactoryManager);
configRetriesParams(accRoot, artifactoryManager);
configInsecureTls(accRoot, artifactoryManager);
deployArtifacts(artifactoryTask.deployDetails, artifactoryManager, patterns, logPrefix, publisher.getMinChecksumDeploySizeKb());
}
}
if (!artifactoryTask.deployDetails.isEmpty()) {
Set<DeployDetails> deployDetailsSet = new LinkedHashSet<>();
for (GradleDeployDetails details : artifactoryTask.deployDetails) {
deployDetailsSet.add(details.getDeployDetails());
}
allDeployDetails.put(artifactoryTask.getProject().getName(), deployDetailsSet);
}
}
} else {
log.debug("Task '{}' did no work", artifactoryTask.getPath());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.
the class SingleSpecDeploymentProducer method processDeployCandidate.
/**
* Receives a candidate file to upload, creates DeployDetails for the file in case should upload it.
* Adds the DeployDetails to the BlockingQueue.
* @param file upload candidate
* @param deploymentSet Set containing the DeployDetails to deploy
*/
private void processDeployCandidate(File file, Set<DeployDetails> deploymentSet, ProducerConsumerExecutor executor) throws IOException, NoSuchAlgorithmException, InterruptedException {
String filePath = file.getAbsolutePath().replace("\\", "/");
// Check if matches pattern
if (!isFileMatchPattern(filePath, regexpPattern, regexpExcludePattern, workspace, baseDirFile)) {
return;
}
// Get the upload path
String uploadPath = UploadSpecHelper.getUploadPath(file, pathPattern, targetPath, isFlat, isAbsolutePath, workspace, isTargetDirectory);
// Create DeployDetails
DeployDetails deployDetails = UploadSpecHelper.buildDeployDetails(uploadPath, file, spec.getTarget(), spec.getExplode(), spec.getProps(), buildProperties);
// Add the created DeploymentDetails if artifact hasn't been added for deployment yet
if (deploymentSet.add(deployDetails)) {
validateUploadLimit(deploymentSet.size());
executor.put(deployDetails);
}
}
use of org.jfrog.build.extractor.clientConfiguration.deploy.DeployDetails in project build-info by JFrogDev.
the class UploadSpecHelper method buildDeployDetails.
/**
* Create a DeployDetails from the given properties
*
* @param targetPath target of the created artifact in Artifactory
* @param artifactFile the artifact to deploy
* @param uploadTarget target repository in Artifactory
* @param explode explode archive
* @param props properties to attach to the deployed file
* @param buildProperties a map of properties to add to the DeployDetails objects
*/
public static DeployDetails buildDeployDetails(String targetPath, File artifactFile, String uploadTarget, String explode, String props, Multimap<String, String> buildProperties) throws IOException, NoSuchAlgorithmException {
String path = UploadSpecHelper.wildcardCalculateTargetPath(targetPath, artifactFile);
path = StringUtils.replace(path, "//", "/");
// calculate the sha1 checksum and add it to the deploy artifactsToDeploy
Map<String, String> checksums;
try {
checksums = FileChecksumCalculator.calculateChecksums(artifactFile, MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM);
} catch (NoSuchAlgorithmException e) {
throw new NoSuchAlgorithmException(String.format("Could not find checksum algorithm for %s or %s or %s.", MD5_ALGORITHM, SHA1_ALGORITHM, SHA256_ALGORITHM), e);
}
DeployDetails.Builder builder = new DeployDetails.Builder().file(artifactFile).artifactPath(path).targetRepository(getRepositoryKey(uploadTarget)).md5(checksums.get(MD5_ALGORITHM)).sha1(checksums.get(SHA1_ALGORITHM)).sha256(checksums.get(SHA256_ALGORITHM)).explode(BooleanUtils.toBoolean(explode)).addProperties(SpecsHelper.getPropertiesMap(props)).packageType(DeployDetails.PackageType.GENERIC);
if (buildProperties != null && !buildProperties.isEmpty()) {
builder.addProperties(buildProperties);
}
return builder.build();
}
Aggregations