Merge pull request #16384 from rjernst/improve_maven_coordinates_check

Plugin cli: Improve maven coordinates detection
This commit is contained in:
Ryan Ernst 2016-02-02 12:27:54 -08:00
commit fa6f34ada3
2 changed files with 11 additions and 2 deletions

View File

@ -160,9 +160,9 @@ class InstallPluginCommand extends CliTool.Command {
return downloadZipAndChecksum(url, tmpDir);
}
// now try as maven coordinates, a valid URL would only have a single colon
// now try as maven coordinates, a valid URL would only have a colon and slash
String[] coordinates = pluginId.split(":");
if (coordinates.length == 3) {
if (coordinates.length == 3 && pluginId.contains("/") == false) {
String mavenUrl = String.format(Locale.ROOT, "https://repo1.maven.org/maven2/%1$s/%2$s/%3$s/%2$s-%3$s.zip",
coordinates[0].replace(".", "/") /* groupId */, coordinates[1] /* artifactId */, coordinates[2] /* version */);
terminal.println("-> Downloading " + pluginId + " from maven central");

View File

@ -20,6 +20,7 @@
package org.elasticsearch.plugins;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
@ -205,6 +206,14 @@ public class InstallPluginCommandTests extends ESTestCase {
assertPlugin("fake", pluginDir, env);
}
public void testMalformedUrlNotMaven() throws Exception {
// has two colons, so it appears similar to maven coordinates
MalformedURLException e = expectThrows(MalformedURLException.class, () -> {
installPlugin("://host:1234", createEnv());
});
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}
public void testPluginsDirMissing() throws Exception {
Environment env = createEnv();
Files.delete(env.pluginsFile());