Skip to content
Permalink
Browse files

[FIXED JENKINS-6079] check to see if the user exists before attemptin…

…g to get their information
  • Loading branch information...
Rob Petti
Rob Petti committed Jun 17, 2011
1 parent 4b678fb commit 4ee1ee3baaeaaaee7bc0a1f5deaa345c614ffc9b
@@ -49,7 +49,16 @@ public Users(Depot depot) {
*/
public User getUser(String name) throws Exception {
UserBuilder builder = new UserBuilder();

//check if the user exists first.
if(!exists(name)) return null;

User user = builder.build(getPerforceResponse(builder.getBuildCmd(getP4Exe(), name)));
return user;
}

private boolean exists(String name) throws Exception {
StringBuilder response = getPerforceResponse(new String[]{getP4Exe(), "users", name});
return !response.toString().contains("no such user");
}
}
@@ -62,14 +62,17 @@ public String findMailAddressFor(User u) {
try {
LOGGER.finer("Trying to get email address from perforce for " + perforceId);
pu = pscm.getDepot(launcher, workspace, p).getUsers().getUser(perforceId);
if (pu != null && pu.getEmail() != null && !pu.getEmail().equals("")) {
LOGGER.fine("Got email (" + pu.getEmail() + ") from perforce for " + perforceId);
return pu.getEmail();
} else {
//operation succeeded, but no email address was found for this user
return null;
}
} catch (Exception e) {
LOGGER.fine("Could not get email address from Perforce: " + e.getMessage());
e.printStackTrace(listener.getLogger());
}
if (pu != null && pu.getEmail() != null && !pu.getEmail().equals("")) {
LOGGER.fine("Got email (" + pu.getEmail() + ") from perforce for " + perforceId);
return pu.getEmail();
}
try {
//gradually increase sleep time
Thread.sleep(tries*300);

0 comments on commit 4ee1ee3

Please sign in to comment.
You can’t perform that action at this time.