-
Notifications
You must be signed in to change notification settings - Fork 68
Fix log4j bad versions #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mgaffigan
wants to merge
3
commits into
OpenIntegrationEngine:main
Choose a base branch
from
mgaffigan:fix/junit-bad-versions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
server/src/main/java/com/mirth/connect/server/launcher/Log4jBootstrap.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2026 Mitch Gaffigan <mitch@gaffigan.net> | ||
|
|
||
| package com.mirth.connect.server.launcher; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileFilter; | ||
| import java.io.IOException; | ||
| import java.net.URL; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.commons.io.filefilter.WildcardFileFilter; | ||
|
|
||
| /** Utility class for bootstrapping Log4j. */ | ||
| final class Log4jBootstrap { | ||
| private static final File LOG4J_LIB_DIR = new File("./server-lib/log4j"); | ||
| private static final String[] JAR_PATTERNS = { "log4j-core-*.jar", "log4j-api-*.jar", "log4j-1.2-api-*.jar" }; | ||
|
|
||
| private Log4jBootstrap() {} | ||
|
|
||
| /** Returns the classpath URLs for the Log4j libraries. */ | ||
| static List<URL> getClasspathUrls() throws IOException { | ||
| return getClasspathUrls(LOG4J_LIB_DIR); | ||
| } | ||
|
|
||
| /** Unit testable version of getClasspathUrls. */ | ||
| static List<URL> getClasspathUrls(File log4jLibDir) throws IOException { | ||
| List<URL> log4jClasspathUrls = new ArrayList<>(); | ||
|
|
||
| for (String jarPattern : JAR_PATTERNS) { | ||
| File[] matchingFiles = log4jLibDir.listFiles((FileFilter) new WildcardFileFilter(jarPattern)); | ||
| if (matchingFiles == null || matchingFiles.length != 1) { | ||
| throw new IOException("Expected exactly one " + jarPattern + " in " + log4jLibDir.getAbsolutePath()); | ||
| } | ||
| log4jClasspathUrls.add(matchingFiles[0].toURI().toURL()); | ||
| } | ||
|
|
||
| return log4jClasspathUrls; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/src/test/java/com/mirth/connect/server/launcher/Log4jBootstrapTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2026 Mitch Gaffigan <mitch@gaffigan.net> | ||
|
|
||
| package com.mirth.connect.server.launcher; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.File; | ||
| import java.net.URL; | ||
| import java.nio.file.Files; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** Unit tests for {@link Log4jBootstrap}. */ | ||
| public class Log4jBootstrapTest { | ||
|
|
||
| /** Tests that {@link Log4jBootstrap#getClasspathUrls(File)} correctly resolves Log4j JARs regardless of version. */ | ||
| @Test | ||
| public void testGetClasspathUrlsDoesNotDependOnVersions() throws Exception { | ||
| File log4jLibDir = Files.createTempDirectory("log4j").toFile(); | ||
| log4jLibDir.deleteOnExit(); | ||
|
|
||
| for (String name : Arrays.asList("log4j-core-99.0.0.jar", "log4j-api-99.0.0.jar", "log4j-1.2-api-99.0.0.jar")) { | ||
| File jarFile = new File(log4jLibDir, name); | ||
| assertTrue(jarFile.createNewFile()); | ||
| jarFile.deleteOnExit(); | ||
| } | ||
|
|
||
| List<URL> classpathUrls = Log4jBootstrap.getClasspathUrls(log4jLibDir); | ||
|
|
||
| assertEquals(Arrays.asList( | ||
| new File(log4jLibDir, "log4j-core-99.0.0.jar").toURI().toURL(), | ||
| new File(log4jLibDir, "log4j-api-99.0.0.jar").toURI().toURL(), | ||
| new File(log4jLibDir, "log4j-1.2-api-99.0.0.jar").toURI().toURL()), classpathUrls); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's going on with the jackson stuff. I don't think it is supposed to be in this PR? Additionally, this version doesn't match what is in libs.versions.toml, and there are already newer versions specified in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was generated by the normal Gradle regen command. I assumed it had some interaction with another package or was missed in a prior PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonygermano, is this blocking or are we good to merge?