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 @@ -211,11 +211,14 @@ private static ComponentManager buildNewComponentManager() {
{
info("ComponentManager version: " + ComponentManagerVersion.VERSION);
info("Creating the contextual ComponentManager instance " + getIdentifiers());

parallelIf(Boolean.getBoolean("talend.component.manager.plugins.parallel"),
container.getDefinedNestedPlugin().stream().filter(p -> !hasPlugin(p)))
.forEach(this::addPlugin);
info("Components: " + availablePlugins());
try {
parallelIf(Boolean.getBoolean("talend.component.manager.plugins.parallel"),
container.getDefinedNestedPlugin().stream().filter(p -> !hasPlugin(p)))
.forEach(this::addPlugin);
info("Components: " + availablePlugins());
} catch (Exception e) {
info("Failed to load plugins from plugins.properties: " + e.getMessage());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ 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("main.jar", dependencies[0]); // transitive-1.0.0.jar is nested
assertEquals(2, dependencies.length); // ignored transitive deps, enables the new root to control it
assertEquals("fatjar.jar", dependencies[0]);
assertEquals("main.jar", dependencies[1]); // transitive-1.0.0.jar is nested
} finally {
if (!transitive.delete()) {
transitive.deleteOnExit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public class ConfigurableClassLoader extends URLClassLoader {
@Getter
private final List<String> cacheableClasses;

private List<URL> nestedURLs = new ArrayList<>();

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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ public Date getCreated() {
return created.get();
}

public boolean hasNestedRepository() {
return hasNestedRepository;
}

public void registerTransformer(final ClassFileTransformer transformer) {
transformers.add(transformer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -104,15 +107,18 @@

private final Pattern versionWithMilestone = Pattern.compile("M\\d+$");

public ContainerManager(final DependenciesResolutionConfiguration dependenciesResolutionConfiguration,

Check failure on line 110 in container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java#L110

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.
final ClassLoaderConfiguration classLoaderConfiguration, final Consumer<Container> containerInitializer,
final Level logInfoLevelMapping) {
this.logInfoLevelMapping = logInfoLevelMapping;
this.containerInitializer = containerInitializer;
this.resolver = dependenciesResolutionConfiguration.getResolver();
this.rootRepositoryLocation = dependenciesResolutionConfiguration.getRootRepositoryLocation();

info("Using root repository: " + this.rootRepositoryLocation.toAbsolutePath());
if (log.isDebugEnabled()) {
getSystemInformations();
}

final String nestedPluginMappingResource = ofNullable(classLoaderConfiguration.getNestedPluginMappingResource())
.orElse("TALEND-INF/plugins.properties");
this.classLoaderConfiguration = new ClassLoaderConfiguration(
Expand All @@ -124,6 +130,12 @@
try (final InputStream mappingStream =
classLoaderConfiguration.getParent().getResourceAsStream(nestedPluginMappingResource)) {
if (mappingStream != null) {
if (log.isDebugEnabled()) {
final URL plug = classLoaderConfiguration.getParent().getResource(nestedPluginMappingResource);
if (plug != null) {
log.debug("[sysinfo] plugins mapping " + plug.toString());
}
}
final Properties properties = new Properties() {

{
Expand All @@ -150,10 +162,13 @@
this.jvmMarkers = Stream
.concat(Stream.concat(Stream.of(getJre()), getComponentModules()), getCustomJvmMarkers())
.toArray(String[]::new);
this.hasNestedRepository =
this.classLoaderConfiguration.isSupportsResourceDependencies() && this.classLoaderConfiguration
.getParent()
.getResource(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY) != null;
final URL nestedMvn = this.classLoaderConfiguration
.getParent()
.getResource(ConfigurableClassLoader.NESTED_MAVEN_REPOSITORY);
this.hasNestedRepository = this.classLoaderConfiguration.isSupportsResourceDependencies() && nestedMvn != null;
if (log.isDebugEnabled() && hasNestedRepository) {
log.debug("[sysinfo] nested maven repository: " + nestedMvn);
}
}

public File getRootRepositoryLocation() {
Expand Down Expand Up @@ -389,6 +404,21 @@
.orElseThrow(IllegalArgumentException::new);
}

private void getSystemInformations() {
try {
final RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
log.debug("[sysinfo] JVM arguments: " + rt.getInputArguments());
try {

Check warning on line 411 in container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java#L411

Extract this nested try block into a separate method.
log.debug("[sysinfo] Boot classpath: " + rt.getBootClassPath());
} catch (Exception e) {

Check warning on line 413 in container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java

View check run for this annotation

sonar-eks / SonarQube Code Analysis

container/container-core/src/main/java/org/talend/sdk/component/container/ContainerManager.java#L413

Either remove or fill this block of code.
}
log.debug("[sysinfo] Runtime classpath: " + rt.getClassPath());
log.debug("[sysinfo] Runtime arguments: " + System.getProperty("sun.java.command"));
} catch (Exception e) {
log.debug("Unable to get JVM information: " + e.getMessage(), e);
}
}

@Override
public void close() {
lifecycle.closeIfNeeded(() -> {
Expand Down Expand Up @@ -472,8 +502,8 @@
? 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import java.io.Serializable;

import org.talend.sdk.component.api.configuration.Option;
import org.talend.sdk.component.api.configuration.type.DynamicDependenciesServiceConfiguration;
import org.talend.sdk.component.api.configuration.type.DynamicDependenciesConfiguration;
import org.talend.sdk.component.api.configuration.ui.layout.GridLayout;
import org.talend.sdk.component.api.meta.Documentation;

import lombok.Data;

@Data
@DynamicDependenciesServiceConfiguration
@DynamicDependenciesConfiguration
@GridLayout({
@GridLayout.Row({ "group" }),
@GridLayout.Row({ "artifact" })
Expand Down
Loading