Plugins: Update jarhell calls with new set based api (elastic/x-pack-elasticsearch#743)
This is the xpack side of elastic/elasticsearch#23596 Original commit: elastic/x-pack-elasticsearch@d1654b1ccd
This commit is contained in:
parent
f7c4c754c2
commit
8a8ed1cfbb
|
@ -28,10 +28,12 @@ import java.nio.file.Path;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
@ -168,8 +170,7 @@ final class InstallXPackExtensionCommand extends EnvironmentAwareCommand {
|
|||
private void jarHellCheck(Path candidate) throws Exception {
|
||||
// create list of current jars in classpath
|
||||
// including the x-pack jars (see $ES_CLASSPATH in bin/extension script)
|
||||
final List<URL> jars = new ArrayList<>();
|
||||
jars.addAll(Arrays.asList(JarHell.parseClassPath()));
|
||||
final Set<URL> jars = new HashSet<>(JarHell.parseClassPath());
|
||||
|
||||
// add extension jars to the list
|
||||
Path extensionJars[] = FileSystemUtils.files(candidate, "*.jar");
|
||||
|
@ -180,7 +181,7 @@ final class InstallXPackExtensionCommand extends EnvironmentAwareCommand {
|
|||
// TODO: verify the classname exists in one of the jars!
|
||||
|
||||
// check combined (current classpath + new jars to-be-added)
|
||||
JarHell.checkJarHell(jars.toArray(new URL[jars.size()]));
|
||||
JarHell.checkJarHell(jars);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,14 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.extensions;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.bootstrap.JarHell;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
@ -23,9 +15,19 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.bootstrap.JarHell;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory;
|
||||
|
||||
public class XPackExtensionsService {
|
||||
|
@ -132,9 +134,9 @@ public class XPackExtensionsService {
|
|||
// jar-hell check the bundle against the parent classloader and the x-pack classloader
|
||||
// pluginmanager does it, but we do it again, in case lusers mess with jar files manually
|
||||
try {
|
||||
final List<URL> jars = new ArrayList<>();
|
||||
final Set<URL> jars = new LinkedHashSet<>();
|
||||
// add the parent jars to the list
|
||||
jars.addAll(Arrays.asList(JarHell.parseClassPath()));
|
||||
jars.addAll(JarHell.parseClassPath());
|
||||
|
||||
// add the x-pack jars to the list
|
||||
ClassLoader xpackLoader = getClass().getClassLoader();
|
||||
|
@ -145,7 +147,7 @@ public class XPackExtensionsService {
|
|||
|
||||
jars.addAll(bundle.urls);
|
||||
|
||||
JarHell.checkJarHell(jars.toArray(new URL[0]));
|
||||
JarHell.checkJarHell(jars);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("failed to load bundle " + bundle.urls + " due to jar hell", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue