in src/org/jetbrains/tfsIntegration/ui/ManageWorkspacesForm.java [543:645]
private void configureCheckinPolicies() {
try {
CheckinPoliciesManager.getInstalledPolicies();
}
catch (DuplicatePolicyIdException e) {
final String message = MessageFormat
.format("Several checkin policies with the same id found: ''{0}''.\nPlease review your extensions.", e.getDuplicateId());
Messages.showErrorDialog(myProject, message, "Edit Checkin Policies");
return;
}
@SuppressWarnings({"ConstantConditions"}) @NotNull final ServerInfo server = getSelectedServer();
final TfsExecutionUtil.Process<Map<String, ProjectEntry>> process = new TfsExecutionUtil.Process<Map<String, ProjectEntry>>() {
@Override
public Map<String, ProjectEntry> run() throws TfsException, VcsException {
Map<String, ProjectEntry> entries = new HashMap<>();
final List<Item> projectItems = server.getVCS().getChildItems(VersionControlPath.ROOT_FOLDER, true, myContentPane, null);
if (projectItems.isEmpty()) {
throw new OperationFailedException("No team project found");
}
for (Item projectItem : projectItems) {
ProjectEntry entry = new ProjectEntry();
// load policies
final Collection<Annotation> policiesAnnotations = server.getVCS()
.queryAnnotations(TFSConstants.STATEFUL_CHECKIN_POLICIES_ANNOTATION, projectItem.getItem(), myContentPane, null, true);
if (!policiesAnnotations.isEmpty()) {
try {
entry.descriptors = StatefulPolicyParser.parseDescriptors(policiesAnnotations.iterator().next().getValue());
}
catch (PolicyParseException ex) {
String message = MessageFormat.format("Cannot load checkin policies definitions:\n{0}", ex.getMessage());
throw new OperationFailedException(message);
}
}
// load overrides
final Collection<Annotation> overridesAnnotations =
server.getVCS()
.queryAnnotations(TFSConstants.OVERRRIDES_ANNOTATION, projectItem.getItem(), myContentPane, null, true);
if (!overridesAnnotations.isEmpty()) {
try {
entry.policiesCompatibilityOverride =
TfsCheckinPoliciesCompatibility.fromOverridesAnnotationValue(overridesAnnotations.iterator().next().getValue());
}
catch (IOException ex) {
String message = MessageFormat.format("Cannot load checkin policies overrides:\n{0}", ex.getMessage());
throw new OperationFailedException(message);
}
catch (JDOMException ex) {
String message = MessageFormat.format("Cannot load checkin policies overrides:\n{0}", ex.getMessage());
throw new OperationFailedException(message);
}
}
entries.put(projectItem.getItem(), entry);
}
return entries;
}
};
final TfsExecutionUtil.ResultWithError<Map<String, ProjectEntry>> loadResult =
TfsExecutionUtil.executeInBackground("Loading Checkin Policies", myProject, process);
if (loadResult.cancelled || loadResult.showDialogIfError("Configure Checkin Policies")) {
return;
}
final Map<String, ProjectEntry> projectToDescriptors = loadResult.result;
final CheckInPoliciesDialog d = new CheckInPoliciesDialog(myProject, getSelectedServer(), projectToDescriptors);
if (d.showAndGet()) {
final Map<String, ProjectEntry> modifications = d.getModifications();
if (!modifications.isEmpty()) {
final TfsExecutionUtil.ResultWithError<Void> saveResult =
TfsExecutionUtil.executeInBackground("Saving Checkin Policies", myProject, new TfsExecutionUtil.VoidProcess() {
@Override
public void run() throws TfsException, VcsException {
for (Map.Entry<String, ProjectEntry> i : modifications.entrySet()) {
// remove annotations
server.getVCS().deleteAnnotation(i.getKey(), TFSConstants.STATEFUL_CHECKIN_POLICIES_ANNOTATION, myContentPane, null);
server.getVCS().deleteAnnotation(i.getKey(), TFSConstants.OVERRRIDES_ANNOTATION, myContentPane, null);
// write checkin policies annotation
ProjectEntry entry = i.getValue();
if (!entry.descriptors.isEmpty()) {
String annotationValue = StatefulPolicyParser.saveDescriptors(entry.descriptors);
server.getVCS()
.createAnnotation(i.getKey(), TFSConstants.STATEFUL_CHECKIN_POLICIES_ANNOTATION, annotationValue, myContentPane, null);
}
// write overrides annotation
if (entry.policiesCompatibilityOverride != null) {
server.getVCS().createAnnotation(i.getKey(), TFSConstants.OVERRRIDES_ANNOTATION,
entry.policiesCompatibilityOverride.toOverridesAnnotationValue(), myContentPane, null);
}
}
}
});
saveResult.showDialogIfError("Save Checkin Policies");
}
}
}