Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
69fe8f30
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
69fe8f30
编写于
8月 02, 2013
作者:
J
Jesse Glick
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jenkinsci/jenkins
上级
af2c8994
72901837
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
13 deletion
+108
-13
core/src/main/java/hudson/tasks/Maven.java
core/src/main/java/hudson/tasks/Maven.java
+4
-2
core/src/main/java/hudson/util/ArgumentListBuilder.java
core/src/main/java/hudson/util/ArgumentListBuilder.java
+32
-11
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
+44
-0
test/src/test/java/hudson/tasks/MavenTest.java
test/src/test/java/hudson/tasks/MavenTest.java
+28
-0
未找到文件。
core/src/main/java/hudson/tasks/Maven.java
浏览文件 @
69fe8f30
...
@@ -55,6 +55,8 @@ import hudson.util.ArgumentListBuilder;
...
@@ -55,6 +55,8 @@ import hudson.util.ArgumentListBuilder;
import
hudson.util.NullStream
;
import
hudson.util.NullStream
;
import
hudson.util.StreamTaskListener
;
import
hudson.util.StreamTaskListener
;
import
hudson.util.VariableResolver
;
import
hudson.util.VariableResolver
;
import
hudson.util.VariableResolver.ByMap
;
import
hudson.util.VariableResolver.Union
;
import
hudson.util.FormValidation
;
import
hudson.util.FormValidation
;
import
hudson.util.XStream2
;
import
hudson.util.XStream2
;
import
net.sf.json.JSONObject
;
import
net.sf.json.JSONObject
;
...
@@ -264,7 +266,6 @@ public class Maven extends Builder {
...
@@ -264,7 +266,6 @@ public class Maven extends Builder {
String
targets
=
Util
.
replaceMacro
(
this
.
targets
,
vr
);
String
targets
=
Util
.
replaceMacro
(
this
.
targets
,
vr
);
targets
=
env
.
expand
(
targets
);
targets
=
env
.
expand
(
targets
);
String
pom
=
env
.
expand
(
this
.
pom
);
String
pom
=
env
.
expand
(
this
.
pom
);
String
properties
=
env
.
expand
(
this
.
properties
);
int
startIndex
=
0
;
int
startIndex
=
0
;
int
endIndex
;
int
endIndex
;
...
@@ -314,7 +315,8 @@ public class Maven extends Builder {
...
@@ -314,7 +315,8 @@ public class Maven extends Builder {
Set
<
String
>
sensitiveVars
=
build
.
getSensitiveBuildVariables
();
Set
<
String
>
sensitiveVars
=
build
.
getSensitiveBuildVariables
();
args
.
addKeyValuePairs
(
"-D"
,
build
.
getBuildVariables
(),
sensitiveVars
);
args
.
addKeyValuePairs
(
"-D"
,
build
.
getBuildVariables
(),
sensitiveVars
);
args
.
addKeyValuePairsFromPropertyString
(
"-D"
,
properties
,
vr
,
sensitiveVars
);
final
VariableResolver
<
String
>
resolver
=
new
Union
<
String
>(
new
ByMap
<
String
>(
env
),
vr
);
args
.
addKeyValuePairsFromPropertyString
(
"-D"
,
this
.
properties
,
resolver
,
sensitiveVars
);
if
(
usesPrivateRepository
())
if
(
usesPrivateRepository
())
args
.
add
(
"-Dmaven.repo.local="
+
build
.
getWorkspace
().
child
(
".repository"
));
args
.
add
(
"-Dmaven.repo.local="
+
build
.
getWorkspace
().
child
(
".repository"
));
args
.
addTokenized
(
normalizedTarget
);
args
.
addTokenized
(
normalizedTarget
);
...
...
core/src/main/java/hudson/util/ArgumentListBuilder.java
浏览文件 @
69fe8f30
...
@@ -192,16 +192,11 @@ public class ArgumentListBuilder implements Serializable, Cloneable {
...
@@ -192,16 +192,11 @@ public class ArgumentListBuilder implements Serializable, Cloneable {
* The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
* The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
* case this method becomes no-op.
* case this method becomes no-op.
* @param vr
* @param vr
* {@link VariableResolver} to
be performed on the values
.
* {@link VariableResolver} to
resolve variables in properties string
.
* @since 1.262
* @since 1.262
*/
*/
public
ArgumentListBuilder
addKeyValuePairsFromPropertyString
(
String
prefix
,
String
properties
,
VariableResolver
vr
)
throws
IOException
{
public
ArgumentListBuilder
addKeyValuePairsFromPropertyString
(
String
prefix
,
String
properties
,
VariableResolver
<
String
>
vr
)
throws
IOException
{
if
(
properties
==
null
)
return
this
;
return
addKeyValuePairsFromPropertyString
(
prefix
,
properties
,
vr
,
null
);
for
(
Entry
<
Object
,
Object
>
entry
:
Util
.
loadProperties
(
properties
).
entrySet
())
{
addKeyValuePair
(
prefix
,
(
String
)
entry
.
getKey
(),
Util
.
replaceMacro
(
entry
.
getValue
().
toString
(),
vr
),
false
);
}
return
this
;
}
}
/**
/**
...
@@ -213,21 +208,47 @@ public class ArgumentListBuilder implements Serializable, Cloneable {
...
@@ -213,21 +208,47 @@ public class ArgumentListBuilder implements Serializable, Cloneable {
* The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
* The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
* case this method becomes no-op.
* case this method becomes no-op.
* @param vr
* @param vr
* {@link VariableResolver} to
be performed on the values
.
* {@link VariableResolver} to
resolve variables in properties string
.
* @param propsToMask
* @param propsToMask
* Set containing key names to mark as masked in the argument list. Key
* Set containing key names to mark as masked in the argument list. Key
* names that do not exist in the set will be added unmasked.
* names that do not exist in the set will be added unmasked.
* @since 1.378
* @since 1.378
*/
*/
public
ArgumentListBuilder
addKeyValuePairsFromPropertyString
(
String
prefix
,
String
properties
,
VariableResolver
vr
,
Set
<
String
>
propsToMask
)
throws
IOException
{
public
ArgumentListBuilder
addKeyValuePairsFromPropertyString
(
String
prefix
,
String
properties
,
VariableResolver
<
String
>
vr
,
Set
<
String
>
propsToMask
)
throws
IOException
{
if
(
properties
==
null
)
return
this
;
if
(
properties
==
null
)
return
this
;
properties
=
Util
.
replaceMacro
(
properties
,
propertiesGeneratingResolver
(
vr
));
for
(
Entry
<
Object
,
Object
>
entry
:
Util
.
loadProperties
(
properties
).
entrySet
())
{
for
(
Entry
<
Object
,
Object
>
entry
:
Util
.
loadProperties
(
properties
).
entrySet
())
{
addKeyValuePair
(
prefix
,
(
String
)
entry
.
getKey
(),
Util
.
replaceMacro
(
entry
.
getValue
().
toString
(),
vr
),
(
propsToMask
==
null
)
?
false
:
propsToMask
.
contains
((
String
)
entry
.
getKey
()));
addKeyValuePair
(
prefix
,
(
String
)
entry
.
getKey
(),
entry
.
getValue
().
toString
(),
(
propsToMask
==
null
)
?
false
:
propsToMask
.
contains
(
entry
.
getKey
()));
}
}
return
this
;
return
this
;
}
}
/**
* Creates a resolver generating values to be safely placed in properties string.
*
* {@link Properties#load} generally removes single backslashes from input and that
* is not desirable for outcomes of macro substitution as the values can
* contain them but user has no way to escape them.
*
* @param original Resolution will be delegated to this resolver. Resolved
* values will be escaped afterwards.
* @see https://issues.jenkins-ci.org/browse/JENKINS-10539
*/
private
static
VariableResolver
<
String
>
propertiesGeneratingResolver
(
final
VariableResolver
<
String
>
original
)
{
return
new
VariableResolver
<
String
>()
{
public
String
resolve
(
String
name
)
{
final
String
value
=
original
.
resolve
(
name
);
if
(
value
==
null
)
return
null
;
// Substitute one backslash with two
return
value
.
replaceAll
(
"\\\\"
,
"\\\\\\\\"
);
}
};
}
public
String
[]
toCommandArray
()
{
public
String
[]
toCommandArray
()
{
return
args
.
toArray
(
new
String
[
args
.
size
()]);
return
args
.
toArray
(
new
String
[
args
.
size
()]);
}
}
...
...
core/src/test/java/hudson/util/ArgumentListBuilderTest.java
浏览文件 @
69fe8f30
...
@@ -23,6 +23,9 @@
...
@@ -23,6 +23,9 @@
*/
*/
package
hudson.util
;
package
hudson.util
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -183,4 +186,45 @@ public class ArgumentListBuilderTest extends Assert {
...
@@ -183,4 +186,45 @@ public class ArgumentListBuilderTest extends Assert {
assertNotNull
(
"The mask array should not be null"
,
array
);
assertNotNull
(
"The mask array should not be null"
,
array
);
assertArrayEquals
(
"The mask array was incorrect"
,
new
boolean
[]{
false
,
false
,
false
},
array
);
assertArrayEquals
(
"The mask array was incorrect"
,
new
boolean
[]{
false
,
false
,
false
},
array
);
}
}
@Test
public
void
addKeyValuePairsFromPropertyString
()
throws
IOException
{
final
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"PATH"
,
"C:\\Windows"
);
final
VariableResolver
<
String
>
resolver
=
new
VariableResolver
.
ByMap
<
String
>(
map
);
final
String
properties
=
"my.path=$PATH"
;
ArgumentListBuilder
builder
=
new
ArgumentListBuilder
();
builder
.
addKeyValuePairsFromPropertyString
(
""
,
properties
,
resolver
);
assertEquals
(
"my.path=C:\\Windows"
,
builder
.
toString
());
builder
=
new
ArgumentListBuilder
();
builder
.
addKeyValuePairsFromPropertyString
(
""
,
properties
,
resolver
,
null
);
assertEquals
(
"my.path=C:\\Windows"
,
builder
.
toString
());
}
@Test
public
void
numberOfBackslashesInPropertiesShouldBePreservedAfterMacroExpansion
()
throws
IOException
{
final
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"ONE"
,
"one\\backslash"
);
map
.
put
(
"TWO"
,
"two\\\\backslashes"
);
map
.
put
(
"FOUR"
,
"four\\\\\\\\backslashes"
);
final
String
properties
=
new
StringBuilder
()
.
append
(
"one=$ONE\n"
)
.
append
(
"two=$TWO\n"
)
.
append
(
"four=$FOUR\n"
)
.
toString
()
;
final
String
args
=
new
ArgumentListBuilder
()
.
addKeyValuePairsFromPropertyString
(
""
,
properties
,
new
VariableResolver
.
ByMap
<
String
>(
map
))
.
toString
()
;
assertThat
(
args
,
containsString
(
"one=one\\backslash"
));
assertThat
(
args
,
containsString
(
"two=two\\\\backslashes"
));
assertThat
(
args
,
containsString
(
"four=four\\\\\\\\backslashes"
));
}
}
}
test/src/test/java/hudson/tasks/MavenTest.java
浏览文件 @
69fe8f30
...
@@ -206,6 +206,34 @@ public class MavenTest {
...
@@ -206,6 +206,34 @@ public class MavenTest {
assertFalse
(
buildLog
.
contains
(
"-Dpassword=12345"
));
assertFalse
(
buildLog
.
contains
(
"-Dpassword=12345"
));
}
}
@Test
public
void
parametersReferencedFromPropertiesShouldRetainBackslashes
()
throws
Exception
{
final
String
properties
=
"global.path=$GLOBAL_PATH\nmy.path=$PATH\\\\Dir"
;
final
StringParameterDefinition
parameter
=
new
StringParameterDefinition
(
"PATH"
,
"C:\\Windows"
);
final
Entry
envVar
=
new
Entry
(
"GLOBAL_PATH"
,
"D:\\Jenkins"
);
FreeStyleProject
project
=
j
.
createFreeStyleProject
();
project
.
getBuildersList
().
add
(
new
Maven
(
"--help"
,
null
,
null
,
properties
,
null
));
project
.
addProperty
(
new
ParametersDefinitionProperty
(
parameter
));
j
.
jenkins
.
getNodeProperties
().
replaceBy
(
Collections
.
singleton
(
new
EnvironmentVariablesNodeProperty
(
envVar
)
));
FreeStyleBuild
build
=
project
.
scheduleBuild2
(
0
).
get
();
@SuppressWarnings
(
"deprecation"
)
String
buildLog
=
build
.
getLog
();
assertNotNull
(
buildLog
);
assertTrue
(
"Parameter my.path should preserve backslashes in:\n"
+
buildLog
,
buildLog
.
contains
(
"-Dmy.path=C:\\Windows\\Dir"
)
);
assertTrue
(
"Parameter global.path should preserve backslashes in:\n"
+
buildLog
,
buildLog
.
contains
(
"-Dglobal.path=D:\\Jenkins"
)
);
}
@Test
public
void
defaultSettingsProvider
()
throws
Exception
{
@Test
public
void
defaultSettingsProvider
()
throws
Exception
{
{
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录