Revised indexer implementation

Issue: SPR-11890
This commit is contained in:
Juergen Hoeller
2017-01-17 12:46:55 +01:00
parent 0c99346829
commit 5471d6a465
20 changed files with 146 additions and 174 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +28,8 @@ import org.springframework.util.MultiValueMap;
/**
* Provide access to the candidates that are defined in {@code META-INF/spring.components}.
* <p>
* An arbitrary number of stereotypes can be registered (and queried) on the index: a
*
* <p>An arbitrary number of stereotypes can be registered (and queried) on the index: a
* typical example is the fully qualified name of an annotation that flags the class for
* a certain use case. The following call returns all the {@code @Component}
* <b>candidate</b> types for the {@code com.example} package (and its sub-packages):
@@ -38,7 +38,7 @@ import org.springframework.util.MultiValueMap;
* "com.example", "org.springframework.stereotype.Component");
* </pre>
*
* The {@code type} is usually the fully qualified name of a class, though this is
* <p>The {@code type} is usually the fully qualified name of a class, though this is
* not a rule. Similarly, the {@code stereotype} is usually the fully qualified name of
* a target type but it can be any marker really.
*
@@ -49,10 +49,12 @@ public class CandidateComponentsIndex {
private final MultiValueMap<String, String> index;
CandidateComponentsIndex(List<Properties> content) {
this.index = parseIndex(content);
}
/**
* Return the candidate types that are associated with the specified stereotype.
* @param basePackage the package to check for candidates

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,6 +87,7 @@ public class CandidateComponentsIndexLoader {
if (shouldIgnoreIndex) {
return null;
}
try {
Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION);
if (!urls.hasMoreElements()) {
@@ -98,14 +99,14 @@ public class CandidateComponentsIndexLoader {
Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
result.add(properties);
}
if (logger.isTraceEnabled()) {
logger.trace("Loaded " + result.size() + "] index(es)");
if (logger.isDebugEnabled()) {
logger.debug("Loaded " + result.size() + "] index(es)");
}
int totalCount = result.stream().mapToInt(Properties::size).sum();
return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
}
catch (IOException ex) {
throw new IllegalArgumentException("Unable to load indexes from location [" +
throw new IllegalStateException("Unable to load indexes from location [" +
COMPONENTS_RESOURCE_LOCATION + "]", ex);
}
}

View File

@@ -1,20 +1,4 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Support package for reading and managing the components index.
*/
package org.springframework.context.index;
package org.springframework.context.index;