Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
24a97805
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
24a97805
编写于
6月 01, 2011
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[SPR-7960] Renamed @ActivateProfiles to @ActiveProfiles and fleshed out JavaDoc.
上级
0c775416
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
34 deletion
+48
-34
org.springframework.test/src/main/java/org/springframework/test/context/ActiveProfiles.java
...java/org/springframework/test/context/ActiveProfiles.java
+4
-4
org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java
.../org/springframework/test/context/ContextLoaderUtils.java
+38
-24
org.springframework.test/src/test/java/org/springframework/test/context/ContextLoaderUtilsTests.java
...springframework/test/context/ContextLoaderUtilsTests.java
+6
-6
未找到文件。
org.springframework.test/src/main/java/org/springframework/test/context/Activ
at
eProfiles.java
→
org.springframework.test/src/main/java/org/springframework/test/context/ActiveProfiles.java
浏览文件 @
24a97805
...
...
@@ -24,9 +24,9 @@ import java.lang.annotation.RetentionPolicy;
import
java.lang.annotation.Target
;
/**
* {@code Activ
ateProfiles} is a class-level annotation that is used to
*
activate the bean definition profiles to use when loading an
* {@link org.springframework.context.ApplicationContext ApplicationContext}
* {@code Activ
eProfiles} is a class-level annotation that is used to declare
*
which <em>active bean definition profiles</em> should be used when loading
*
an
{@link org.springframework.context.ApplicationContext ApplicationContext}
* for test classes.
*
* @author Sam Brannen
...
...
@@ -40,7 +40,7 @@ import java.lang.annotation.Target;
@Inherited
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
TYPE
)
public
@interface
Activ
at
eProfiles
{
public
@interface
ActiveProfiles
{
/**
* Alias for {@link #profiles() profiles}.
...
...
org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java
浏览文件 @
24a97805
...
...
@@ -54,9 +54,9 @@ abstract class ContextLoaderUtils {
/**
* Resolves the {@link ContextLoader}
*
{@link Class} to use for the supplied {@link Class testClass} and
* th
en instantiates and returns th
at <code>ContextLoader</code>.
* Resolves the {@link ContextLoader}
{@link Class} to use for the
*
supplied {@link Class testClass} and then instantiates and returns
* that <code>ContextLoader</code>.
*
* <p>If the supplied <code>defaultContextLoaderClassName</code> is
* <code>null</code> or <em>empty</em>, the <em>standard</em>
...
...
@@ -68,7 +68,7 @@ abstract class ContextLoaderUtils {
* @param defaultContextLoaderClassName the name of the default
* <code>ContextLoader</code> class to use (may be <code>null</code>)
* @return the resolved <code>ContextLoader</code> for the supplied
* <code>testClass</code>
* <code>testClass</code>
(never <code>null</code>)
* @see #resolveContextLoaderClass(Class, String)
*/
static
ContextLoader
resolveContextLoader
(
Class
<?>
testClass
,
String
defaultContextLoaderClassName
)
{
...
...
@@ -85,8 +85,9 @@ abstract class ContextLoaderUtils {
}
/**
* Resolve the {@link ContextLoader} {@link Class} to use for the supplied
* Resolve
s
the {@link ContextLoader} {@link Class} to use for the supplied
* {@link Class test class}.
*
* <ol>
* <li>If the {@link ContextConfiguration#loader() loader} attribute of
* {@link ContextConfiguration @ContextConfiguration} is configured
...
...
@@ -98,11 +99,13 @@ abstract class ContextLoaderUtils {
* the class hierarchy, an attempt will be made to load and return the class
* with the supplied <code>defaultContextLoaderClassName</code>.</li>
* </ol>
* @param clazz the class for which to retrieve <code>ContextLoader</code>
*
* @param clazz the class for which to resolve the <code>ContextLoader</code>
* class; must not be <code>null</code>
* @param defaultContextLoaderClassName the name of the default
* <code>ContextLoader</code> class to use; must not be <code>null</code> or empty
* @return the <code>ContextLoader</code> class to use for the specified class
* (never <code>null</code>)
* @throws IllegalArgumentException if {@link ContextConfiguration
* @ContextConfiguration} is not <em>present</em> on the supplied class
*/
...
...
@@ -155,7 +158,7 @@ abstract class ContextLoaderUtils {
}
/**
* Re
trieve
{@link ApplicationContext} resource locations for the supplied
* Re
solves
{@link ApplicationContext} resource locations for the supplied
* {@link Class class}, using the supplied {@link ContextLoader} to
* {@link ContextLoader#processLocations(Class, String...) process} the
* locations.
...
...
@@ -166,12 +169,14 @@ abstract class ContextLoaderUtils {
* Specifically, if the <code>inheritLocations</code> flag is set to
* <code>true</code>, locations defined in the annotated class will be
* appended to the locations defined in superclasses.
*
* @param contextLoader the ContextLoader to use for processing the
* locations (must not be <code>null</code>)
* @param clazz the class for which to re
trie
ve the resource locations (must
* @param clazz the class for which to re
sol
ve the resource locations (must
* not be <code>null</code>)
* @return the list of ApplicationContext resource locations for the
* specified class, including locations from superclasses if appropriate
* (never <code>null</code>)
* @throws IllegalArgumentException if {@link ContextConfiguration
* @ContextConfiguration} is not <em>present</em> on the supplied class
*/
...
...
@@ -190,7 +195,7 @@ abstract class ContextLoaderUtils {
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]"
,
annotationType
,
clazz
));
List
<
String
>
locationsList
=
new
ArrayList
<
String
>();
final
List
<
String
>
locationsList
=
new
ArrayList
<
String
>();
while
(
declaringClass
!=
null
)
{
ContextConfiguration
contextConfiguration
=
declaringClass
.
getAnnotation
(
annotationType
);
...
...
@@ -202,25 +207,34 @@ abstract class ContextLoaderUtils {
String
[]
resolvedLocations
=
locationsResolver
.
resolveLocations
(
contextConfiguration
,
declaringClass
);
String
[]
processedLocations
=
contextLoader
.
processLocations
(
declaringClass
,
resolvedLocations
);
locationsList
.
addAll
(
0
,
Arrays
.
<
String
>
asList
(
processedLocations
));
locationsList
.
addAll
(
0
,
Arrays
.
asList
(
processedLocations
));
declaringClass
=
contextConfiguration
.
inheritLocations
()
?
AnnotationUtils
.
findAnnotationDeclaringClass
(
annotationType
,
declaringClass
.
getSuperclass
())
:
null
;
}
return
locationsList
.
toArray
(
new
String
[
locationsList
.
size
()]
);
return
StringUtils
.
toStringArray
(
locationsList
);
}
/**
* TODO Document resolveActiveProfiles().
* Resolves <em>active bean definition profiles</em> for the supplied
* {@link Class class}.
*
* <p>Note that the {@link ActiveProfiles#inheritProfiles() inheritProfiles}
* flag of {@link ActiveProfiles @ActiveProfiles} will be taken into
* consideration. Specifically, if the <code>inheritProfiles</code> flag is
* set to <code>true</code>, profiles defined in the annotated class will be
* merged with those defined in superclasses.
*
* @param clazz
* @return
* @param clazz the class for which to resolve the active profiles (must
* not be <code>null</code>)
* @return the set of active profiles for the specified class, including
* active profiles from superclasses if appropriate (never <code>null</code>)
*/
static
String
[]
resolveActiveProfiles
(
Class
<?>
clazz
)
{
Assert
.
notNull
(
clazz
,
"Class must not be null"
);
Class
<
Activ
ateProfiles
>
annotationType
=
Activat
eProfiles
.
class
;
Class
<
Activ
eProfiles
>
annotationType
=
Activ
eProfiles
.
class
;
Class
<?>
declaringClass
=
AnnotationUtils
.
findAnnotationDeclaringClass
(
annotationType
,
clazz
);
if
(
declaringClass
==
null
&&
logger
.
isDebugEnabled
())
{
...
...
@@ -232,20 +246,20 @@ abstract class ContextLoaderUtils {
final
Set
<
String
>
activeProfiles
=
new
LinkedHashSet
<
String
>();
while
(
declaringClass
!=
null
)
{
Activ
ateProfiles
activateProfiles
=
declaringClass
.
getAnnotation
(
annotationType
);
Activ
eProfiles
annotation
=
declaringClass
.
getAnnotation
(
annotationType
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
String
.
format
(
"Retrieved @Activ
ateProfiles [%s] for declaring class [%s]."
,
activateProfiles
,
declaringClass
));
logger
.
trace
(
String
.
format
(
"Retrieved @Activ
eProfiles [%s] for declaring class [%s]."
,
activeProfiles
,
declaringClass
));
}
String
[]
profiles
=
a
ctivateProfiles
.
profiles
();
String
[]
valueProfiles
=
a
ctivateProfiles
.
value
();
String
[]
profiles
=
a
nnotation
.
profiles
();
String
[]
valueProfiles
=
a
nnotation
.
value
();
if
(!
ObjectUtils
.
isEmpty
(
valueProfiles
)
&&
!
ObjectUtils
.
isEmpty
(
profiles
))
{
String
msg
=
String
.
format
(
"Test class [%s] has been configured with @Activ
at
eProfiles' 'value' [%s] "
+
"and 'profiles' [%s] attributes. Only one declaration of bean "
+
"definition profiles is permitted per @Activ
at
eProfiles annotation."
,
declaringClass
,
String
msg
=
String
.
format
(
"Test class [%s] has been configured with @ActiveProfiles' 'value' [%s] "
+
"and 'profiles' [%s] attributes. Only one declaration of
active
bean "
+
"definition profiles is permitted per @ActiveProfiles annotation."
,
declaringClass
,
ObjectUtils
.
nullSafeToString
(
valueProfiles
),
ObjectUtils
.
nullSafeToString
(
profiles
));
logger
.
error
(
msg
);
throw
new
IllegalStateException
(
msg
);
...
...
@@ -260,7 +274,7 @@ abstract class ContextLoaderUtils {
}
}
declaringClass
=
a
ctivateProfiles
.
inheritProfiles
()
?
AnnotationUtils
.
findAnnotationDeclaringClass
(
declaringClass
=
a
nnotation
.
inheritProfiles
()
?
AnnotationUtils
.
findAnnotationDeclaringClass
(
annotationType
,
declaringClass
.
getSuperclass
())
:
null
;
}
...
...
org.springframework.test/src/test/java/org/springframework/test/context/ContextLoaderUtilsTests.java
浏览文件 @
24a97805
...
...
@@ -108,30 +108,30 @@ public class ContextLoaderUtilsTests {
private
static
class
Enigma
{
}
@Activ
at
eProfiles
@ActiveProfiles
private
static
class
NoProfilesDeclared
{
}
@Activ
at
eProfiles
({
" "
,
"\t"
})
@ActiveProfiles
({
" "
,
"\t"
})
private
static
class
EmptyProfiles
{
}
@Activ
at
eProfiles
({
"foo"
,
"bar"
,
"foo"
,
"bar"
,
"baz"
})
@ActiveProfiles
({
"foo"
,
"bar"
,
"foo"
,
"bar"
,
"baz"
})
private
static
class
DuplicatedProfiles
{
}
@Activ
at
eProfiles
(
profiles
=
"foo"
)
@ActiveProfiles
(
profiles
=
"foo"
)
private
static
class
Foo
{
}
private
static
class
InheritedFoo
extends
Foo
{
}
@Activ
at
eProfiles
(
"bar"
)
@ActiveProfiles
(
"bar"
)
private
static
class
Bar
extends
Foo
{
}
@Activ
at
eProfiles
(
profiles
=
{
"dog"
,
"cat"
},
inheritProfiles
=
false
)
@ActiveProfiles
(
profiles
=
{
"dog"
,
"cat"
},
inheritProfiles
=
false
)
private
static
class
Animals
extends
Bar
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录