Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Artifactory null safe (#49)
Browse files Browse the repository at this point in the history
* Artifactory null safe

* Artifactory null safe
  • Loading branch information
nireeshT authored Sep 20, 2021
1 parent e2cc9a8 commit c0e3ebf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<packaging>jar</packaging>
<artifactId>artifactory-artifact-collector</artifactId>
<url>https://github.com/Hygieia/${repository.name}</url>
<version>3.2.4-SNAPSHOT</version>
<version>3.2.5-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,37 @@ protected void collectHybridMode(ArtifactoryCollector collector){
int counter = 0;
Map<ArtifactItem,List<BinaryArtifact>> processing = artifactoryClient.getLatestBinaryArtifacts(collector,getPattern(repo),instanceUrl,repo);
for (ArtifactItem artifactItem: enabledArtifactItems) {
artifactoryClient.normalize(artifactItem);
String rootRepoName = replaceSubRepos(artifactItem.getRepoName(),subRepoMap);
if(Objects.nonNull(rootRepoName)){
artifactItem.setRepoName(rootRepoName);
}
if(processing.keySet().contains(artifactItem)){
LOGGER.info("processing artifact=" + artifactItem.getArtifactName()+", repo="+artifactItem.getRepoName());
List<BinaryArtifact> binaryArtifacts = processing.get(artifactItem);
for (BinaryArtifact newBinaryArtifact: binaryArtifacts) {
newBinaryArtifact.setCollectorItemId(artifactItem.getId());
BinaryArtifact existingBinaryArtifact = binaryArtifactRepository.findTopByCollectorItemIdAndArtifactVersionOrderByTimestampDesc(artifactItem.getId(),
newBinaryArtifact.getArtifactVersion());
if (Objects.nonNull(existingBinaryArtifact)) {
// update existing binary artifact for that version and update timestamp
updateExistingBinaryArtifact(newBinaryArtifact, existingBinaryArtifact);
binaryArtifactRepository.save(newBinaryArtifact);
} else {
// get latest binary artifact for this artifact item with build info
attachLatestBuildInfo(artifactItem, newBinaryArtifact);
// save immediately to avoid creating multiple new BAs for same collectorItemId and artifactVersion
binaryArtifactRepository.save(newBinaryArtifact);
try{
artifactoryClient.normalize(artifactItem);
String rootRepoName = replaceSubRepos(artifactItem.getRepoName(),subRepoMap);
if(Objects.nonNull(rootRepoName)){
artifactItem.setRepoName(rootRepoName);
}
if(processing.keySet().contains(artifactItem)){
LOGGER.info("processing artifact=" + artifactItem.getArtifactName()+", repo="+artifactItem.getRepoName());
List<BinaryArtifact> binaryArtifacts = processing.get(artifactItem);
for (BinaryArtifact newBinaryArtifact: binaryArtifacts) {
newBinaryArtifact.setCollectorItemId(artifactItem.getId());
BinaryArtifact existingBinaryArtifact = binaryArtifactRepository.findTopByCollectorItemIdAndArtifactVersionOrderByTimestampDesc(artifactItem.getId(),
newBinaryArtifact.getArtifactVersion());
if (Objects.nonNull(existingBinaryArtifact)) {
// update existing binary artifact for that version and update timestamp
updateExistingBinaryArtifact(newBinaryArtifact, existingBinaryArtifact);
binaryArtifactRepository.save(newBinaryArtifact);
} else {
// get latest binary artifact for this artifact item with build info
attachLatestBuildInfo(artifactItem, newBinaryArtifact);
// save immediately to avoid creating multiple new BAs for same collectorItemId and artifactVersion
binaryArtifactRepository.save(newBinaryArtifact);
}
}
artifactItem.setLastUpdated(System.currentTimeMillis());
artifactItemRepository.save(artifactItem);
count.getAndIncrement();
counter++;
}
artifactItem.setLastUpdated(System.currentTimeMillis());
artifactItemRepository.save(artifactItem);
count.getAndIncrement();
counter++;
}catch (Exception e) {
LOGGER.error(String.format("collect() : artifactName=%s & artifactRepo=%s, unexpected error occurred while collecting data from instance_url=%s with exception=%s", artifactItem.getArtifactName(), artifactItem.getRepoName(), instanceUrl, e.getClass().getCanonicalName()), e);
}
}
LOGGER.info("updated artifacts for repo=" + repo+", updatedCount="+counter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,10 @@ private String removeLeadAndTrailingSlash(String path){
}

private String removeSlash(String path, String s) {
return path.replaceAll(s, "");
if(StringUtils.isNotEmpty(path)){
return path.replaceAll(s, "");
}
return "";
}

private String truncate(String name){
Expand Down

0 comments on commit c0e3ebf

Please sign in to comment.