summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2015-06-15 10:27:14 -0600
committerJames Moger <james.moger@gitblit.com>2015-06-15 10:27:14 -0600
commit35a925961d5df5cbdf5ddb7df80b616064b3e0e9 (patch)
tree9e0366b3cdc21d2a5e139c00bc7e4bd42dbeabe5
parent8cff8e7f58661529801f987e745d7876d56ca5ff (diff)
parentf790d5cfe645f1e2075ab7c053517631be4458c7 (diff)
downloadgitblit-35a925961d5df5cbdf5ddb7df80b616064b3e0e9.tar.gz
gitblit-35a925961d5df5cbdf5ddb7df80b616064b3e0e9.zip
Merged #258 "Create an avatar provider that defaults to Gravatar"
-rw-r--r--src/main/distrib/data/defaults.properties5
-rw-r--r--src/main/java/com/gitblit/AvatarGenerator.java22
-rw-r--r--src/main/java/com/gitblit/GravatarGenerator.java34
-rw-r--r--src/main/java/com/gitblit/guice/AvatarGeneratorProvider.java71
-rw-r--r--src/main/java/com/gitblit/guice/WebModule.java5
-rw-r--r--src/main/java/com/gitblit/utils/ActivityUtils.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/CommitPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/ForksPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RootPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/TagPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/TicketPage.java12
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ActivityPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/AvatarImage.html (renamed from src/main/java/com/gitblit/wicket/panels/GravatarImage.html)0
-rw-r--r--src/main/java/com/gitblit/wicket/panels/AvatarImage.java (renamed from src/main/java/com/gitblit/wicket/panels/GravatarImage.java)23
-rw-r--r--src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/DigestsPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/ReflogPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/TicketListPanel.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java2
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java3
-rw-r--r--src/test/java/com/gitblit/tests/GravatarTest.java74
23 files changed, 247 insertions, 40 deletions
diff --git a/src/main/distrib/data/defaults.properties b/src/main/distrib/data/defaults.properties
index ae519a10..cc42d907 100644
--- a/src/main/distrib/data/defaults.properties
+++ b/src/main/distrib/data/defaults.properties
@@ -975,6 +975,11 @@ web.useResponsiveLayout = true
# SINCE 0.8.0
web.allowGravatar = true
+# Define which class will generate the avatar URL.
+#
+# SINCE 1.7.0
+web.avatarClass = com.gitblit.GravatarGenerator
+
# Allow dynamic zip downloads.
#
# SINCE 0.5.0
diff --git a/src/main/java/com/gitblit/AvatarGenerator.java b/src/main/java/com/gitblit/AvatarGenerator.java
new file mode 100644
index 00000000..0415f925
--- /dev/null
+++ b/src/main/java/com/gitblit/AvatarGenerator.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2015 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+public interface AvatarGenerator {
+
+ String getURL(String username, String emailaddress, boolean identicon, int width);
+
+}
diff --git a/src/main/java/com/gitblit/GravatarGenerator.java b/src/main/java/com/gitblit/GravatarGenerator.java
new file mode 100644
index 00000000..1ba02e55
--- /dev/null
+++ b/src/main/java/com/gitblit/GravatarGenerator.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+import com.gitblit.utils.ActivityUtils;
+import com.google.inject.Singleton;
+
+@Singleton
+public class GravatarGenerator implements AvatarGenerator {
+
+ @Override
+ public String getURL(String username, String emailaddress, boolean identicon, int width) {
+ String email = emailaddress == null ? username : emailaddress;
+ if (identicon) {
+ return ActivityUtils.getGravatarIdenticonUrl(email, width);
+ } else {
+ return ActivityUtils.getGravatarThumbnailUrl(email, width);
+ }
+ }
+
+}
diff --git a/src/main/java/com/gitblit/guice/AvatarGeneratorProvider.java b/src/main/java/com/gitblit/guice/AvatarGeneratorProvider.java
new file mode 100644
index 00000000..a18e2996
--- /dev/null
+++ b/src/main/java/com/gitblit/guice/AvatarGeneratorProvider.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2015 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.guice;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.gitblit.AvatarGenerator;
+import com.gitblit.GravatarGenerator;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.utils.StringUtils;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+/**
+ * Provides a lazily-instantiated AvatarGenerator configured from IStoredSettings.
+ *
+ * @author James Moger
+ *
+ */
+@Singleton
+public class AvatarGeneratorProvider implements Provider<AvatarGenerator> {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private final IRuntimeManager runtimeManager;
+
+ private volatile AvatarGenerator avatarGenerator;
+
+ @Inject
+ public AvatarGeneratorProvider(IRuntimeManager runtimeManager) {
+ this.runtimeManager = runtimeManager;
+ }
+
+ @Override
+ public synchronized AvatarGenerator get() {
+ if (avatarGenerator != null) {
+ return avatarGenerator;
+ }
+
+ IStoredSettings settings = runtimeManager.getSettings();
+ String clazz = settings.getString(Keys.web.avatarClass, GravatarGenerator.class.getName());
+ if (StringUtils.isEmpty(clazz)) {
+ clazz = GravatarGenerator.class.getName();
+ }
+ try {
+ Class<? extends AvatarGenerator> generatorClass = (Class<? extends AvatarGenerator>) Class.forName(clazz);
+ avatarGenerator = runtimeManager.getInjector().getInstance(generatorClass);
+ } catch (Exception e) {
+ logger.error("failed to create avatar generator", e);
+ avatarGenerator = new GravatarGenerator();
+ }
+ return avatarGenerator;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/guice/WebModule.java b/src/main/java/com/gitblit/guice/WebModule.java
index c6172c3d..a4062703 100644
--- a/src/main/java/com/gitblit/guice/WebModule.java
+++ b/src/main/java/com/gitblit/guice/WebModule.java
@@ -18,6 +18,7 @@ package com.gitblit.guice;
import java.util.HashMap;
import java.util.Map;
+import com.gitblit.AvatarGenerator;
import com.gitblit.Constants;
import com.gitblit.servlet.AccessDeniedServlet;
import com.gitblit.servlet.BranchGraphServlet;
@@ -56,6 +57,10 @@ public class WebModule extends ServletModule {
@Override
protected void configureServlets() {
+
+ // bind web component providers
+ bind(AvatarGenerator.class).toProvider(AvatarGeneratorProvider.class);
+
// servlets
serve(fuzzy(Constants.R_PATH), fuzzy(Constants.GIT_PATH)).with(GitServlet.class);
serve(fuzzy(Constants.RAW_PATH)).with(RawServlet.class);
diff --git a/src/main/java/com/gitblit/utils/ActivityUtils.java b/src/main/java/com/gitblit/utils/ActivityUtils.java
index ba5599a1..ab1dad96 100644
--- a/src/main/java/com/gitblit/utils/ActivityUtils.java
+++ b/src/main/java/com/gitblit/utils/ActivityUtils.java
@@ -169,7 +169,7 @@ public class ActivityUtils {
if (width <= 0) {
width = 50;
}
- String emailHash = StringUtils.getMD5(email);
+ String emailHash = StringUtils.getMD5(email.toLowerCase());
String url = MessageFormat.format(
"https://www.gravatar.com/avatar/{0}?s={1,number,0}&d=identicon", emailHash, width);
return url;
@@ -188,7 +188,7 @@ public class ActivityUtils {
if (width <= 0) {
width = 50;
}
- String emailHash = StringUtils.getMD5(email);
+ String emailHash = StringUtils.getMD5(email.toLowerCase());
String url = MessageFormat.format(
"https://www.gravatar.com/avatar/{0}?s={1,number,0}&d=mm", emailHash, width);
return url;
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
index 3754f3ef..b56d721c 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitDiffPage.java
@@ -47,7 +47,7 @@ import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -116,7 +116,7 @@ public class CommitDiffPage extends RepositoryPage {
item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
Constants.SearchType.AUTHOR));
- item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
+ item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
diff --git a/src/main/java/com/gitblit/wicket/pages/CommitPage.java b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
index 072bb200..0a1a68d4 100644
--- a/src/main/java/com/gitblit/wicket/pages/CommitPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/CommitPage.java
@@ -44,7 +44,7 @@ import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.CompressedDownloadsPanel;
import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -133,7 +133,7 @@ public class CommitPage extends RepositoryPage {
item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
Constants.SearchType.AUTHOR));
- item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
+ item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
diff --git a/src/main/java/com/gitblit/wicket/pages/ForksPage.java b/src/main/java/com/gitblit/wicket/pages/ForksPage.java
index 9fd7f4db..93fc9faf 100644
--- a/src/main/java/com/gitblit/wicket/pages/ForksPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/ForksPage.java
@@ -34,7 +34,7 @@ import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
public class ForksPage extends RepositoryPage {
@@ -63,7 +63,7 @@ public class ForksPage extends RepositoryPage {
user = new UserModel(repository.projectPath.substring(1));
}
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);
- item.add(new GravatarImage("anAvatar", ident, 20));
+ item.add(new AvatarImage("anAvatar", ident, 20));
if (pageRepository.equals(repository)) {
// do not link to self
item.add(new Label("aProject", user.getDisplayName()));
diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java
index 37e98702..6d7ebd85 100644
--- a/src/main/java/com/gitblit/wicket/pages/RootPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java
@@ -73,7 +73,7 @@ import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.SessionlessForm;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.NavigationPanel;
@@ -612,7 +612,7 @@ public abstract class RootPage extends BasePage {
boolean standardLogin = authenticationType.isStandard();
if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
- add(new GravatarImage("username", user, "navbarGravatar", 20, false));
+ add(new AvatarImage("username", user, "navbarGravatar", 20, false));
} else {
add(new Label("username", user.getDisplayName()));
}
diff --git a/src/main/java/com/gitblit/wicket/pages/TagPage.java b/src/main/java/com/gitblit/wicket/pages/TagPage.java
index 9eed2797..ffeea6f2 100644
--- a/src/main/java/com/gitblit/wicket/pages/TagPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/TagPage.java
@@ -31,7 +31,7 @@ import com.gitblit.utils.JGitUtils;
import com.gitblit.wicket.CacheControl;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -77,7 +77,7 @@ public class TagPage extends RepositoryPage {
linkClass = CommitPage.class;
break;
}
- add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));
+ add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));
add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
add(new Label("tagId", tagRef.getObjectId().getName()));
diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java
index 254d3c9b..1aa89540 100644
--- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java
@@ -91,7 +91,7 @@ import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt;
import com.gitblit.wicket.panels.CommentPanel;
import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.IconAjaxLink;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.ShockWaveComponent;
@@ -312,7 +312,7 @@ public class TicketPage extends RepositoryPage {
if (user == null) {
user = new UserModel(username);
}
- item.add(new GravatarImage("participant", user.getDisplayName(),
+ item.add(new AvatarImage("participant", user.getDisplayName(),
user.emailAddress, null, 25, true));
}
};
@@ -736,7 +736,7 @@ public class TicketPage extends RepositoryPage {
} else {
// permit user to comment
Fragment newComment = new Fragment("newComment", "newCommentFragment", this);
- GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,
+ AvatarImage img = new AvatarImage("newCommentAvatar", user.username, user.emailAddress,
"gravatar-round", avatarWidth, true);
newComment.add(img);
CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);
@@ -816,7 +816,7 @@ public class TicketPage extends RepositoryPage {
public void populateItem(final Item<RevCommit> item) {
RevCommit commit = item.getModelObject();
PersonIdent author = commit.getAuthorIdent();
- item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
+ item.add(new AvatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));
item.add(new Label("author", commit.getAuthorIdent().getName()));
item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));
@@ -987,12 +987,12 @@ public class TicketPage extends RepositoryPage {
UserModel commenter = app().users().getUserModel(entry.author);
if (commenter == null) {
// unknown user
- container.add(new GravatarImage("changeAvatar", entry.author,
+ container.add(new AvatarImage("changeAvatar", entry.author,
entry.author, null, avatarSize, false).setVisible(avatarSize > 0));
container.add(new Label("changeAuthor", entry.author.toLowerCase()));
} else {
// known user
- container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),
+ container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),
commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,
avatarSize, true).setVisible(avatarSize > 0));
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),
diff --git a/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java b/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java
index 35513bb3..062df84e 100644
--- a/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/ActivityPanel.java
@@ -76,7 +76,7 @@ public class ActivityPanel extends BasePanel {
.getWhen(), getTimeZone(), getTimeUtils()));
// avatar
- commitItem.add(new GravatarImage("avatar", commit.getAuthorIdent(), 40));
+ commitItem.add(new AvatarImage("avatar", commit.getAuthorIdent(), 40));
// merge icon
if (commit.getParentCount() > 1) {
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.html b/src/main/java/com/gitblit/wicket/panels/AvatarImage.html
index 846a8f1b..846a8f1b 100644
--- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.html
+++ b/src/main/java/com/gitblit/wicket/panels/AvatarImage.html
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java b/src/main/java/com/gitblit/wicket/panels/AvatarImage.java
index e4157577..a562042d 100644
--- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
+++ b/src/main/java/com/gitblit/wicket/panels/AvatarImage.java
@@ -17,9 +17,9 @@ package com.gitblit.wicket.panels;
import org.eclipse.jgit.lib.PersonIdent;
+import com.gitblit.AvatarGenerator;
import com.gitblit.Keys;
import com.gitblit.models.UserModel;
-import com.gitblit.utils.ActivityUtils;
import com.gitblit.wicket.ExternalImage;
import com.gitblit.wicket.WicketUtils;
@@ -29,36 +29,31 @@ import com.gitblit.wicket.WicketUtils;
* @author James Moger
*
*/
-public class GravatarImage extends BasePanel {
+public class AvatarImage extends BasePanel {
private static final long serialVersionUID = 1L;
- public GravatarImage(String id, PersonIdent person) {
+ public AvatarImage(String id, PersonIdent person) {
this(id, person, 0);
}
- public GravatarImage(String id, PersonIdent person, int width) {
+ public AvatarImage(String id, PersonIdent person, int width) {
this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
}
- public GravatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
+ public AvatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
}
- public GravatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
+ public AvatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
}
- public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
+ public AvatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
super(id);
- String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
- String url;
- if (identicon) {
- url = ActivityUtils.getGravatarIdenticonUrl(email, width);
- } else {
- url = ActivityUtils.getGravatarThumbnailUrl(email, width);
- }
+ AvatarGenerator avatarGenerator = app().runtime().getInjector().getInstance(AvatarGenerator.class);
+ String url = avatarGenerator.getURL(username, emailaddress, identicon, width);
ExternalImage image = new ExternalImage("image", url);
if (cssClass != null) {
WicketUtils.setCssClass(image, cssClass);
diff --git a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java
index eb757501..249cd4ac 100644
--- a/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/CommitHeaderPanel.java
@@ -44,6 +44,6 @@ public class CommitHeaderPanel extends BasePanel {
add(new Label("commitid", c.getName()));
add(new Label("author", c.getAuthorIdent().getName()));
add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
- add(new GravatarImage("authorAvatar", c.getAuthorIdent()));
+ add(new AvatarImage("authorAvatar", c.getAuthorIdent()));
}
} \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
index decfda50..d901945d 100644
--- a/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/DigestsPanel.java
@@ -216,7 +216,7 @@ public class DigestsPanel extends BasePanel {
final RepositoryCommit commit = commitItem.getModelObject();
// author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+ commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
// merge icon
if (commit.getParentCount() > 1) {
diff --git a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
index baefc6bd..2235fd3d 100644
--- a/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/ReflogPanel.java
@@ -271,7 +271,7 @@ public class ReflogPanel extends BasePanel {
final RepositoryCommit commit = commitItem.getModelObject();
// author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+ commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
// merge icon
if (commit.getParentCount() > 1) {
diff --git a/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java b/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
index f37cc2aa..447e1789 100644
--- a/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
@@ -145,7 +145,7 @@ public class RegistrantPermissionsPanel extends BasePanel {
}
Fragment userFragment = new Fragment("registrant", "userRegistrant", RegistrantPermissionsPanel.this);
- userFragment.add(new GravatarImage("userAvatar", ident, 20));
+ userFragment.add(new AvatarImage("userAvatar", ident, 20));
userFragment.add(new Label("userName", entry.registrant));
item.add(userFragment);
} else {
diff --git a/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java b/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java
index 2ac33d53..1fbe87cd 100644
--- a/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/TicketListPanel.java
@@ -156,7 +156,7 @@ public class TicketListPanel extends BasePanel {
if (responsible == null) {
responsible = new UserModel(ticket.responsible);
}
- GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
+ AvatarImage avatar = new AvatarImage("responsible", responsible.getDisplayName(),
responsible.emailAddress, null, 16, true);
avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
item.add(avatar);
diff --git a/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java b/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java
index 2bf5ee7b..063889b2 100644
--- a/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/UserTitlePanel.java
@@ -25,7 +25,7 @@ public class UserTitlePanel extends BasePanel {
public UserTitlePanel(String wicketId, UserModel user, String title) {
super(wicketId);
- add(new GravatarImage("userGravatar", user, "gravatar", 36, false));
+ add(new AvatarImage("userGravatar", user, "gravatar", 36, false));
add(new Label("userDisplayName", user.getDisplayName()));
add(new Label("userTitle", title));
}
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 79a0920d..af20a487 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -65,7 +65,8 @@ import com.gitblit.utils.JGitUtils;
FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class,
ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class,
BranchTicketServiceTest.class, RedisTicketServiceTest.class, AuthenticationManagerTest.class,
- SshKeysDispatcherTest.class, UITicketTest.class, PathUtilsTest.class, SshKerberosAuthenticationTest.class })
+ SshKeysDispatcherTest.class, UITicketTest.class, PathUtilsTest.class, SshKerberosAuthenticationTest.class,
+ GravatarTest.class })
public class GitBlitSuite {
public static final File BASEFOLDER = new File("data");
diff --git a/src/test/java/com/gitblit/tests/GravatarTest.java b/src/test/java/com/gitblit/tests/GravatarTest.java
new file mode 100644
index 00000000..ba989d56
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/GravatarTest.java
@@ -0,0 +1,74 @@
+package com.gitblit.tests;
+
+import org.junit.Test;
+
+import com.gitblit.AvatarGenerator;
+import com.gitblit.GravatarGenerator;
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.guice.AvatarGeneratorProvider;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.tests.mock.MemorySettings;
+import com.gitblit.utils.ActivityUtils;
+import com.gitblit.utils.XssFilter;
+import com.gitblit.utils.XssFilter.AllowXssFilter;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class GravatarTest extends GitblitUnitTest {
+
+ public static class AvatarModule extends AbstractModule {
+ private final IStoredSettings settings;
+
+ AvatarModule(IStoredSettings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ protected void configure() {
+ bind(IStoredSettings.class).toInstance(settings);
+ bind(XssFilter.class).to(AllowXssFilter.class);
+ bind(IRuntimeManager.class).to(RuntimeManager.class);
+ bind(AvatarGenerator.class).toProvider(AvatarGeneratorProvider.class);
+ }
+ }
+
+ @Test
+ public void gravatarIdenticonTest() {
+ IStoredSettings settings = new MemorySettings();
+ settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
+
+ Injector injector = Guice.createInjector(new AvatarModule(settings));
+ AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
+
+ String username = "username";
+ String emailAddress = "emailAddress";
+ int width = 10;
+
+ String url = avatarGenerator.getURL(username, emailAddress, true, width);
+ assertNotNull(url);
+
+ assertEquals(ActivityUtils.getGravatarIdenticonUrl(emailAddress, width), url);
+ }
+
+ @Test
+ public void gravatarThumbnailTest() {
+ IStoredSettings settings = new MemorySettings();
+ settings.overrideSetting(Keys.web.avatarClass, GravatarGenerator.class.getName());
+
+ Injector injector = Guice.createInjector(new AvatarModule(settings));
+ AvatarGenerator avatarGenerator = injector.getInstance(AvatarGenerator.class);
+
+ String username = "username";
+ String emailAddress = "emailAddress";
+ int width = 10;
+
+ String url = avatarGenerator.getURL(username, emailAddress, false, width);
+ assertNotNull(url);
+
+ assertEquals(ActivityUtils.getGravatarThumbnailUrl(emailAddress, width), url);
+ }
+
+}