From 3fd9f4b82e6aab6b3c91f97936561838b9ed3d6e Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 9 Jul 2015 11:09:12 -0400 Subject: [PATCH] remove elasticsearch- from name of official plugins This change fixes the plugin manager to trim `elasticsearch-` and `es-` prefixes from plugin names for our official plugins. This restores the old behavior prior to #11805. Closes #12143 --- .../elasticsearch/plugins/PluginManager.java | 22 ++++++++----------- .../plugins/PluginManagerUnitTests.java | 12 ++++++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index 96d35685971..83895e7622e 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -759,19 +759,15 @@ public class PluginManager { } if (isOfficialPlugin(repo, user, version)) { - return new PluginHandle(repo, Version.CURRENT.number(), null, repo); - } - - if (repo.startsWith("elasticsearch-")) { - // remove elasticsearch- prefix - String endname = repo.substring("elasticsearch-".length()); - return new PluginHandle(endname, version, user, repo); - } - - if (name.startsWith("es-")) { - // remove es- prefix - String endname = repo.substring("es-".length()); - return new PluginHandle(endname, version, user, repo); + String endname = repo; + if (repo.startsWith("elasticsearch-")) { + // remove elasticsearch- prefix + endname = repo.substring("elasticsearch-".length()); + } else if (name.startsWith("es-")) { + // remove es- prefix + endname = repo.substring("es-".length()); + } + return new PluginHandle(endname, Version.CURRENT.number(), null, repo); } return new PluginHandle(repo, version, user, repo); diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java index 4517f82c2ea..eb5e691e98d 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginManagerUnitTests.java @@ -67,4 +67,16 @@ public class PluginManagerUnitTests extends ElasticsearchTestCase { pluginName + "-" + Version.CURRENT.number() + ".zip"); assertThat(handle.urls().get(0), is(expected)); } + + @Test + public void testTrimmingElasticsearchFromPluginName() throws IOException { + String randomName = randomAsciiOfLength(10); + String pluginName = randomFrom("elasticsearch-", "es-") + randomName; + PluginManager.PluginHandle handle = PluginManager.PluginHandle.parse(pluginName); + assertThat(handle.name, is(randomName)); + assertThat(handle.urls(), hasSize(1)); + URL expected = new URL("http", "download.elastic.co", "/org.elasticsearch.plugins/" + pluginName + "/" + + pluginName + "-" + Version.CURRENT.number() + ".zip"); + assertThat(handle.urls().get(0), is(expected)); + } }