Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

@Target(TYPE)
@Retention(RUNTIME)
@ConfigurationType("dynamicDependenciesServiceConfiguration")
@Documentation("Mark a model (complex object) as being the configuration used in services annotated with @DynamicDependencies.")
public @interface DynamicDependenciesServiceConfiguration {
@ConfigurationType("dynamicDependenciesConfiguration")
@Documentation("Mark a model (complex object) as being the configuration expected to compute dynamic dependencies.")
public @interface DynamicDependenciesConfiguration {

String value() default "default";
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import org.apache.xbean.finder.archive.FileArchive;
import org.apache.xbean.finder.archive.FilteredArchive;
import org.apache.xbean.finder.archive.JarArchive;
import org.apache.xbean.finder.filter.ContainsFilter;
import org.apache.xbean.finder.filter.ExcludeIncludeFilter;
import org.apache.xbean.finder.filter.Filter;
import org.apache.xbean.finder.filter.FilterList;
Expand Down Expand Up @@ -312,6 +313,8 @@
// + tcomp "runtime" indeed (invisible from the components but required for the runtime
private final Filter classesFilter;

private final Filter resourcesFilter;

private final ParameterModelService parameterModelService;

private final InternationalizationServiceFactory internationalizationServiceFactory;
Expand Down Expand Up @@ -427,6 +430,13 @@
.map(PrefixFilter::new)
.toArray(Filter[]::new));

resourcesFilter = new FilterList(Stream.concat(
Stream.of("META-INF/services/"),
additionalParentResources())
.distinct()
.map(ContainsFilter::new)
.toArray(Filter[]::new));

jsonpProvider = loadJsonProvider();
jsonbProvider = loadJsonbProvider();
// these factories have memory caches so ensure we reuse them properly
Expand Down Expand Up @@ -460,13 +470,15 @@
migrationHandlerFactory = new MigrationHandlerFactory(reflections);

final Predicate<String> isContainerClass = name -> isContainerClass(classesFilter, name);
final Predicate<String> isParentResource = name -> isContainerResource(resourcesFilter, name);
final ContainerManager.ClassLoaderConfiguration defaultClassLoaderConfiguration =
ContainerManager.ClassLoaderConfiguration
.builder()
.parent(tccl)
.parentClassesFilter(isContainerClass)
.classesFilter(isContainerClass.negate())
.supportsResourceDependencies(true)
.parentResourcesFilter(isParentResource)
.create();
this.container = new ContainerManager(ContainerManager.DependenciesResolutionConfiguration
.builder()
Expand Down Expand Up @@ -611,6 +623,16 @@
.orElseGet(Stream::empty));
}

private Stream<String> additionalParentResources() {
return Stream
.concat(customizers.stream().flatMap(Customizer::parentResources),
ofNullable(
System.getProperty("talend.component.manager.classloader.container.parentResources"))
.map(s -> s.split(","))
.map(Stream::of)
.orElseGet(Stream::empty));
}

public static Path findM2() {
return new MavenRepositoryDefaultResolver().discover();
}
Expand Down Expand Up @@ -891,7 +913,7 @@
}
}

private void autoDiscoverPlugins0(final boolean callers, final boolean classpath) {

Check failure on line 916 in component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java#L916

Refactor this method to reduce its Cognitive Complexity from 31 to the 15 allowed.
if (callers && !Boolean.getBoolean("component.manager.callers.skip")) {
addCallerAsPlugin();
}
Expand All @@ -899,16 +921,30 @@
// common for studio until job generation is updated to build a tcomp friendly bundle
if (classpath && !Boolean.getBoolean("component.manager.classpath.skip")) {
try {
final String markerValue = "TALEND-INF/dependencies.txt";
final Enumeration<URL> componentMarkers =
Thread.currentThread().getContextClassLoader().getResources("TALEND-INF/dependencies.txt");
Thread.currentThread().getContextClassLoader().getResources(markerValue);
while (componentMarkers.hasMoreElements()) {
File file = Files.toFile(componentMarkers.nextElement());
if (file.getName().equals("dependencies.txt") && file.getParentFile() != null
&& file.getParentFile().getName().equals("TALEND-INF")) {
file = file.getParentFile().getParentFile();
}
if (!hasPlugin(container.buildAutoIdFromName(file.getName()))) {
addPlugin(file.getAbsolutePath());
final URL marker = componentMarkers.nextElement();
File file = Files.toFile(marker);
if (file != null) {
if (file.getName().equals("dependencies.txt") && file.getParentFile() != null
&& file.getParentFile().getName().equals("TALEND-INF")) {
file = file.getParentFile().getParentFile();
}
if (!hasPlugin(container.buildAutoIdFromName(file.getName()))) {
addPlugin(file.getAbsolutePath());
}
} else {
// lookup nested jar
if (marker != null && "jar".equals(marker.getProtocol())) {
final String urlFile = marker.getFile();
final String jarPath = urlFile.substring(0, urlFile.lastIndexOf("!"));
final String jarFilePath = jarPath.substring(jarPath.lastIndexOf("/") + 1);
Comment on lines +942 to +943
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using lastIndexOf(\"/\") for extracting the filename is platform-dependent and will fail on Windows where paths use backslashes. Use Paths.get(new URI(jarPath)).getFileName().toString() or similar platform-independent approach.

Copilot uses AI. Check for mistakes.
if (!hasPlugin(container.buildAutoIdFromName(jarFilePath))) {
addPlugin(jarPath);
}
}
}
}
} catch (final IOException e) {
Expand Down Expand Up @@ -1045,6 +1081,10 @@
return name != null && filter.accept(name);
}

protected boolean isContainerResource(final Filter filter, final String name) {
return name != null && filter.accept(name);
}

@Override
public void close() {
container.close();
Expand Down Expand Up @@ -1292,18 +1332,21 @@
.collect(toSet());

@Override
public void onCreate(final Container container) {

Check failure on line 1335 in component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

component-runtime-manager/src/main/java/org/talend/sdk/component/runtime/manager/ComponentManager.java#L1335

Refactor this method to reduce its Cognitive Complexity from 25 to the 15 allowed.
final ConfigurableClassLoader loader = container.getLoader();
final OriginalId originalId = OriginalId.class.cast(container.get(OriginalId.class));
final Map<java.lang.reflect.Type, Optional<Converter>> xbeanConverterCache = new ConcurrentHashMap<>();

final AnnotationFinder finder;
Archive archive = null;
final String rootModule = container.getRootModule();
final boolean nested = rootModule != null && rootModule.startsWith("nested:");
try {
String alreadyScannedClasses = null;
Filter filter = KnownClassesFilter.INSTANCE;
try (final InputStream containerFilterConfig =
container.getLoader().getResourceAsStream("TALEND-INF/scanning.properties")) {
try (final InputStream containerFilterConfig = nested
? loader.getNestedResource(rootModule + "!/TALEND-INF/scanning.properties")
: loader.getResourceAsStream("TALEND-INF/scanning.properties")) {
if (containerFilterConfig != null) {
final Properties config = new Properties();
config.load(containerFilterConfig);
Expand Down Expand Up @@ -1778,8 +1821,10 @@
}
}
info(module + " (" + moduleId + ") is not a file, will try to look it up from a nested maven repository");
final URL nestedJar =
loader.getParent().getResource(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + module);
URL nestedJar = loader.getParent().getResource(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY + module);
if (nestedJar == null) {
nestedJar = loader.getParent().getResource(module);
}
if (nestedJar != null) {
InputStream nestedStream = null;
final JarInputStream jarStream;
Expand Down Expand Up @@ -2207,6 +2252,13 @@
*/
Stream<String> containerClassesAndPackages();

/**
* @return
*/
default Stream<String> parentResources() {
return Stream.empty();
}

/**
* @return advanced toggle to ignore built-in beam exclusions and let this customizer override them.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ClassLoaderDescriptor mapDescriptorToClassLoader(final InputStream descri
} catch (final MalformedURLException e) {
throw new IllegalStateException(e);
}
} else if (loader.getResource("MAVEN-INF/repository/" + path) != null) {
} else if (loader.getResource(path) != null) {
nested.add(path);
resolved.add(artifact.toCoordinate());
} // else will be missing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
import javax.management.ReflectionException;

import org.apache.xbean.finder.util.Files;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -98,6 +100,16 @@ private ComponentManager newManager() {
return newManager(new File("target/test-dependencies"));
}

@BeforeAll
static void setup() {
System.setProperty("talend.component.manager.m2.fallback", "true");
}

@AfterAll
static void teardown() {
System.clearProperty("talend.component.manager.m2.fallback");
}

@Test
void doubleClose() {
final ComponentManager instance = ComponentManager.instance();
Expand Down Expand Up @@ -417,7 +429,7 @@ void extendFamilyInNestedRepo(@TempDir final File temporaryFolder) throws Except
final URLClassLoader parentLoader =
new URLClassLoader(new URL[] { fatJar.toURI().toURL() }, thread.getContextClassLoader());
thread.setContextClassLoader(parentLoader);
try (final ComponentManager manager = newManager(new File("target/missing_" + UUID.randomUUID().toString()))) {
try (final ComponentManager manager = newManager(pluginFolder)) {
try {
manager.addPlugin(plugin2.getAbsolutePath());

Expand All @@ -429,7 +441,7 @@ void extendFamilyInNestedRepo(@TempDir final File temporaryFolder) throws Except
.map(File::getName)
.sorted()
.toArray(String[]::new);
assertEquals(1, dependencies.length); // ignored transitive deps, enables the new root to control it
assertEquals(2, dependencies.length); // ignored transitive deps, enables the new root to control it
assertEquals("main.jar", dependencies[0]); // transitive-1.0.0.jar is nested
} finally {
if (!transitive.delete()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void resolvefromDescriptor() throws IOException {

private void addDepToJar(final String dep, final JarOutputStream out) {
final String[] segments = dep.split(":");
final String path = "MAVEN-INF/repository/" + segments[0].replace(".", "/") + "/" + segments[1] + "/"
final String path = segments[0].replace(".", "/") + "/" + segments[1] + "/"
+ segments[3] + "/" + segments[1] + "-" + segments[3] + "." + segments[2];

// create folders for this m2 embedded deps
Expand All @@ -114,7 +114,7 @@ private void addDepToJar(final String dep, final JarOutputStream out) {
}
}
// add the dep
final File jar = new File("target/test-dependencies", path.substring("MAVEN-INF/repository/".length()));
final File jar = new File("target/test-dependencies", path);
try {
out.putNextEntry(new ZipEntry(path));
Files.copy(jar.toPath(), out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void xbeanNestedScanning(final TestInfo info, @TempDir final File temporaryFolde
final File jar = createPlugin(temporaryFolder, info.getTestMethod().get().getName());
final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0],
new URLClassLoader(new URL[] { jar.toURI().toURL() }, Thread.currentThread().getContextClassLoader()),
n -> true, n -> true, new String[] { "com/foo/bar/1.0/bar-1.0.jar" }, new String[0]);
n -> true, n -> true, new String[] { "BOOT-INF/lib/com/foo/bar/1.0/bar-1.0.jar" }, new String[0]);
try (final JarInputStream jis = new JarInputStream(
configurableClassLoader.getResourceAsStream("MAVEN-INF/repository/com/foo/bar/1.0/bar-1.0.jar"))) {
configurableClassLoader.getResourceAsStream("BOOT-INF/lib/com/foo/bar/1.0/bar-1.0.jar"))) {
assertNotNull(jis, "test is wrongly setup, no nested jar, fix the createPlugin() method please");
final AnnotationFinder finder =
new AnnotationFinder(new NestedJarArchive(null, jis, configurableClassLoader));
Expand All @@ -72,7 +72,7 @@ private File createPlugin(final File pluginFolder, final String name) throws IOE
final File target = new File(pluginFolder, name);
target.getParentFile().mkdirs();
try (final JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(target))) {
outputStream.putNextEntry(new ZipEntry("MAVEN-INF/repository/com/foo/bar/1.0/bar-1.0.jar"));
outputStream.putNextEntry(new ZipEntry("BOOT-INF/lib/com/foo/bar/1.0/bar-1.0.jar"));
try (final JarOutputStream nestedStream = new JarOutputStream(outputStream)) {
final String packageName = "org/talend/test/generated/" + name.replace(".jar", "");
{ // the factory (declaration)
Expand Down
Loading
Loading