use of jetbrains.buildServer.server.rest.data.change.BuildChangeData in project teamcity-rest by JetBrains.
the class Build method getArtifactDependencyChanges.
@NotNull
private static List<BuildChangeData> getArtifactDependencyChanges(@NotNull final BuildPromotion build, @NotNull final ServiceLocator serviceLocator) {
// see also jetbrains.buildServer.server.rest.data.ChangeFinder.getBuildChanges
ArtifactDependencyChangesProvider changesProvider = new ArtifactDependencyChangesProvider(build, ChangeFinder.getBuildChangesPolicy(), serviceLocator.getSingletonService(BuildsManager.class), serviceLocator.getSingletonService(DownloadedArtifactsLoggerImpl.class));
List<ChangeDescriptor> detectedChanges = changesProvider.getDetectedChanges();
if (detectedChanges.isEmpty()) {
return Collections.emptyList();
}
if (detectedChanges.size() > 1) {
throw new OperationException("Unexpected state: more than one (" + detectedChanges.size() + ") artifact changes found");
}
ChangeDescriptor changeDescriptor = detectedChanges.get(0);
if (!ChangeDescriptorConstants.ARTIFACT_DEPENDENCY_CHANGE.equals(changeDescriptor.getType())) {
throw new OperationException("Unexpected state: unknown type of artifact dependency change: '" + changeDescriptor.getType() + "'");
}
try {
Object o = changeDescriptor.getAssociatedData().get(ArtifactDependencyChangesProvider.CHANGED_DEPENDENCIES_ATTR);
// Actually result is List<ArtifactDependencyChangesProvider.ArtifactsChangeDescriptor>
if (o == null) {
return Collections.emptyList();
} else {
// noinspection unchecked
return ((List<ChangeDescriptor>) o).stream().map(descr -> {
Map<String, Object> associatedData = descr.getAssociatedData();
SBuild prevBuild = (SBuild) associatedData.get(ArtifactDependencyChangesProvider.OLD_BUILD_ATTR);
SBuild nextBuild = (SBuild) associatedData.get(ArtifactDependencyChangesProvider.NEW_BUILD_ATTR);
if (prevBuild == null && nextBuild == null)
return null;
return new BuildChangeData(Util.resolveNull(prevBuild, (b) -> b.getBuildPromotion()), Util.resolveNull(nextBuild, (b) -> b.getBuildPromotion()));
}).filter(Objects::nonNull).collect(Collectors.toList());
}
} catch (Exception e) {
throw new OperationException("Unexpected state while getting artifact dependency details: " + e.toString(), e);
}
}
Aggregations