Demon has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/60662


Change subject: Allow JS plugins to contribute JS located outside a plugin
......................................................................

Allow JS plugins to contribute JS located outside a plugin

This allows for serving your Javascript from a source that's not
necessarily in the plugin's static directory. Useful for loading
something like JQuery from a CDN.

Change-Id: Ieff3254e7ee8e9ad728b5e9b344c2aa028097df5
---
M 
gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebUiPlugin.java
M gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java
2 files changed, 23 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/gerrit refs/changes/62/60662/1

diff --git 
a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebUiPlugin.java
 
b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebUiPlugin.java
index 5cd1981..7cc9876 100644
--- 
a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebUiPlugin.java
+++ 
b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebUiPlugin.java
@@ -18,6 +18,8 @@
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.inject.Inject;
 
+import java.util.HashMap;
+
 /**
  * Specifies JavaScript to dynamically load into the web UI.
  * <p>
@@ -66,4 +68,13 @@
   public String toString() {
     return getJavaScriptResourcePath();
   }
+
+  /**
+   * Subclasses should override this and return a map of dependencies.
+   * The key should be the name of the library, and the value the url
+   * (local or remote) for the library to be included.
+   */
+  public HashMap<String,String> getJavaScriptDependencies() {
+    return new HashMap<String,String>();
+  }
 }
diff --git 
a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java 
b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java
index ea2168a..b9b9492 100644
--- 
a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java
+++ 
b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java
@@ -221,7 +221,19 @@
 
   private void plugins(StringWriter w) {
     List<String> urls = Lists.newArrayList();
+    List<String> injectedDependencies = Lists.newArrayList();
     for (WebUiPlugin u : plugins) {
+      for(Map.Entry<String,String> dep : 
u.getJavaScriptDependencies().entrySet()) {
+        String depName = dep.getKey();
+        if(injectedDependencies.contains(depName)) {
+          log.info("Plugin dependency '" + depName +
+              "' already injected. Skipping loading it a second time.");
+          continue;
+        } else {
+          urls.add(dep.getValue());
+          injectedDependencies.add(depName);
+        }
+      }
       urls.add(String.format("plugins/%s/%s",
           u.getPluginName(),
           u.getJavaScriptResourcePath()));

-- 
To view, visit https://gerrit.wikimedia.org/r/60662
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieff3254e7ee8e9ad728b5e9b344c2aa028097df5
Gerrit-PatchSet: 1
Gerrit-Project: gerrit
Gerrit-Branch: wmf
Gerrit-Owner: Demon <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to