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");
}
}
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;
});
}
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);
}
}
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());
}
}
Aggregations