-
Notifications
You must be signed in to change notification settings - Fork 50
feat(QTDI-693): manage nested jars #969
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
base: master
Are you sure you want to change the base?
Changes from all commits
13c0656
b52c305
c079f78
b2386f1
e34c77c
fb44b73
409e850
940ab2b
5667ddb
f2bad61
a003c2a
1cfe2a6
29cdac2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -111,6 +111,8 @@ public class ConfigurableClassLoader extends URLClassLoader { | |||||
@Getter | ||||||
private final List<String> cacheableClasses; | ||||||
|
||||||
private List<URL> nestedURLs = new ArrayList<>(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The field should be declared as final since it's initialized once and never reassigned. Consider making it final for better immutability.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
public ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent, | ||||||
final Predicate<String> parentFilter, final Predicate<String> childFirstFilter, | ||||||
final String[] nestedDependencies, final String[] jvmPrefixes) { | ||||||
|
@@ -155,6 +157,7 @@ private void loadNestedDependencies(final ClassLoader parent, final String[] nes | |||||
if (url == null) { | ||||||
throw new IllegalArgumentException("Didn't find " + resource + " in " + asList(nestedDependencies)); | ||||||
} | ||||||
nestedURLs.add(url); | ||||||
final Map<String, Resource> resources = new HashMap<>(); | ||||||
final URLConnection urlConnection; | ||||||
final Manifest manifest; | ||||||
|
@@ -458,6 +461,15 @@ public Enumeration<URL> findResources(final String name) throws IOException { | |||||
return enumeration(aggregated); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public URL[] getURLs() { | ||||||
final List<URL> urls = new ArrayList<>(Arrays.asList(super.getURLs())); | ||||||
if (!nestedURLs.isEmpty()) { | ||||||
urls.addAll(nestedURLs); | ||||||
} | ||||||
return urls.toArray(new URL[0]); | ||||||
} | ||||||
|
||||||
private boolean isNestedDependencyResource(final String name) { | ||||||
return name != null && name.startsWith(NESTED_MAVEN_REPOSITORY); | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,9 +29,11 @@ | |||||||||||||
import java.io.IOException; | ||||||||||||||
import java.io.InputStream; | ||||||||||||||
import java.io.InputStreamReader; | ||||||||||||||
import java.net.URL; | ||||||||||||||
import java.nio.charset.StandardCharsets; | ||||||||||||||
import java.nio.file.Files; | ||||||||||||||
import java.nio.file.Path; | ||||||||||||||
import java.nio.file.Paths; | ||||||||||||||
import java.security.MessageDigest; | ||||||||||||||
import java.security.NoSuchAlgorithmException; | ||||||||||||||
import java.util.ArrayList; | ||||||||||||||
|
@@ -110,13 +112,19 @@ public ContainerManager(final DependenciesResolutionConfiguration dependenciesRe | |||||||||||||
this.logInfoLevelMapping = logInfoLevelMapping; | ||||||||||||||
this.containerInitializer = containerInitializer; | ||||||||||||||
this.resolver = dependenciesResolutionConfiguration.getResolver(); | ||||||||||||||
this.rootRepositoryLocation = ofNullable(dependenciesResolutionConfiguration.getRootRepositoryLocation()) | ||||||||||||||
.filter(Files::exists) | ||||||||||||||
.orElseGet(() -> PathFactory.get(System.getProperty("user.home", "")).resolve(".m2/repository")); | ||||||||||||||
|
||||||||||||||
if (log.isDebugEnabled()) { | ||||||||||||||
log.debug("Using root repository: " + this.rootRepositoryLocation.toAbsolutePath()); | ||||||||||||||
Path rootRepo = ofNullable(dependenciesResolutionConfiguration.getRootRepositoryLocation()) | ||||||||||||||
.filter(Files::exists) | ||||||||||||||
.orElseGet(() -> PathFactory.get(System.getProperty("user.home")).resolve(".m2/repository")); | ||||||||||||||
// if we've defaulted to user home m2 (fallback), we want to check if we're in running in a fatjar | ||||||||||||||
if (PathFactory.get(System.getProperty("user.home")).resolve(".m2/repository").equals(rootRepo)) { | ||||||||||||||
ozhelezniak-talend marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+118
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed null fallback for System.getProperty("user.home") that was present in the original code. This could cause NullPointerException if the system property is not set.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
final URL nested = classLoaderConfiguration.getParent().getResource("MAVEN-INF/repository"); | ||||||||||||||
if (nested != null) { | ||||||||||||||
rootRepo = Paths.get(nested.getFile().replace("file:", "")); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using simple string replacement for URL handling is unreliable and may fail with encoded URLs or different URL formats. Consider using URI.create(nested.toString()).getPath() or proper URL decoding instead.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
this.rootRepositoryLocation = rootRepo; | ||||||||||||||
info("Using root repository: " + this.rootRepositoryLocation.toAbsolutePath()); | ||||||||||||||
|
||||||||||||||
final String nestedPluginMappingResource = ofNullable(classLoaderConfiguration.getNestedPluginMappingResource()) | ||||||||||||||
.orElse("TALEND-INF/plugins.properties"); | ||||||||||||||
|
@@ -477,8 +485,8 @@ public Container create() { | |||||||||||||
? nestedContainerMapping.getOrDefault(module, module) | ||||||||||||||
: module; | ||||||||||||||
final Path resolved = resolve(moduleLocation); | ||||||||||||||
info("Creating module " + moduleLocation + " (from " + module | ||||||||||||||
+ (Files.exists(resolved) ? ", location=" + resolved.toAbsolutePath().toString() : "") + ")"); | ||||||||||||||
info(String.format("Creating module %s (from %s, location=%s)", moduleLocation, module, | ||||||||||||||
resolved.toAbsolutePath())); | ||||||||||||||
final Stream<Artifact> classpath = Stream | ||||||||||||||
.concat(getBuiltInClasspath(moduleLocation), | ||||||||||||||
additionalClasspath == null ? Stream.empty() : additionalClasspath.stream()); | ||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.