DATACMNS-1172 - Removed ability to use scanning all packages for repository implementations again.

Kept in a separate commit, so that it's easy to add again by reverting this commit. Removed, as the new behavior is effectively what had been documented as intended behavior all the time.

Original pull request: #248.
This commit is contained in:
Oliver Gierke
2017-09-27 16:05:41 +02:00
parent da88163141
commit 8da9679fc1
8 changed files with 3 additions and 98 deletions

View File

@@ -65,7 +65,6 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
private static final String REPOSITORY_FACTORY_BEAN_CLASS = "repositoryFactoryBeanClass";
private static final String REPOSITORY_BASE_CLASS = "repositoryBaseClass";
private static final String CONSIDER_NESTED_REPOSITORIES = "considerNestedRepositories";
private static final String LIMIT_IMPLEMENTATION_BASE_PACKAGES = "limitImplementationBasePackages";
private final AnnotationMetadata configMetadata;
private final AnnotationMetadata enableAnnotationMetadata;
@@ -322,20 +321,6 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
return attributes.containsKey(CONSIDER_NESTED_REPOSITORIES) && attributes.getBoolean(CONSIDER_NESTED_REPOSITORIES);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationSourceSupport#shouldLimitRepositoryImplementationBasePackages()
*/
@Override
public boolean shouldLimitRepositoryImplementationBasePackages() {
if (!attributes.containsKey(LIMIT_IMPLEMENTATION_BASE_PACKAGES)) {
return true;
}
return attributes.getBoolean(LIMIT_IMPLEMENTATION_BASE_PACKAGES);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#getAttribute(java.lang.String)

View File

@@ -78,10 +78,7 @@ public class DefaultRepositoryConfiguration<T extends RepositoryConfigurationSou
*/
@Override
public Streamable<String> getImplementationBasePackages() {
return configurationSource.shouldLimitRepositoryImplementationBasePackages()
? Streamable.of(ClassUtils.getPackageName(getRepositoryInterface()))
: getBasePackages();
return Streamable.of(ClassUtils.getPackageName(getRepositoryInterface()));
}
/*

View File

@@ -311,10 +311,7 @@ class RepositoryBeanDefinitionBuilder {
* @return
*/
public Iterable<String> getBasePackages() {
return configuration.getConfigurationSource().shouldLimitRepositoryImplementationBasePackages() ? //
Collections.singleton(ClassUtils.getPackageName(fragmentInterfaceName)) : //
configuration.getImplementationBasePackages();
return Collections.singleton(ClassUtils.getPackageName(fragmentInterfaceName));
}
/**

View File

@@ -63,17 +63,6 @@ public interface RepositoryConfigurationSource {
*/
Optional<String> getRepositoryImplementationPostfix();
/**
* Returns whether to limit repository implementation base packages for custom implementation scanning. If
* {@literal true}, then custom implementation scanning considers only the package of the repository/fragment
* interface and its subpackages for a scan. Otherwise, all {@link #getBasePackages()} are scanned for repository
* implementations
*
* @return {@literal true} if base packages are limited to the actual repository package.
* @since 2.0
*/
boolean shouldLimitRepositoryImplementationBasePackages();
/**
* @return
*/

View File

@@ -117,13 +117,4 @@ public abstract class RepositoryConfigurationSourceSupport implements Repository
public boolean shouldConsiderNestedRepositories() {
return false;
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationSource#isLimitRepositoryImplementationBasePackages()
*/
@Override
public boolean shouldLimitRepositoryImplementationBasePackages() {
return true;
}
}

View File

@@ -103,14 +103,6 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
assertThat(source.shouldConsiderNestedRepositories()).isTrue();
}
@Test // DATACMNS-1172
public void returnsLimitImplementationBasePackages() {
assertThat(getConfigSource(DefaultConfiguration.class).shouldLimitRepositoryImplementationBasePackages()).isTrue();
assertThat(getConfigSource(DefaultConfigurationWithoutBasePackageLimit.class)
.shouldLimitRepositoryImplementationBasePackages()).isFalse();
}
@Test // DATACMNS-456
public void findsStringAttributeByName() {
@@ -164,9 +156,6 @@ public class AnnotationRepositoryConfigurationSourceUnitTests {
@EnableRepositories(considerNestedRepositories = true)
static class DefaultConfigurationWithNestedRepositories {}
@EnableRepositories(limitImplementationBasePackages = false)
static class DefaultConfigurationWithoutBasePackageLimit {}
@EnableRepositories(excludeFilters = { @Filter(Primary.class) })
static class ConfigurationWithExplicitFilter {}

View File

@@ -34,7 +34,6 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.util.Streamable;
/**
* Unit tests for {@link DefaultRepositoryConfiguration}.
@@ -84,33 +83,6 @@ public class DefaultRepositoryConfigurationUnitTests {
assertThat(getConfiguration(source).getRepositoryFactoryBeanClassName()).isEqualTo("custom");
}
@Test // DATACMNS-1172
public void limitsImplementationBasePackages() {
when(source.shouldLimitRepositoryImplementationBasePackages()).thenReturn(true);
assertThat(getConfiguration(source, "com.acme.MyRepository").getImplementationBasePackages())
.containsOnly("com.acme");
}
@Test // DATACMNS-1172
public void limitsImplementationBasePackagesOfNestedClass() {
when(source.shouldLimitRepositoryImplementationBasePackages()).thenReturn(true);
assertThat(getConfiguration(source, NestedInterface.class.getName()).getImplementationBasePackages())
.containsOnly("org.springframework.data.repository.config");
}
@Test // DATACMNS-1172
public void shouldNotLimitImplementationBasePackages() {
when(source.getBasePackages()).thenReturn(Streamable.of("com", "org.coyote"));
assertThat(getConfiguration(source, "com.acme.MyRepository").getImplementationBasePackages()).contains("com",
"org.coyote");
}
private DefaultRepositoryConfiguration<RepositoryConfigurationSource> getConfiguration(
RepositoryConfigurationSource source) {
return getConfiguration(source, "com.acme.MyRepository");

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.repository.config;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.annotation.Annotation;
@@ -96,17 +95,6 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
assertNoBeanDefinitionRegisteredFor("fragmentImpl");
}
@Test // DATACMNS-1172
public void shouldNotLimitImplementationBasePackages() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(UnlimitedImplementationBasePackages.class, true);
registrar.registerBeanDefinitions(metadata, registry);
assertBeanDefinitionRegisteredFor("personRepository");
assertBeanDefinitionRegisteredFor("fragmentImpl");
}
@Test // DATACMNS-360
public void registeredProfileRepositoriesIfProfileActivated() {
@@ -179,7 +167,4 @@ public class RepositoryBeanDefinitionRegistrarSupportUnitTests {
@EnableRepositories(basePackageClasses = FragmentImpl.class)
static class LimitsImplementationBasePackages {}
@EnableRepositories(basePackageClasses = FragmentImpl.class, limitImplementationBasePackages = false)
static class UnlimitedImplementationBasePackages {}
}