Use '${user}' as placeholder for the username
Placeholders in the format '${placeholder}' are commonly used in
Gerrit and we should use the same format here, especially since we
already have a second placeholder '${size}'.
Since we just created the project newly to fix the project name, it's
a good opportunity to change the placeholder as well.
Change-Id: Ie41915171bfb88ddc2a3818fec43d769c82137a0
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/avatars/external/ExternalUrlAvatarProvider.java b/src/main/java/com/googlesource/gerrit/plugins/avatars/external/ExternalUrlAvatarProvider.java
index 093aacd..c022427 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/avatars/external/ExternalUrlAvatarProvider.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/avatars/external/ExternalUrlAvatarProvider.java
@@ -33,7 +33,7 @@
@Singleton
public class ExternalUrlAvatarProvider implements AvatarProvider {
- private static final String REPLACE_MARKER = "%s";
+ private static final String USER_PLACEHOLDER = "${user}";
private final String pluginName;
private final boolean ssl;
@@ -63,11 +63,11 @@
}
// it is unrealistic that all users share the same avatar image, thus we're
- // warning if we can't find our marker (%s)
- if (!externalAvatarUrl.contains(REPLACE_MARKER)) {
+ // warning if we can't find our marker
+ if (!externalAvatarUrl.contains(USER_PLACEHOLDER)) {
Logger log = LoggerFactory.getLogger(ExternalUrlAvatarProvider.class);
log.warn("Avatar provider url '" + externalAvatarUrl
- + "' does not contain " + REPLACE_MARKER
+ + "' does not contain " + USER_PLACEHOLDER
+ ", so cannot replace it with username");
return null;
}
@@ -94,20 +94,20 @@
}
/**
- * Takes #{replacement} and substitutes the marker REPLACE_MARKER in #{url}
+ * Takes #{replacement} and substitutes the marker USER_PLACEHOLDER in #{url}
* after it has been URL encoded
*
- * @param url The URL, usually containing #{REPLACE_MARKER}
+ * @param url The URL, usually containing #{USER_PLACEHOLDER}
* @param replacement String to be put inside
* @return new URL
*/
private String replaceInUrl(String url, String replacement) {
if (replacement == null || url == null
- || url.contains(REPLACE_MARKER) == false) {
+ || url.contains(USER_PLACEHOLDER) == false) {
return url;
}
// as we can't assume anything of 'replacement', we're URL encoding it
- return url.replace(REPLACE_MARKER, Url.encode(replacement));
+ return url.replace(USER_PLACEHOLDER, Url.encode(replacement));
}
}
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 507c83f..f76d7a9 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -6,15 +6,15 @@
```
[plugin "@PLUGIN@"]
- url = http://example.org/avatars/%s.jpg
+ url = http://example.org/avatars/${user}.jpg
changeUrl = http://example.org/account.html
sizeParameter = s=${size}x${size}
```
<a id="url">
`plugin.@PLUGIN@.url`
-: The location of avatar images containing `%s`, which will then be
- replaced by the `username`. Required.
+: The location of avatar images containing `${user}`, which will then
+ be replaced by the `username`. Required.
<a id="changeUrl">
`plugin.@PLUGIN@.changeUrl`