Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
e23599a0
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e23599a0
编写于
8月 12, 2014
作者:
C
CloudBees DEV@Cloud
浏览文件
操作
浏览文件
下载
差异文件
Merge REMERGE_HEAD into HEAD
上级
936fb569
978d1922
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
71 addition
and
2 deletion
+71
-2
core/src/main/java/hudson/model/User.java
core/src/main/java/hudson/model/User.java
+2
-2
core/src/main/java/jenkins/model/IdStrategy.java
core/src/main/java/jenkins/model/IdStrategy.java
+63
-0
test/src/test/java/hudson/model/UserTest.java
test/src/test/java/hudson/model/UserTest.java
+6
-0
未找到文件。
core/src/main/java/hudson/model/User.java
浏览文件 @
e23599a0
...
...
@@ -459,6 +459,7 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* Gets all the users.
*/
public
static
Collection
<
User
>
getAll
()
{
final
IdStrategy
strategy
=
idStrategy
();
if
(
System
.
currentTimeMillis
()
-
lastScanned
>
10000
)
{
// occasionally scan the file system to check new users
// whether we should do this only once at start up or not is debatable.
...
...
@@ -471,7 +472,7 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
for
(
File
subdir
:
subdirs
)
if
(
new
File
(
subdir
,
"config.xml"
).
exists
())
{
String
name
=
s
ubdir
.
getName
(
);
String
name
=
s
trategy
.
idFromFilename
(
subdir
.
getName
()
);
User
.
getOrCreate
(
name
,
name
,
true
);
}
...
...
@@ -486,7 +487,6 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
byNameLock
.
readLock
().
unlock
();
}
Collections
.
sort
(
r
,
new
Comparator
<
User
>()
{
IdStrategy
strategy
=
idStrategy
();
public
int
compare
(
User
o1
,
User
o2
)
{
return
strategy
.
compare
(
o1
.
getId
(),
o2
.
getId
());
...
...
core/src/main/java/jenkins/model/IdStrategy.java
浏览文件 @
e23599a0
...
...
@@ -57,6 +57,16 @@ public abstract class IdStrategy extends AbstractDescribableImpl<IdStrategy> imp
@Nonnull
public
abstract
String
filenameOf
(
@Nonnull
String
id
);
/**
* Converts a filename into the corresponding id.
* @param filename the filename.
* @return the corresponding id.
* @since 1.577
*/
public
String
idFromFilename
(
@Nonnull
String
filename
)
{
return
filename
;
}
/**
* Converts an ID into a key for use in a Java Map.
*
...
...
@@ -214,6 +224,59 @@ public abstract class IdStrategy extends AbstractDescribableImpl<IdStrategy> imp
}
}
@Override
public
String
idFromFilename
(
@Nonnull
String
filename
)
{
if
(
filename
.
matches
(
"[a-z0-9_. -]+"
))
{
return
filename
;
}
else
{
StringBuilder
buf
=
new
StringBuilder
(
filename
.
length
());
final
char
[]
chars
=
filename
.
toCharArray
();
for
(
int
i
=
0
;
i
<
chars
.
length
;
i
++)
{
char
c
=
chars
[
i
];
if
(
'a'
<=
c
&&
c
<=
'z'
)
{
buf
.
append
(
c
);
}
else
if
(
'0'
<=
c
&&
c
<=
'9'
)
{
buf
.
append
(
c
);
}
else
if
(
'_'
==
c
||
'.'
==
c
||
'-'
==
c
||
' '
==
c
||
'@'
==
c
)
{
buf
.
append
(
c
);
}
else
if
(
c
==
'~'
)
{
i
++;
if
(
i
<
chars
.
length
)
{
buf
.
append
(
Character
.
toUpperCase
(
chars
[
i
]));
}
}
else
if
(
c
==
'$'
)
{
StringBuilder
hex
=
new
StringBuilder
(
4
);
i
++;
if
(
i
<
chars
.
length
)
{
hex
.
append
(
chars
[
i
]);
}
else
{
break
;
}
i
++;
if
(
i
<
chars
.
length
)
{
hex
.
append
(
chars
[
i
]);
}
else
{
break
;
}
i
++;
if
(
i
<
chars
.
length
)
{
hex
.
append
(
chars
[
i
]);
}
else
{
break
;
}
i
++;
if
(
i
<
chars
.
length
)
{
hex
.
append
(
chars
[
i
]);
}
else
{
break
;
}
buf
.
append
(
Character
.
valueOf
((
char
)
Integer
.
parseInt
(
hex
.
toString
(),
16
)));
}
}
return
buf
.
toString
();
}
}
/**
* {@inheritDoc}
*/
...
...
test/src/test/java/hudson/model/UserTest.java
浏览文件 @
e23599a0
...
...
@@ -174,6 +174,8 @@ public class UserTest {
User
user
=
User
.
get
(
"john smith"
);
User
user2
=
User
.
get
(
"John Smith"
);
assertSame
(
"Users should have the same id."
,
user
.
getId
(),
user2
.
getId
());
assertEquals
(
user
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user
.
getId
())));
assertEquals
(
user2
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user2
.
getId
())));
}
@Test
...
...
@@ -191,6 +193,8 @@ public class UserTest {
assertEquals
(
"john smith"
,
User
.
idStrategy
().
filenameOf
(
user
.
getId
()));
assertEquals
(
"John Smith"
,
User
.
idStrategy
().
keyFor
(
user2
.
getId
()));
assertEquals
(
"~john ~smith"
,
User
.
idStrategy
().
filenameOf
(
user2
.
getId
()));
assertEquals
(
user
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user
.
getId
())));
assertEquals
(
user2
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user2
.
getId
())));
}
@Test
...
...
@@ -212,6 +216,8 @@ public class UserTest {
assertEquals
(
"Users should have the same id."
,
user
.
getId
(),
user2
.
getId
());
assertEquals
(
"john.smith@acme.org"
,
User
.
idStrategy
().
keyFor
(
user2
.
getId
()));
assertEquals
(
"john.smith@acme.org"
,
User
.
idStrategy
().
filenameOf
(
user2
.
getId
()));
assertEquals
(
user
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user
.
getId
())));
assertEquals
(
user2
.
getId
(),
User
.
idStrategy
().
idFromFilename
(
User
.
idStrategy
().
filenameOf
(
user2
.
getId
())));
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录