if (!(p instanceof TopLevelItem)) continue;
if (p.isDisabled()) continue;
if (p.getScm() instanceof PerforceSCM) {
LOGGER.finer("Checking " + p.getName() + "'s Perforce SCM for " + perforceId + "'s address.");
PerforceSCM pscm = (PerforceSCM) p.getScm();
TaskListener listener = new StreamTaskListener(System.out);
Node node = p.getLastBuiltOn();
// If the node is offline, skip the project.
// The node needs to be online for us to execute commands.
if (node == null) {
LOGGER.finer("Build doesn't seem to have been run before. Cannot resolve email address using this project.");
continue;
}
if (node.getChannel() == null) {
LOGGER.finer("Node " + node.getDisplayName() + " is not up, cannot resolve email address using this project.");
continue;
}
// TODO: replace this with p.getLastBuild().getWorkspace()
// which is the way it should be, but doesn't work with this version of hudson.
for (int tries = 0; tries < 5; tries++) {
FilePath workspace = p.getLastBuiltOn().getRootPath();
Launcher launcher = p.getLastBuiltOn().createLauncher(listener);
com.tek42.perforce.model.User pu = null;
try {
LOGGER.finer("Trying to get email address from perforce for " + perforceId);
pu = pscm.getDepot(launcher, workspace, p, null, node).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());
}
try {
//gradually increase sleep time
Thread.sleep(tries);
} catch (InterruptedException e){