From 15e55e882fddf332d761bddd834857661e6caaa6 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 27 Oct 2015 21:24:48 -0400 Subject: [PATCH] support symlinked .m2/repository in tests Some jenkins servers have this, but our codebase normalization doesn't follow symlinks. Add this so that its correct. Only really impacts tests, i suppose it helps if someone has a symlinked plugins/ but that is not recommended :) --- .../org/elasticsearch/bootstrap/Security.java | 3 ++- .../bootstrap/BootstrapForTesting.java | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Security.java b/core/src/main/java/org/elasticsearch/bootstrap/Security.java index 2208eea7d2e..f7a0500312d 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -133,10 +133,11 @@ final class Security { Path policyFile = plugin.resolve(PluginInfo.ES_PLUGIN_POLICY); if (Files.exists(policyFile)) { // first get a list of URLs for the plugins' jars: + // we resolve symlinks so map is keyed on the normalize codebase name List codebases = new ArrayList<>(); try (DirectoryStream jarStream = Files.newDirectoryStream(plugin, "*.jar")) { for (Path jar : jarStream) { - codebases.add(jar.toUri().toURL()); + codebases.add(jar.toRealPath().toUri().toURL()); } } diff --git a/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java b/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java index 2c195a9a014..c6d02c8d89b 100644 --- a/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java +++ b/core/src/test/java/org/elasticsearch/bootstrap/BootstrapForTesting.java @@ -174,7 +174,7 @@ public class BootstrapForTesting { } // compute classpath minus obvious places, all other jars will get the permission. - Set codebases = new HashSet<>(Arrays.asList(JarHell.parseClassPath())); + Set codebases = new HashSet<>(Arrays.asList(parseClassPathWithSymlinks())); Set excluded = new HashSet<>(Arrays.asList( // es core Bootstrap.class.getProtectionDomain().getCodeSource().getLocation(), @@ -214,6 +214,19 @@ public class BootstrapForTesting { return Collections.unmodifiableMap(map); } + /** + * return parsed classpath, but with symlinks resolved to destination files for matching + * this is for matching the toRealPath() in the code where we have a proper plugin structure + */ + @SuppressForbidden(reason = "does evil stuff with paths and urls because devs and jenkins do evil stuff with paths and urls") + static URL[] parseClassPathWithSymlinks() throws Exception { + URL raw[] = JarHell.parseClassPath(); + for (int i = 0; i < raw.length; i++) { + raw[i] = PathUtils.get(raw[i].toURI()).toRealPath().toUri().toURL(); + } + return raw; + } + // does nothing, just easy way to make sure the class is loaded. public static void ensureInitialized() {} }