Skip to content

Commit 185b176

Browse files
committed
Remove log4j dependency from elasticsearch-core (#28705)
* 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 #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 #28504 * Add javadocs for `output` parameter * Change @code to @link
1 parent 421b097 commit 185b176

File tree

48 files changed

+195
-441
lines changed

Some content is hidden

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

48 files changed

+195
-441
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: 16 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,23 @@ 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
76+
* @param output A {@link String} {@link Consumer} to which debug output will be sent
7777
* @throws IllegalStateException if jar hell was found
7878
*/
79-
public static void checkJarHell() throws IOException, URISyntaxException {
79+
public static void checkJarHell(Consumer<String> output) throws IOException, URISyntaxException {
8080
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-
}
81+
output.accept("java.class.path: " + System.getProperty("java.class.path"));
82+
output.accept("sun.boot.class.path: " + System.getProperty("sun.boot.class.path"));
83+
if (loader instanceof URLClassLoader) {
84+
output.accept("classloader urls: " + Arrays.toString(((URLClassLoader)loader).getURLs()));
8885
}
89-
checkJarHell(parseClassPath());
86+
checkJarHell(parseClassPath(), output);
9087
}
9188

9289
/**
@@ -152,31 +149,32 @@ static Set<URL> parseClassPath(String classPath) {
152149

153150
/**
154151
* Checks the set of URLs for duplicate classes
152+
* @param urls A set of URLs from the classpath to be checked for conflicting jars
153+
* @param output A {@link String} {@link Consumer} to which debug output will be sent
155154
* @throws IllegalStateException if jar hell was found
156155
*/
157156
@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);
157+
public static void checkJarHell(Set<URL> urls, Consumer<String> output) throws URISyntaxException, IOException {
160158
// we don't try to be sneaky and use deprecated/internal/not portable stuff
161159
// like sun.boot.class.path, and with jigsaw we don't yet have a way to get
162160
// a "list" at all. So just exclude any elements underneath the java home
163161
String javaHome = System.getProperty("java.home");
164-
logger.debug("java.home: {}", javaHome);
162+
output.accept("java.home: " + javaHome);
165163
final Map<String,Path> clazzes = new HashMap<>(32768);
166164
Set<Path> seenJars = new HashSet<>();
167165
for (final URL url : urls) {
168166
final Path path = PathUtils.get(url.toURI());
169167
// exclude system resources
170168
if (path.startsWith(javaHome)) {
171-
logger.debug("excluding system resource: {}", path);
169+
output.accept("excluding system resource: " + path);
172170
continue;
173171
}
174172
if (path.toString().endsWith(".jar")) {
175173
if (!seenJars.add(path)) {
176174
throw new IllegalStateException("jar hell!" + System.lineSeparator() +
177175
"duplicate jar on classpath: " + path);
178176
}
179-
logger.debug("examining jar: {}", path);
177+
output.accept("examining jar: " + path);
180178
try (JarFile file = new JarFile(path.toString())) {
181179
Manifest manifest = file.getManifest();
182180
if (manifest != null) {
@@ -194,7 +192,7 @@ public static void checkJarHell(Set<URL> urls) throws URISyntaxException, IOExce
194192
}
195193
}
196194
} else {
197-
logger.debug("examining directory: {}", path);
195+
output.accept("examining directory: " + path);
198196
// case for tests: where we have class files in the classpath
199197
final Path root = PathUtils.get(url.toURI());
200198
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)