Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FIY695
jenkins
提交
74d2d437
J
jenkins
项目概览
FIY695
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
74d2d437
编写于
11月 21, 2011
作者:
I
imod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add extension to intercept maven arguments
上级
28b50276
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
263 addition
and
2 deletion
+263
-2
maven-plugin/src/main/java/hudson/maven/MavenArgumentInterceptorAction.java
...ain/java/hudson/maven/MavenArgumentInterceptorAction.java
+73
-0
maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
...lugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
+19
-2
test/src/test/java/hudson/maven/MavenArgumentInterceptorTest.java
.../test/java/hudson/maven/MavenArgumentInterceptorTest.java
+171
-0
未找到文件。
maven-plugin/src/main/java/hudson/maven/MavenArgumentInterceptorAction.java
0 → 100644
浏览文件 @
74d2d437
/*
* The MIT License
*
* Copyright (c) 2011, Dominik Bartholdi
*
* 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
hudson.maven
;
import
hudson.model.Action
;
import
hudson.util.ArgumentListBuilder
;
/**
* Provides a hook to change the arguments passed to the maven execution. This
* enables plugins to transiently change the arguments of a maven build (e.g.
* change the arguments for a release build).
*
* @author Dominik Bartholdi (imod)
*
*/
public
interface
MavenArgumentInterceptorAction
extends
Action
{
/**
* Provides maven goals and options to start the build with. This is the
* preferred way to provide other goals then the default ones to a build.
* The goals and options returned by this method will not be persist and do
* not affect the default configuration.
* <p>
* This method will be called on one and only one action during a build. If
* there are two actions present in the build, the second will be ignored.
*
* @return the maven goals and options to start maven with. Result is
* ignored if <code>null</code> or empty. Variables will be expanded
* by the caller.
*/
public
String
getGoalsAndOptions
();
/**
* Change/add arguments to any needs, but special care has to be taken, as
* the list contains every argument needed for the default execution (e.g.
* -f /path/to/pom.xml or -B). <br />
* An easy example would be to add "<code>-DskipTests</code>" to skip the
* test execution on request.
*
* <p>
* This method is called on all present MavenArgumentInterceptorAction
* during a build (kind of chaining, each action can add the arguments it
* thinks are missing).
*
* @param mavenargs
* the calculated default maven arguments (never
* <code>null</code>).
* @return the new arguments to be used.
*/
public
ArgumentListBuilder
intercept
(
ArgumentListBuilder
mavenargs
);
}
maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java
浏览文件 @
74d2d437
...
...
@@ -2,7 +2,7 @@
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
* Red Hat, Inc., Victor Glushenkov, Alan Harder, Olivier Lamy
* Red Hat, Inc., Victor Glushenkov, Alan Harder, Olivier Lamy
, Dominik Bartholdi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
...
...
@@ -754,7 +754,24 @@ public class MavenModuleSetBuild extends AbstractMavenBuild<MavenModuleSet,Maven
}
}
margs
.
addTokenized
(
envVars
.
expand
(
project
.
getGoals
()));
// find the correct maven goals and options, there might by an action overruling the defaults
// only one action is allowed to overwrite the hole "goals and options" string
final
MavenArgumentInterceptorAction
interceptorAction
=
this
.
getBuild
().
getAction
(
MavenArgumentInterceptorAction
.
class
);
final
String
goals
=
interceptorAction
!=
null
&&
StringUtils
.
isNotBlank
(
interceptorAction
.
getGoalsAndOptions
())
?
interceptorAction
.
getGoalsAndOptions
()
:
project
.
getGoals
();
margs
.
addTokenized
(
envVars
.
expand
(
goals
));
// enable the interceptors to change the whole command argument list
// all available interceptors are allowed to modify the argument list
final
List
<
MavenArgumentInterceptorAction
>
argInterceptors
=
this
.
getBuild
().
getActions
(
MavenArgumentInterceptorAction
.
class
);
for
(
MavenArgumentInterceptorAction
mavenArgInterceptor
:
argInterceptors
)
{
final
ArgumentListBuilder
newMargs
=
mavenArgInterceptor
.
intercept
(
margs
);
if
(
newMargs
!=
null
)
{
margs
=
newMargs
;
}
}
if
(
maven3orLater
)
{
...
...
test/src/test/java/hudson/maven/MavenArgumentInterceptorTest.java
0 → 100644
浏览文件 @
74d2d437
package
hudson.maven
;
/*
* The MIT License
*
* Copyright (c) 2011, Dominik Bartholdi
*
* 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.
*/
import
hudson.Extension
;
import
hudson.Launcher
;
import
hudson.model.AbstractBuild
;
import
hudson.model.AbstractProject
;
import
hudson.model.BuildListener
;
import
hudson.model.Result
;
import
hudson.tasks.BuildWrapper
;
import
hudson.tasks.BuildWrapperDescriptor
;
import
hudson.tasks.Maven.MavenInstallation
;
import
hudson.util.ArgumentListBuilder
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.List
;
import
net.sf.json.JSONObject
;
import
org.jvnet.hudson.test.ExtractResourceSCM
;
import
org.jvnet.hudson.test.HudsonTestCase
;
import
org.kohsuke.stapler.StaplerRequest
;
/**
* @author Dominik Bartholdi (imod)
*/
public
class
MavenArgumentInterceptorTest
extends
HudsonTestCase
{
public
void
testSimpleMaven3BuildWithArgInterceptor_Goals
()
throws
Exception
{
MavenModuleSet
m
=
createMavenProject
();
MavenInstallation
mavenInstallation
=
configureMaven3
();
m
.
setMaven
(
mavenInstallation
.
getName
());
m
.
setScm
(
new
ExtractResourceSCM
(
getClass
().
getResource
(
"maven3-project.zip"
)));
m
.
setGoals
(
"dummygoal"
);
// build would fail with this goal
// add an action to build, redefining the goals and options to be
// executed
m
.
getBuildWrappersList
().
add
(
new
TestMvnBuildWrapper
(
"clean"
));
MavenModuleSetBuild
b
=
buildAndAssertSuccess
(
m
);
assertTrue
(
MavenUtil
.
maven3orLater
(
b
.
getMavenVersionUsed
()));
}
public
void
testSimpleMaven3BuildWithArgInterceptor_ArgBuilder
()
throws
Exception
{
MavenModuleSet
m
=
createMavenProject
();
MavenInstallation
mavenInstallation
=
configureMaven3
();
m
.
setMaven
(
mavenInstallation
.
getName
());
m
.
setScm
(
new
ExtractResourceSCM
(
getClass
().
getResource
(
"maven-multimodule-unit-failure.zip"
)));
m
.
setGoals
(
"clean install"
);
// build would fail because of failing unit
// tests
// add an action to build, adding argument to skip the test execution
m
.
getBuildWrappersList
().
add
(
new
TestMvnBuildWrapper
(
Arrays
.
asList
(
"-DskipTests"
)));
MavenModuleSetBuild
b
=
buildAndAssertSuccess
(
m
);
assertTrue
(
MavenUtil
.
maven3orLater
(
b
.
getMavenVersionUsed
()));
}
private
static
class
TestMvnArgInterceptor
implements
MavenArgumentInterceptorAction
{
private
String
goalsAndOptions
;
private
List
<
String
>
args
;
public
TestMvnArgInterceptor
(
String
goalsAndOptions
)
{
this
.
goalsAndOptions
=
goalsAndOptions
;
}
public
TestMvnArgInterceptor
(
List
<
String
>
args
)
{
this
.
args
=
args
;
}
public
String
getIconFileName
()
{
return
null
;
}
public
String
getDisplayName
()
{
return
null
;
}
public
String
getUrlName
()
{
return
null
;
}
public
String
getGoalsAndOptions
()
{
return
goalsAndOptions
;
}
public
ArgumentListBuilder
intercept
(
ArgumentListBuilder
mavenargs
)
{
if
(
args
!=
null
)
{
for
(
String
arg
:
this
.
args
)
{
mavenargs
.
add
(
arg
);
}
}
return
mavenargs
;
}
}
public
static
class
TestMvnBuildWrapper
extends
BuildWrapper
{
public
Result
buildResultInTearDown
;
private
String
goalsAndOptions
;
private
List
<
String
>
args
;
public
TestMvnBuildWrapper
(
String
goalsAndOptions
)
{
this
.
goalsAndOptions
=
goalsAndOptions
;
}
public
TestMvnBuildWrapper
(
List
<
String
>
args
)
{
this
.
args
=
args
;
}
@Override
public
Environment
setUp
(
AbstractBuild
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
IOException
,
InterruptedException
{
if
(
goalsAndOptions
!=
null
)
{
build
.
addAction
(
new
TestMvnArgInterceptor
(
goalsAndOptions
));
}
else
if
(
args
!=
null
)
{
build
.
addAction
(
new
TestMvnArgInterceptor
(
args
));
}
return
new
BuildWrapper
.
Environment
()
{
@Override
public
boolean
tearDown
(
AbstractBuild
build
,
BuildListener
listener
)
throws
IOException
,
InterruptedException
{
buildResultInTearDown
=
build
.
getResult
();
return
true
;
}
};
}
@Extension
public
static
class
TestMvnBuildWrapperDescriptor
extends
BuildWrapperDescriptor
{
@Override
public
boolean
isApplicable
(
AbstractProject
<?,
?>
project
)
{
return
true
;
}
@Override
public
BuildWrapper
newInstance
(
StaplerRequest
req
,
JSONObject
formData
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
String
getDisplayName
()
{
return
this
.
getClass
().
getName
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录