Skip to content

Commit

Permalink
[FIXED JENKINS-6079] check to see if the user exists before attemptin…
Browse files Browse the repository at this point in the history
…g to get their information
  • Loading branch information
Rob Petti committed Jun 17, 2011
1 parent 4b678fb commit 4ee1ee3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/tek42/perforce/parse/Users.java
Expand Up @@ -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");
}
}
11 changes: 7 additions & 4 deletions src/main/java/hudson/plugins/perforce/PerforceMailResolver.java
Expand Up @@ -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);
Expand Down

0 comments on commit 4ee1ee3

Please sign in to comment.