mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
Merge pull request #16384 from rjernst/improve_maven_coordinates_check
Plugin cli: Improve maven coordinates detection
This commit is contained in:
commit
fa6f34ada3
@ -160,9 +160,9 @@ class InstallPluginCommand extends CliTool.Command {
|
|||||||
return downloadZipAndChecksum(url, tmpDir);
|
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(":");
|
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",
|
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 */);
|
coordinates[0].replace(".", "/") /* groupId */, coordinates[1] /* artifactId */, coordinates[2] /* version */);
|
||||||
terminal.println("-> Downloading " + pluginId + " from maven central");
|
terminal.println("-> Downloading " + pluginId + " from maven central");
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package org.elasticsearch.plugins;
|
package org.elasticsearch.plugins;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
@ -205,6 +206,14 @@ public class InstallPluginCommandTests extends ESTestCase {
|
|||||||
assertPlugin("fake", pluginDir, env);
|
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 {
|
public void testPluginsDirMissing() throws Exception {
|
||||||
Environment env = createEnv();
|
Environment env = createEnv();
|
||||||
Files.delete(env.pluginsFile());
|
Files.delete(env.pluginsFile());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user