Skip to content

Commit

Permalink
add case and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Hernán Carle committed Feb 16, 2022
1 parent 8862e5e commit 49b012b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -53,9 +54,13 @@ private List<ExtensionDefinition> getEnabledExtensions() {
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
ObjectMapper jsonMapper = new ObjectMapper();

log.info("installed components: " + Arrays.toString(installedComponents.toArray()));
log.info("enabled components: " + Arrays.toString(enabledComponents.toArray()));

for (String installedComponent : installedComponents) {
if (enabledComponents.contains(installedComponent)) {
String parentPath = environment.getExtensionDirectory() + File.separator + installedComponent;
log.info("check path: " + parentPath);
Path manifestYamlPath = Paths.get(parentPath + "/manifest.yaml");
Path manifestJsonPath = Paths.get(parentPath + "/manifest.json");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public void onApplicationEvent(ApplicationContextInitializedEvent event) {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) event.getApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry);

scanner.scan(configReader.getBasePackages());
String[] extensionsBasePackages = configReader.getBasePackages();
if (extensionsBasePackages.length > 0) {
scanner.scan(configReader.getBasePackages());

String[] beanNames = scanner.getRegistry().getBeanDefinitionNames();
for (String name : beanNames) {
if (!registry.containsBeanDefinition(name)) {
registry.registerBeanDefinition(name, scanner.getRegistry().getBeanDefinition(name));
} else {
log.info("Bean with name " + name + " is already registered in the context");
String[] beanNames = scanner.getRegistry().getBeanDefinitionNames();
for (String name : beanNames) {
if (!registry.containsBeanDefinition(name)) {
registry.registerBeanDefinition(name, scanner.getRegistry().getBeanDefinition(name));
} else {
log.info("Bean with name " + name + " is already registered in the context");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ void onEvent_ContextAlreadyHasBean() {
verify(registry, never()).registerBeanDefinition(anyString(), any());
}

@Test
void onEvent_noExtensions() {
ConfigurableApplicationContext registry = mock(ConfigurableApplicationContext.class);
when(reader.getBasePackages()).thenReturn(new String[]{ });
ReflectionTestUtils.setField(extensionsLoader, "configReader", reader);
SpringApplication application = mock(SpringApplication.class);
ApplicationContextInitializedEvent event = new ApplicationContextInitializedEvent(application, new String[]{}, registry);
doCallRealMethod().when(extensionsLoader).onApplicationEvent(event);
publisher.publishEvent(event);
verify(registry, never()).containsBeanDefinition(anyString());
}

@Test
void onEvent_ContextIsRightType() {
AnnotationConfigApplicationContext context = (AnnotationConfigApplicationContext) new TestContextManager(this.getClass()).getTestContext().getApplicationContext();
Expand Down

0 comments on commit 49b012b

Please sign in to comment.