Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
ce29cdb3
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,发现更多精彩内容 >>
提交
ce29cdb3
编写于
10月 07, 2013
作者:
O
Oliver Gondža
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jenkinsci/jenkins
上级
6f0a471e
7ca4dc47
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
134 addition
and
35 deletion
+134
-35
changelog.html
changelog.html
+3
-0
core/src/main/java/hudson/model/AbstractBuild.java
core/src/main/java/hudson/model/AbstractBuild.java
+9
-14
core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
.../main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
+5
-1
test/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java
...main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java
+2
-0
test/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java
...rc/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java
+73
-0
test/src/test/groovy/hudson/model/AbstractBuildTest.groovy
test/src/test/groovy/hudson/model/AbstractBuildTest.groovy
+42
-20
未找到文件。
changelog.html
浏览文件 @
ce29cdb3
...
...
@@ -61,6 +61,9 @@ Upcoming changes</a>
<li
class=
bug
>
Windows JDK installer should not install a public JRE.
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-8957"
>
issue 8957
</a>
)
<li
class=
'major bug'
>
After deleting last build, next build of last build is zombie.
(
<a
href=
"https://issues.jenkins-ci.org/browse/JENKINS-19920"
>
issue 19920
</a>
)
<li
class=
'rfe'
>
Split matrix authorization strategies into an independent plugin.
<li
class=
'rfe'
>
...
...
core/src/main/java/hudson/model/AbstractBuild.java
浏览文件 @
ce29cdb3
...
...
@@ -162,10 +162,13 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
* <p>
* Unlike {@link Run}, {@link AbstractBuild}s do lazy-loading, so we don't use
* {@link Run#previousBuild} and {@link Run#nextBuild}, and instead use these
* fields and point to {@link #selfReference} of adjacent builds.
* fields and point to {@link #selfReference}
(or {@link #none})
of adjacent builds.
*/
private
volatile
transient
BuildReference
<
R
>
previousBuild
,
nextBuild
;
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
static
final
BuildReference
NONE
=
new
BuildReference
(
"NONE"
,
null
);
@SuppressWarnings
(
"unchecked"
)
private
BuildReference
<
R
>
none
()
{
return
NONE
;}
/*package*/
final
transient
BuildReference
<
R
>
selfReference
=
new
BuildReference
<
R
>(
getId
(),
_this
());
...
...
@@ -193,11 +196,7 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
if
(
nextBuild
!=
null
)
{
AbstractBuild
nb
=
nextBuild
.
get
();
if
(
nb
!=
null
)
{
// remove the oldest build
if
(
previousBuild
==
selfReference
)
nb
.
previousBuild
=
nextBuild
;
else
nb
.
previousBuild
=
previousBuild
;
nb
.
previousBuild
=
previousBuild
;
}
}
if
(
previousBuild
!=
null
)
{
...
...
@@ -223,13 +222,11 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
this
.
previousBuild
=
pb
.
selfReference
;
return
pb
;
}
else
{
// this indicates that we know there's no previous build
// (as opposed to we don't know if/what our previous build is.
this
.
previousBuild
=
selfReference
;
this
.
previousBuild
=
none
();
return
null
;
}
}
if
(
r
==
selfReference
)
if
(
r
==
none
()
)
return
null
;
R
referent
=
r
.
get
();
...
...
@@ -253,13 +250,11 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
this
.
nextBuild
=
nb
.
selfReference
;
return
nb
;
}
else
{
// this indicates that we know there's no next build
// (as opposed to we don't know if/what our next build is.
this
.
nextBuild
=
selfReference
;
this
.
nextBuild
=
none
();
return
null
;
}
}
if
(
r
==
selfReference
)
if
(
r
==
none
()
)
return
null
;
R
referent
=
r
.
get
();
...
...
core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java
浏览文件 @
ce29cdb3
...
...
@@ -723,7 +723,11 @@ public abstract class AbstractLazyLoadRunMap<R> extends AbstractMap<Integer,R> i
public
synchronized
boolean
removeValue
(
R
run
)
{
Index
copy
=
copy
();
copy
.
byNumber
.
remove
(
getNumberOf
(
run
));
int
n
=
getNumberOf
(
run
);
copy
.
byNumber
.
remove
(
n
);
SortedIntList
a
=
new
SortedIntList
(
numberOnDisk
);
a
.
removeValue
(
n
);
numberOnDisk
=
a
;
BuildReference
<
R
>
old
=
copy
.
byId
.
remove
(
getIdOf
(
run
));
this
.
index
=
copy
;
...
...
test/src/main/java/org/jvnet/hudson/test/GroovyHudsonTestCase.java
浏览文件 @
ce29cdb3
...
...
@@ -15,7 +15,9 @@ import java.io.IOException;
* {@link HudsonTestCase} with more convenience methods for Groovy.
*
* @author Kohsuke Kawaguchi
* @deprecated Use {@link GroovyJenkinsRule} instead.
*/
@Deprecated
public
abstract
class
GroovyHudsonTestCase
extends
HudsonTestCase
{
/**
* Executes the given closure on the server, in the context of an HTTP request.
...
...
test/src/main/java/org/jvnet/hudson/test/GroovyJenkinsRule.java
0 → 100644
浏览文件 @
ce29cdb3
/*
* The MIT License
*
* Copyright 2013 Jesse Glick.
*
* 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
org.jvnet.hudson.test
;
import
groovy.lang.Closure
;
import
hudson.Launcher
;
import
hudson.model.AbstractBuild
;
import
hudson.model.BuildListener
;
import
hudson.tasks.Builder
;
import
java.io.IOException
;
import
java.util.concurrent.Callable
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
/**
* {@link JenkinsRule} variant with special options for tests written in Groovy.
* @since 1.535
*/
public
class
GroovyJenkinsRule
extends
JenkinsRule
{
/**
* Executes the given closure on the server, in the context of an HTTP request.
* This is useful for testing some methods that require {@link StaplerRequest} and {@link StaplerResponse}.
*
* <p>
* The closure will get the request and response as parameters.
*/
public
Object
executeOnServer
(
final
Closure
c
)
throws
Exception
{
return
executeOnServer
(
new
Callable
<
Object
>()
{
@Override
public
Object
call
()
throws
Exception
{
return
c
.
call
();
}
});
}
/**
* Wraps a closure as a {@link Builder}.
*/
public
Builder
builder
(
final
Closure
c
)
{
return
new
TestBuilder
()
{
@Override
public
boolean
perform
(
AbstractBuild
<?,?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
Object
r
=
c
.
call
(
new
Object
[]
{
build
,
launcher
,
listener
});
if
(
r
instanceof
Boolean
)
{
return
(
Boolean
)
r
;
}
return
true
;
}
};
}
}
test/src/test/groovy/hudson/model/AbstractBuildTest.groovy
浏览文件 @
ce29cdb3
...
...
@@ -29,21 +29,29 @@ import hudson.slaves.EnvironmentVariablesNodeProperty
import
hudson.slaves.EnvironmentVariablesNodeProperty.Entry
import
org.jvnet.hudson.test.CaptureEnvironmentBuilder
import
org.jvnet.hudson.test.Groovy
HudsonTestCas
e
import
org.jvnet.hudson.test.Groovy
JenkinsRul
e
import
org.jvnet.hudson.test.FakeChangeLogSCM
import
org.jvnet.hudson.test.FailureBuilder
import
org.jvnet.hudson.test.UnstableBuilder
public
class
AbstractBuildTest
extends
GroovyHudsonTestCase
{
void
testVariablesResolved
()
{
def
project
=
createFreeStyleProject
();
jenkins
.
nodeProperties
.
replaceBy
([
import
static
org
.
junit
.
Assert
.*
import
org.junit.Rule
import
org.junit.Test
import
org.jvnet.hudson.test.Bug
public
class
AbstractBuildTest
{
@Rule
public
GroovyJenkinsRule
j
=
new
GroovyJenkinsRule
();
@Test
void
variablesResolved
()
{
def
project
=
j
.
createFreeStyleProject
();
j
.
jenkins
.
nodeProperties
.
replaceBy
([
new
EnvironmentVariablesNodeProperty
(
new
Entry
(
"KEY1"
,
"value"
),
new
Entry
(
"KEY2"
,
'$KEY1'
))]);
def
builder
=
new
CaptureEnvironmentBuilder
();
project
.
buildersList
.
add
(
builder
);
buildAndAssertSuccess
(
project
);
j
.
buildAndAssertSuccess
(
project
);
def
envVars
=
builder
.
getEnvVars
();
assertEquals
(
"value"
,
envVars
[
"KEY1"
]);
...
...
@@ -53,15 +61,15 @@ public class AbstractBuildTest extends GroovyHudsonTestCase {
/**
* Makes sure that raw console output doesn't get affected by XML escapes.
*/
void
testR
awConsoleOutput
()
{
@Test
void
r
awConsoleOutput
()
{
def
out
=
"<test>&</test>"
;
def
p
=
createFreeStyleProject
();
p
.
buildersList
.
add
(
builder
{
builder
,
launcher
,
BuildListener
listener
->
def
p
=
j
.
createFreeStyleProject
();
p
.
buildersList
.
add
(
j
.
builder
{
builder
,
launcher
,
BuildListener
listener
->
listener
.
logger
.
println
(
out
);
})
def
b
=
buildAndAssertSuccess
(
p
);
Page
rsp
=
createWebClient
().
goTo
(
"${b.url}/consoleText"
,
"text/plain"
);
def
b
=
j
.
buildAndAssertSuccess
(
p
);
Page
rsp
=
j
.
createWebClient
().
goTo
(
"${b.url}/consoleText"
,
"text/plain"
);
println
"Output:\n"
+
rsp
.
webResponse
.
contentAsString
assertTrue
(
rsp
.
webResponse
.
contentAsString
.
contains
(
out
));
}
...
...
@@ -70,48 +78,62 @@ public class AbstractBuildTest extends GroovyHudsonTestCase {
assertEquals
(
expectedIds
as
Set
,
b
.
culprits
*.
id
as
Set
);
}
void
testC
ulprits
()
{
@Test
void
c
ulprits
()
{
def
p
=
createFreeStyleProject
();
def
p
=
j
.
createFreeStyleProject
();
def
scm
=
new
FakeChangeLogSCM
()
p
.
scm
=
scm
// 1st build, successful, no culprits
scm
.
addChange
().
withAuthor
(
"alice"
)
def
b
=
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
def
b
=
j
.
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"alice"
])
// 2nd build
scm
.
addChange
().
withAuthor
(
"bob"
)
p
.
buildersList
.
add
(
new
FailureBuilder
())
b
=
assertBuildStatus
(
Result
.
FAILURE
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
FAILURE
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"bob"
])
// 3rd build. bob continues to be in culprit
scm
.
addChange
().
withAuthor
(
"charlie"
)
b
=
assertBuildStatus
(
Result
.
FAILURE
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
FAILURE
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"bob"
,
"charlie"
])
// 4th build, unstable. culprit list should continue
scm
.
addChange
().
withAuthor
(
"dave"
)
p
.
buildersList
.
replaceBy
([
new
UnstableBuilder
()])
b
=
assertBuildStatus
(
Result
.
UNSTABLE
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
UNSTABLE
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"bob"
,
"charlie"
,
"dave"
])
// 5th build, unstable. culprit list should continue
scm
.
addChange
().
withAuthor
(
"eve"
)
b
=
assertBuildStatus
(
Result
.
UNSTABLE
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
UNSTABLE
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"bob"
,
"charlie"
,
"dave"
,
"eve"
])
// 6th build, success, accumulation continues up to this point
scm
.
addChange
().
withAuthor
(
"fred"
)
p
.
buildersList
.
replaceBy
([])
b
=
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"bob"
,
"charlie"
,
"dave"
,
"eve"
,
"fred"
])
// 7th build, back to empty culprits
scm
.
addChange
().
withAuthor
(
"george"
)
b
=
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
b
=
j
.
assertBuildStatus
(
Result
.
SUCCESS
,
p
.
scheduleBuild2
(
0
).
get
())
assertCulprits
(
b
,[
"george"
])
}
@Bug
(
19920
)
@Test
void
lastBuildNextBuild
()
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
();
AbstractBuild
b1
=
j
.
assertBuildStatusSuccess
(
p
.
scheduleBuild2
(
0
));
AbstractBuild
b2
=
j
.
assertBuildStatusSuccess
(
p
.
scheduleBuild2
(
0
));
assertEquals
(
b2
,
p
.
getLastBuild
());
b2
.
getNextBuild
();
// force this to be initialized
b2
.
delete
();
assertEquals
(
b1
,
p
.
getLastBuild
());
b1
=
p
.
getLastBuild
();
assertEquals
(
null
,
b1
.
getNextBuild
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录