private void processBuild()

in server/src/jetbrains/buildServer/sharedResources/server/SharedResourcesContextProcessor.java [108:157]


  private void processBuild(@NotNull final BuildStartContext context,
                            @NotNull final BuildPromotion currentBuildPromotion,
                            @NotNull final Map<String, Map<String, Resource>> projectTreeResources,
                            @NotNull final Map<String, Map<String, CustomResource>> projectTreeCustomResources) {
    if (currentBuildPromotion.getBuildType() == null || currentBuildPromotion.getProjectId() == null) {
      return;
    }
    final Map<String, Lock> locks = extractLocks(currentBuildPromotion);
    final Map<Lock, String> myTakenValues = initTakenValues(locks.values());
    // get custom resources from our locks
    final Map<String, Resource> projectResources = getResources(currentBuildPromotion.getProjectId(), projectTreeResources);
    // FIXME: disable custom resources processing for composite builds until method of consistent delivery of values to the chain is implemented
    // from UI: user should not be able to add a lock on custom resource in composite build => initTakenValues will not contain any custom resources
    // locks on regular resources will be saved
    if (!currentBuildPromotion.isCompositeBuild()) {
      final Map<String, CustomResource> myCustomResources = matchCustomResources(getCustomResources(currentBuildPromotion.getProjectId(), projectResources, projectTreeCustomResources), locks);
      // decide whether we need to resolve values
      if (!myCustomResources.isEmpty()) {
        for (Map.Entry<String, CustomResource> entry : myCustomResources.entrySet()) {
          if (entry.getValue().isEnabled()) {
            // get value space for current resources
            final List<String> values = new ArrayList<>(entry.getValue().getValues());
            final String name = entry.getKey();
            final Lock currentLock = locks.get(name);
            final String paramName = myLocks.asBuildParameter(currentLock);
            String reservedValue;
            if (LockType.READ.equals(currentLock.getType())) {
              if (currentLock.isAnyValueLock()) { // ANY lock
                reservedValue = (String)((BuildPromotionEx)currentBuildPromotion).getAttribute(getReservedResourceAttributeKey(entry.getValue().getId()));
                if (reservedValue == null) {
                  final String message = "Expected reserved value for resource (" + entry.getValue().getId() + "|" + name
                                         + ") in build promotion " + currentBuildPromotion.getId() + ", got null";
                  LOG.error(message);
                  throw new RuntimeException(message);
                }
              } else { // SPECIFIC lock
                reservedValue = currentLock.getValue();
              }
              myTakenValues.put(currentLock, reservedValue);
            } else { // ALL lock
              reservedValue = StringUtil.join(values, ";");
            }
            context.addSharedParameter(paramName, reservedValue);
          }
        }
      }
    }
    myLocksStorage.store(currentBuildPromotion, myTakenValues);
    myBuildUsedResourcesReport.save((BuildPromotionEx)currentBuildPromotion, projectResources, myTakenValues);
  }