summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Aistleitner <christian@quelltextlich.at>2020-05-31 09:42:52 +0200
committerChristian Aistleitner <christian@quelltextlich.at>2020-07-03 13:57:59 +0200
commitc3afed68787074c51bb3360414cf0f84b6f27642 (patch)
treee34481407dbd6bd2afce828b9609722b19f3f932
parentb5a08cf8191ee998a3a5ea75f13f27e6a923daca (diff)
Expose Api version through PluginInfo
By adding Api version to PluginInfo, it becomes easier to check if all plugins of a Gerrit server got built for the correct Api. This is especially useful when upgrading servers. This commit only exposes the Api version through the Api. Showing it in the default output of the corresponding Ssh list command or in the UI will happen in follow-up commits. Change-Id: Id0c459dd104b4582fde1846e7710d6ad0ffc2f93
-rw-r--r--Documentation/rest-api-plugins.txt14
-rw-r--r--java/com/google/gerrit/extensions/common/PluginInfo.java10
-rw-r--r--java/com/google/gerrit/server/plugins/ListPlugins.java4
-rw-r--r--java/com/google/gerrit/server/plugins/Plugin.java5
-rw-r--r--java/com/google/gerrit/server/plugins/ServerPlugin.java7
-rw-r--r--javatests/com/google/gerrit/acceptance/api/plugin/PluginIT.java57
6 files changed, 87 insertions, 10 deletions
diff --git a/Documentation/rest-api-plugins.txt b/Documentation/rest-api-plugins.txt
index 255704a521..92b692fa33 100644
--- a/Documentation/rest-api-plugins.txt
+++ b/Documentation/rest-api-plugins.txt
@@ -48,6 +48,7 @@ by plugin ID.
"id": "delete-project",
"index_url": "plugins/delete-project/",
"filename": "delete-project.jar",
+ "api_version": "2.9.3-SNAPSHOT",
"version": "2.9-SNAPSHOT"
}
}
@@ -437,12 +438,13 @@ The `PluginInfo` entity describes a plugin.
[options="header",cols="1,^2,4"]
|=======================
-|Field Name ||Description
-|`id` ||The ID of the plugin.
-|`version` ||The version of the plugin.
-|`index_url`|optional|URL of the plugin's default page.
-|`filename` |optional|The plugin's filename.
-|`disabled` |not set if `false`|Whether the plugin is disabled.
+|Field Name ||Description
+|`id` ||The ID of the plugin.
+|`version` ||The version of the plugin.
+|`api_version`|optional|The version of the Gerrit Api used by the plugin.
+|`index_url` |optional|URL of the plugin's default page.
+|`filename` |optional|The plugin's filename.
+|`disabled` |not set if `false`|Whether the plugin is disabled.
|=======================
[[plugin-input]]
diff --git a/java/com/google/gerrit/extensions/common/PluginInfo.java b/java/com/google/gerrit/extensions/common/PluginInfo.java
index 0df6235c9c..47f9b6ac14 100644
--- a/java/com/google/gerrit/extensions/common/PluginInfo.java
+++ b/java/com/google/gerrit/extensions/common/PluginInfo.java
@@ -17,13 +17,21 @@ package com.google.gerrit.extensions.common;
public class PluginInfo {
public final String id;
public final String version;
+ public final String apiVersion;
public final String indexUrl;
public final String filename;
public final Boolean disabled;
- public PluginInfo(String id, String version, String indexUrl, String filename, Boolean disabled) {
+ public PluginInfo(
+ String id,
+ String version,
+ String apiVersion,
+ String indexUrl,
+ String filename,
+ Boolean disabled) {
this.id = id;
this.version = version;
+ this.apiVersion = apiVersion;
this.indexUrl = indexUrl;
this.filename = filename;
this.disabled = disabled;
diff --git a/java/com/google/gerrit/server/plugins/ListPlugins.java b/java/com/google/gerrit/server/plugins/ListPlugins.java
index 84e63d09a5..438a0c4a10 100644
--- a/java/com/google/gerrit/server/plugins/ListPlugins.java
+++ b/java/com/google/gerrit/server/plugins/ListPlugins.java
@@ -144,12 +144,14 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
public static PluginInfo toPluginInfo(Plugin p) {
String id;
String version;
+ String apiVersion;
String indexUrl;
String filename;
Boolean disabled;
id = Url.encode(p.getName());
version = p.getVersion();
+ apiVersion = p.getApiVersion();
disabled = p.isDisabled() ? true : null;
if (p.getSrcFile() != null) {
indexUrl = String.format("plugins/%s/", p.getName());
@@ -159,6 +161,6 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
filename = null;
}
- return new PluginInfo(id, version, indexUrl, filename, disabled);
+ return new PluginInfo(id, version, apiVersion, indexUrl, filename, disabled);
}
}
diff --git a/java/com/google/gerrit/server/plugins/Plugin.java b/java/com/google/gerrit/server/plugins/Plugin.java
index 57597054ed..238066b507 100644
--- a/java/com/google/gerrit/server/plugins/Plugin.java
+++ b/java/com/google/gerrit/server/plugins/Plugin.java
@@ -116,6 +116,11 @@ public abstract class Plugin {
return apiType;
}
+ @Nullable
+ public String getApiVersion() {
+ return null;
+ }
+
public Plugin.CacheKey getCacheKey() {
return cacheKey;
}
diff --git a/java/com/google/gerrit/server/plugins/ServerPlugin.java b/java/com/google/gerrit/server/plugins/ServerPlugin.java
index f2362020d0..320b618f85 100644
--- a/java/com/google/gerrit/server/plugins/ServerPlugin.java
+++ b/java/com/google/gerrit/server/plugins/ServerPlugin.java
@@ -154,6 +154,13 @@ public class ServerPlugin extends Plugin {
}
@Override
+ @Nullable
+ public String getApiVersion() {
+ Attributes main = manifest.getMainAttributes();
+ return main.getValue("Gerrit-ApiVersion");
+ }
+
+ @Override
protected boolean canReload() {
Attributes main = manifest.getMainAttributes();
String v = main.getValue("Gerrit-ReloadMode");
diff --git a/javatests/com/google/gerrit/acceptance/api/plugin/PluginIT.java b/javatests/com/google/gerrit/acceptance/api/plugin/PluginIT.java
index 1d3eb176b4..2e455528c3 100644
--- a/javatests/com/google/gerrit/acceptance/api/plugin/PluginIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/plugin/PluginIT.java
@@ -35,7 +35,12 @@ import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.inject.Inject;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
import org.junit.Test;
@NoHttpd
@@ -49,7 +54,14 @@ public class PluginIT extends AbstractDaemonTest {
private static final ImmutableList<String> PLUGINS =
ImmutableList.of(
- "plugin-a.js", "plugin-b.html", "plugin-c.js", "plugin-d.html", "plugin_e.js");
+ "plugin-a.js",
+ "plugin-b.html",
+ "plugin-c.js",
+ "plugin-d.html",
+ "plugin-normal.jar",
+ "plugin-empty.jar",
+ "plugin-unset.jar",
+ "plugin_e.js");
@Inject private RequestScopeOperations requestScopeOperations;
@@ -64,13 +76,14 @@ public class PluginIT extends AbstractDaemonTest {
// Install all the plugins
InstallPluginInput input = new InstallPluginInput();
for (String plugin : PLUGINS) {
- input.raw = plugin.endsWith(".js") ? JS_PLUGIN_CONTENT : HTML_PLUGIN_CONTENT;
+ input.raw = pluginContent(plugin);
api = gApi.plugins().install(plugin, input);
assertThat(api).isNotNull();
PluginInfo info = api.get();
String name = pluginName(plugin);
assertThat(info.id).isEqualTo(name);
assertThat(info.version).isEqualTo(pluginVersion(plugin));
+ assertThat(info.apiVersion).isEqualTo(pluginApiVersion(plugin));
assertThat(info.indexUrl).isEqualTo(String.format("plugins/%s/", name));
assertThat(info.filename).isEqualTo(plugin);
assertThat(info.disabled).isNull();
@@ -163,12 +176,52 @@ public class PluginIT extends AbstractDaemonTest {
return plugin.substring(0, dot);
}
+ private RawInput pluginJarContent(String plugin) throws IOException {
+ ByteArrayOutputStream arrayStream = new ByteArrayOutputStream();
+ Manifest manifest = new Manifest();
+ Attributes attributes = manifest.getMainAttributes();
+ attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ if (!plugin.endsWith("-unset.jar")) {
+ attributes.put(Attributes.Name.IMPLEMENTATION_VERSION, pluginVersion(plugin));
+ attributes.put(new Attributes.Name("Gerrit-ApiVersion"), pluginApiVersion(plugin));
+ }
+ try (JarOutputStream jarStream = new JarOutputStream(arrayStream, manifest)) {}
+ return RawInputUtil.create(arrayStream.toByteArray());
+ }
+
+ private RawInput pluginContent(String plugin) throws IOException {
+ if (plugin.endsWith(".js")) {
+ return JS_PLUGIN_CONTENT;
+ }
+ if (plugin.endsWith(".html")) {
+ return HTML_PLUGIN_CONTENT;
+ }
+ assertThat(plugin).endsWith(".jar");
+ return pluginJarContent(plugin);
+ }
+
private String pluginVersion(String plugin) {
String name = pluginName(plugin);
+ if (name.endsWith("empty")) {
+ return "";
+ }
+ if (name.endsWith("unset")) {
+ return null;
+ }
int dash = name.lastIndexOf("-");
return dash > 0 ? name.substring(dash + 1) : "";
}
+ private String pluginApiVersion(String plugin) {
+ if (plugin.endsWith("normal.jar")) {
+ return "2.16.19-SNAPSHOT";
+ }
+ if (plugin.endsWith("empty.jar")) {
+ return "";
+ }
+ return null;
+ }
+
private void assertBadRequest(ListRequest req) throws Exception {
try {
req.get();