Search in sources :

Example 1 with Changes

use of jetbrains.buildServer.server.rest.model.change.Changes in project teamcity-rest by JetBrains.

the class BuildTest method testChanges.

@Test
public void testChanges() throws IOException, ExecutionException, InterruptedException {
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    // vcs.setDAGBased(true); //see jetbrains.buildServer.server.rest.data.ChangeFinderTest.testBranches1() for branches setup  example
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", myBuildType);
    VcsRootInstance root1 = myBuildType.getVcsRootInstanceForParent(parentRoot1);
    assert root1 != null;
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    addChange(root1, 10, changesPolicy);
    addChange(root1, 20, changesPolicy);
    ensureChangesDetected();
    SFinishedBuild build1 = build().in(myBuildType).finish();
    addChange(root1, 30, changesPolicy);
    addChange(root1, 40, changesPolicy);
    ensureChangesDetected();
    SFinishedBuild build2 = build().in(myBuildType).finish();
    addChange(root1, 50, changesPolicy);
    addChange(root1, 60, changesPolicy);
    ensureChangesDetected();
    BuildPromotionEx bp = (BuildPromotionEx) build2.getBuildPromotion();
    // makes sure changes are cached and thus getCount will return not null value
    bp.getDetectedChanges(SelectPrevBuildPolicy.SINCE_LAST_BUILD);
    {
        Build build = new Build(build2, Fields.SHORT, getBeanContext(myFixture));
        assertNull(build.getChanges());
    }
    {
        Build build = new Build(build2, Fields.LONG, getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals("/app/rest/changes?locator=build:(id:" + build2.getBuildId() + ")", changes.getHref());
        // changes are cached
        assertEquals(Integer.valueOf(2), changes.getCount());
        assertEquals(null, changes.getChanges());
        assertNull(changes.getNextHref());
    }
    {
        ((BuildPromotionEx) build2.getBuildPromotion()).resetChangesCache();
        Build build = new Build(build2, Fields.LONG, getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals("/app/rest/changes?locator=build:(id:" + build2.getBuildId() + ")", changes.getHref());
        // changes are cached
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
        assertNull(changes.getNextHref());
    }
    {
        Build build = new Build(build2, new Fields("changes($long)"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(Integer.valueOf(2), changes.getCount());
        assertEquals(2, changes.getChanges().size());
        assertNull(changes.getNextHref());
    }
    {
        Build build = new Build(build2, new Fields("changes($long,$locator(count(1)))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals("/app/rest/changes?locator=build:(id:" + build2.getBuildId() + "),count:1", changes.getHref());
        assertEquals(Integer.valueOf(1), changes.getCount());
        assertEquals(1, changes.getChanges().size());
    }
    {
        setInternalProperty("rest.defaultPageSize", "1");
        Build build = new Build(build2, new Fields("changes($long)"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals("/app/rest/changes?locator=build:(id:" + build2.getBuildId() + ")", changes.getHref());
        // all the changes are present in the node
        assertEquals(Integer.valueOf(2), changes.getCount());
        assertEquals(2, changes.getChanges().size());
        removeInternalProperty("rest.defaultPageSize");
    }
}
Also used : Changes(jetbrains.buildServer.server.rest.model.change.Changes) Build(jetbrains.buildServer.server.rest.model.build.Build) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 2 with Changes

use of jetbrains.buildServer.server.rest.model.change.Changes in project teamcity-rest by JetBrains.

the class Build method getLastChanges.

/**
 * Lists last change(s) included into the build so that this can be used in the build start request. The changes correspond to the revisions used by the build.
 * The set of the changes included can vary in the future TeamCity versions. In TeamCity 8.1 this is the last usual change and also a personal change (for personal build only)
 *
 * @return
 */
@XmlElement(name = "lastChanges")
public Changes getLastChanges() {
    if (!myFields.isIncluded("lastChanges", false, true)) {
        return null;
    }
    return ValueWithDefault.decideDefault(myFields.isIncluded("lastChanges", false), () -> {
        final Changes result = Changes.fromSVcsModificationsSupplier(() -> {
            final List<SVcsModification> modifications = new ArrayList<SVcsModification>();
            final Long lastModificationId = myBuildPromotion.getLastModificationId();
            if (lastModificationId != null && lastModificationId != -1) {
                try {
                    SVcsModification modification = myBeanContext.getSingletonService(VcsModificationHistory.class).findChangeById(lastModificationId);
                    if (modification != null && modification.getRelatedConfigurations().contains(myBuildPromotion.getParentBuildType())) {
                        modifications.add(modification);
                    }
                } catch (AccessDeniedException e) {
                // ignore: the associated modification id probably does not belong to the build configuration (related to TW-35390)
                }
            }
            modifications.addAll(myBuildPromotion.getPersonalChanges());
            return modifications;
        }, null, myFields.getNestedField("lastChanges", Fields.NONE, Fields.LONG), myBeanContext);
        return result.isDefault() ? null : result;
    });
}
Also used : Changes(jetbrains.buildServer.server.rest.model.change.Changes) BuildChanges(jetbrains.buildServer.server.rest.model.change.BuildChanges) SVcsModification(jetbrains.buildServer.vcs.SVcsModification) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) VcsModificationHistory(jetbrains.buildServer.vcs.VcsModificationHistory) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 3 with Changes

use of jetbrains.buildServer.server.rest.model.change.Changes 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)

Example 4 with Changes

use of jetbrains.buildServer.server.rest.model.change.Changes in project teamcity-rest by JetBrains.

the class BuildTest method testChangesOptional.

@Test
public void testChangesOptional() throws IOException, ExecutionException, InterruptedException {
    MockVcsSupport vcs = new MockVcsSupport("vcs");
    myFixture.getVcsManager().registerVcsSupport(vcs);
    SVcsRootEx parentRoot1 = myFixture.addVcsRoot(vcs.getName(), "", myBuildType);
    VcsRootInstance root1 = myBuildType.getVcsRootInstanceForParent(parentRoot1);
    assert root1 != null;
    final BuildFinderTestBase.MockCollectRepositoryChangesPolicy changesPolicy = new BuildFinderTestBase.MockCollectRepositoryChangesPolicy();
    vcs.setCollectChangesPolicy(changesPolicy);
    for (int i = 0; i < 10; i++) {
        addChange(root1, i, changesPolicy);
    }
    ensureChangesDetected();
    SFinishedBuild build1 = build().in(myBuildType).finish();
    ((BuildPromotionEx) build1.getBuildPromotion()).resetChangesCache();
    assertFalse(myChangeFinder.isCheap(build1.getBuildPromotion(), null));
    {
        Build build = new Build(build1, new Fields("changes"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals("/app/rest/changes?locator=build:(id:" + build1.getBuildId() + ")", changes.getHref());
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
    }
    {
        Build build = new Build(build1, new Fields("changes(change($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
    }
    {
        Build build = new Build(build1, new Fields("changes(change($optional),count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
    }
    {
        Build build = new Build(build1, new Fields("changes(count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
    }
    {
        Build build = new Build(build1, new Fields("changes($locator(count:2),count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getCount());
        assertEquals(null, changes.getChanges());
    }
    {
        // no fields requested
        Build build = new Build(build1, new Fields("changes($locator(count:2))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getChanges());
        assertEquals(null, changes.getCount());
    }
    // still not calculated
    assertFalse(myChangeFinder.isCheap(build1.getBuildPromotion(), null));
    {
        Build build = new Build(build1, new Fields("changes($locator(count:2),count)"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getChanges());
        assertEquals(Integer.valueOf(2), changes.getCount());
    }
    assertFalse(myChangeFinder.isCheap(build1.getBuildPromotion(), null));
    assertTrue(myChangeFinder.isCheap(build1.getBuildPromotion(), "count:2"));
    {
        Build build = new Build(build1, new Fields("changes($locator(count:2),count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(Integer.valueOf(2), changes.getCount());
    }
    {
        // less than cached
        Build build = new Build(build1, new Fields("changes($locator(count:1),count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(Integer.valueOf(1), changes.getCount());
    }
    {
        // morethan cached
        Build build = new Build(build1, new Fields("changes($locator(count:3),count($optional))"), getBeanContext(myFixture));
        Changes changes = build.getChanges();
        assertEquals(null, changes.getCount());
    }
    // still not calculated
    assertFalse(myChangeFinder.isCheap(build1.getBuildPromotion(), "count:3"));
    {
        // $optional should not be included when not supported
        Build build = new Build(build1, new Fields("changes($optional)"), getBeanContext(myFixture));
        assertNull(build.getChanges());
    }
}
Also used : Changes(jetbrains.buildServer.server.rest.model.change.Changes) Build(jetbrains.buildServer.server.rest.model.build.Build) BuildFinderTestBase(jetbrains.buildServer.server.rest.data.BuildFinderTestBase) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

Changes (jetbrains.buildServer.server.rest.model.change.Changes)4 XmlElement (javax.xml.bind.annotation.XmlElement)2 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 BuildFinderTestBase (jetbrains.buildServer.server.rest.data.BuildFinderTestBase)2 Build (jetbrains.buildServer.server.rest.model.build.Build)2 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 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