Skip to content
Permalink
Browse files
[FIXED JENKINS-18118] Introduced UserAvatarResolver.resolveOrNull to …
…properly produce fallback icon URL.
  • Loading branch information
jglick committed May 28, 2013
1 parent 94a3b43 commit 8549e7b32debae32827cca4cd6e7aa69858140b0
Showing with 18 additions and 6 deletions.
  1. +3 −1 changelog.html
  2. +3 −3 core/src/main/java/hudson/model/View.java
  3. +12 −2 core/src/main/java/hudson/tasks/UserAvatarResolver.java
@@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
User icon in People broken if Jenkins root URL unconfigured.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-18118">issue 18118</a>)
</ul>
</div><!--=TRUNK-END=-->

@@ -792,7 +792,7 @@ public AsynchPeople(View parent) {
UserInfo info = users.get(user);
if (info == null) {
UserInfo userInfo = new UserInfo(user, p, build.getTimestamp());
userInfo.avatar = UserAvatarResolver.resolve(user, iconSize);
userInfo.avatar = UserAvatarResolver.resolveOrNull(user, iconSize);
synchronized (this) {
users.put(user, userInfo);
modified.add(user);
@@ -824,7 +824,7 @@ public AsynchPeople(View parent) {
}
if (!users.containsKey(u)) {
UserInfo userInfo = new UserInfo(u, null, null);
userInfo.avatar = UserAvatarResolver.resolve(u, iconSize);
userInfo.avatar = UserAvatarResolver.resolveOrNull(u, iconSize);
synchronized (this) {
users.put(u, userInfo);
modified.add(u);
@@ -842,7 +842,7 @@ public AsynchPeople(View parent) {
accumulate("id", u.getId()).
accumulate("fullName", u.getFullName()).
accumulate("url", u.getUrl()).
accumulate("avatar", i.avatar).
accumulate("avatar", i.avatar != null ? i.avatar : Stapler.getCurrentRequest().getContextPath() + Functions.getResourcePath() + "/images/" + iconSize + "/user.png").
accumulate("timeSortKey", i.getTimeSortKey()).
accumulate("lastChangeTimeString", i.getLastChangeTimeString());
AbstractProject<?,?> p = i.getProject();
@@ -33,6 +33,7 @@
import hudson.ExtensionPoint;
import hudson.Functions;
import hudson.model.User;
import javax.annotation.CheckForNull;

/**
* Infers avatar image URLs for users
@@ -78,13 +79,22 @@
public abstract String findAvatarFor(User u, int width, int height);

/**
* Resolve an avatar image URL string for the user
* Resolve an avatar image URL string for the user.
* Note that this method must be called from an HTTP request to be reliable; else use {@link #resolveOrNull}.
* @param u user
* @param avatarSize the preferred image size, "[width]x[height]"
* @return a URL string for a user Avatar image.
*/
public static String resolve(User u, String avatarSize) {
String avatar = resolveOrNull(u, avatarSize);
return avatar != null ? avatar : Jenkins.getInstance().getRootUrl() + Functions.getResourcePath() + "/images/" + avatarSize + "/user.png";
}

/**
* Like {@link #resolve} but returns null rather than a fallback URL in case there is no special avatar.
* @since 1.518
*/
public static @CheckForNull String resolveOrNull(User u, String avatarSize) {
Matcher matcher = iconSizeRegex.matcher(avatarSize);
if (matcher.matches() && matcher.groupCount() == 2) {
int width = Integer.parseInt(matcher.group(1));
@@ -97,7 +107,7 @@ public static String resolve(User u, String avatarSize) {
LOGGER.warning(String.format("Could not split up the avatar size (%s) into a width and height.", avatarSize));
}

return Jenkins.getInstance().getRootUrl() + Functions.getResourcePath() + "/images/" + avatarSize + "/user.png";
return null;
}

/**

0 comments on commit 8549e7b

Please sign in to comment.