Skip to content

Commit

Permalink
Merge pull request #35 from OP-TED/feature/TEDEFO-3325-improve-and-fi…
Browse files Browse the repository at this point in the history
…x-core-reflection-logs

TEDEFO-3325 added more debug logs which give insight into the package…
  • Loading branch information
rouschr authored May 6, 2024
2 parents db8bb0e + 83c1fb6 commit 287e763
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
SdkComponentDescriptor<?> other = (SdkComponentDescriptor<?>) obj;
return componentType == other.componentType
return componentType == other.componentType
&& Objects.equals(sdkVersion, other.sdkVersion)
&& Objects.equals(qualifier, other.qualifier)
&& Objects.equals(implType, other.implType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -78,6 +80,12 @@ private void populateComponents() {
.map(Package::getName)
.toArray(String[]::new);

if (logger.isTraceEnabled()) {
final List<String> packages = Arrays.asList(availablePackages);
packages.stream().sorted()
.forEach(p -> logger.trace(p));
}

new Reflections(ConfigurationBuilder.build().forPackages(availablePackages))
.getTypesAnnotatedWith(annotationType).stream()
.forEach((Class<?> clazz) -> {
Expand Down Expand Up @@ -126,22 +134,39 @@ protected <T> T getComponentImpl(String sdkVersion, final SdkComponentType compo
}

protected <T> T getComponentImpl(String sdkVersion, final SdkComponentType componentType,
final String qualifier, final Class<T> intf, Object... initArgs) throws InstantiationException {
final String qualifier, final Class<T> intf, Object... initArgs)
throws InstantiationException {

String normalizedVersion = normalizeVersion(sdkVersion);

ComponentSelector selector = new ComponentSelector(componentType, qualifier);

Map<ComponentSelector, SdkComponentDescriptor<?>> map =
Optional.ofNullable(componentsMap.get(normalizedVersion))
.orElseGet(Collections::emptyMap);

if (logger.isTraceEnabled()) {
logger.trace("Looking for component with version=[{}], componentType=[{}], qualifier=[{}]",
normalizedVersion, selector.componentType, selector.qualifier);
for (Entry<ComponentSelector, SdkComponentDescriptor<?>> entry : map.entrySet()) {
logger.trace(
"Available component for this version: "
+ "componentType=[{}], qualifier=[{}], value=[{}]",
entry.getKey().componentType,
entry.getKey().qualifier,
entry.getValue().getImplType().getName());
}
}

@SuppressWarnings("unchecked")
SdkComponentDescriptor<T> descriptor =
(SdkComponentDescriptor<T>) Optional.ofNullable(componentsMap.get(normalizedVersion))
.orElseGet(Collections::emptyMap).get(selector);
(SdkComponentDescriptor<T>) map.get(selector);

if (descriptor == null) {
logger.error("Failed to load required components of SDK [{}]", sdkVersion);
throw new IllegalArgumentException(
MessageFormat.format(
"No implementation found for SDK [{0}], component type [{1}] and qualifier '{2}'.",
"No implementation found for SDK [{0}], component type [{1}] and qualifier [{2}].",
sdkVersion, componentType, qualifier));
}

Expand Down

0 comments on commit 287e763

Please sign in to comment.