Skip to content

Commit dddc014

Browse files
committed
Remove log4j dependency from elasticsearch-core
This removes the log4j dependency from our elasticsearch-core project. It was originally necessary only for our jar classpath checking. It is now replaced by a `Consumer<String>` so that the es-core dependency doesn't have external dependencies. The parts of elastic#28191 which were moved in conjunction (like `ESLoggerFactory` and `Loggers`) have been moved back where appropriate, since they are not required in the core jar. This is tangentially related to elastic#28504
1 parent 3059862 commit dddc014

File tree

47 files changed

+191
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+191
-440
lines changed

libs/elasticsearch-core/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ publishing {
3535
}
3636

3737
dependencies {
38-
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
39-
4038
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
4139
testCompile "junit:junit:${versions.junit}"
4240
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
@@ -78,4 +76,4 @@ thirdPartyAudit.excludes = [
7876
'org/osgi/framework/SynchronousBundleListener',
7977
'org/osgi/framework/wiring/BundleWire',
8078
'org/osgi/framework/wiring/BundleWiring'
81-
]
79+
]

libs/elasticsearch-core/licenses/log4j-api-2.9.1.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/elasticsearch-core/licenses/log4j-api-LICENSE.txt

Lines changed: 0 additions & 202 deletions
This file was deleted.

libs/elasticsearch-core/licenses/log4j-api-NOTICE.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

libs/elasticsearch-core/src/main/java/org/elasticsearch/bootstrap/JarHell.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
package org.elasticsearch.bootstrap;
2121

22-
import org.apache.logging.log4j.Logger;
2322
import org.elasticsearch.common.SuppressForbidden;
2423
import org.elasticsearch.common.io.PathUtils;
25-
import org.elasticsearch.common.logging.Loggers;
2624

2725
import java.io.IOException;
2826
import java.net.MalformedURLException;
@@ -43,6 +41,7 @@
4341
import java.util.Locale;
4442
import java.util.Map;
4543
import java.util.Set;
44+
import java.util.function.Consumer;
4645
import java.util.jar.JarEntry;
4746
import java.util.jar.JarFile;
4847
import java.util.jar.Manifest;
@@ -68,25 +67,22 @@ private JarHell() {}
6867
@SuppressForbidden(reason = "command line tool")
6968
public static void main(String args[]) throws Exception {
7069
System.out.println("checking for jar hell...");
71-
checkJarHell();
70+
checkJarHell(System.out::println);
7271
System.out.println("no jar hell found");
7372
}
7473

7574
/**
7675
* Checks the current classpath for duplicate classes
7776
* @throws IllegalStateException if jar hell was found
7877
*/
79-
public static void checkJarHell() throws IOException, URISyntaxException {
78+
public static void checkJarHell(Consumer<String> output) throws IOException, URISyntaxException {
8079
ClassLoader loader = JarHell.class.getClassLoader();
81-
Logger logger = Loggers.getLogger(JarHell.class);
82-
if (logger.isDebugEnabled()) {
83-
logger.debug("java.class.path: {}", System.getProperty("java.class.path"));
84-
logger.debug("sun.boot.class.path: {}", System.getProperty("sun.boot.class.path"));
85-
if (loader instanceof URLClassLoader ) {
86-
logger.debug("classloader urls: {}", Arrays.toString(((URLClassLoader)loader).getURLs()));
87-
}
80+
output.accept("java.class.path: " + System.getProperty("java.class.path"));
81+
output.accept("sun.boot.class.path: " + System.getProperty("sun.boot.class.path"));
82+
if (loader instanceof URLClassLoader ) {
83+
output.accept("classloader urls: " + Arrays.toString(((URLClassLoader)loader).getURLs()));
8884
}
89-
checkJarHell(parseClassPath());
85+
checkJarHell(parseClassPath(), output);
9086
}
9187

9288
/**
@@ -155,28 +151,27 @@ static Set<URL> parseClassPath(String classPath) {
155151
* @throws IllegalStateException if jar hell was found
156152
*/
157153
@SuppressForbidden(reason = "needs JarFile for speed, just reading entries")
158-
public static void checkJarHell(Set<URL> urls) throws URISyntaxException, IOException {
159-
Logger logger = Loggers.getLogger(JarHell.class);
154+
public static void checkJarHell(Set<URL> urls, Consumer<String> output) throws URISyntaxException, IOException {
160155
// we don't try to be sneaky and use deprecated/internal/not portable stuff
161156
// like sun.boot.class.path, and with jigsaw we don't yet have a way to get
162157
// a "list" at all. So just exclude any elements underneath the java home
163158
String javaHome = System.getProperty("java.home");
164-
logger.debug("java.home: {}", javaHome);
159+
output.accept("java.home: " + javaHome);
165160
final Map<String,Path> clazzes = new HashMap<>(32768);
166161
Set<Path> seenJars = new HashSet<>();
167162
for (final URL url : urls) {
168163
final Path path = PathUtils.get(url.toURI());
169164
// exclude system resources
170165
if (path.startsWith(javaHome)) {
171-
logger.debug("excluding system resource: {}", path);
166+
output.accept("excluding system resource: " + path);
172167
continue;
173168
}
174169
if (path.toString().endsWith(".jar")) {
175170
if (!seenJars.add(path)) {
176171
throw new IllegalStateException("jar hell!" + System.lineSeparator() +
177172
"duplicate jar on classpath: " + path);
178173
}
179-
logger.debug("examining jar: {}", path);
174+
output.accept("examining jar: " + path);
180175
try (JarFile file = new JarFile(path.toString())) {
181176
Manifest manifest = file.getManifest();
182177
if (manifest != null) {
@@ -194,7 +189,7 @@ public static void checkJarHell(Set<URL> urls) throws URISyntaxException, IOExce
194189
}
195190
}
196191
} else {
197-
logger.debug("examining directory: {}", path);
192+
output.accept("examining directory: " + path);
198193
// case for tests: where we have class files in the classpath
199194
final Path root = PathUtils.get(url.toURI());
200195
final String sep = root.getFileSystem().getSeparator();

libs/elasticsearch-core/src/main/java/org/elasticsearch/common/logging/Loggers.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)