public CheckinParameters()

in src/org/jetbrains/tfsIntegration/checkin/CheckinParameters.java [108:275]


  public CheckinParameters(final CheckinProjectPanel panel, final boolean evaluatePolicies) throws OperationFailedException {
    myPanel = panel;
    final Collection<FilePath> filePaths = new ArrayList<>(panel.getFiles().size());
    for (File file : panel.getFiles()) {
      FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
      if (!TFSVcs.isUnderTFS(filePath, myPanel.getProject())) {
        continue;
      }
      filePaths.add(filePath);
    }

    final TfsExecutionUtil.ResultWithError<Void> result =
      TfsExecutionUtil.executeInBackground("Validating Checkin", panel.getProject(), new TfsExecutionUtil.VoidProcess() {
        @Override
        public void run() throws TfsException, VcsException {
          ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
          if (pi == null) {
            pi = new MockProgressIndicator();
          }
          pi.setText("Loading checkin notes and policy definitions");
          final MultiMap<ServerInfo, String> serverToProjects = MultiMap.createSet();
          final Map<ServerInfo, Collection<FilePath>> serverToFiles = new HashMap<>();
          WorkstationHelper.processByWorkspaces(filePaths, false, panel.getProject(), new WorkstationHelper.VoidProcessDelegate() {
            @Override
            public void executeRequest(final WorkspaceInfo workspace, final List<ItemPath> paths) throws TfsException {
              Collection<FilePath> files = serverToFiles.get(workspace.getServer());
              if (files == null) {
                files = new ArrayList<>();
                serverToFiles.put(workspace.getServer(), files);
              }
              for (ItemPath path : paths) {
                serverToProjects.putValue(workspace.getServer(), VersionControlPath.getPathToProject(path.getServerPath()));
                files.add(path.getLocalPath());
              }
            }
          });

          if (serverToProjects.isEmpty()) {
            throw new OperationFailedException("Team Foundation Server mappings not found.");
          }
          pi.checkCanceled();

          List<ServerInfo> sortedServers = new ArrayList<>(serverToProjects.keySet());
          Collections.sort(sortedServers, (o1, o2) -> o1.getPresentableUri().compareTo(o2.getPresentableUri()));

          Map<ServerInfo, ServerData> data = new LinkedHashMap<>();
          StringBuilder policiesLoadError = new StringBuilder();
          for (ServerInfo server : sortedServers) {
            final Collection<String> teamProjects = serverToProjects.get(server);
            final List<CheckinNoteFieldDefinition> checkinNoteDefinitions =
              server.getVCS().queryCheckinNoteDefinition(teamProjects, myPanel.getProject(), null);
            pi.checkCanceled();
            Map<String, CheckinNoteFieldDefinition> nameToDefinition = new HashMap<>();
            // factorize different team projects definitions by name and sort them by display order field
            for (CheckinNoteFieldDefinition definition : checkinNoteDefinitions) {
              if (!nameToDefinition.containsKey(definition.getName()) || definition.getReq()) {
                nameToDefinition.put(definition.getName(), definition);
              }
            }
            List<CheckinNoteFieldDefinition> sortedDefinitions = new ArrayList<>(nameToDefinition.values());
            Collections.sort(sortedDefinitions, (o1, o2) -> o1.get_do() - o2.get_do());

            List<CheckinNote> checkinNotes = new ArrayList<>(sortedDefinitions.size());
            for (CheckinNoteFieldDefinition checkinNote : sortedDefinitions) {
              checkinNotes.add(new CheckinNote(checkinNote.getName(), checkinNote.getReq()));
            }

            Map<String, TeamProjectData> project2policies = new HashMap<>();
            for (String teamProject : teamProjects) {
              project2policies.put(teamProject, new TeamProjectData());
            }

            try {
              Collection<Annotation> overridesAnnotations = new ArrayList<>();
              for (String teamProjectPath : teamProjects) {
                overridesAnnotations.addAll(
                  server.getVCS().queryAnnotations(TFSConstants.OVERRRIDES_ANNOTATION, teamProjectPath, myPanel.getProject(), null, false));
              }

              boolean teamExplorerFound = TFSConfigurationManager.getInstance().getCheckinPoliciesCompatibility().teamExplorer;
              boolean teampriseFound = TFSConfigurationManager.getInstance().getCheckinPoliciesCompatibility().teamprise;
              for (Annotation annotation : overridesAnnotations) {
                if (annotation.getValue() == null) continue;
                String teamProject = VersionControlPath.getPathToProject(annotation.getItem());

                TfsCheckinPoliciesCompatibility override =
                  TfsCheckinPoliciesCompatibility.fromOverridesAnnotationValue(annotation.getValue());
                project2policies.get(teamProject).myCompatibility = override;
                teamExplorerFound |= override.teamExplorer;
                teampriseFound |= override.teamprise;
              }

              if (teamExplorerFound) {
                Collection<Annotation> annotations = new ArrayList<>();
                for (String teamProjectPath : teamProjects) {
                  annotations.addAll(server.getVCS()
                                       .queryAnnotations(TFSConstants.TFS_CHECKIN_POLICIES_ANNOTATION, teamProjectPath,
                                                         myPanel.getProject(), null, false));
                }

                for (Annotation annotation : annotations) {
                  if (annotation.getValue() == null) continue;
                  String teamProject = VersionControlPath.getPathToProject(annotation.getItem());

                  TeamProjectData teamProjectData = project2policies.get(teamProject);
                  if (teamProjectData.myCompatibility.teamExplorer) {
                    for (PolicyDescriptor descriptor : StatelessPolicyParser.parseDescriptors(annotation.getValue())) {
                      if (descriptor.isEnabled()) {
                        teamProjectData.myPolicies.add(descriptor);
                      }
                    }
                  }
                }
              }

              if (teampriseFound) {
                Collection<Annotation> annotations = new ArrayList<>();
                for (String teamProjectPath : teamProjects) {
                  annotations.addAll(server.getVCS()
                                       .queryAnnotations(TFSConstants.STATEFUL_CHECKIN_POLICIES_ANNOTATION, teamProjectPath,
                                                         myPanel.getProject(), null, false));
                }
                for (Annotation annotation : annotations) {
                  if (annotation.getValue() == null) continue;
                  String teamProject = VersionControlPath.getPathToProject(annotation.getItem());

                  TeamProjectData teamProjectData = project2policies.get(teamProject);
                  if (teamProjectData.myCompatibility.teamprise) {
                    for (PolicyDescriptor descriptor : StatefulPolicyParser.parseDescriptors(annotation.getValue())) {
                      if (descriptor.isEnabled()) {
                        teamProjectData.myPolicies.add(descriptor);
                      }
                    }
                  }
                }
              }
            }
            catch (PolicyParseException e) {
              policiesLoadError.append(e.getMessage());
            }
            catch (JDOMException e) {
              policiesLoadError.append(e.getMessage());
            }
            catch (IOException e) {
              policiesLoadError.append(e.getMessage());
            }
            pi.checkCanceled();

            data.put(server, new ServerData(checkinNotes, new WorkItemsCheckinParameters(), serverToFiles.get(server), project2policies));
          }

          myPoliciesLoadError = policiesLoadError.length() > 0 ? policiesLoadError.toString() : null;
          myData = data;

          if (evaluatePolicies) {
            pi.setText("Evaluating checkin policies");
            evaluatePolicies(pi);
            myPoliciesEvaluated = true;
          }
        }
      });

    if (myData == null) {
      throw new OperationFailedException(result.cancelled ? "Validation cancelled by user" : result.error.getMessage());
    }

    validateNotes();
  }