in plugin/src/com/microsoft/alm/plugin/operations/ServerContextLookupOperation.java [57:134]
public void doWork(final Inputs inputs) {
onLookupStarted();
try {
final boolean throwOnError = contextList.size() == 1;
final List<Throwable> operationExceptions = new CopyOnWriteArrayList<Throwable>();
final List<Future> tasks = new ArrayList<Future>();
for (final ServerContext context : contextList) {
// submit each account as a separate piece of work to the executor
tasks.add(OperationExecutor.getInstance().submitOperationTask(new Runnable() {
@Override
public void run() {
if (isCancelled()) {
return;
}
try {
if (context.getType() == ServerContext.Type.TFS) {
doSoapCollectionLookup(context);
} else { // VSO_DEPLOYMENT || VSO
doRestCollectionLookup(context);
}
} catch (final Throwable t) {
boolean shouldReportError = true;
logger.warn("doWork: Unable to do lookup on context: " + context.getUri().toString());
logger.warn("doWork: Exception", t);
if (AuthHelper.isNotAuthorizedError(t)) {
final ServerContext newContext
= ServerContextManager.getInstance().updateAuthenticationInfo(context.getUri().toString());
// try again with updated authentication info
try {
if (context.getType() == ServerContext.Type.TFS) {
doSoapCollectionLookup(newContext);
} else { // VSO_DEPLOYMENT || VSO
doRestCollectionLookup(newContext);
}
// auth issue has been handled properly, no need to report this error anymore
shouldReportError = false;
} catch (final Throwable tAgain) {
logger.warn("Failed to lookup repositories even after re-authentication.", tAgain);
}
}
if (shouldReportError) {
operationExceptions.add(t);
// If there's only one context we need to bubble the exception out
// But if there's more than one let's just continue
if (throwOnError) {
// check if error is due to the server URI not being found after a valid authentication
// this is an indication that the server URI contains more than just the base URI
if (t instanceof VssResourceNotFoundException) {
logger.warn(String.format("User authenticated but 404 on server so URI (%s) is malformed", context.getServerUri().toString()));
terminate(new TeamServicesException(TeamServicesException.KEY_TFS_MALFORMED_SERVER_URI, t));
} else {
terminate(t);
}
}
}
}
}
}));
}
// wait for all tasks to complete
OperationExecutor.getInstance().wait(tasks);
if (operationExceptions.size() > 0) {
terminate(new TeamServicesException(TeamServicesException.KEY_OPERATION_ERRORS));
}
onLookupCompleted();
} catch (Throwable ex) {
logger.warn("ServerContextLookupOperation failed with an exception", ex);
terminate(ex);
}
}