Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
af42534d
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,发现更多精彩内容 >>
提交
af42534d
编写于
8月 18, 2012
作者:
N
Nicolas De Loof
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[JENKINS-11759] extension point to resolve jenkins user from SCM id
上级
6dfd8db3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
11 deletion
+102
-11
core/src/main/java/hudson/model/User.java
core/src/main/java/hudson/model/User.java
+37
-11
core/src/main/java/jenkins/model/DefaultUserCannonicalIdResolver.java
...n/java/jenkins/model/DefaultUserCannonicalIdResolver.java
+65
-0
未找到文件。
core/src/main/java/hudson/model/User.java
浏览文件 @
af42534d
...
...
@@ -26,12 +26,7 @@ package hudson.model;
import
com.infradna.tool.bridge_method_injector.WithBridgeMethods
;
import
com.thoughtworks.xstream.XStream
;
import
hudson.CopyOnWrite
;
import
hudson.FeedAdapter
;
import
hudson.Functions
;
import
hudson.Util
;
import
hudson.XmlFile
;
import
hudson.BulkChange
;
import
hudson.*
;
import
hudson.model.Descriptor.FormException
;
import
hudson.model.listeners.SaveableListener
;
import
hudson.security.ACL
;
...
...
@@ -77,7 +72,6 @@ import java.util.logging.Level;
import
java.util.logging.Logger
;
import
javax.annotation.CheckForNull
;
import
javax.annotation.Nonnull
;
import
javax.annotation.Nullable
;
/**
* Represents a user.
...
...
@@ -295,12 +289,21 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* If false, this method will return null if {@link User} object
* with the given name doesn't exist.
*/
public
static
@Nullable
User
get
(
String
idOrFullName
,
boolean
create
)
{
public
static
User
get
(
String
idOrFullName
,
boolean
create
)
{
if
(
idOrFullName
==
null
)
return
null
;
String
id
=
idOrFullName
.
replace
(
'\\'
,
'_'
).
replace
(
'/'
,
'_'
).
replace
(
'<'
,
'_'
)
.
replace
(
'>'
,
'_'
);
// 4 replace() still faster than regex
if
(
Functions
.
isWindows
())
id
=
id
.
replace
(
':'
,
'_'
);
// sort resolvers by priority
List
<
CannonicalIdResolver
>
resolvers
=
new
ArrayList
<
CannonicalIdResolver
>(
Jenkins
.
getInstance
().
getExtensionList
(
CannonicalIdResolver
.
class
));
Collections
.
sort
(
resolvers
);
String
id
=
null
;
for
(
CannonicalIdResolver
resolver
:
resolvers
)
{
id
=
resolver
.
resolveCannonicalId
(
idOrFullName
);
if
(
id
!=
null
)
break
;
}
// DefaultUserCannonicalIdResolver will always return a non-null id if all other CannonicalIdResolver failed
String
idkey
=
id
.
toLowerCase
(
Locale
.
ENGLISH
);
...
...
@@ -635,5 +638,28 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
}
return
Collections
.
unmodifiableList
(
actions
);
}
public
static
abstract
class
CannonicalIdResolver
extends
AbstractDescribableImpl
<
CannonicalIdResolver
>
implements
Comparable
<
CannonicalIdResolver
>
{
public
int
compareTo
(
CannonicalIdResolver
o
)
{
// reverse priority order
int
i
=
getPriority
();
int
j
=
o
.
getPriority
();
return
i
>
j
?
-
1
:
(
i
==
j
?
0
:
1
);
}
/**
* extract user ID from idOrFullName with help from contextual infos.
* can return <code>null</code> if no user ID matched the input
*/
public
abstract
String
resolveCannonicalId
(
String
idOrFullName
);
public
int
getPriority
()
{
return
1
;
}
}
}
core/src/main/java/jenkins/model/DefaultUserCannonicalIdResolver.java
0 → 100644
浏览文件 @
af42534d
/*
* The MIT License
*
* Copyright (c) 2004-2012, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
* Tom Huybrechts, Vincent Latombe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
jenkins.model
;
import
hudson.Extension
;
import
hudson.Functions
;
import
hudson.model.Descriptor
;
import
hudson.model.User
;
/**
* Default User.CannonicalIdResolver to escape unsupported characters and generate user ID.
* Compared to other implementations, this resolver will always return an ID
*
* @author: <a hef="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
@Extension
public
class
DefaultUserCannonicalIdResolver
extends
User
.
CannonicalIdResolver
{
@Override
public
String
resolveCannonicalId
(
String
idOrFullName
)
{
String
id
=
idOrFullName
.
replace
(
'\\'
,
'_'
).
replace
(
'/'
,
'_'
).
replace
(
'<'
,
'_'
)
.
replace
(
'>'
,
'_'
);
// 4 replace() still faster than regex
if
(
Functions
.
isWindows
())
id
=
id
.
replace
(
':'
,
'_'
);
return
id
;
}
@Override
public
int
getPriority
()
{
return
Integer
.
MIN_VALUE
;
}
@Override
public
Descriptor
<
User
.
CannonicalIdResolver
>
getDescriptor
()
{
return
DESCRIPTOR
;
}
public
static
final
Descriptor
<
User
.
CannonicalIdResolver
>
DESCRIPTOR
=
new
Descriptor
<
User
.
CannonicalIdResolver
>()
{
public
String
getDisplayName
()
{
return
"compute default user ID"
;
}
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录