Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  Upgrade bazlets to latest stable-2.14 to build with 2.14.20 API

Change-Id: Ief8db55b9d0d7cafec33b44e4b77281b1b3a3a57
diff --git a/WORKSPACE b/WORKSPACE
index 0baff8e..7b4f79b 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "8386b3fbf80e375f0a10c8386c0a8dfe260c5c1b",
+    commit = "c827ba79413585ab9dfc1bbd0d7f609eedd6aa80",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java b/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
index edc2a12..4880e46 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
@@ -57,7 +57,7 @@
   @Override
   public ConfigInfo apply(AccountResource rsrc) throws AuthException, PermissionBackendException {
     if (self.get() != rsrc.getUser()) {
-      permissionBackend.user(self).check(ADMINISTRATE_SERVER);
+      permissionBackend.currentUser().check(ADMINISTRATE_SERVER);
     }
 
     ConfigInfo globalCfg = getConfig.get().apply(new ConfigResource());
@@ -66,7 +66,7 @@
     info.showEmoticons =
         db.getBoolean(
             PREFERENCE,
-            self.get().getUserName(),
+            self.get().getUserName().orElse(null),
             KEY_SHOW_EMOTICONS,
             (globalCfg.showEmoticons != null ? globalCfg.showEmoticons : true));
     if (!info.showEmoticons) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/emoticons/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/emoticons/HttpModule.java
index 0994a8e..df906d1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/emoticons/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/emoticons/HttpModule.java
@@ -25,5 +25,6 @@
   protected void configureServlets() {
     DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new GwtPlugin("emoticons"));
     DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("emoticons.js"));
+    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("emoticons.html"));
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java b/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
index d3bcd91..f9e7416 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
@@ -25,11 +25,11 @@
 import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.account.AccountResource;
-import com.google.gerrit.server.git.MetaDataUpdate;
-import com.google.gerrit.server.git.ProjectLevelConfig;
+import com.google.gerrit.server.git.meta.MetaDataUpdate;
 import com.google.gerrit.server.permissions.PermissionBackend;
 import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.gerrit.server.project.ProjectCache;
+import com.google.gerrit.server.project.ProjectLevelConfig;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.googlesource.gerrit.plugins.emoticons.PutConfig.Input;
@@ -63,13 +63,13 @@
       throws AuthException, RepositoryNotFoundException, IOException, UnprocessableEntityException,
           PermissionBackendException {
     if (self.get() != rsrc.getUser()) {
-      permissionBackend.user(self).check(ADMINISTRATE_SERVER);
+      permissionBackend.currentUser().check(ADMINISTRATE_SERVER);
     }
     if (input == null) {
       input = new Input();
     }
 
-    String username = self.get().getUserName();
+    String username = self.get().getUserName().orElse(null);
 
     ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".config");
     Config db = storage.get();
diff --git a/src/main/resources/static/emoticons.html b/src/main/resources/static/emoticons.html
new file mode 100644
index 0000000..21bf3ab
--- /dev/null
+++ b/src/main/resources/static/emoticons.html
@@ -0,0 +1,17 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// 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.
+
+<dom-module id="emoticons">
+  <script src="./emoticons.js"></script>
+</dom-module>
diff --git a/src/main/resources/static/emoticons.js b/src/main/resources/static/emoticons.js
index f761810..996487d 100644
--- a/src/main/resources/static/emoticons.js
+++ b/src/main/resources/static/emoticons.js
@@ -13,12 +13,21 @@
 // limitations under the License.
 
 Gerrit.install(function(self) {
+
+    function get(url, callback) {
+      if (window.Polymer) {
+        self.restApi().get(url).then(callback)
+      } else {
+        Gerrit.get(url, callback)
+      }
+    }
+
     function onComment(e) {
       var prefs = getPrefsFromCookie();
       if (prefs !== null) {
         insertEmoticons(e, prefs)
       } else {
-        Gerrit.get('/accounts/self/' + self.getPluginName()
+        get('/accounts/self/' + self.getPluginName()
             + '~preference', function(prefs) {
           storePrefsInCookie(prefs);
           insertEmoticons(e, prefs)
@@ -97,5 +106,5 @@
       });
     }
 
-    Gerrit.on('comment', onComment);
+    self.on('comment', onComment);
   });