Skip to content
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

Enhance MavenURLHandler to quarkus classloader #693

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.classpath
target/
release/ant\.properties
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
public class MavenURLHandler extends URLStreamHandler {

private static final String SEPARATOR = "!";
private static final String DIR_SEPARATOR = "/";

/**
* Default constructor, constructs a new object.
Expand All @@ -64,7 +65,15 @@ protected URLConnection openConnection(URL url) throws IOException {
if (StringUtils.contains(path, SEPARATOR)) {
path = StringUtils.substringAfter(path, SEPARATOR);
}
URL classPathUrl = Thread.currentThread().getContextClassLoader().getResource(path);
// Some runtime packaging (like Quarkus) may not be able to find the resource in the classpath.
// Quarkus dev mode vs package works differently.
// In dev mode, the resource is found in the classpath, but in the package needs to be searched for in the relative path.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL classPathUrl = classLoader.getResource(path);
if (classPathUrl == null && StringUtils.startsWith(path, DIR_SEPARATOR)) {
// If it cannot be found in the classpath, try to search for it using the relative path
classPathUrl = classLoader.getResource(StringUtils.substringAfter(path, DIR_SEPARATOR));
}

// Later on, you can simply search within the actual class.
return classPathUrl.openConnection();
Expand Down
3 changes: 2 additions & 1 deletion docs/en/migration/migration270to280.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ Changes are backwards compatible doesn't need any migration. It is recommended t

=== coffee-tool

The `RandomUtil` has been deprecated. The new `hu.icellmobilsoft.coffee.se.util.string.RandomUtil` should be used
* The `RandomUtil` has been deprecated. The new `hu.icellmobilsoft.coffee.se.util.string.RandomUtil` should be used
instean from the `coffee-se-util` module.
* The `MavenURLHandler` is optimized for Quarkus packaging.

==== Migration

Expand Down
3 changes: 2 additions & 1 deletion docs/hu/migration/migration270to280.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ A változtatások nem eredményeznek átállási munkálatokat, visszafelé komp

=== coffee-tool

A `RandomUtil` deprecated lett, helyette a `coffee-se-util` modulban található
* A `RandomUtil` deprecated lett, helyette a `coffee-se-util` modulban található
`hu.icellmobilsoft.coffee.se.util.string.RandomUtil` használandó.
* A `MavenURLHandler` optimalizálva lett a Quarkus csomagoláshoz.

==== Átállás

Expand Down
Loading