private List<Tuple<PluginInfo,Plugin>> loadBundles(Set<Bundle> bundles) { List<Tuple<PluginInfo, Plugin>> plugins = new ArrayList<>(); Map<String, Plugin> loaded = new HashMap<>(); Map<String, Set<URL>> transitiveUrls = new HashMap<>(); List<Bundle> sortedBundles = sortBundles(bundles); for (Bundle bundle : sortedBundles) { checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveUrls); final Plugin plugin = loadBundle(bundle, loaded); plugins.add(new Tuple<>(bundle.plugin, plugin)); } return Collections.unmodifiableList(plugins); }
JarHell.checkJarHell(urls, logger::debug); // check jarhell as we add each extended plugin's urls JarHell.checkJarHell(urls, logger::debug); // check jarhell of each extended plugin against this plugin transitiveUrls.put(bundle.plugin.getName(), urls); JarHell.checkJarHell(union, logger::debug); } catch (Exception e) { throw new IllegalStateException("failed to load plugin " + bundle.plugin.getName() + " due to jar hell", e);
/** inspect manifest for sure incompatibilities */ private static void checkManifest(Manifest manifest, Path jar) { // give a nice error if jar requires a newer java version String targetVersion = manifest.getMainAttributes().getValue("X-Compile-Target-JDK"); if (targetVersion != null) { checkVersionFormat(targetVersion); checkJavaVersion(jar.toString(), targetVersion); } }
/** * Checks the current classpath for duplicate classes * @param output A {@link String} {@link Consumer} to which debug output will be sent * @throws IllegalStateException if jar hell was found */ public static void checkJarHell(Consumer<String> output) throws IOException, URISyntaxException { ClassLoader loader = JarHell.class.getClassLoader(); output.accept("java.class.path: " + System.getProperty("java.class.path")); output.accept("sun.boot.class.path: " + System.getProperty("sun.boot.class.path")); if (loader instanceof URLClassLoader) { output.accept("classloader urls: " + Arrays.toString(((URLClassLoader)loader).getURLs())); } checkJarHell(parseClassPath(), output); }
Manifest manifest = file.getManifest(); if (manifest != null) { checkManifest(manifest, path); checkClass(clazzes, entry, path);
/** * Verify the given plugin is compatible with the current Elasticsearch installation. */ static void verifyCompatibility(PluginInfo info) { if (info.getElasticsearchVersion().equals(Version.CURRENT) == false) { throw new IllegalArgumentException("Plugin [" + info.getName() + "] was built for Elasticsearch version " + info.getElasticsearchVersion() + " but version " + Version.CURRENT + " is running"); } JarHell.checkJavaVersion(info.getName(), info.getJavaVersion()); }
"property [java.version] is missing for plugin [" + name + "]"); JarHell.checkVersionFormat(javaVersionString); final String classname = propsMap.remove("classname"); if (classname == null) {
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String entry = root.relativize(file).toString(); if (entry.endsWith(".class")) { // normalize with the os separator, remove '.class' entry = entry.replace(sep, ".").substring(0, entry.length() - ".class".length()); checkClass(clazzes, entry, path); } return super.visitFile(file, attrs); } });
/** * Checks the current classpath for duplicate classes * @throws IllegalStateException if jar hell was found */ public static void checkJarHell() throws IOException, URISyntaxException { ClassLoader loader = JarHell.class.getClassLoader(); Logger logger = Loggers.getLogger(JarHell.class); if (logger.isDebugEnabled()) { logger.debug("java.class.path: {}", System.getProperty("java.class.path")); logger.debug("sun.boot.class.path: {}", System.getProperty("sun.boot.class.path")); if (loader instanceof URLClassLoader ) { logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader)loader).getURLs())); } } checkJarHell(parseClassPath()); }
Manifest manifest = file.getManifest(); if (manifest != null) { checkManifest(manifest, path); checkClass(clazzes, entry, path);
/** * Verify the given plugin is compatible with the current Elasticsearch installation. */ static void verifyCompatibility(PluginInfo info) { if (info.getElasticsearchVersion().equals(Version.CURRENT) == false) { throw new IllegalArgumentException("Plugin [" + info.getName() + "] was built for Elasticsearch version " + info.getElasticsearchVersion() + " but version " + Version.CURRENT + " is running"); } JarHell.checkJavaVersion(info.getName(), info.getJavaVersion()); }
"property [java.version] is missing for plugin [" + name + "]"); JarHell.checkVersionFormat(javaVersionString); final String classname = propsMap.remove("classname"); if (classname == null) {
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String entry = root.relativize(file).toString(); if (entry.endsWith(".class")) { // normalize with the os separator entry = entry.replace(sep, ".").substring(0, entry.length() - 6); checkClass(clazzes, entry, path); } return super.visitFile(file, attrs); } });
/** * Checks the current classpath for duplicate classes * @throws IllegalStateException if jar hell was found */ public static void checkJarHell() throws IOException, URISyntaxException { ClassLoader loader = JarHell.class.getClassLoader(); Logger logger = Loggers.getLogger(JarHell.class); if (logger.isDebugEnabled()) { logger.debug("java.class.path: {}", System.getProperty("java.class.path")); logger.debug("sun.boot.class.path: {}", System.getProperty("sun.boot.class.path")); if (loader instanceof URLClassLoader ) { logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader)loader).getURLs())); } } checkJarHell(parseClassPath()); }
/** Adds access to classpath jars/classes for jar hell scan, etc */ @SuppressForbidden(reason = "accesses fully qualified URLs to configure security") static void addClasspathPermissions(Permissions policy) throws IOException { // add permissions to everything in classpath // really it should be covered by lib/, but there could be e.g. agents or similar configured) for (URL url : JarHell.parseClassPath()) { Path path; try { path = PathUtils.get(url.toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e); } // resource itself if (Files.isDirectory(path)) { addDirectoryPath(policy, "class.path", path, "read,readlink"); } else { addSingleFilePath(policy, path, "read,readlink"); } } }
/** inspect manifest for sure incompatibilities */ private static void checkManifest(Manifest manifest, Path jar) { // give a nice error if jar requires a newer java version String targetVersion = manifest.getMainAttributes().getValue("X-Compile-Target-JDK"); if (targetVersion != null) { checkVersionFormat(targetVersion); checkJavaVersion(jar.toString(), targetVersion); } }
JarHell.checkJarHell(logger::debug); } catch (IOException | URISyntaxException e) { throw new BootstrapException(e);
Manifest manifest = file.getManifest(); if (manifest != null) { checkManifest(manifest, path); checkClass(clazzes, entry, path);
/** * Verify the given plugin is compatible with the current Elasticsearch installation. */ static void verifyCompatibility(PluginInfo info) { if (info.getElasticsearchVersion().equals(Version.CURRENT) == false) { throw new IllegalArgumentException("Plugin [" + info.getName() + "] was built for Elasticsearch version " + info.getElasticsearchVersion() + " but version " + Version.CURRENT + " is running"); } JarHell.checkJavaVersion(info.getName(), info.getJavaVersion()); }
"property [java.version] is missing for plugin [" + name + "]"); JarHell.checkVersionFormat(javaVersionString); final String classname = propsMap.remove("classname"); if (classname == null) {