This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-12361-parent-60 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-spi.git
commit d1e33f5631ff8857e127696942fda63bcfc86f2f Author: Stefan Seifert <stefanseif...@users.noreply.github.com> AuthorDate: Mon Jun 24 14:15:29 2024 +0200 SLING-12361 apply spotless code formatting --- pom.xml | 36 +++++++++---------- .../resource/spi/CollectionInheritanceDecider.java | 4 +-- .../ConfigurationResourceResolvingStrategy.java | 24 +++++++++---- .../caconfig/resource/spi/ContextPathStrategy.java | 4 +-- .../caconfig/resource/spi/ContextResource.java | 3 +- .../caconfig/resource/spi/InheritanceDecision.java | 3 +- .../spi/ConfigurationCollectionPersistData.java | 9 ++--- .../spi/ConfigurationInheritanceStrategy.java | 4 +-- ...nfigurationInjectResourceDetectionStrategy.java | 1 - .../spi/ConfigurationMetadataProvider.java | 7 ++-- .../spi/ConfigurationOverrideProvider.java | 4 +-- .../caconfig/spi/ConfigurationPersistData.java | 3 +- ...figurationPersistenceAccessDeniedException.java | 1 - .../spi/ConfigurationPersistenceException.java | 1 - .../spi/ConfigurationPersistenceStrategy.java | 19 ++++++---- .../spi/ConfigurationPersistenceStrategy2.java | 40 ++++++++++++++-------- .../caconfig/spi/metadata/AbstractMetadata.java | 13 ++++--- .../spi/metadata/ConfigurationMetadata.java | 14 ++++---- .../caconfig/spi/metadata/PropertyMetadata.java | 20 ++++------- .../caconfig/resource/spi/ContextResourceTest.java | 18 +++++----- .../ConfigurationCollectionPersistDataTest.java | 19 +++++----- .../caconfig/spi/ConfigurationPersistDataTest.java | 12 +++---- .../spi/metadata/ConfigurationMetadataTest.java | 40 ++++++++++++---------- .../spi/metadata/PropertyMetadataTest.java | 32 ++++++++--------- 24 files changed, 172 insertions(+), 159 deletions(-) diff --git a/pom.xml b/pom.xml index d4647f3..69b30df 100644 --- a/pom.xml +++ b/pom.xml @@ -28,34 +28,21 @@ </parent> <artifactId>org.apache.sling.caconfig.spi</artifactId> - <packaging>jar</packaging> <version>1.4.1-SNAPSHOT</version> + <packaging>jar</packaging> <name>Apache Sling Context-Aware Configuration SPI</name> <description>Apache Sling Context-Aware Configuration SPI</description> - <properties> - <project.build.outputTimestamp>2022-01-03T11:35:43Z</project.build.outputTimestamp> - </properties> - <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-spi.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-spi.git</developerConnection> - <url>https://github.com/apache/sling-org-apache-sling-caconfig-spi.git</url> <tag>HEAD</tag> + <url>https://github.com/apache/sling-org-apache-sling-caconfig-spi.git</url> </scm> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-baseline-maven-plugin</artifactId> - </plugin> - </plugins> - </build> + <properties> + <project.build.outputTimestamp>2022-01-03T11:35:43Z</project.build.outputTimestamp> + </properties> <dependencies> <dependency> @@ -121,4 +108,17 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-baseline-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + </project> diff --git a/src/main/java/org/apache/sling/caconfig/resource/spi/CollectionInheritanceDecider.java b/src/main/java/org/apache/sling/caconfig/resource/spi/CollectionInheritanceDecider.java index 896920a..378e77b 100644 --- a/src/main/java/org/apache/sling/caconfig/resource/spi/CollectionInheritanceDecider.java +++ b/src/main/java/org/apache/sling/caconfig/resource/spi/CollectionInheritanceDecider.java @@ -42,6 +42,6 @@ public interface CollectionInheritanceDecider { * @param resource The resource * @return The decision or {@code null} */ - @Nullable InheritanceDecision decide(@NotNull Resource resource, @NotNull String bucketName); - + @Nullable + InheritanceDecision decide(@NotNull Resource resource, @NotNull String bucketName); } diff --git a/src/main/java/org/apache/sling/caconfig/resource/spi/ConfigurationResourceResolvingStrategy.java b/src/main/java/org/apache/sling/caconfig/resource/spi/ConfigurationResourceResolvingStrategy.java index 04b04ef..96904be 100644 --- a/src/main/java/org/apache/sling/caconfig/resource/spi/ConfigurationResourceResolvingStrategy.java +++ b/src/main/java/org/apache/sling/caconfig/resource/spi/ConfigurationResourceResolvingStrategy.java @@ -47,7 +47,9 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Configuration resource or {@code null} if this strategy did not found matching resources. */ - @Nullable Resource getResource(@NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); + @Nullable + Resource getResource( + @NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); /** * Get a collection of context-aware configuration resources defined by the given configuration name. @@ -57,7 +59,9 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Collection of configuration resources or {@code null} if this strategy did not found matching resources. */ - @Nullable Collection<Resource> getResourceCollection(@NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); + @Nullable + Collection<Resource> getResourceCollection( + @NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); /** * Get a context-aware singleton configuration resource inheritance chain defined by the given configuration name. @@ -68,7 +72,9 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Configuration resource inheritance chain or {@code null} if this strategy did not found matching resources. */ - @Nullable Iterator<Resource> getResourceInheritanceChain(@NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); + @Nullable + Iterator<Resource> getResourceInheritanceChain( + @NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); /** * Get a collection of context-aware configuration resource inheritance chains defined by the given configuration name. @@ -79,7 +85,9 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Collection of configuration resource inheritance chains or {@code null} if this strategy did not found matching resources. */ - @Nullable Collection<Iterator<Resource>> getResourceCollectionInheritanceChain(@NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); + @Nullable + Collection<Iterator<Resource>> getResourceCollectionInheritanceChain( + @NotNull Resource resource, @NotNull Collection<String> bucketNames, @NotNull String configName); /** * Get the configuration resource path for storing configuration data for the given context resource and configuration name. @@ -92,7 +100,8 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Resource path, or null if no matching configuration resource path can be determined */ - @Nullable String getResourcePath(@NotNull Resource resource, @NotNull String bucketName, @NotNull String configName); + @Nullable + String getResourcePath(@NotNull Resource resource, @NotNull String bucketName, @NotNull String configName); /** * Get the configuration resource collection parent path for storing configuration data for the given context resource and configuration name. @@ -105,6 +114,7 @@ public interface ConfigurationResourceResolvingStrategy { * @param configName Configuration name or relative path. * @return Resource path, or null if no matching configuration resource path can be determined */ - @Nullable String getResourceCollectionParentPath(@NotNull Resource resource, @NotNull String bucketName, @NotNull String configName); - + @Nullable + String getResourceCollectionParentPath( + @NotNull Resource resource, @NotNull String bucketName, @NotNull String configName); } diff --git a/src/main/java/org/apache/sling/caconfig/resource/spi/ContextPathStrategy.java b/src/main/java/org/apache/sling/caconfig/resource/spi/ContextPathStrategy.java index b57c30d..c46e87f 100644 --- a/src/main/java/org/apache/sling/caconfig/resource/spi/ContextPathStrategy.java +++ b/src/main/java/org/apache/sling/caconfig/resource/spi/ContextPathStrategy.java @@ -40,6 +40,6 @@ public interface ContextPathStrategy { * Only one of the parent resources or the resource itself may be included in the result. * If none are found an empty list is returned. */ - @NotNull Iterator<ContextResource> findContextResources(@NotNull Resource resource); - + @NotNull + Iterator<ContextResource> findContextResources(@NotNull Resource resource); } diff --git a/src/main/java/org/apache/sling/caconfig/resource/spi/ContextResource.java b/src/main/java/org/apache/sling/caconfig/resource/spi/ContextResource.java index cbbd18a..c2e00c3 100644 --- a/src/main/java/org/apache/sling/caconfig/resource/spi/ContextResource.java +++ b/src/main/java/org/apache/sling/caconfig/resource/spi/ContextResource.java @@ -90,9 +90,8 @@ public final class ContextResource { @Override public boolean equals(Object obj) { if (obj instanceof ContextResource) { - return StringUtils.equals(key, ((ContextResource)obj).key); + return StringUtils.equals(key, ((ContextResource) obj).key); } return false; } - } diff --git a/src/main/java/org/apache/sling/caconfig/resource/spi/InheritanceDecision.java b/src/main/java/org/apache/sling/caconfig/resource/spi/InheritanceDecision.java index ce60f5f..4b71dbb 100644 --- a/src/main/java/org/apache/sling/caconfig/resource/spi/InheritanceDecision.java +++ b/src/main/java/org/apache/sling/caconfig/resource/spi/InheritanceDecision.java @@ -24,8 +24,7 @@ package org.apache.sling.caconfig.resource.spi; * @since 1.1 */ public enum InheritanceDecision { - INCLUDE, // include the resource. EXCLUDE, // exclude the resource, but allow others to provide it. - BLOCK // exclude the resource, no one else can provide it. + BLOCK // exclude the resource, no one else can provide it. } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistData.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistData.java index 80a4ad0..5401058 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistData.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistData.java @@ -38,7 +38,7 @@ public final class ConfigurationCollectionPersistData { private static final Pattern ITEM_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+$"); private final Collection<ConfigurationPersistData> items; - private Map<String,Object> properties; + private Map<String, Object> properties; /** * @param items Collection of configuration collection items @@ -56,10 +56,12 @@ public final class ConfigurationCollectionPersistData { throw new ConfigurationPersistenceException("Collection item name is missing."); } if (!ITEM_NAME_PATTERN.matcher(item.getCollectionItemName()).matches()) { - throw new ConfigurationPersistenceException("Invalid collection item name: " + item.getCollectionItemName()); + throw new ConfigurationPersistenceException( + "Invalid collection item name: " + item.getCollectionItemName()); } if (keyNames.contains(item.getCollectionItemName())) { - throw new ConfigurationPersistenceException("Duplicate collection item name: " + item.getCollectionItemName()); + throw new ConfigurationPersistenceException( + "Duplicate collection item name: " + item.getCollectionItemName()); } keyNames.add(item.getCollectionItemName()); } @@ -87,5 +89,4 @@ public final class ConfigurationCollectionPersistData { this.properties = value; return this; } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInheritanceStrategy.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInheritanceStrategy.java index bf97348..67c58c8 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInheritanceStrategy.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInheritanceStrategy.java @@ -38,6 +38,6 @@ public interface ConfigurationInheritanceStrategy { * First resource is the "closest" match, the other resources may be used to inherit from. * @return Inherited resource or null if this strategy does not support the given resources */ - @Nullable Resource getResource(@NotNull Iterator<Resource> configResources); - + @Nullable + Resource getResource(@NotNull Iterator<Resource> configResources); } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInjectResourceDetectionStrategy.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInjectResourceDetectionStrategy.java index 7ac7b13..0b48de1 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInjectResourceDetectionStrategy.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationInjectResourceDetectionStrategy.java @@ -38,5 +38,4 @@ public interface ConfigurationInjectResourceDetectionStrategy { */ @Nullable Resource detectResource(@NotNull SlingHttpServletRequest request); - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationMetadataProvider.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationMetadataProvider.java index 9888678..8410883 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationMetadataProvider.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationMetadataProvider.java @@ -35,13 +35,14 @@ public interface ConfigurationMetadataProvider { * Get all configuration names. * @return Configuration names */ - @NotNull SortedSet<String> getConfigurationNames(); + @NotNull + SortedSet<String> getConfigurationNames(); /** * Get configuration metadata. * @param configName Configuration name * @return Configuration metadata or null if none exists for the given name. */ - @Nullable ConfigurationMetadata getConfigurationMetadata(String configName); - + @Nullable + ConfigurationMetadata getConfigurationMetadata(String configName); } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationOverrideProvider.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationOverrideProvider.java index be2ea5d..c24f1b0 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationOverrideProvider.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationOverrideProvider.java @@ -39,6 +39,6 @@ public interface ConfigurationOverrideProvider { * </ul> * @return Override strings */ - @NotNull Collection<String> getOverrideStrings(); - + @NotNull + Collection<String> getOverrideStrings(); } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistData.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistData.java index 1310aa3..a8b65f1 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistData.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistData.java @@ -30,7 +30,7 @@ import org.osgi.annotation.versioning.ProviderType; @ProviderType public final class ConfigurationPersistData { - private final Map<String,Object> properties; + private final Map<String, Object> properties; private String collectionItemName; /** @@ -62,5 +62,4 @@ public final class ConfigurationPersistData { this.collectionItemName = value; return this; } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java index a152808..be9f963 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java @@ -34,5 +34,4 @@ public final class ConfigurationPersistenceAccessDeniedException extends Configu public ConfigurationPersistenceAccessDeniedException(String message) { super(message); } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java index c800e00..2fd967c 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java @@ -34,5 +34,4 @@ public class ConfigurationPersistenceException extends RuntimeException { public ConfigurationPersistenceException(String message) { super(message); } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy.java index 62560d4..1d6c206 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy.java @@ -39,7 +39,8 @@ public interface ConfigurationPersistenceStrategy { * @param resource Configuration resource * @return Transformed configuration resource. If null is returned this strategy does not support the given configuration resource. */ - @Nullable Resource getResource(@NotNull Resource resource); + @Nullable + Resource getResource(@NotNull Resource resource); /** * Allows the strategy to transform the given configuration resource path according to it's persistent strategies, @@ -47,7 +48,8 @@ public interface ConfigurationPersistenceStrategy { * @param resourcePath Configuration resource path or part of it (e.g. config name) * @return Transformed configuration resource path. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getResourcePath(@NotNull String resourcePath); + @Nullable + String getResourcePath(@NotNull String resourcePath); /** * Stores configuration data for a singleton configuration resource. @@ -58,8 +60,10 @@ public interface ConfigurationPersistenceStrategy { * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy * (in case of error throw an exception). */ - boolean persistConfiguration(@NotNull ResourceResolver resourceResolver, - @NotNull String configResourcePath, @NotNull ConfigurationPersistData data); + boolean persistConfiguration( + @NotNull ResourceResolver resourceResolver, + @NotNull String configResourcePath, + @NotNull ConfigurationPersistData data); /** * Stores configuration data for a configuration resource collection. @@ -71,8 +75,10 @@ public interface ConfigurationPersistenceStrategy { * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy * (in case of error throw an exception). */ - boolean persistConfigurationCollection(@NotNull ResourceResolver resourceResolver, - @NotNull String configResourceCollectionParentPath, @NotNull ConfigurationCollectionPersistData data); + boolean persistConfigurationCollection( + @NotNull ResourceResolver resourceResolver, + @NotNull String configResourceCollectionParentPath, + @NotNull ConfigurationCollectionPersistData data); /** * Delete configuration or configuration collection data from repository using the inner-most context path as reference. @@ -82,5 +88,4 @@ public interface ConfigurationPersistenceStrategy { * (in case of error throw an exception). */ boolean deleteConfiguration(@NotNull ResourceResolver resourceResolver, @NotNull String configResourcePath); - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy2.java b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy2.java index 6ae2a8c..4061e08 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy2.java +++ b/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceStrategy2.java @@ -37,7 +37,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resource Singleton configuration resource * @return Transformed configuration resource. If null is returned this strategy does not support the given configuration resource. */ - @Nullable Resource getResource(@NotNull Resource resource); + @Nullable + Resource getResource(@NotNull Resource resource); /** * Allows the strategy to transform the given configuration resource according to it's persistent strategies, @@ -45,7 +46,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resource Configuration collection parent resource * @return Transformed configuration resource. If null is returned this strategy does not support the given configuration resource. */ - @Nullable Resource getCollectionParentResource(@NotNull Resource resource); + @Nullable + Resource getCollectionParentResource(@NotNull Resource resource); /** * Allows the strategy to transform the given configuration resource according to it's persistent strategies, @@ -53,7 +55,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resource Configuration collection item resource * @return Transformed configuration resource. If null is returned this strategy does not support the given configuration resource. */ - @Nullable Resource getCollectionItemResource(@NotNull Resource resource); + @Nullable + Resource getCollectionItemResource(@NotNull Resource resource); /** * Allows the strategy to transform the given configuration resource path according to it's persistent strategies, @@ -61,7 +64,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resourcePath Configuration resource path (full path) * @return Transformed configuration resource path. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getResourcePath(@NotNull String resourcePath); + @Nullable + String getResourcePath(@NotNull String resourcePath); /** * Allows the strategy to transform the given configuration resource path according to it's persistent strategies, @@ -69,7 +73,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resourcePath Configuration collection parent resource path (full path) * @return Transformed configuration resource path. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getCollectionParentResourcePath(@NotNull String resourcePath); + @Nullable + String getCollectionParentResourcePath(@NotNull String resourcePath); /** * Allows the strategy to transform the given configuration resource path according to it's persistent strategies, @@ -77,7 +82,8 @@ public interface ConfigurationPersistenceStrategy2 { * @param resourcePath Configuration collection item resource path (full path) * @return Transformed configuration resource path. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getCollectionItemResourcePath(@NotNull String resourcePath); + @Nullable + String getCollectionItemResourcePath(@NotNull String resourcePath); /** * Allows the strategy to transform the given configuration name for nested configurations according to it's persistent strategies, @@ -87,7 +93,8 @@ public interface ConfigurationPersistenceStrategy2 { * This can be used to detect if the persistence strategy supports the configuration location. If null it should be assumed that it matches. * @return Transformed configuration name. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getConfigName(@NotNull String configName, @Nullable String relatedConfigPath); + @Nullable + String getConfigName(@NotNull String configName, @Nullable String relatedConfigPath); /** * Allows the strategy to transform the given configuration name for nested configurations according to it's persistent strategies, @@ -97,7 +104,8 @@ public interface ConfigurationPersistenceStrategy2 { * This can be used to detect if the persistence strategy supports the configuration location. If null it should be assumed that it matches. * @return Transformed configuration name. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getCollectionParentConfigName(@NotNull String configName, @Nullable String relatedConfigPath); + @Nullable + String getCollectionParentConfigName(@NotNull String configName, @Nullable String relatedConfigPath); /** * Allows the strategy to transform the given configuration name for nested configurations according to it's persistent strategies, @@ -107,7 +115,8 @@ public interface ConfigurationPersistenceStrategy2 { * This can be used to detect if the persistence strategy supports the configuration location. If null it should be assumed that it matches. * @return Transformed configuration name. If null is returned this strategy does not support the given configuration resource path. */ - @Nullable String getCollectionItemConfigName(@NotNull String configName, @Nullable String relatedConfigPath); + @Nullable + String getCollectionItemConfigName(@NotNull String configName, @Nullable String relatedConfigPath); /** * Stores configuration data for a singleton configuration resource. @@ -118,8 +127,10 @@ public interface ConfigurationPersistenceStrategy2 { * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy * (in case of error throw an exception). */ - boolean persistConfiguration(@NotNull ResourceResolver resourceResolver, - @NotNull String configResourcePath, @NotNull ConfigurationPersistData data); + boolean persistConfiguration( + @NotNull ResourceResolver resourceResolver, + @NotNull String configResourcePath, + @NotNull ConfigurationPersistData data); /** * Stores configuration data for a configuration resource collection. @@ -131,8 +142,10 @@ public interface ConfigurationPersistenceStrategy2 { * @return true if the data was persisted. false if persisting the data was not accepted by this persistence strategy * (in case of error throw an exception). */ - boolean persistConfigurationCollection(@NotNull ResourceResolver resourceResolver, - @NotNull String configResourceCollectionParentPath, @NotNull ConfigurationCollectionPersistData data); + boolean persistConfigurationCollection( + @NotNull ResourceResolver resourceResolver, + @NotNull String configResourceCollectionParentPath, + @NotNull ConfigurationCollectionPersistData data); /** * Delete configuration or configuration collection data from repository using the inner-most context path as reference. @@ -142,5 +155,4 @@ public interface ConfigurationPersistenceStrategy2 { * (in case of error throw an exception). */ boolean deleteConfiguration(@NotNull ResourceResolver resourceResolver, @NotNull String configResourcePath); - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/metadata/AbstractMetadata.java b/src/main/java/org/apache/sling/caconfig/spi/metadata/AbstractMetadata.java index feb3c25..8b44176 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/metadata/AbstractMetadata.java +++ b/src/main/java/org/apache/sling/caconfig/spi/metadata/AbstractMetadata.java @@ -30,7 +30,7 @@ abstract class AbstractMetadata<T> { private final String name; private String label; private String description; - private Map<String,String> properties; + private Map<String, String> properties; @SuppressWarnings("unused") public AbstractMetadata(@NotNull String name) { @@ -61,7 +61,7 @@ abstract class AbstractMetadata<T> { @SuppressWarnings("unchecked") public T label(String label) { this.label = label; - return (T)this; + return (T) this; } /** @@ -78,13 +78,13 @@ abstract class AbstractMetadata<T> { @SuppressWarnings("unchecked") public T description(String description) { this.description = description; - return (T)this; + return (T) this; } /** * @return Further properties for documentation and configuration of behavior in configuration editor. */ - public Map<String,String> getProperties() { + public Map<String, String> getProperties() { return this.properties; } @@ -93,14 +93,13 @@ abstract class AbstractMetadata<T> { * @return this; */ @SuppressWarnings("unchecked") - public T properties(Map<String,String> properties) { + public T properties(Map<String, String> properties) { this.properties = properties; - return (T)this; + return (T) this; } @Override public String toString() { return this.name; } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadata.java b/src/main/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadata.java index 0b4c075..49dc6fe 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadata.java +++ b/src/main/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadata.java @@ -31,7 +31,7 @@ import org.osgi.annotation.versioning.ProviderType; @ProviderType public final class ConfigurationMetadata extends AbstractMetadata<ConfigurationMetadata> { - private final Map<String,PropertyMetadata<?>> propertyMetadata; + private final Map<String, PropertyMetadata<?>> propertyMetadata; private final boolean collection; /** @@ -39,16 +39,15 @@ public final class ConfigurationMetadata extends AbstractMetadata<ConfigurationM * @param propertyMetadata Property metadata * @param collection Collection */ - public ConfigurationMetadata(@NotNull String name, - Collection<PropertyMetadata<?>> propertyMetadata, - boolean collection) { + public ConfigurationMetadata( + @NotNull String name, Collection<PropertyMetadata<?>> propertyMetadata, boolean collection) { super(name); this.propertyMetadata = toMap(propertyMetadata); this.collection = collection; } - private static Map<String,PropertyMetadata<?>> toMap(Collection<PropertyMetadata<?>> propertyMetadata) { - Map<String,PropertyMetadata<?>> map = new LinkedHashMap<>(); + private static Map<String, PropertyMetadata<?>> toMap(Collection<PropertyMetadata<?>> propertyMetadata) { + Map<String, PropertyMetadata<?>> map = new LinkedHashMap<>(); for (PropertyMetadata<?> item : propertyMetadata) { if (map.containsKey(item.getName())) { throw new IllegalArgumentException("Duplicate property name: " + item.getName()); @@ -75,8 +74,7 @@ public final class ConfigurationMetadata extends AbstractMetadata<ConfigurationM /** * @return Configuration properties */ - public Map<String,PropertyMetadata<?>> getPropertyMetadata() { + public Map<String, PropertyMetadata<?>> getPropertyMetadata() { return this.propertyMetadata; } - } diff --git a/src/main/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadata.java b/src/main/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadata.java index 7543e9c..e222e63 100644 --- a/src/main/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadata.java +++ b/src/main/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadata.java @@ -36,18 +36,14 @@ public final class PropertyMetadata<T> extends AbstractMetadata<PropertyMetadata // these are all types supported for fields of annotation classes (plus class which indicates nested configurations) private static final Class<?>[] SUPPORTED_TYPES_ARRAY = { - String.class, - int.class, - long.class, - double.class, - boolean.class + String.class, int.class, long.class, double.class, boolean.class }; /** * Set with all types support for property metadata (not including nested configurations). */ - public static final Set<Class<?>> SUPPORTED_TYPES = Collections.unmodifiableSet( - new HashSet<>(Arrays.asList(SUPPORTED_TYPES_ARRAY))); + public static final Set<Class<?>> SUPPORTED_TYPES = + Collections.unmodifiableSet(new HashSet<>(Arrays.asList(SUPPORTED_TYPES_ARRAY))); private final Class<T> type; private T defaultValue; @@ -58,10 +54,10 @@ public final class PropertyMetadata<T> extends AbstractMetadata<PropertyMetadata * @param name Property name * @param type Property type */ - @SuppressWarnings({ "unchecked", "null" }) + @SuppressWarnings({"unchecked", "null"}) public PropertyMetadata(@NotNull String name, @NotNull Class<T> type) { super(name); - Class<T> convertedType = (Class<T>)typeToPrimitive(type); + Class<T> convertedType = (Class<T>) typeToPrimitive(type); if (!isSupportedType(convertedType)) { throw new IllegalArgumentException("Invalid type for property '" + name + "': " + type); } @@ -74,7 +70,7 @@ public final class PropertyMetadata<T> extends AbstractMetadata<PropertyMetadata */ @SuppressWarnings("unchecked") public PropertyMetadata(@NotNull String name, @NotNull T defaultValue) { - this(name, (Class<T>)defaultValue.getClass()); + this(name, (Class<T>) defaultValue.getClass()); this.defaultValue = defaultValue; } @@ -94,8 +90,7 @@ public final class PropertyMetadata<T> extends AbstractMetadata<PropertyMetadata return boolean[].class; } } - } - else if (ClassUtils.isPrimitiveWrapper(clazz)) { + } else if (ClassUtils.isPrimitiveWrapper(clazz)) { if (clazz == Integer.class) { return int.class; } @@ -195,5 +190,4 @@ public final class PropertyMetadata<T> extends AbstractMetadata<PropertyMetadata public String toString() { return getName() + "[" + this.type.getSimpleName() + "]"; } - } diff --git a/src/test/java/org/apache/sling/caconfig/resource/spi/ContextResourceTest.java b/src/test/java/org/apache/sling/caconfig/resource/spi/ContextResourceTest.java index dbf8c44..a948c97 100644 --- a/src/test/java/org/apache/sling/caconfig/resource/spi/ContextResourceTest.java +++ b/src/test/java/org/apache/sling/caconfig/resource/spi/ContextResourceTest.java @@ -18,16 +18,16 @@ */ package org.apache.sling.caconfig.resource.spi; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import org.apache.sling.api.resource.Resource; import org.apache.sling.testing.mock.sling.junit.SlingContext; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + public class ContextResourceTest { @Rule @@ -52,15 +52,17 @@ public class ContextResourceTest { @Test public void testEquals() { - assertTrue(new ContextResource(resource1, "/conf/test", 0).equals(new ContextResource(resource1, "/conf/test", 10))); + assertTrue(new ContextResource(resource1, "/conf/test", 0) + .equals(new ContextResource(resource1, "/conf/test", 10))); assertTrue(new ContextResource(resource1, null, 0).equals(new ContextResource(resource1, null, 0))); } @Test public void testNotEquals() { - assertFalse(new ContextResource(resource1, "/conf/test", 0).equals(new ContextResource(resource2, "/conf/test", 0))); - assertFalse(new ContextResource(resource1, "/conf/test1", 0).equals(new ContextResource(resource1, "/conf/test2", 0))); + assertFalse(new ContextResource(resource1, "/conf/test", 0) + .equals(new ContextResource(resource2, "/conf/test", 0))); + assertFalse(new ContextResource(resource1, "/conf/test1", 0) + .equals(new ContextResource(resource1, "/conf/test2", 0))); assertFalse(new ContextResource(resource1, null, 0).equals(new ContextResource(resource1, "/conf/test", 0))); } - } diff --git a/src/test/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistDataTest.java b/src/test/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistDataTest.java index 280a74a..68d3c22 100644 --- a/src/test/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistDataTest.java +++ b/src/test/java/org/apache/sling/caconfig/spi/ConfigurationCollectionPersistDataTest.java @@ -18,24 +18,23 @@ */ package org.apache.sling.caconfig.spi; -import static org.junit.Assert.assertSame; - import java.util.Collection; import java.util.Map; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import static org.junit.Assert.assertSame; @RunWith(MockitoJUnitRunner.class) public class ConfigurationCollectionPersistDataTest { @Mock - private Map<String,Object> props; + private Map<String, Object> props; @Test public void testProperties() { @@ -44,14 +43,13 @@ public class ConfigurationCollectionPersistDataTest { new ConfigurationPersistData(ImmutableMap.<String, Object>of()).collectionItemName("item2"), new ConfigurationPersistData(ImmutableMap.<String, Object>of()).collectionItemName("item3")); - ConfigurationCollectionPersistData underTest = new ConfigurationCollectionPersistData(items) - .properties(props); + ConfigurationCollectionPersistData underTest = new ConfigurationCollectionPersistData(items).properties(props); assertSame(items, underTest.getItems()); assertSame(props, underTest.getProperties()); } - @Test(expected=ConfigurationPersistenceException.class) + @Test(expected = ConfigurationPersistenceException.class) public void testItemsDuplicateKeys() { Collection<ConfigurationPersistData> itemList = ImmutableList.of( new ConfigurationPersistData(ImmutableMap.<String, Object>of()).collectionItemName("item1"), @@ -61,7 +59,7 @@ public class ConfigurationCollectionPersistDataTest { new ConfigurationCollectionPersistData(itemList); } - @Test(expected=ConfigurationPersistenceException.class) + @Test(expected = ConfigurationPersistenceException.class) public void testItemsMissingItemName() { Collection<ConfigurationPersistData> itemList = ImmutableList.of( new ConfigurationPersistData(ImmutableMap.<String, Object>of()).collectionItemName("item1"), @@ -71,7 +69,7 @@ public class ConfigurationCollectionPersistDataTest { new ConfigurationCollectionPersistData(itemList); } - @Test(expected=ConfigurationPersistenceException.class) + @Test(expected = ConfigurationPersistenceException.class) public void testItemsInvalidItemNAme() { Collection<ConfigurationPersistData> itemList = ImmutableList.of( new ConfigurationPersistData(ImmutableMap.<String, Object>of()).collectionItemName("item1"), @@ -80,5 +78,4 @@ public class ConfigurationCollectionPersistDataTest { new ConfigurationCollectionPersistData(itemList); } - } diff --git a/src/test/java/org/apache/sling/caconfig/spi/ConfigurationPersistDataTest.java b/src/test/java/org/apache/sling/caconfig/spi/ConfigurationPersistDataTest.java index eb9d527..fde78a9 100644 --- a/src/test/java/org/apache/sling/caconfig/spi/ConfigurationPersistDataTest.java +++ b/src/test/java/org/apache/sling/caconfig/spi/ConfigurationPersistDataTest.java @@ -18,9 +18,6 @@ */ package org.apache.sling.caconfig.spi; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - import java.util.Map; import org.junit.Test; @@ -28,19 +25,20 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + @RunWith(MockitoJUnitRunner.class) public class ConfigurationPersistDataTest { @Mock - private Map<String,Object> props; + private Map<String, Object> props; @Test public void testGetProperties() { - ConfigurationPersistData underTest = new ConfigurationPersistData(props) - .collectionItemName("item1"); + ConfigurationPersistData underTest = new ConfigurationPersistData(props).collectionItemName("item1"); assertSame(props, underTest.getProperties()); assertEquals("item1", underTest.getCollectionItemName()); } - } diff --git a/src/test/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadataTest.java b/src/test/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadataTest.java index 30bb4ed..8012344 100644 --- a/src/test/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadataTest.java +++ b/src/test/java/org/apache/sling/caconfig/spi/metadata/ConfigurationMetadataTest.java @@ -18,30 +18,28 @@ */ package org.apache.sling.caconfig.spi.metadata; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.Map; -import org.junit.Test; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class ConfigurationMetadataTest { @Test public void testProps() { - ConfigurationMetadata underTest = new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of(), false); + ConfigurationMetadata underTest = + new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of(), false); assertEquals("name1", underTest.getName()); assertTrue(underTest.isSingleton()); assertFalse(underTest.isCollection()); - Map<String,String> props = ImmutableMap.of("p1", "v1"); - underTest.label("label1") - .description("desc1") - .properties(props); + Map<String, String> props = ImmutableMap.of("p1", "v1"); + underTest.label("label1").description("desc1").properties(props); assertEquals("label1", underTest.getLabel()); assertEquals("desc1", underTest.getDescription()); @@ -50,7 +48,8 @@ public class ConfigurationMetadataTest { @Test public void testCollectionProps() { - ConfigurationMetadata underTest = new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of(), true); + ConfigurationMetadata underTest = + new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of(), true); assertEquals("name1", underTest.getName()); assertFalse(underTest.isSingleton()); assertTrue(underTest.isCollection()); @@ -58,9 +57,11 @@ public class ConfigurationMetadataTest { @Test public void testPropertyMap() { - ConfigurationMetadata underTest = new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of( - new PropertyMetadata<>("prop1", "devValue"), - new PropertyMetadata<>("prop2", 5)), false); + ConfigurationMetadata underTest = new ConfigurationMetadata( + "name1", + ImmutableList.<PropertyMetadata<?>>of( + new PropertyMetadata<>("prop1", "devValue"), new PropertyMetadata<>("prop2", 5)), + false); assertEquals(2, underTest.getPropertyMetadata().size()); assertTrue(underTest.getPropertyMetadata().containsKey("prop1")); assertTrue(underTest.getPropertyMetadata().containsKey("prop2")); @@ -68,9 +69,10 @@ public class ConfigurationMetadataTest { @Test(expected = IllegalArgumentException.class) public void testDuplicateKey() { - new ConfigurationMetadata("name1", ImmutableList.<PropertyMetadata<?>>of( - new PropertyMetadata<>("prop1", "devValue"), - new PropertyMetadata<>("prop1", 5)), false); + new ConfigurationMetadata( + "name1", + ImmutableList.<PropertyMetadata<?>>of( + new PropertyMetadata<>("prop1", "devValue"), new PropertyMetadata<>("prop1", 5)), + false); } - } diff --git a/src/test/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadataTest.java b/src/test/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadataTest.java index ae70e1d..daa171f 100644 --- a/src/test/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadataTest.java +++ b/src/test/java/org/apache/sling/caconfig/spi/metadata/PropertyMetadataTest.java @@ -18,15 +18,14 @@ */ package org.apache.sling.caconfig.spi.metadata; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - import java.util.Map; -import org.junit.Test; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; public class PropertyMetadataTest { @@ -36,13 +35,15 @@ public class PropertyMetadataTest { assertEquals("name1", underTest.getName()); assertEquals(String.class, underTest.getType()); - ConfigurationMetadata configMetadata = new ConfigurationMetadata("test", ImmutableList.<PropertyMetadata<?>>of(), false); - Map<String,String> props = ImmutableMap.of("p1", "v1"); - underTest.label("label1") - .description("desc1") - .defaultValue("value1") - .properties(props) - .configurationMetadata(configMetadata); + ConfigurationMetadata configMetadata = + new ConfigurationMetadata("test", ImmutableList.<PropertyMetadata<?>>of(), false); + Map<String, String> props = ImmutableMap.of("p1", "v1"); + underTest + .label("label1") + .description("desc1") + .defaultValue("value1") + .properties(props) + .configurationMetadata(configMetadata); assertEquals("label1", underTest.getLabel()); assertEquals("desc1", underTest.getDescription()); @@ -83,12 +84,12 @@ public class PropertyMetadataTest { new PropertyMetadata<>("name1", ConfigurationMetadata[].class); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testDisallowedType() { new PropertyMetadata<>("name1", Object.class); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) @SuppressWarnings("null") public void testNullNale() { new PropertyMetadata<>(null, Object.class); @@ -101,8 +102,7 @@ public class PropertyMetadataTest { assertEquals(String.class, stringProp.getType()); PropertyMetadata<Integer> intProp = new PropertyMetadata<>("name1", 5); - assertEquals((Integer)5, intProp.getDefaultValue()); + assertEquals((Integer) 5, intProp.getDefaultValue()); assertEquals(int.class, intProp.getType()); } - }