Search in sources :

Example 1 with BuildChangeData

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);
    }
}
Also used : MetadataStorageEx(jetbrains.buildServer.serverSide.metadata.impl.MetadataStorageEx) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) Files(jetbrains.buildServer.server.rest.model.files.Files) VcsModificationHistory(jetbrains.buildServer.vcs.VcsModificationHistory) Agent(jetbrains.buildServer.server.rest.model.agent.Agent) AuthorityHolder(jetbrains.buildServer.serverSide.auth.AuthorityHolder) BuildDependency(jetbrains.buildServer.serverSide.dependency.BuildDependency) PasswordReplacer(jetbrains.buildServer.util.PasswordReplacer) BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) ActionTypesFilter(jetbrains.buildServer.serverSide.impl.audit.filters.ActionTypesFilter) jetbrains.buildServer.server.rest.data(jetbrains.buildServer.server.rest.data) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) BigDecimal(java.math.BigDecimal) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) ActionType(jetbrains.buildServer.serverSide.audit.ActionType) TestOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.TestOccurrenceFinder) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) SArtifactDependency(jetbrains.buildServer.serverSide.artifacts.SArtifactDependency) StringUtil(jetbrains.buildServer.util.StringUtil) LogUtil(jetbrains.buildServer.serverSide.impl.LogUtil) Logger(com.intellij.openapi.diagnostic.Logger) CollectionsUtil(jetbrains.buildServer.util.CollectionsUtil) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) AuditLogAction(jetbrains.buildServer.serverSide.audit.AuditLogAction) CanceledInfo(jetbrains.buildServer.serverSide.userChanges.CanceledInfo) SelectPrevBuildPolicy(jetbrains.buildServer.vcs.SelectPrevBuildPolicy) WaitReason(jetbrains.buildServer.serverSide.buildDistribution.WaitReason) AgentTypeFinder(jetbrains.buildServer.serverSide.agentTypes.AgentTypeFinder) AgentRestrictor(jetbrains.buildServer.AgentRestrictor) ServiceLocator(jetbrains.buildServer.ServiceLocator) BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) UserModel(jetbrains.buildServer.users.UserModel) jetbrains.buildServer.serverSide(jetbrains.buildServer.serverSide) Changes(jetbrains.buildServer.server.rest.model.change.Changes) BuildProblemImpl(jetbrains.buildServer.serverSide.impl.problems.BuildProblemImpl) TagFinder(jetbrains.buildServer.server.rest.data.build.TagFinder) Revisions(jetbrains.buildServer.server.rest.model.change.Revisions) Collectors(java.util.stream.Collectors) ChangesBean(jetbrains.buildServer.controllers.changes.ChangesBean) ProblemOccurrenceFinder(jetbrains.buildServer.server.rest.data.problem.ProblemOccurrenceFinder) Nullable(org.jetbrains.annotations.Nullable) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) BuildAgent(jetbrains.buildServer.BuildAgent) RevisionRule(jetbrains.buildServer.artifacts.RevisionRule) PasswordParametersFilterCore(jetbrains.buildServer.parameters.PasswordParametersFilterCore) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) AgentRestrictorType(jetbrains.buildServer.AgentRestrictorType) Branch(jetbrains.buildServer.serverSide.Branch) BuildChangeData(jetbrains.buildServer.server.rest.data.change.BuildChangeData) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) ChangesPopupUtil(jetbrains.buildServer.controllers.changes.ChangesPopupUtil) java.util(java.util) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) User(jetbrains.buildServer.server.rest.model.user.User) Converter(jetbrains.buildServer.util.Converter) IssueUsages(jetbrains.buildServer.server.rest.model.issue.IssueUsages) Hex(org.apache.commons.codec.binary.Hex) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ParametersProvider(jetbrains.buildServer.parameters.ParametersProvider) jetbrains.buildServer.server.rest.model(jetbrains.buildServer.server.rest.model) Agents(jetbrains.buildServer.server.rest.model.agent.Agents) AgentPool(jetbrains.buildServer.serverSide.agentPools.AgentPool) Element(jetbrains.buildServer.util.browser.Element) PropEntitiesArtifactDep(jetbrains.buildServer.server.rest.model.buildType.PropEntitiesArtifactDep) XmlType(javax.xml.bind.annotation.XmlType) PasswordsSearcher(jetbrains.buildServer.serverSide.parameters.types.PasswordsSearcher) SAgentType(jetbrains.buildServer.serverSide.agentTypes.SAgentType) RevisionRules(jetbrains.buildServer.artifacts.RevisionRules) Revision(jetbrains.buildServer.server.rest.model.change.Revision) ProblemOccurrences(jetbrains.buildServer.server.rest.model.problem.ProblemOccurrences) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) BuildChanges(jetbrains.buildServer.server.rest.model.change.BuildChanges) Properties(jetbrains.buildServer.server.rest.model.Properties) CachingValue(jetbrains.buildServer.server.rest.util.CachingValue) IOException(java.io.IOException) ArtifactDependencyChangesProvider(jetbrains.buildServer.serverSide.impl.changeProviders.ArtifactDependencyChangesProvider) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) DownloadedArtifacts(jetbrains.buildServer.server.rest.model.build.downloadedArtifacts.DownloadedArtifacts) DownloadedArtifactsLoggerImpl(jetbrains.buildServer.serverSide.impl.DownloadedArtifactsLoggerImpl) jetbrains.buildServer.server.rest.request(jetbrains.buildServer.server.rest.request) MapParametersProviderImpl(jetbrains.buildServer.parameters.impl.MapParametersProviderImpl) VcsLabelManager(jetbrains.buildServer.serverSide.vcs.VcsLabelManager) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) Permission(jetbrains.buildServer.serverSide.auth.Permission) BuildMetadataEntry(jetbrains.buildServer.serverSide.metadata.BuildMetadataEntry) SUser(jetbrains.buildServer.users.SUser) XmlElement(javax.xml.bind.annotation.XmlElement) DownloadedArtifactsLoggerImpl(jetbrains.buildServer.serverSide.impl.DownloadedArtifactsLoggerImpl) BuildChangeData(jetbrains.buildServer.server.rest.data.change.BuildChangeData) SVcsModificationOrChangeDescriptor(jetbrains.buildServer.server.rest.data.change.SVcsModificationOrChangeDescriptor) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) InvalidStateException(jetbrains.buildServer.server.rest.errors.InvalidStateException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) IOException(java.io.IOException) ArtifactDependencyChangesProvider(jetbrains.buildServer.serverSide.impl.changeProviders.ArtifactDependencyChangesProvider) OperationException(jetbrains.buildServer.server.rest.errors.OperationException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Logger (com.intellij.openapi.diagnostic.Logger)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 java.util (java.util)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 XmlAttribute (javax.xml.bind.annotation.XmlAttribute)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 XmlType (javax.xml.bind.annotation.XmlType)1 AgentRestrictor (jetbrains.buildServer.AgentRestrictor)1 AgentRestrictorType (jetbrains.buildServer.AgentRestrictorType)1 BuildAgent (jetbrains.buildServer.BuildAgent)1 ServiceLocator (jetbrains.buildServer.ServiceLocator)1 RevisionRule (jetbrains.buildServer.artifacts.RevisionRule)1 RevisionRules (jetbrains.buildServer.artifacts.RevisionRules)1 ChangesBean (jetbrains.buildServer.controllers.changes.ChangesBean)1 ChangesPopupUtil (jetbrains.buildServer.controllers.changes.ChangesPopupUtil)1 ParametersProvider (jetbrains.buildServer.parameters.ParametersProvider)1