in server/src/jetbrains/buildServer/sharedResources/server/runtime/TakenLocksImpl.java [55:92]
public Map<Resource, TakenLock> collectTakenLocks(@NotNull final Collection<RunningBuildEx> runningBuilds,
@NotNull final Collection<QueuedBuildInfo> queuedBuilds) {
Set<BuildPromotionEx> buildPromotions = new HashSet<>();
runningBuilds.forEach(rb -> buildPromotions.add(rb.getBuildPromotion()));
queuedBuilds.forEach(qb -> buildPromotions.add((BuildPromotionEx)qb.getBuildPromotionInfo()));
final Map<Resource, TakenLock> result = new HashMap<>();
CachingProjectResourcesMap projectResourcesMap = new CachingProjectResourcesMap(myResources);
for (BuildPromotionEx bpEx : buildPromotions) {
final Collection<SharedResourcesFeature> features = myFeatures.searchForFeatures(bpEx);
if (features.isEmpty()) continue;
// at this point we have features
Map<String, Lock> locks;
if (myLocksStorage.locksStored(bpEx)) { // lock values are already resolved
locks = myLocksStorage.load(bpEx);
} else {
locks = myLocks.fromBuildFeaturesAsMap(features); // in the future: <String, Set<Lock>>
}
if (locks.isEmpty()) continue;
final SBuildType buildType = bpEx.getBuildType();
if (buildType != null) {
// get resources defined in project tree, respecting inheritance
final Map<String, Resource> resources = projectResourcesMap.getResourcesMap(buildType.getProject());
// resolve locks against resources defined in project tree
locks.forEach((name, lock) -> {
// collection, promotion, resource, lock
final Resource resource = resources.get(name);
if (resource != null) {
updateTakenLocks(resource, lock, bpEx, result);
}
});
}
}
return result;
}