use of org.jfrog.build.api.dependency.pattern.BuildDependencyPattern in project build-info by JFrogDev.
the class BuildDependenciesHelper method toArtifactsRequests.
private List<BuildPatternArtifactsRequest> toArtifactsRequests(Map<String, Map<String, List<BuildDependencyPattern>>> dependencyPatterns) {
List<BuildPatternArtifactsRequest> artifactsRequests = Lists.newLinkedList();
for (String buildName : dependencyPatterns.keySet()) {
Map<String, List<BuildDependencyPattern>> buildNumbers = dependencyPatterns.get(buildName);
for (String buildNumber : buildNumbers.keySet()) {
List<BuildDependencyPattern> buildDependencyPatterns = buildNumbers.get(buildNumber);
BuildPatternArtifactsRequestBuilder builder = new BuildPatternArtifactsRequestBuilder().buildName(buildName).buildNumber(buildNumber);
for (BuildDependencyPattern buildDependencyPattern : buildDependencyPatterns) {
builder.pattern(buildDependencyPattern.getPattern());
}
artifactsRequests.add(builder.build());
}
}
return artifactsRequests;
}
use of org.jfrog.build.api.dependency.pattern.BuildDependencyPattern in project build-info by JFrogDev.
the class BuildDependenciesHelper method collectArtifactsToDownload.
private Set<DownloadableArtifact> collectArtifactsToDownload(Map<String, Map<String, List<BuildDependencyPattern>>> dependencyPatterns, List<BuildPatternArtifactsRequest> artifactsRequests, List<BuildPatternArtifacts> artifactsResponses, Set<BuildDependency> buildDependencies) {
Set<DownloadableArtifact> downloadableArtifacts = Sets.newHashSet();
verifySameSize(artifactsRequests, artifactsResponses);
for (int i = 0; i < artifactsRequests.size(); i++) {
BuildPatternArtifacts artifacts = artifactsResponses.get(i);
if (artifacts == null) {
// Pattern didn't match any results: wrong build name or build number.
continue;
}
List<BuildDependencyPattern> buildDependencyPatterns = dependencyPatterns.get(artifacts.getBuildName()).get(artifactsRequests.get(i).getBuildNumber());
for (int j = 0; j < buildDependencyPatterns.size(); j++) {
BuildDependencyPattern buildDependencyPattern = buildDependencyPatterns.get(j);
if (!buildDependencyPattern.getBuildName().equals(artifacts.getBuildName())) {
throw new IllegalArgumentException(String.format("Build names don't match: [%s] != [%s]", buildDependencyPattern.getBuildName(), artifacts.getBuildName()));
}
final String message = String.format("Dependency on build [%s], number [%s]", buildDependencyPattern.getBuildName(), buildDependencyPattern.getBuildNumber());
/**
* Build number response is null for unresolved dependencies (wrong build name or build number).
*/
if (artifacts.getBuildNumber() == null) {
log.info(message + " - no results found, check correctness of dependency build name and build number.");
} else {
PatternResult patternResult = artifacts.getPatternResults().get(j);
List<PatternArtifact> patternArtifacts = patternResult.getPatternArtifacts();
log.info(message + String.format(", pattern [%s] - [%s] result%s found.", buildDependencyPattern.getPattern(), patternArtifacts.size(), (patternArtifacts.size() == 1 ? "" : "s")));
for (PatternArtifact patternArtifact : patternArtifacts) {
// "libs-release-local/com/goldin/plugins/gradle/0.1.1/gradle-0.1.1.jar"
final String uri = patternArtifact.getUri();
final int indexOfFirstSlash = uri.indexOf('/');
assert (indexOfFirstSlash > 0) : String.format("Failed to locate '/' in [%s]", uri);
final String repoUrl = patternArtifact.getArtifactoryUrl() + '/' + uri.substring(0, indexOfFirstSlash);
final String filePath = uri.substring(indexOfFirstSlash + 1);
downloadableArtifacts.add(new DownloadableArtifact(repoUrl, buildDependencyPattern.getTargetDirectory(), filePath, buildDependencyPattern.getMatrixParams(), buildDependencyPattern.getPattern(), buildDependencyPattern.getPatternType()));
}
if (!patternArtifacts.isEmpty()) {
BuildDependency buildDependency = new BuildDependencyBuilder().name(artifacts.getBuildName()).number(artifacts.getBuildNumber()).url(artifacts.getUrl()).started(artifacts.getStarted()).build();
buildDependencies.add(buildDependency);
}
}
}
}
return downloadableArtifacts;
}
use of org.jfrog.build.api.dependency.pattern.BuildDependencyPattern in project build-info by JFrogDev.
the class BuildDependenciesHelper method getBuildDependencies.
private Map<String, Map<String, List<BuildDependencyPattern>>> getBuildDependencies(List<String> patternLines) {
Map<String, Map<String, List<BuildDependencyPattern>>> buildsMap = Maps.newHashMap();
for (String patternLine : patternLines) {
DependencyPattern dependencyPattern = PatternFactory.create(patternLine);
if (dependencyPattern instanceof BuildDependencyPattern) {
BuildDependencyPattern buildDependencyPattern = (BuildDependencyPattern) dependencyPattern;
String buildName = buildDependencyPattern.getBuildName();
Map<String, List<BuildDependencyPattern>> numbersMap = buildsMap.get(buildName);
if (numbersMap == null) {
buildsMap.put(buildName, Maps.<String, List<BuildDependencyPattern>>newHashMap());
numbersMap = buildsMap.get(buildName);
}
String buildNumber = buildDependencyPattern.getBuildNumber();
List<BuildDependencyPattern> dependencyPatternList = numbersMap.get(buildNumber);
if (dependencyPatternList == null) {
numbersMap.put(buildNumber, Lists.<BuildDependencyPattern>newLinkedList());
dependencyPatternList = numbersMap.get(buildNumber);
}
dependencyPatternList.add(buildDependencyPattern);
}
}
return buildsMap;
}
Aggregations