From 6da0b4d1b054ec9204cf0741a49c79fdf9406224 Mon Sep 17 00:00:00 2001 From: danhaywood Date: Mon, 13 Nov 2023 11:04:31 +0000 Subject: [PATCH] CAUSEWAY-3636: fixes name of config prop; fixes injection on bootstrap... ... need to use Provider --- .../causeway/core/config/CausewayConfiguration.java | 4 ++-- .../github/CausewayModuleExtLayoutLoadersGithub.java | 6 +++--- .../github/menu/LayoutLoadersGitHubMenu.java | 2 +- .../spiimpl/LayoutResourceLoaderFromGithub.java | 11 ++++++----- ...ceLoaderFromGithub_tryLoadLayoutResource_Test.java | 6 +++--- .../gitlab/src/test/resources/.gitignore | 1 + 6 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 extensions/core/layoutloaders/gitlab/src/test/resources/.gitignore diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java index e157fdeec04..787cc9a3790 100644 --- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java +++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java @@ -3446,9 +3446,9 @@ public enum PersistPolicy { @Data public static class LayoutLoaders { - private final GitHub gitHub = new GitHub(); + private final Github github = new Github(); @Data - public static class GitHub { + public static class Github { /** * eg apache/causeway-app-simpleapp diff --git a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/CausewayModuleExtLayoutLoadersGithub.java b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/CausewayModuleExtLayoutLoadersGithub.java index a23aa856ab9..b56e46b482b 100644 --- a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/CausewayModuleExtLayoutLoadersGithub.java +++ b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/CausewayModuleExtLayoutLoadersGithub.java @@ -81,7 +81,7 @@ public class CausewayModuleExtLayoutLoadersGithub { @Bean(name = "GithubSearch") public RestTemplate restTemplateForGithubSearch(final CausewayConfiguration causewayConfiguration) { - val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getApiKey(); + val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getApiKey(); return new RestTemplateBuilder() .rootUri("https://api.github.com") @@ -108,8 +108,8 @@ public RestTemplate restTemplateForGithubSearch(final CausewayConfiguration caus @Bean(name = "GithubContent") public RestTemplate restTemplateForGithubContent(final CausewayConfiguration causewayConfiguration) { - val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getApiKey(); - val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getRepository(); + val apiKey = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getApiKey(); + val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getRepository(); return new RestTemplateBuilder() .rootUri(String.format("https://api.github.com/repos/%s", repo)) diff --git a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/menu/LayoutLoadersGitHubMenu.java b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/menu/LayoutLoadersGitHubMenu.java index bf7ca8fceab..1d8a66cea93 100644 --- a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/menu/LayoutLoadersGitHubMenu.java +++ b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/menu/LayoutLoadersGitHubMenu.java @@ -114,7 +114,7 @@ public class ActionDomainEvent extends LayoutLoadersGitHubMenu.ActionDomainEvent } boolean isConfigured() { - val layoutLoadersGitHub = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub(); + val layoutLoadersGitHub = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub(); return layoutLoadersGitHub.getRepository() != null && layoutLoadersGitHub.getApiKey() != null; } diff --git a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub.java b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub.java index 8f04f969aed..71e88d1ef48 100644 --- a/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub.java +++ b/extensions/core/layoutloaders/github/src/main/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub.java @@ -23,6 +23,7 @@ import javax.annotation.Priority; import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Provider; import org.apache.causeway.extensions.layoutloaders.github.menu.LayoutLoadersGitHubMenu; @@ -57,7 +58,7 @@ public class LayoutResourceLoaderFromGithub implements LayoutResourceLoader { final RestTemplate restTemplateForContent; final CausewayConfiguration causewayConfiguration; final LayoutLoadersGitHubMenu layoutLoadersGitHubMenu; - final QueryResultsCache queryResultsCache; + final Provider queryResultsCacheProvider; @Inject public LayoutResourceLoaderFromGithub( @@ -65,12 +66,12 @@ public LayoutResourceLoaderFromGithub( final @Qualifier("GithubContent") RestTemplate restTemplateForContent, final CausewayConfiguration causewayConfiguration, final LayoutLoadersGitHubMenu layoutLoadersGitHubMenu, - final QueryResultsCache queryResultsCache) { + final Provider queryResultsCacheProvider) { this.restTemplateForSearch = restTemplateForSearch; this.restTemplateForContent = restTemplateForContent; this.causewayConfiguration = causewayConfiguration; this.layoutLoadersGitHubMenu = layoutLoadersGitHubMenu; - this.queryResultsCache = queryResultsCache; + this.queryResultsCacheProvider = queryResultsCacheProvider; } @Override @@ -78,7 +79,7 @@ public Try tryLoadLayoutResource( final @NonNull Class type, final @NonNull String candidateResourceName) { return layoutLoadersGitHubMenu.isEnabled() - ? queryResultsCache.execute(() -> tryLoadLayoutResource(candidateResourceName), + ? queryResultsCacheProvider.get().execute(() -> tryLoadLayoutResource(candidateResourceName), getClass(), "tryLoadLayoutResource", candidateResourceName) : Try.empty(); } @@ -95,7 +96,7 @@ private Try tryLoadLayoutResource(final String candidateResource private Try search(final @NonNull String candidateResourceName) { try { - val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().getRepository(); + val repo = causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().getRepository(); val searchParams = new HashMap(); searchParams.put("q", String.format("%s+in:path+repo:%s", candidateResourceName, repo)); diff --git a/extensions/core/layoutloaders/github/src/test/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub_tryLoadLayoutResource_Test.java b/extensions/core/layoutloaders/github/src/test/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub_tryLoadLayoutResource_Test.java index 26ac1efeb28..3be9403e939 100644 --- a/extensions/core/layoutloaders/github/src/test/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub_tryLoadLayoutResource_Test.java +++ b/extensions/core/layoutloaders/github/src/test/java/org/apache/causeway/extensions/layoutloaders/github/spiimpl/LayoutResourceLoaderFromGithub_tryLoadLayoutResource_Test.java @@ -34,8 +34,8 @@ void preconditions() { void setup() { val causewayConfiguration = new CausewayConfiguration(null); - causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().setApiKey(getApiKey()); - causewayConfiguration.getExtensions().getLayoutLoaders().getGitHub().setRepository("apache/causeway-app-simpleapp"); + causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().setApiKey(getApiKey()); + causewayConfiguration.getExtensions().getLayoutLoaders().getGithub().setRepository("apache/causeway-app-simpleapp"); val module = new CausewayModuleExtLayoutLoadersGithub(); val restTemplateForSearch = module.restTemplateForGithubSearch(causewayConfiguration); @@ -46,7 +46,7 @@ void setup() { layoutLoaderMenu.new enableDynamicLayoutLoading().act(); Assertions.assertThat(layoutLoaderMenu.isEnabled()).isTrue(); - loader = new LayoutResourceLoaderFromGithub(restTemplateForSearch, restTemplateForContent, causewayConfiguration, layoutLoaderMenu, queryResultsCache); + loader = new LayoutResourceLoaderFromGithub(restTemplateForSearch, restTemplateForContent, causewayConfiguration, layoutLoaderMenu, () -> queryResultsCache); } @Test diff --git a/extensions/core/layoutloaders/gitlab/src/test/resources/.gitignore b/extensions/core/layoutloaders/gitlab/src/test/resources/.gitignore new file mode 100644 index 00000000000..bc910ca2037 --- /dev/null +++ b/extensions/core/layoutloaders/gitlab/src/test/resources/.gitignore @@ -0,0 +1 @@ +*.http \ No newline at end of file