Browse Source

Polishing.

Rename store-specific property to spring.aot.%s.repositories.enabled.

See #3322
Original pull request: #3323
pull/3337/head
Mark Paluch 5 months ago
parent
commit
1fae9b7be6
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 1
      pom.xml
  2. 20
      src/main/java/org/springframework/data/aot/AotContext.java
  3. 3
      src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java
  4. 3
      src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java
  5. 4
      src/test/java/org/springframework/data/aot/AotContextUnitTests.java

1
pom.xml

@ -325,6 +325,7 @@ @@ -325,6 +325,7 @@
<version>${jmolecules-integration}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>

20
src/main/java/org/springframework/data/aot/AotContext.java

@ -87,23 +87,23 @@ public interface AotContext extends EnvironmentCapable { @@ -87,23 +87,23 @@ public interface AotContext extends EnvironmentCapable {
/**
* Checks if repository code generation is enabled for a given module by checking environment variables for general
* enablement ({@link #GENERATED_REPOSITORIES_ENABLED}) and store specific ones following the pattern
* {@literal spring.aot.repositories.&lt;module-name&gt;.enabled}.
* enablement ({@link #GENERATED_REPOSITORIES_ENABLED}) and store-specific ones following the pattern
* {@literal spring.aot.&lt;module-name&gt;.repositories.enabled}.
* <p>
* {@link #GENERATED_REPOSITORIES_ENABLED} acts as a kill switch, if disabled, store specific flags have no effect.
* {@link #GENERATED_REPOSITORIES_ENABLED} acts as a main switch, if disabled, store specific flags have no effect.
* <p>
* Missing properties are interpreted as {@literal true}.
* Unset properties are considered being {@literal true}.
*
* @param moduleName The name of the module. Can be {@literal null} or {@literal empty}, in which case it will only
* check the general {@link #GENERATED_REPOSITORIES_ENABLED} flag.
* @param moduleName name of the module. Can be {@literal null} or {@literal empty}, in which case it will only check
* the general {@link #GENERATED_REPOSITORIES_ENABLED} flag.
* @return indicator if repository code generation is enabled.
* @since 5.0
*/
default boolean isGeneratedRepositoriesEnabled(@Nullable String moduleName) {
Environment environment = getEnvironment();
Boolean codeGenerationEnabled = environment.getProperty(GENERATED_REPOSITORIES_ENABLED, Boolean.class, true);
if (!codeGenerationEnabled) {
if (!environment.getProperty(GENERATED_REPOSITORIES_ENABLED, Boolean.class, true)) {
return false;
}
@ -111,8 +111,8 @@ public interface AotContext extends EnvironmentCapable { @@ -111,8 +111,8 @@ public interface AotContext extends EnvironmentCapable {
return true;
}
String modulePropertyName = GENERATED_REPOSITORIES_ENABLED.replace("enabled",
"%s.enabled".formatted(moduleName.toLowerCase(Locale.US)));
String modulePropertyName = GENERATED_REPOSITORIES_ENABLED.replace("repositories",
"%s.repositories".formatted(moduleName.toLowerCase(Locale.ROOT)));
return environment.getProperty(modulePropertyName, Boolean.class, true);
}

3
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationDelegate.java

@ -216,9 +216,6 @@ public class RepositoryConfigurationDelegate { @@ -216,9 +216,6 @@ public class RepositoryConfigurationDelegate {
configurations.size() == 1 ? "" : "s"));
}
// TODO: AOT Processing -> guard this one with a flag so it's not always present
// TODO: With regard to AOT Processing, perhaps we need to be smart and detect whether "core" AOT components are
// (or rather configuration is) present on the classpath to enable Spring Data AOT component registration.
registerAotComponents(registry, extension, metadataByRepositoryBeanName);
return definitions;

3
src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java

@ -43,8 +43,7 @@ public interface RepositoryConfigurationExtension { @@ -43,8 +43,7 @@ public interface RepositoryConfigurationExtension {
* @since 3.0
*/
default String getModuleIdentifier() {
return getModuleName().toLowerCase(Locale.ENGLISH).replace(' ', '-');
return getModuleName().toLowerCase(Locale.ROOT).replace(' ', '-');
}
/**

4
src/test/java/org/springframework/data/aot/AotContextUnitTests.java

@ -49,13 +49,13 @@ class AotContextUnitTests { @@ -49,13 +49,13 @@ class AotContextUnitTests {
ctx.withProperty(generalFlag, generalValue);
}
if (StringUtils.hasText(storeName) && StringUtils.hasText(storeValue)) {
ctx.withProperty("spring.aot.repositories.%s.enabled".formatted(storeName), storeValue);
ctx.withProperty("spring.aot.%s.repositories.enabled".formatted(storeName), storeValue);
}
Assertions.assertThat(ctx.isGeneratedRepositoriesEnabled(storeName)).isEqualTo(enabled);
}
class MockAotContext implements AotContext {
static class MockAotContext implements AotContext {
private final MockEnvironment environment;

Loading…
Cancel
Save