diff --git a/core/common/boot/src/main/java/org/eclipse/edc/boot/BootServicesExtension.java b/core/common/boot/src/main/java/org/eclipse/edc/boot/BootServicesExtension.java index 94a47f78d57..30b7e395881 100644 --- a/core/common/boot/src/main/java/org/eclipse/edc/boot/BootServicesExtension.java +++ b/core/common/boot/src/main/java/org/eclipse/edc/boot/BootServicesExtension.java @@ -18,7 +18,6 @@ import org.eclipse.edc.boot.health.HealthCheckServiceImpl; import org.eclipse.edc.boot.system.ExtensionLoader; import org.eclipse.edc.boot.vault.InMemoryVault; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Provider; import org.eclipse.edc.runtime.metamodel.annotation.Setting; @@ -33,7 +32,6 @@ import java.time.Clock; -@BaseExtension @Extension(value = BootServicesExtension.NAME) public class BootServicesExtension implements ServiceExtension { diff --git a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/DependencyGraph.java b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/DependencyGraph.java index d6559d7d862..e3fd5e437a5 100644 --- a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/DependencyGraph.java +++ b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/DependencyGraph.java @@ -23,8 +23,6 @@ import org.eclipse.edc.boot.system.injection.lifecycle.ServiceProvider; import org.eclipse.edc.boot.util.CyclicDependencyException; import org.eclipse.edc.boot.util.TopologicalSort; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; -import org.eclipse.edc.runtime.metamodel.annotation.CoreExtension; import org.eclipse.edc.runtime.metamodel.annotation.Provides; import org.eclipse.edc.runtime.metamodel.annotation.Requires; import org.eclipse.edc.spi.EdcException; @@ -33,7 +31,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -45,7 +42,6 @@ import static java.util.Optional.ofNullable; import static java.util.function.Function.identity; -import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import static java.util.stream.Collectors.toSet; @@ -67,14 +63,13 @@ public DependencyGraph(ServiceExtensionContext context) { * Depending Extensions (i.e. those who express a dependency) are sorted first, providing extensions (i.e. those * who provide a dependency) are sorted last. * - * @param loadedExtensions A list of {@link ServiceExtension} instances that were picked up by the {@link ServiceLocator} + * @param extensions A list of {@link ServiceExtension} instances that were picked up by the {@link ServiceLocator} * @return A list of {@link InjectionContainer}s that are sorted topologically according to their dependencies. * @throws CyclicDependencyException when there is a dependency cycle * @see TopologicalSort * @see InjectionContainer */ - public List> of(List loadedExtensions) { - var extensions = sortByType(loadedExtensions); + public List> of(List extensions) { Map, ServiceProvider> defaultServiceProviders = new HashMap<>(); Map> serviceProviders = new HashMap<>(); Map, List> dependencyMap = new HashMap<>(); @@ -136,19 +131,18 @@ public List> of(List load })); if (!unsatisfiedInjectionPoints.isEmpty()) { - var string = "The following injected fields were not provided:\n"; - string += unsatisfiedInjectionPoints.stream().map(InjectionPoint::toString).collect(Collectors.joining("\n")); - throw new EdcInjectionException(string); + var message = "The following injected fields were not provided:\n"; + message += unsatisfiedInjectionPoints.stream().map(InjectionPoint::toString).collect(Collectors.joining("\n")); + throw new EdcInjectionException(message); } if (!unsatisfiedRequirements.isEmpty()) { - var string = String.format("The following @Require'd features were not provided: [%s]", String.join(", ", unsatisfiedRequirements)); - throw new EdcException(string); + var message = String.format("The following @Require'd features were not provided: [%s]", String.join(", ", unsatisfiedRequirements)); + throw new EdcException(message); } sort.sort(extensions); - // convert the sorted list of extensions into an equally sorted list of InjectionContainers return extensions.stream() .map(key -> new InjectionContainer<>(key, injectionPoints.get(key), serviceProviders.get(key))) .toList(); @@ -188,24 +182,4 @@ private Set> getProvidedFeatures(ServiceExtension ext) { return allProvides; } - /** - * Handles core-, transfer- and contract-extensions and inserts them at the beginning of the list so that - * explicit @Requires annotations are not necessary - */ - private List sortByType(List loadedExtensions) { - return loadedExtensions.stream().sorted(new SortByType()).collect(toList()); - } - - private static class SortByType implements Comparator { - @Override - public int compare(ServiceExtension o1, ServiceExtension o2) { - return orderFor(o1.getClass()).compareTo(orderFor(o2.getClass())); - } - - private Integer orderFor(Class class1) { - return class1.getAnnotation(BaseExtension.class) != null - ? 0 : class1.getAnnotation(CoreExtension.class) != null - ? 1 : 2; - } - } } diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/DependencyGraphTest.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/DependencyGraphTest.java index e9cf2b27d6e..11aa365ca30 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/DependencyGraphTest.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/DependencyGraphTest.java @@ -14,37 +14,28 @@ package org.eclipse.edc.boot.system; -import org.assertj.core.data.Index; import org.eclipse.edc.boot.system.injection.EdcInjectionException; import org.eclipse.edc.boot.system.injection.InjectionContainer; -import org.eclipse.edc.spi.system.ServiceExtensionContext; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.eclipse.edc.boot.system.TestFunctions.mutableListOf; import static org.mockito.Mockito.mock; class DependencyGraphTest { - private DependencyGraph graph; - - @BeforeEach - void setUp() { - graph = new DependencyGraph(mock(ServiceExtensionContext.class)); - } + private final DependencyGraph graph = new DependencyGraph(mock()); @Test void sortExtensions_withDefaultProvider() { var providerExtension = TestFunctions.createProviderExtension(true); - var dependentExtension = TestFunctions.createDependentExtension(true); - var list = graph.of(TestFunctions.createList(dependentExtension, providerExtension)); - assertThat(list).extracting(InjectionContainer::getInjectionTarget) - .contains(providerExtension, Index.atIndex(2)) - .contains(dependentExtension, Index.atIndex(3)); + var list = graph.of(mutableListOf(dependentExtension, providerExtension)); + assertThat(list).extracting(InjectionContainer::getInjectionTarget) + .containsExactly(providerExtension, dependentExtension); } @Test @@ -53,27 +44,28 @@ void sortExtensions_withNoDefaultProvider() { var provider = TestFunctions.createProviderExtension(true); var dependentExtension = TestFunctions.createDependentExtension(true); - var list = graph.of(TestFunctions.createList(dependentExtension, provider, defaultProvider)); + var list = graph.of(mutableListOf(dependentExtension, provider, defaultProvider)); + assertThat(list).extracting(InjectionContainer::getInjectionTarget) - .contains(provider, Index.atIndex(2)) - .contains(defaultProvider, Index.atIndex(3)) - .contains(dependentExtension, Index.atIndex(4)); + .containsExactly(provider, defaultProvider, dependentExtension); } @Test void sortExtensions_missingDependency() { - var dependentExtension = TestFunctions.createDependentExtension(true); - assertThatThrownBy(() -> graph.of(TestFunctions.createList(dependentExtension))).isInstanceOf(EdcInjectionException.class); + + assertThatThrownBy(() -> graph.of(mutableListOf(dependentExtension))) + .isInstanceOf(EdcInjectionException.class); } @Test void sortExtensions_missingOptionalDependency() { - var dependentExtension = TestFunctions.createDependentExtension(false); - assertThat(graph.of(TestFunctions.createList(dependentExtension))).hasSize(3) + + var injectionContainers = graph.of(mutableListOf(dependentExtension)); + + assertThat(injectionContainers).hasSize(1) .extracting(InjectionContainer::getInjectionTarget) - .usingRecursiveFieldByFieldElementComparator() - .containsOnly(dependentExtension); + .containsExactly(dependentExtension); } -} \ No newline at end of file +} diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/ExtensionLoaderTest.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/ExtensionLoaderTest.java index c00591932b3..6d1f3a3624d 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/ExtensionLoaderTest.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/ExtensionLoaderTest.java @@ -21,7 +21,6 @@ import org.eclipse.edc.boot.system.injection.EdcInjectionException; import org.eclipse.edc.boot.system.injection.InjectionContainer; import org.eclipse.edc.boot.util.CyclicDependencyException; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provides; import org.eclipse.edc.runtime.metamodel.annotation.Requires; @@ -49,7 +48,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -59,7 +57,6 @@ class ExtensionLoaderTest { private final ServiceLocator serviceLocator = mock(); - private final ServiceExtension coreExtension = new TestCoreExtension(); private final ServiceExtensionContext context = mock(); private final ExtensionLoader loader = new ExtensionLoader(serviceLocator); @@ -88,14 +85,14 @@ void loadMonitor_whenMultipleMonitorExtensions() { var monitor = ExtensionLoader.loadMonitor(exts); - assertTrue(monitor instanceof MultiplexingMonitor); + assertThat(monitor).isInstanceOf(MultiplexingMonitor.class); } @Test void loadMonitor_whenNoMonitorExtension() { var monitor = ExtensionLoader.loadMonitor(new ArrayList<>()); - assertTrue(monitor instanceof ConsoleMonitor); + assertThat(monitor).isInstanceOf(ConsoleMonitor.class); } @ParameterizedTest @@ -148,12 +145,11 @@ void loadServiceExtensions_noDependencies() { var service1 = new ServiceExtension() { }; - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(service1, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(service1)); var list = loader.loadServiceExtensions(context); - assertThat(list).hasSize(2); - assertThat(list).extracting(InjectionContainer::getInjectionTarget).contains(service1); + assertThat(list).hasSize(1).extracting(InjectionContainer::getInjectionTarget).containsExactly(service1); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -165,11 +161,11 @@ void loadServiceExtensions_whenMultipleServices() { var service2 = new ServiceExtension() { }; - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(service1, service2, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(service1, service2)); var list = loader.loadServiceExtensions(context); - assertThat(list).hasSize(3); - assertThat(list).extracting(InjectionContainer::getInjectionTarget).containsExactlyInAnyOrder(service1, service2, coreExtension); + + assertThat(list).hasSize(2).extracting(InjectionContainer::getInjectionTarget).containsExactly(service1, service2); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -180,14 +176,13 @@ void loadServiceExtensions_withBackwardsDependency() { var someExtension = new SomeExtension(); var providing = new ProvidingExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(providing, depending, someExtension, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(providing, depending, someExtension)); var services = loader.loadServiceExtensions(context); - assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(coreExtension, providing, depending, someExtension); + assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(providing, depending, someExtension); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } - @Test @DisplayName("A service extension has a dependency on another one of the same loading stage") void loadServiceExtensions_withEqualDependency() { @@ -199,10 +194,10 @@ void loadServiceExtensions_withEqualDependency() { var thirdService = new ServiceExtension() { }; - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, thirdService, coreService, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, thirdService, coreService)); var services = loader.loadServiceExtensions(context); - assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactlyInAnyOrder(coreService, depending, thirdService, coreExtension); + assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactlyInAnyOrder(coreService, depending, thirdService); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -212,7 +207,7 @@ void loadServiceExtensions_withCircularDependency() { var s1 = new TestProvidingExtension2(); var s2 = new TestProvidingExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(s1, s2, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(s1, s2)); assertThatThrownBy(() -> loader.loadServiceExtensions(context)).isInstanceOf(CyclicDependencyException.class); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); @@ -224,7 +219,7 @@ void loadServiceExtensions_dependencyNotSatisfied() { var depending = new DependingExtension(); var someExtension = new SomeExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, someExtension, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, someExtension)); assertThatThrownBy(() -> loader.loadServiceExtensions(context)).isInstanceOf(EdcException.class).hasMessageContaining("The following injected fields were not provided:\nField \"someService\" of type "); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); @@ -237,10 +232,10 @@ void loadServiceExtensions_dependenciesAreSorted() { var providingExtension = new ProvidingExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, providingExtension, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, providingExtension)); var services = loader.loadServiceExtensions(context); - assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(coreExtension, providingExtension, depending); + assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(providingExtension, depending); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -260,11 +255,11 @@ void loadServiceExtensions_withAnnotation() { var depending = new DependingExtension(); var providingExtension = new ProvidingExtension(); var annotatedExtension = new AnnotatedExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, annotatedExtension, providingExtension, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(depending, annotatedExtension, providingExtension)); var services = loader.loadServiceExtensions(context); - assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(coreExtension, providingExtension, depending, annotatedExtension); + assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(providingExtension, depending, annotatedExtension); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -273,7 +268,7 @@ void loadServiceExtensions_withAnnotation() { void loadServiceExtensions_withAnnotation_notSatisfied() { var annotatedExtension = new AnnotatedExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(annotatedExtension, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(annotatedExtension)); assertThatThrownBy(() -> loader.loadServiceExtensions(context)).isNotInstanceOf(EdcInjectionException.class).isInstanceOf(EdcException.class); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); @@ -286,10 +281,10 @@ void loadServiceExtensions_withMixedInjectAndAnnotation() { var anotherProvidingExt = new AnotherProvidingExtension(); //provides AnotherObject var mixedAnnotation = new MixedAnnotation(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(mixedAnnotation, providingExtension, coreExtension, anotherProvidingExt)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(mixedAnnotation, providingExtension, anotherProvidingExt)); var services = loader.loadServiceExtensions(context); - assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(coreExtension, providingExtension, anotherProvidingExt, mixedAnnotation); + assertThat(services).extracting(InjectionContainer::getInjectionTarget).containsExactly(providingExtension, anotherProvidingExt, mixedAnnotation); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); } @@ -299,7 +294,7 @@ void loadServiceExtensions_withMixedInjectAndAnnotation_withCircDependency() { var s1 = new TestProvidingExtension3(); var s2 = new TestProvidingExtension(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(s1, s2, coreExtension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(s1, s2)); assertThatThrownBy(() -> loader.loadServiceExtensions(context)).isInstanceOf(CyclicDependencyException.class); verify(serviceLocator).loadImplementors(eq(ServiceExtension.class), anyBoolean()); @@ -362,7 +357,7 @@ private static class AnotherObject { private static class LogLevelWrongArgProvider implements ArgumentsProvider { @Override - public Stream provideArguments(ExtensionContext context) throws Exception { + public Stream provideArguments(ExtensionContext context) { return Stream.of( Arguments.of(ConsoleMonitor.LEVEL_PROG_ARG + "=INF", "Invalid value \"INF\" for the --log-level argument."), Arguments.of(ConsoleMonitor.LEVEL_PROG_ARG + "=", "Value missing for the --log-level argument."), @@ -376,7 +371,7 @@ public Stream provideArguments(ExtensionContext context) th private static class LogLevelVariantArgsProvider implements ArgumentsProvider { @Override - public Stream provideArguments(ExtensionContext context) throws Exception { + public Stream provideArguments(ExtensionContext context) { return Stream.of( Arguments.of("", ConsoleMonitor.Level.DEBUG), //default case Arguments.of(ConsoleMonitor.LEVEL_PROG_ARG + "=INFO", ConsoleMonitor.Level.INFO), @@ -390,8 +385,4 @@ public Stream provideArguments(ExtensionContext context) th } } - @BaseExtension - private static class TestCoreExtension implements ServiceExtension { - - } } diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/InjectorImplTest.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/InjectorImplTest.java index 8310ce83ba4..e48a3761200 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/InjectorImplTest.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/InjectorImplTest.java @@ -29,9 +29,10 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.Collections; import java.util.Set; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptySet; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; @@ -72,7 +73,7 @@ void teardown() { @DisplayName("Testing ServiceExtension with no injection points") void templateWithNoInjectionPoints() { var serviceExtension = new EmptyTestExtension(); - var template = new InjectionContainer<>(serviceExtension, Collections.emptySet(), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, emptySet(), emptyList()); injector.inject(template, context); @@ -84,7 +85,7 @@ void templateWithNoInjectionPoints() { void allInjectionPointsSatisfied() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), emptyList()); when(context.hasService(eq(SomeObject.class))).thenReturn(true); when(context.getService(eq(SomeObject.class), anyBoolean())).thenReturn(new SomeObject()); @@ -100,7 +101,7 @@ void allInjectionPointsSatisfied() throws NoSuchFieldException { void defaultInjectionPoint() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), emptyList()); when(context.hasService(SomeObject.class)).thenReturn(false); when(context.getService(SomeObject.class, false)).thenThrow(new EdcException("Service not found")); when(defaultServiceSupplier.provideFor(any(), any())).thenReturn(new SomeObject()); @@ -116,7 +117,7 @@ void defaultInjectionPoint() throws NoSuchFieldException { void notAllInjectionPointsSatisfied_shouldThrowException() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field)), emptyList()); var rootCauseException = new EdcInjectionException("Service not found"); when(context.hasService(SomeObject.class)).thenReturn(false); when(defaultServiceSupplier.provideFor(any(), any())).thenThrow(rootCauseException); @@ -135,7 +136,7 @@ void cannotSetInjectionPoint_shouldThrowException() throws NoSuchFieldException, var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); var injectionPoint = spy(new FieldInjectionPoint<>(serviceExtension, field)); - var template = new InjectionContainer<>(serviceExtension, Set.of(injectionPoint), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(injectionPoint), emptyList()); var value = new SomeObject(); when(context.hasService(eq(SomeObject.class))).thenReturn(true); @@ -155,7 +156,7 @@ void cannotSetInjectionPoint_shouldThrowException() throws NoSuchFieldException, void optionalService_provided() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), emptyList()); when(context.hasService(eq(SomeObject.class))).thenReturn(true); when(context.getService(any(), anyBoolean())).thenReturn(new SomeObject()); @@ -172,7 +173,7 @@ void optionalService_provided() throws NoSuchFieldException { void optionalService_defaultProvided() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), emptyList()); when(context.hasService(eq(SomeObject.class))).thenReturn(false); when(defaultServiceSupplier.provideFor(any(), any())).thenReturn(new SomeObject()); @@ -188,7 +189,7 @@ void optionalService_defaultProvided() throws NoSuchFieldException { void optionalService_defaultNotProvided() throws NoSuchFieldException { var serviceExtension = new TestServiceExtension(); var field = serviceExtension.getClass().getDeclaredField("someObject"); - var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), Collections.emptyList()); + var template = new InjectionContainer<>(serviceExtension, Set.of(new FieldInjectionPoint<>(serviceExtension, field, false)), emptyList()); when(context.hasService(eq(SomeObject.class))).thenReturn(false); when(defaultServiceSupplier.provideFor(any(), any())).thenReturn(null); diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/TestFunctions.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/TestFunctions.java index 74d54dd9f99..6b4a1a133ca 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/TestFunctions.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/TestFunctions.java @@ -14,8 +14,6 @@ package org.eclipse.edc.boot.system; -import org.eclipse.edc.boot.system.testextensions.BaseExtension; -import org.eclipse.edc.boot.system.testextensions.CoreExtension; import org.eclipse.edc.boot.system.testextensions.DependentExtension; import org.eclipse.edc.boot.system.testextensions.ProviderDefaultServicesExtension; import org.eclipse.edc.boot.system.testextensions.ProviderExtension; @@ -26,11 +24,8 @@ import java.util.List; public class TestFunctions { - public static List createList(ServiceExtension... extensions) { - var l = new ArrayList<>(List.of(extensions)); - l.add(new CoreExtension()); - l.add(new BaseExtension()); - return l; + public static List mutableListOf(ServiceExtension... extensions) { + return new ArrayList<>(List.of(extensions)); } public static ServiceExtension createProviderExtension(boolean isDefault) { diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/injection/lifecycle/ExtensionLifecycleManagerTest.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/injection/lifecycle/ExtensionLifecycleManagerTest.java index 90aa6435466..376f10f3cb1 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/injection/lifecycle/ExtensionLifecycleManagerTest.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/injection/lifecycle/ExtensionLifecycleManagerTest.java @@ -16,7 +16,6 @@ import org.eclipse.edc.boot.system.DefaultServiceExtensionContext; import org.eclipse.edc.boot.system.DependencyGraph; -import org.eclipse.edc.boot.system.TestFunctions; import org.eclipse.edc.boot.system.TestObject; import org.eclipse.edc.boot.system.injection.InjectionContainer; import org.eclipse.edc.boot.system.testextensions.DependentExtension; @@ -32,6 +31,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.boot.system.TestFunctions.mutableListOf; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -119,7 +119,7 @@ void shouldInvokeNonDefaultProvider_whenDependencyIsOptional() { } public void boot(ServiceExtension... serviceExtensions) { - var injectionContainers = createInjectionContainers(TestFunctions.createList(serviceExtensions)); + var injectionContainers = createInjectionContainers(mutableListOf(serviceExtensions)); ExtensionLifecycleManager.bootServiceExtensions(injectionContainers, context); } diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/runtime/BaseRuntimeTest.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/runtime/BaseRuntimeTest.java index b39c9de3ea8..aaac21b4281 100644 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/runtime/BaseRuntimeTest.java +++ b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/runtime/BaseRuntimeTest.java @@ -16,7 +16,6 @@ package org.eclipse.edc.boot.system.runtime; import org.eclipse.edc.boot.system.ServiceLocator; -import org.eclipse.edc.boot.system.testextensions.BaseExtension; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.spi.system.ConfigurationExtension; @@ -26,9 +25,8 @@ import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.eclipse.edc.boot.system.TestFunctions.mutableListOf; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; @@ -47,19 +45,9 @@ public class BaseRuntimeTest { private final ServiceLocator serviceLocator = mock(); private final BaseRuntime runtime = new BaseRuntimeFixture(monitor, serviceLocator); - @NotNull - private static ServiceExtension registerService(Class serviceClass, HealthCheckService healthCheckService) { - return new ServiceExtension() { - @Override - public void initialize(ServiceExtensionContext context) { - context.registerService(serviceClass, healthCheckService); - } - }; - } - @Test void baseRuntime_shouldBoot() { - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(List.of(new BaseExtension())); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf()); runtime.boot(true); @@ -68,10 +56,10 @@ void baseRuntime_shouldBoot() { @Test void baseRuntime_shouldNotBootWithException() { - var extension = spy(new BaseExtension()); + var extension = spy(extensionThatRegisters(Object.class, "any")); doThrow(new EdcException("Failed to start base extension")).when(extension).start(); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(List.of(extension)); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf(extension)); assertThatThrownBy(() -> runtime.boot(true)).isInstanceOf(EdcException.class); verify(monitor).severe(startsWith("Error booting runtime: Failed to start base extension"), any(EdcException.class)); @@ -80,8 +68,8 @@ void baseRuntime_shouldNotBootWithException() { @Test void shouldSetStartupCheckProvider_whenHealthCheckServiceIsRegistered() { var healthCheckService = mock(HealthCheckService.class); - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(List.of( - new BaseExtension(), registerService(HealthCheckService.class, healthCheckService))); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())) + .thenReturn(mutableListOf(extensionThatRegisters(HealthCheckService.class, healthCheckService))); runtime.boot(true); @@ -90,13 +78,23 @@ void shouldSetStartupCheckProvider_whenHealthCheckServiceIsRegistered() { @Test void shouldLoadConfiguration() { - when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(List.of(new BaseExtension())); + when(serviceLocator.loadImplementors(eq(ServiceExtension.class), anyBoolean())).thenReturn(mutableListOf()); runtime.boot(true); verify(serviceLocator).loadImplementors(ConfigurationExtension.class, false); } + @NotNull + private ServiceExtension extensionThatRegisters(Class serviceClass, T service) { + return new ServiceExtension() { + @Override + public void initialize(ServiceExtensionContext context) { + context.registerService(serviceClass, service); + } + }; + } + private static class BaseRuntimeFixture extends BaseRuntime { private final Monitor monitor; diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/BaseExtension.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/BaseExtension.java deleted file mode 100644 index bef00ccc5b8..00000000000 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/BaseExtension.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.boot.system.testextensions; - -import org.eclipse.edc.spi.system.ServiceExtension; - -@org.eclipse.edc.runtime.metamodel.annotation.BaseExtension -public class BaseExtension implements ServiceExtension { -} diff --git a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/CoreExtension.java b/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/CoreExtension.java deleted file mode 100644 index cad421cd195..00000000000 --- a/core/common/boot/src/test/java/org/eclipse/edc/boot/system/testextensions/CoreExtension.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.boot.system.testextensions; - -import org.eclipse.edc.spi.system.ServiceExtension; - -@org.eclipse.edc.runtime.metamodel.annotation.CoreExtension -public class CoreExtension implements ServiceExtension { -} diff --git a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java b/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java index e7b01fd5f63..9b9313cdd85 100644 --- a/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java +++ b/core/common/connector-core/src/main/java/org/eclipse/edc/connector/core/CoreServicesExtension.java @@ -35,7 +35,6 @@ import org.eclipse.edc.policy.engine.validation.RuleValidator; import org.eclipse.edc.policy.model.PolicyRegistrationTypes; import org.eclipse.edc.query.CriterionOperatorRegistryImpl; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; @@ -55,7 +54,6 @@ import static org.eclipse.edc.participant.spi.ParticipantAgentService.DEFAULT_IDENTITY_CLAIM_KEY; -@BaseExtension @Extension(value = CoreServicesExtension.NAME) public class CoreServicesExtension implements ServiceExtension { diff --git a/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractCoreExtension.java b/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractCoreExtension.java index 34d3924a357..0bad3efff20 100644 --- a/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractCoreExtension.java +++ b/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractCoreExtension.java @@ -39,7 +39,6 @@ import org.eclipse.edc.policy.engine.spi.PolicyEngine; import org.eclipse.edc.policy.engine.spi.RuleBindingRegistry; import org.eclipse.edc.policy.model.Permission; -import org.eclipse.edc.runtime.metamodel.annotation.CoreExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provides; @@ -73,7 +72,6 @@ ContractValidationService.class, ConsumerContractNegotiationManager.class, ProviderContractNegotiationManager.class }) -@CoreExtension @Extension(value = ContractCoreExtension.NAME) public class ContractCoreExtension implements ServiceExtension { diff --git a/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractNegotiationCommandExtension.java b/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractNegotiationCommandExtension.java index 9aa5d15f379..3fd22a5f512 100644 --- a/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractNegotiationCommandExtension.java +++ b/core/control-plane/control-plane-contract/src/main/java/org/eclipse/edc/connector/controlplane/contract/ContractNegotiationCommandExtension.java @@ -16,7 +16,6 @@ import org.eclipse.edc.connector.controlplane.contract.negotiation.command.handlers.TerminateNegotiationCommandHandler; import org.eclipse.edc.connector.controlplane.contract.spi.negotiation.store.ContractNegotiationStore; -import org.eclipse.edc.runtime.metamodel.annotation.CoreExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.command.CommandHandlerRegistry; @@ -29,7 +28,6 @@ * Adds a {@link CommandHandlerRegistry} to the context and registers the * handlers the core provides. */ -@CoreExtension @Extension(value = NAME) public class ContractNegotiationCommandExtension implements ServiceExtension { diff --git a/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferCoreExtension.java b/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferCoreExtension.java index 3b6df1e1969..49236b23cab 100644 --- a/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferCoreExtension.java +++ b/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferCoreExtension.java @@ -37,7 +37,6 @@ import org.eclipse.edc.connector.controlplane.transfer.spi.store.TransferProcessStore; import org.eclipse.edc.connector.controlplane.transfer.spi.types.DeprovisionedResource; import org.eclipse.edc.connector.controlplane.transfer.spi.types.ProvisionedContentResource; -import org.eclipse.edc.runtime.metamodel.annotation.CoreExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provides; @@ -67,7 +66,6 @@ /** * Provides core data transfer services to the system. */ -@CoreExtension @Provides({ TransferProcessManager.class, EndpointDataReferenceReceiverRegistry.class }) @Extension(value = TransferCoreExtension.NAME) public class TransferCoreExtension implements ServiceExtension { diff --git a/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferProcessCommandExtension.java b/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferProcessCommandExtension.java index a68517ec0df..ddc91c88352 100644 --- a/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferProcessCommandExtension.java +++ b/core/control-plane/control-plane-transfer/src/main/java/org/eclipse/edc/connector/controlplane/transfer/TransferProcessCommandExtension.java @@ -20,7 +20,6 @@ import org.eclipse.edc.connector.controlplane.transfer.command.handlers.SuspendTransferCommandHandler; import org.eclipse.edc.connector.controlplane.transfer.command.handlers.TerminateTransferCommandHandler; import org.eclipse.edc.connector.controlplane.transfer.spi.store.TransferProcessStore; -import org.eclipse.edc.runtime.metamodel.annotation.CoreExtension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.spi.command.CommandHandlerRegistry; import org.eclipse.edc.spi.system.ServiceExtension; @@ -29,7 +28,6 @@ /** * Registers command handlers that the core provides */ -@CoreExtension public class TransferProcessCommandExtension implements ServiceExtension { @Inject diff --git a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java index 39afe3a20f5..1e407625335 100644 --- a/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java +++ b/extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java @@ -17,7 +17,6 @@ import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.spi.transformer.JsonLdTransformer; import org.eclipse.edc.jsonld.util.JacksonJsonLd; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; @@ -44,7 +43,6 @@ * for {@link JsonLdTransformer}s. The module also offers * functions for working with JSON-LD structures. */ -@BaseExtension @Extension(value = JsonLdExtension.NAME) public class JsonLdExtension implements ServiceExtension { diff --git a/extensions/common/metrics/micrometer-core/src/main/java/org/eclipse/edc/metrics/micrometer/MicrometerExtension.java b/extensions/common/metrics/micrometer-core/src/main/java/org/eclipse/edc/metrics/micrometer/MicrometerExtension.java index dd25d9227ee..12e415608ab 100644 --- a/extensions/common/metrics/micrometer-core/src/main/java/org/eclipse/edc/metrics/micrometer/MicrometerExtension.java +++ b/extensions/common/metrics/micrometer-core/src/main/java/org/eclipse/edc/metrics/micrometer/MicrometerExtension.java @@ -23,7 +23,6 @@ import io.micrometer.core.instrument.binder.okhttp3.OkHttpMetricsEventListener; import io.micrometer.core.instrument.binder.system.ProcessorMetrics; import okhttp3.EventListener; -import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Provides; import org.eclipse.edc.runtime.metamodel.annotation.Setting; @@ -31,7 +30,6 @@ import org.eclipse.edc.spi.system.ServiceExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; -@BaseExtension @Provides({ EventListener.class, ExecutorInstrumentation.class, MeterRegistry.class }) @Extension(value = MicrometerExtension.NAME) public class MicrometerExtension implements ServiceExtension {