Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-45434] Adds a caching resizing avatar service
  • Loading branch information
stephenc committed Jul 11, 2017
1 parent 850d9d2 commit 800f171
Show file tree
Hide file tree
Showing 3 changed files with 912 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/jenkins/scm/api/metadata/AvatarMetadataAction.java
Expand Up @@ -33,6 +33,7 @@
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.avatars.AvatarCache;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
Expand Down Expand Up @@ -139,6 +140,23 @@ protected final String avatarIconClassNameImageOf(@CheckForNull String iconClass
return null;
}

/**
* Helper method to resolve an external image, cache it and resize it to the specified size. If the external URL
* cannot be retrieved by Jenkins, then a randomly generated avatar will be generated using the external URL as
* a seed (so that the generated avatar image for any given external URL will be consistent across both Jenkins
* instances and restarts).
*
* @param url the URL of the image to cache.
* @param size the size string, e.g. {@code 16x16}, {@code 24x24}, etc.
* @return the icon image url.
* @throws IllegalStateException if called outside of a request handling thread.
* @since 2.2.0
*/
@NonNull
protected final String cachedResizedImageOf(@NonNull String url, @NonNull String size) {
return AvatarCache.buildUrl(url, size);
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 800f171

Please sign in to comment.