Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
79fbe28b
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,发现更多精彩内容 >>
提交
79fbe28b
编写于
1月 19, 2013
作者:
C
Christoph Kutzinski
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #668 from kutzi/maven-testmojo-heuristic
Use 'duck-typing' approach for detecting test mojos
上级
cff4f406
b68b84ea
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
848 addition
and
215 deletion
+848
-215
core/src/main/java/hudson/tasks/junit/TestResult.java
core/src/main/java/hudson/tasks/junit/TestResult.java
+62
-16
maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
+7
-5
maven-plugin/src/main/java/hudson/maven/MavenBuilder.java
maven-plugin/src/main/java/hudson/maven/MavenBuilder.java
+17
-3
maven-plugin/src/main/java/hudson/maven/MavenReportInfo.java
maven-plugin/src/main/java/hudson/maven/MavenReportInfo.java
+3
-2
maven-plugin/src/main/java/hudson/maven/MojoInfo.java
maven-plugin/src/main/java/hudson/maven/MojoInfo.java
+12
-4
maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java
...rc/main/java/hudson/maven/reporters/SurefireArchiver.java
+133
-159
maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java
...plugin/src/main/java/hudson/maven/reporters/TestMojo.java
+223
-0
maven-plugin/src/test/java/hudson/maven/ExecutedMojoTest.java
...n-plugin/src/test/java/hudson/maven/ExecutedMojoTest.java
+2
-2
maven-plugin/src/test/java/hudson/maven/MojoInfoBuilder.java
maven-plugin/src/test/java/hudson/maven/MojoInfoBuilder.java
+91
-0
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverDetectTestMojosTest.java
.../maven/reporters/SurefireArchiverDetectTestMojosTest.java
+182
-0
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverFilterReportsFileTest.java
...aven/reporters/SurefireArchiverFilterReportsFileTest.java
+101
-0
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverUnitTest.java
...java/hudson/maven/reporters/SurefireArchiverUnitTest.java
+15
-24
未找到文件。
core/src/main/java/hudson/tasks/junit/TestResult.java
浏览文件 @
79fbe28b
...
@@ -27,15 +27,10 @@ import hudson.AbortException;
...
@@ -27,15 +27,10 @@ import hudson.AbortException;
import
hudson.Util
;
import
hudson.Util
;
import
hudson.model.AbstractBuild
;
import
hudson.model.AbstractBuild
;
import
hudson.model.Run
;
import
hudson.model.Run
;
import
hudson.tasks.test.AbstractTestResultAction
;
import
hudson.tasks.test.MetaTabulatedResult
;
import
hudson.tasks.test.MetaTabulatedResult
;
import
hudson.tasks.test.TestObject
;
import
hudson.tasks.test.TestObject
;
import
hudson.tasks.test.AbstractTestResultAction
;
import
hudson.util.IOException2
;
import
hudson.util.IOException2
;
import
org.apache.tools.ant.DirectoryScanner
;
import
org.dom4j.DocumentException
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
org.kohsuke.stapler.export.Exported
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -49,6 +44,12 @@ import java.util.List;
...
@@ -49,6 +44,12 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.TreeMap
;
import
org.apache.tools.ant.DirectoryScanner
;
import
org.dom4j.DocumentException
;
import
org.kohsuke.stapler.StaplerRequest
;
import
org.kohsuke.stapler.StaplerResponse
;
import
org.kohsuke.stapler.export.Exported
;
/**
/**
* Root of all the test results for one build.
* Root of all the test results for one build.
*
*
...
@@ -153,15 +154,8 @@ public final class TestResult extends MetaTabulatedResult {
...
@@ -153,15 +154,8 @@ public final class TestResult extends MetaTabulatedResult {
for
(
String
value
:
reportFiles
)
{
for
(
String
value
:
reportFiles
)
{
File
reportFile
=
new
File
(
baseDir
,
value
);
File
reportFile
=
new
File
(
baseDir
,
value
);
// only count files that were actually updated during this build
// only count files that were actually updated during this build
if
(
(
buildTime
-
3000
/*error margin*/
<=
reportFile
.
lastModified
())
||
!
checkTimestamps
)
{
if
(
(
buildTime
-
3000
/*error margin*/
<=
reportFile
.
lastModified
()))
{
if
(
reportFile
.
length
()==
0
)
{
parsePossiblyEmpty
(
reportFile
);
// this is a typical problem when JVM quits abnormally, like OutOfMemoryError during a test.
SuiteResult
sr
=
new
SuiteResult
(
reportFile
.
getName
(),
""
,
""
);
sr
.
addCase
(
new
CaseResult
(
sr
,
"<init>"
,
"Test report file "
+
reportFile
.
getAbsolutePath
()+
" was length 0"
));
add
(
sr
);
}
else
{
parse
(
reportFile
);
}
parsed
=
true
;
parsed
=
true
;
}
}
}
}
...
@@ -183,7 +177,60 @@ public final class TestResult extends MetaTabulatedResult {
...
@@ -183,7 +177,60 @@ public final class TestResult extends MetaTabulatedResult {
Util
.
getTimeSpanString
(
buildTime
-
f
.
lastModified
())));
Util
.
getTimeSpanString
(
buildTime
-
f
.
lastModified
())));
}
}
}
}
public
void
parse
(
long
buildTime
,
Iterable
<
File
>
reportFiles
)
throws
IOException
{
boolean
parsed
=
false
;
for
(
File
reportFile
:
reportFiles
)
{
// only count files that were actually updated during this build
if
(
(
buildTime
-
3000
/*error margin*/
<=
reportFile
.
lastModified
()))
{
parsePossiblyEmpty
(
reportFile
);
parsed
=
true
;
}
}
if
(!
parsed
)
{
long
localTime
=
System
.
currentTimeMillis
();
if
(
localTime
<
buildTime
-
1000
)
/*margin*/
// build time is in the the future. clock on this slave must be running behind
throw
new
AbortException
(
"Clock on this slave is out of sync with the master, and therefore \n"
+
"I can't figure out what test results are new and what are old.\n"
+
"Please keep the slave clock in sync with the master."
);
File
f
=
reportFiles
.
iterator
().
next
();
throw
new
AbortException
(
String
.
format
(
"Test reports were found but none of them are new. Did tests run? %n"
+
"For example, %s is %s old%n"
,
f
,
Util
.
getTimeSpanString
(
buildTime
-
f
.
lastModified
())));
}
}
/**
* Collect reports from the given report files
*
* @since TODO
*/
public
void
parse
(
Iterable
<
File
>
reportFiles
)
throws
IOException
{
for
(
File
reportFile
:
reportFiles
)
{
parsePossiblyEmpty
(
reportFile
);
}
}
private
void
parsePossiblyEmpty
(
File
reportFile
)
throws
IOException
{
if
(
reportFile
.
length
()==
0
)
{
// this is a typical problem when JVM quits abnormally, like OutOfMemoryError during a test.
SuiteResult
sr
=
new
SuiteResult
(
reportFile
.
getName
(),
""
,
""
);
sr
.
addCase
(
new
CaseResult
(
sr
,
"<init>"
,
"Test report file "
+
reportFile
.
getAbsolutePath
()+
" was length 0"
));
add
(
sr
);
}
else
{
parse
(
reportFile
);
}
}
private
void
add
(
SuiteResult
sr
)
{
private
void
add
(
SuiteResult
sr
)
{
for
(
SuiteResult
s
:
suites
)
{
for
(
SuiteResult
s
:
suites
)
{
// JENKINS-12457: If a testsuite is distributed over multiple files, merge it into a single SuiteResult:
// JENKINS-12457: If a testsuite is distributed over multiple files, merge it into a single SuiteResult:
...
@@ -588,6 +635,5 @@ public final class TestResult extends MetaTabulatedResult {
...
@@ -588,6 +635,5 @@ public final class TestResult extends MetaTabulatedResult {
}
}
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
boolean
checkTimestamps
=
true
;
// TODO: change to System.getProperty
}
}
maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
浏览文件 @
79fbe28b
...
@@ -218,8 +218,10 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
...
@@ -218,8 +218,10 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
return
reporters
.
get
(
new
ModuleName
(
mavenProject
)
);
return
reporters
.
get
(
new
ModuleName
(
mavenProject
)
);
}
}
private
void
initMojoStartTime
(
MavenProject
mavenProject
)
{
private
long
initMojoStartTime
(
MavenProject
mavenProject
)
{
this
.
currentMojoStartPerModuleName
.
put
(
new
ModuleName
(
mavenProject
),
System
.
currentTimeMillis
());
long
mojoStartTime
=
System
.
currentTimeMillis
();
this
.
currentMojoStartPerModuleName
.
put
(
new
ModuleName
(
mavenProject
),
mojoStartTime
);
return
mojoStartTime
;
}
}
private
Long
getMojoStartTime
(
MavenProject
mavenProject
)
{
private
Long
getMojoStartTime
(
MavenProject
mavenProject
)
{
...
@@ -395,10 +397,10 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
...
@@ -395,10 +397,10 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
}
}
private
void
recordMojoStarted
(
ExecutionEvent
event
)
{
private
void
recordMojoStarted
(
ExecutionEvent
event
)
{
initMojoStartTime
(
event
.
getProject
()
);
long
startTime
=
initMojoStartTime
(
event
.
getProject
()
);
MavenProject
mavenProject
=
event
.
getProject
();
MavenProject
mavenProject
=
event
.
getProject
();
MojoInfo
mojoInfo
=
new
MojoInfo
(
event
);
MojoInfo
mojoInfo
=
new
MojoInfo
(
event
,
startTime
);
List
<
MavenReporter
>
mavenReporters
=
getMavenReporters
(
mavenProject
);
List
<
MavenReporter
>
mavenReporters
=
getMavenReporters
(
mavenProject
);
...
@@ -426,7 +428,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
...
@@ -426,7 +428,7 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
private
void
recordMojoEnded
(
ExecutionEvent
event
,
Exception
problem
)
{
private
void
recordMojoEnded
(
ExecutionEvent
event
,
Exception
problem
)
{
MavenProject
mavenProject
=
event
.
getProject
();
MavenProject
mavenProject
=
event
.
getProject
();
MojoInfo
mojoInfo
=
new
MojoInfo
(
event
);
MojoInfo
mojoInfo
=
new
MojoInfo
(
event
,
getMojoStartTime
(
event
.
getProject
())
);
recordExecutionTime
(
event
,
mojoInfo
);
recordExecutionTime
(
event
,
mojoInfo
);
...
...
maven-plugin/src/main/java/hudson/maven/MavenBuilder.java
浏览文件 @
79fbe28b
...
@@ -43,6 +43,7 @@ import java.text.NumberFormat;
...
@@ -43,6 +43,7 @@ import java.text.NumberFormat;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
org.apache.maven.BuildFailureException
;
import
org.apache.maven.BuildFailureException
;
...
@@ -275,6 +276,7 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
...
@@ -275,6 +276,7 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
private
final
MavenBuilder
listener
;
private
final
MavenBuilder
listener
;
private
final
AtomicBoolean
hasTestFailures
=
new
AtomicBoolean
();
private
final
AtomicBoolean
hasTestFailures
=
new
AtomicBoolean
();
private
final
Map
<
ModuleName
,
Long
>
currentMojoStartPerModuleName
=
new
ConcurrentHashMap
<
ModuleName
,
Long
>();
/**
/**
* Number of total nanoseconds {@link MavenBuilder} spent.
* Number of total nanoseconds {@link MavenBuilder} spent.
...
@@ -284,6 +286,16 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
...
@@ -284,6 +286,16 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
public
Adapter
(
MavenBuilder
listener
)
{
public
Adapter
(
MavenBuilder
listener
)
{
this
.
listener
=
listener
;
this
.
listener
=
listener
;
}
}
private
long
initMojoStartTime
(
MavenProject
mavenProject
)
{
long
mojoStartTime
=
System
.
currentTimeMillis
();
this
.
currentMojoStartPerModuleName
.
put
(
new
ModuleName
(
mavenProject
),
mojoStartTime
);
return
mojoStartTime
;
}
private
Long
getMojoStartTime
(
MavenProject
mavenProject
)
{
return
currentMojoStartPerModuleName
.
get
(
new
ModuleName
(
mavenProject
)
);
}
public
void
preBuild
(
MavenSession
session
,
ReactorManager
rm
,
EventDispatcher
dispatcher
)
throws
BuildFailureException
,
LifecycleExecutionException
,
IOException
,
InterruptedException
{
public
void
preBuild
(
MavenSession
session
,
ReactorManager
rm
,
EventDispatcher
dispatcher
)
throws
BuildFailureException
,
LifecycleExecutionException
,
IOException
,
InterruptedException
{
long
startTime
=
System
.
nanoTime
();
long
startTime
=
System
.
nanoTime
();
...
@@ -312,13 +324,14 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
...
@@ -312,13 +324,14 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
fireEnterModule
(
project
);
fireEnterModule
(
project
);
}
}
listener
.
preExecute
(
project
,
new
MojoInfo
(
exec
,
mojo
,
mergedConfig
,
eval
));
long
mojoStartTime
=
initMojoStartTime
(
project
);
listener
.
preExecute
(
project
,
new
MojoInfo
(
exec
,
mojo
,
mergedConfig
,
eval
,
mojoStartTime
));
overheadTime
+=
System
.
nanoTime
()-
startTime
;
overheadTime
+=
System
.
nanoTime
()-
startTime
;
}
}
public
void
postExecute
(
MavenProject
project
,
MojoExecution
exec
,
Mojo
mojo
,
PlexusConfiguration
mergedConfig
,
ExpressionEvaluator
eval
,
Exception
exception
)
throws
IOException
,
InterruptedException
{
public
void
postExecute
(
MavenProject
project
,
MojoExecution
exec
,
Mojo
mojo
,
PlexusConfiguration
mergedConfig
,
ExpressionEvaluator
eval
,
Exception
exception
)
throws
IOException
,
InterruptedException
{
long
startTime
=
System
.
nanoTime
();
long
startTime
=
System
.
nanoTime
();
listener
.
postExecute
(
project
,
new
MojoInfo
(
exec
,
mojo
,
mergedConfig
,
eval
),
exception
);
listener
.
postExecute
(
project
,
new
MojoInfo
(
exec
,
mojo
,
mergedConfig
,
eval
,
getMojoStartTime
(
project
)
),
exception
);
if
(
listener
.
hasBuildFailures
())
if
(
listener
.
hasBuildFailures
())
hasTestFailures
.
compareAndSet
(
false
,
true
);
hasTestFailures
.
compareAndSet
(
false
,
true
);
overheadTime
+=
System
.
nanoTime
()-
startTime
;
overheadTime
+=
System
.
nanoTime
()-
startTime
;
...
@@ -326,7 +339,8 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
...
@@ -326,7 +339,8 @@ public abstract class MavenBuilder extends AbstractMavenBuilder implements Deleg
public
void
onReportGenerated
(
MavenReport
report
,
MojoExecution
mojoExecution
,
PlexusConfiguration
mergedConfig
,
ExpressionEvaluator
eval
)
throws
IOException
,
InterruptedException
{
public
void
onReportGenerated
(
MavenReport
report
,
MojoExecution
mojoExecution
,
PlexusConfiguration
mergedConfig
,
ExpressionEvaluator
eval
)
throws
IOException
,
InterruptedException
{
long
startTime
=
System
.
nanoTime
();
long
startTime
=
System
.
nanoTime
();
listener
.
onReportGenerated
(
lastModule
,
new
MavenReportInfo
(
mojoExecution
,
report
,
mergedConfig
,
eval
));
listener
.
onReportGenerated
(
lastModule
,
new
MavenReportInfo
(
mojoExecution
,
report
,
mergedConfig
,
eval
,
getMojoStartTime
(
lastModule
)));
overheadTime
+=
System
.
nanoTime
()-
startTime
;
overheadTime
+=
System
.
nanoTime
()-
startTime
;
}
}
...
...
maven-plugin/src/main/java/hudson/maven/MavenReportInfo.java
浏览文件 @
79fbe28b
...
@@ -49,8 +49,9 @@ public final class MavenReportInfo extends MojoInfo {
...
@@ -49,8 +49,9 @@ public final class MavenReportInfo extends MojoInfo {
*/
*/
public
final
MavenReport
report
;
public
final
MavenReport
report
;
public
MavenReportInfo
(
MojoExecution
mojoExecution
,
MavenReport
mojo
,
PlexusConfiguration
configuration
,
ExpressionEvaluator
expressionEvaluator
)
{
public
MavenReportInfo
(
MojoExecution
mojoExecution
,
MavenReport
mojo
,
PlexusConfiguration
configuration
,
ExpressionEvaluator
expressionEvaluator
,
super
(
mojoExecution
,
(
Mojo
)
mojo
,
configuration
,
expressionEvaluator
);
long
mojoStartTime
)
{
super
(
mojoExecution
,
(
Mojo
)
mojo
,
configuration
,
expressionEvaluator
,
mojoStartTime
);
this
.
report
=
mojo
;
this
.
report
=
mojo
;
}
}
}
}
maven-plugin/src/main/java/hudson/maven/MojoInfo.java
浏览文件 @
79fbe28b
...
@@ -103,7 +103,10 @@ public class MojoInfo {
...
@@ -103,7 +103,10 @@ public class MojoInfo {
*/
*/
private
final
ConverterLookup
converterLookup
=
new
DefaultConverterLookup
();
private
final
ConverterLookup
converterLookup
=
new
DefaultConverterLookup
();
public
MojoInfo
(
MojoExecution
mojoExecution
,
Mojo
mojo
,
PlexusConfiguration
configuration
,
ExpressionEvaluator
expressionEvaluator
)
{
private
long
startTime
;
public
MojoInfo
(
MojoExecution
mojoExecution
,
Mojo
mojo
,
PlexusConfiguration
configuration
,
ExpressionEvaluator
expressionEvaluator
,
long
startTime
)
{
// in Maven3 there's no easy way to get the Mojo instance that's being executed,
// in Maven3 there's no easy way to get the Mojo instance that's being executed,
// so we just can't pass it in.
// so we just can't pass it in.
if
(
mojo
==
null
)
mojo
=
new
Maven3ProvidesNoAccessToMojo
();
if
(
mojo
==
null
)
mojo
=
new
Maven3ProvidesNoAccessToMojo
();
...
@@ -112,12 +115,13 @@ public class MojoInfo {
...
@@ -112,12 +115,13 @@ public class MojoInfo {
this
.
configuration
=
configuration
;
this
.
configuration
=
configuration
;
this
.
expressionEvaluator
=
expressionEvaluator
;
this
.
expressionEvaluator
=
expressionEvaluator
;
this
.
pluginName
=
new
PluginName
(
mojoExecution
.
getMojoDescriptor
().
getPluginDescriptor
());
this
.
pluginName
=
new
PluginName
(
mojoExecution
.
getMojoDescriptor
().
getPluginDescriptor
());
this
.
startTime
=
startTime
;
}
}
public
MojoInfo
(
ExecutionEvent
event
)
{
public
MojoInfo
(
ExecutionEvent
event
,
long
startTime
)
{
this
(
event
.
getMojoExecution
(),
null
,
this
(
event
.
getMojoExecution
(),
null
,
new
XmlPlexusConfiguration
(
event
.
getMojoExecution
().
getConfiguration
()
),
new
XmlPlexusConfiguration
(
event
.
getMojoExecution
().
getConfiguration
()
),
new
PluginParameterExpressionEvaluator
(
event
.
getSession
(),
event
.
getMojoExecution
()
));
new
PluginParameterExpressionEvaluator
(
event
.
getSession
(),
event
.
getMojoExecution
()
)
,
startTime
);
}
}
/**
/**
...
@@ -148,7 +152,7 @@ public class MojoInfo {
...
@@ -148,7 +152,7 @@ public class MojoInfo {
* the configuration in POM is syntactically incorrect.
* the configuration in POM is syntactically incorrect.
*/
*/
public
<
T
>
T
getConfigurationValue
(
String
configName
,
Class
<
T
>
type
)
throws
ComponentConfigurationException
{
public
<
T
>
T
getConfigurationValue
(
String
configName
,
Class
<
T
>
type
)
throws
ComponentConfigurationException
{
PlexusConfiguration
child
=
configuration
.
getChild
(
configName
);
PlexusConfiguration
child
=
configuration
.
getChild
(
configName
,
false
);
if
(
child
==
null
)
return
null
;
// no such config
if
(
child
==
null
)
return
null
;
// no such config
final
ClassLoader
cl
;
final
ClassLoader
cl
;
...
@@ -278,4 +282,8 @@ public class MojoInfo {
...
@@ -278,4 +282,8 @@ public class MojoInfo {
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
}
}
public
long
getStartTime
()
{
return
this
.
startTime
;
}
}
}
maven-plugin/src/main/java/hudson/maven/reporters/SurefireArchiver.java
浏览文件 @
79fbe28b
...
@@ -25,7 +25,6 @@ package hudson.maven.reporters;
...
@@ -25,7 +25,6 @@ package hudson.maven.reporters;
import
hudson.Extension
;
import
hudson.Extension
;
import
hudson.Launcher
;
import
hudson.Launcher
;
import
hudson.Util
;
import
hudson.maven.Maven3Builder
;
import
hudson.maven.Maven3Builder
;
import
hudson.maven.MavenBuild
;
import
hudson.maven.MavenBuild
;
import
hudson.maven.MavenBuildInformation
;
import
hudson.maven.MavenBuildInformation
;
...
@@ -47,6 +46,7 @@ import java.io.File;
...
@@ -47,6 +46,7 @@ import java.io.File;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.ListIterator
;
import
java.util.ListIterator
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -55,26 +55,29 @@ import java.util.concurrent.atomic.AtomicBoolean;
...
@@ -55,26 +55,29 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.plugin.MojoFailureException
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.tools.ant.DirectoryScanner
;
import
org.apache.tools.ant.types.FileSet
;
import
org.codehaus.plexus.component.configurator.ComponentConfigurationException
;
import
org.codehaus.plexus.component.configurator.ComponentConfigurationException
;
import
org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration
;
import
org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration
;
import
org.codehaus.plexus.util.xml.Xpp3Dom
;
import
org.codehaus.plexus.util.xml.Xpp3Dom
;
import
com.google.common.base.Function
;
import
com.google.common.base.Predicate
;
import
com.google.common.collect.Iterables
;
import
com.google.common.collect.Iterators
;
/**
/**
* Records the surefire test result.
* Records the surefire test result.
* @author Kohsuke Kawaguchi
* @author Kohsuke Kawaguchi
* @author Christoph Kutzinski
*/
*/
public
class
SurefireArchiver
extends
TestFailureDetector
{
public
class
SurefireArchiver
extends
TestFailureDetector
{
private
transient
TestResult
result
;
private
transient
TestResult
result
;
private
final
AtomicBoolean
hasTestFailures
=
new
AtomicBoolean
();
private
final
AtomicBoolean
hasTestFailures
=
new
AtomicBoolean
();
/**
/**
* Store the filesets here as we want to track ignores between multiple runs of this class<br/>
* Store result files already parsed, so we don't parse them again,
* Note: Because this class can be run with different mojo goals with different path settings,
* if a later running mojo specifies the same reports directory.
* we track multiple {@link FileSet}s for each encountered <tt>reportsDir</tt>
*/
*/
private
transient
ConcurrentMap
<
File
,
File
Set
>
fileSets
=
new
ConcurrentHashMap
<
File
,
FileSet
>();
private
transient
ConcurrentMap
<
File
,
File
>
parsedFiles
=
new
ConcurrentHashMap
<
File
,
File
>();
@Override
@Override
public
boolean
hasTestFailures
()
{
public
boolean
hasTestFailures
()
{
...
@@ -83,25 +86,27 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -83,25 +86,27 @@ public class SurefireArchiver extends TestFailureDetector {
public
boolean
preExecute
(
MavenBuildProxy
build
,
MavenProject
pom
,
MojoInfo
mojo
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
public
boolean
preExecute
(
MavenBuildProxy
build
,
MavenProject
pom
,
MojoInfo
mojo
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
if
(
isTestMojo
(
mojo
))
{
if
(
isTestMojo
(
mojo
))
{
if
(!
isSoapUiMojo
(
mojo
))
{
// tell test mojo to keep going even if there was a failure,
// tell surefire:test to keep going even if there was a failure,
// so that we can record this as yellow.
// so that we can record this as yellow.
// note that because of the way Maven works, just updating system property at this point is too late
// note that because of the way Maven works, just updating system property at this point is too late
XmlPlexusConfiguration
c
=
(
XmlPlexusConfiguration
)
mojo
.
configuration
.
getChild
(
"testFailureIgnore"
);
// Many test plugins have - as surefire - a configuration key 'testFailureIgnore' which defaults to
if
(
c
!=
null
&&
c
.
getValue
()
!=
null
&&
c
.
getValue
().
equals
(
"${maven.test.failure.ignore}"
)
&&
System
.
getProperty
(
"maven.test.failure.ignore"
)==
null
)
{
// ${maven.test.failure.ignore}, so just try that one and change value to true,
if
(
build
.
getMavenBuildInformation
().
isMaven3OrLater
())
{
// if it's still at that default:
String
fieldName
=
"testFailureIgnore"
;
XmlPlexusConfiguration
c
=
(
XmlPlexusConfiguration
)
mojo
.
configuration
.
getChild
(
"testFailureIgnore"
);
if
(
mojo
.
mojoExecution
.
getConfiguration
().
getChild
(
fieldName
)
!=
null
)
{
if
(
c
!=
null
&&
c
.
getValue
()
!=
null
&&
c
.
getValue
().
equals
(
"${maven.test.failure.ignore}"
)
&&
System
.
getProperty
(
"maven.test.failure.ignore"
)==
null
)
{
mojo
.
mojoExecution
.
getConfiguration
().
getChild
(
fieldName
).
setValue
(
Boolean
.
TRUE
.
toString
()
);
if
(
build
.
getMavenBuildInformation
().
isMaven3OrLater
())
{
}
else
{
String
fieldName
=
"testFailureIgnore"
;
Xpp3Dom
child
=
new
Xpp3Dom
(
fieldName
);
if
(
mojo
.
mojoExecution
.
getConfiguration
().
getChild
(
fieldName
)
!=
null
)
{
child
.
setValue
(
Boolean
.
TRUE
.
toString
()
);
mojo
.
mojoExecution
.
getConfiguration
().
getChild
(
fieldName
).
setValue
(
Boolean
.
TRUE
.
toString
()
);
mojo
.
mojoExecution
.
getConfiguration
().
addChild
(
child
);
}
}
else
{
}
else
{
c
.
setValue
(
Boolean
.
TRUE
.
toString
());
Xpp3Dom
child
=
new
Xpp3Dom
(
fieldName
);
child
.
setValue
(
Boolean
.
TRUE
.
toString
()
);
mojo
.
mojoExecution
.
getConfiguration
().
addChild
(
child
);
}
}
}
else
{
c
.
setValue
(
Boolean
.
TRUE
.
toString
());
}
}
}
}
}
}
...
@@ -109,41 +114,45 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -109,41 +114,45 @@ public class SurefireArchiver extends TestFailureDetector {
}
}
public
boolean
postExecute
(
MavenBuildProxy
build
,
MavenProject
pom
,
MojoInfo
mojo
,
final
BuildListener
listener
,
Throwable
error
)
throws
InterruptedException
,
IOException
{
public
boolean
postExecute
(
MavenBuildProxy
build
,
MavenProject
pom
,
MojoInfo
mojo
,
final
BuildListener
listener
,
Throwable
error
)
throws
InterruptedException
,
IOException
{
if
(!
isTestMojo
(
mojo
))
return
true
;
TestMojo
testMojo
=
TestMojo
.
lookup
(
mojo
);
if
(
testMojo
==
null
)
return
true
;
listener
.
getLogger
().
println
(
Messages
.
SurefireArchiver_Recording
());
listener
.
getLogger
().
println
(
Messages
.
SurefireArchiver_Recording
());
File
reportsDir
;
Iterable
<
File
>
fileSet
;
if
(
isSurefireOrFailsafeMojo
(
mojo
))
{
try
{
try
{
reportsDir
=
mojo
.
getConfigurationValue
(
"reportsDirectory"
,
File
.
class
);
fileSet
=
testMojo
.
getReportFiles
(
pom
,
mojo
);
}
catch
(
ComponentConfigurationException
e
)
{
}
catch
(
ComponentConfigurationException
e
)
{
e
.
printStackTrace
(
listener
.
fatalError
(
Messages
.
SurefireArchiver_NoReportsDir
()));
e
.
printStackTrace
(
listener
.
fatalError
(
Messages
.
SurefireArchiver_NoReportsDir
()));
build
.
setResult
(
Result
.
FAILURE
);
build
.
setResult
(
Result
.
FAILURE
);
return
true
;
return
true
;
}
}
else
{
reportsDir
=
new
File
(
pom
.
getBasedir
(),
"target/surefire-reports"
);
}
}
if
(
reportsDir
.
exists
())
{
if
(
fileSet
!=
null
)
{
// surefire:test just skips itself when the current project is not a java project
synchronized
(
build
)
{
synchronized
(
build
)
{
FileSet
fileSet
=
getFileSet
(
reportsDir
);
DirectoryScanner
ds
=
fileSet
.
getDirectoryScanner
();
if
(
result
==
null
)
result
=
new
TestResult
();
if
(
ds
.
getIncludedFilesCount
()==
0
)
// filter all the already parsed files:
// no test in this module
fileSet
=
Iterables
.
filter
(
fileSet
,
new
Predicate
<
File
>()
{
@Override
public
boolean
apply
(
File
input
)
{
return
!
parsedFiles
.
containsKey
(
input
);
}
});
if
(!
fileSet
.
iterator
().
hasNext
())
return
true
;
return
true
;
String
[]
reportFiles
=
ds
.
getIncludedFiles
();
result
.
parse
(
System
.
currentTimeMillis
()
-
build
.
getMilliSecsSinceBuildStart
(),
fileSet
);
rememberCheckedFiles
(
reportsDir
,
reportFiles
);
// TODO kutzi: the following is a 'more correct' way to get the reports associated to a mojo,
// but needs more testing
if
(
result
==
null
)
result
=
new
TestResult
();
// Iterable<File> reportFilesFiltered = getFilesBetween(reportsDir, reportFiles, mojo.getStartTime(), System.currentTimeMillis());
result
.
parse
(
System
.
currentTimeMillis
()
-
build
.
getMilliSecsSinceBuildStart
(),
reportsDir
,
reportFiles
);
// result.parse(reportFilesFiltered);
rememberCheckedFiles
(
fileSet
);
// final reference in order to serialize it:
// final reference in order to serialize it:
final
TestResult
r
=
result
;
final
TestResult
r
=
result
;
...
@@ -199,33 +208,13 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -199,33 +208,13 @@ public class SurefireArchiver extends TestFailureDetector {
}
}
}
}
/**
* Returns the appropriate FileSet for the selected baseDir
* @param baseDir
* @return
*/
FileSet
getFileSet
(
File
baseDir
)
{
FileSet
fs
=
fileSets
.
get
(
baseDir
);
if
(
fs
==
null
)
{
fs
=
Util
.
createFileSet
(
baseDir
,
"*.xml"
,
"testng-results.xml,testng-failed.xml"
);
FileSet
previous
=
fileSets
.
putIfAbsent
(
baseDir
,
fs
);
if
(
previous
!=
null
)
{
return
previous
;
}
}
return
fs
;
}
/**
/**
* Add checked files to the exclude list of the fileSet
* Add checked files to the exclude list of the fileSet
*/
*/
private
void
rememberCheckedFiles
(
File
baseDir
,
String
[]
reportFiles
)
{
private
void
rememberCheckedFiles
(
Iterable
<
File
>
fileSet
)
{
FileSet
fileSet
=
getFileSet
(
baseDir
);
for
(
File
f
:
fileSet
)
{
this
.
parsedFiles
.
put
(
f
,
f
);
for
(
String
file
:
reportFiles
)
{
}
fileSet
.
createExclude
().
setName
(
file
);
}
}
}
/**
/**
...
@@ -244,6 +233,65 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -244,6 +233,65 @@ public class SurefireArchiver extends TestFailureDetector {
}
}
}
}
// private static Iterable<File> getFilesBetween(final File reportsDir,
// final String[] reportFiles, final long from, final long to) {
// return new FilteredReportsFileIterable(reportsDir, reportFiles, from, to);
// }
/**
* Provides an {@link Iterable} view on the reports files while filtering out all files
* which don't have a lastModified time in between from and to.
*/
static
class
FilteredReportsFileIterable
implements
Iterable
<
File
>
{
private
final
File
reportsDir
;
private
final
String
[]
reportFiles
;
private
final
long
from
;
private
final
long
to
;
FilteredReportsFileIterable
(
File
reportsDir
,
String
[]
reportFiles
,
long
from
,
long
to
)
{
this
.
reportsDir
=
reportsDir
;
this
.
reportFiles
=
reportFiles
;
// FAT filesystems have a max resolution of 2 seconds so we need to subtract/add 2 seconds to
// the range borders.
// All other fs should have a equal or better precision
this
.
from
=
from
-
2000
;
this
.
to
=
to
+
2000
;
}
@Override
public
Iterator
<
File
>
iterator
()
{
Predicate
<
File
>
fileWithinFromAndTo
=
new
Predicate
<
File
>()
{
@Override
public
boolean
apply
(
File
file
)
{
long
lastModified
=
file
.
lastModified
();
if
(
lastModified
>=
from
&&
lastModified
<=
to
)
{
return
true
;
}
return
false
;
}
};
return
Iterators
.
filter
(
Iterators
.
transform
(
Iterators
.
forArray
(
reportFiles
),
new
Function
<
String
,
File
>()
{
@Override
public
File
apply
(
String
file
)
{
return
getFile
(
reportsDir
,
file
);
}
}),
fileWithinFromAndTo
);
}
// here for mocking purposes:
File
getFile
(
File
parent
,
String
child
)
{
return
new
File
(
parent
,
child
);
}
}
/**
/**
* Part of the serialization data attached to {@link MavenBuild}.
* Part of the serialization data attached to {@link MavenBuild}.
*/
*/
...
@@ -253,80 +301,21 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -253,80 +301,21 @@ public class SurefireArchiver extends TestFailureDetector {
}
}
}
}
private
boolean
isTestMojo
(
MojoInfo
mojo
)
{
boolean
isTestMojo
(
MojoInfo
mojo
)
{
if
((!
mojo
.
is
(
"com.sun.maven"
,
"maven-junit-plugin"
,
"test"
))
&&
(!
mojo
.
is
(
"org.sonatype.flexmojos"
,
"flexmojos-maven-plugin"
,
"test-run"
))
TestMojo
testMojo
=
TestMojo
.
lookup
(
mojo
);
&&
(!
mojo
.
is
(
"org.eclipse.tycho"
,
"tycho-surefire-plugin"
,
"test"
))
&&
(!
mojo
.
is
(
"org.sonatype.tycho"
,
"maven-osgi-test-plugin"
,
"test"
))
&&
(!
mojo
.
is
(
"org.codehaus.mojo"
,
"gwt-maven-plugin"
,
"test"
))
&&
(!
isAndroidMojo
(
mojo
))
&&
(!
isSurefireOrFailsafeMojo
(
mojo
))
&&
(!
isSoapUiMojo
(
mojo
)))
return
false
;
if
(
testMojo
==
null
)
return
false
;
try
{
try
{
if
(
isSurefireOrFailsafeMojo
(
mojo
))
{
// most test plugins have at least on of the test-skip properties:
Boolean
skip
=
mojo
.
getConfigurationValue
(
"skip"
,
Boolean
.
class
);
String
[]
skipProperties
=
{
"skip"
,
"skipExec"
,
"skipTests"
,
"skipTest"
};
for
(
String
skipProperty
:
skipProperties
)
{
Boolean
skip
=
mojo
.
getConfigurationValue
(
skipProperty
,
Boolean
.
class
);
if
(((
skip
!=
null
)
&&
(
skip
)))
{
if
(((
skip
!=
null
)
&&
(
skip
)))
{
return
false
;
return
false
;
}
}
if
(
mojo
.
pluginName
.
version
.
compareTo
(
"2.3"
)
>=
0
)
{
Boolean
skipExec
=
mojo
.
getConfigurationValue
(
"skipExec"
,
Boolean
.
class
);
if
(((
skipExec
!=
null
)
&&
(
skipExec
)))
{
return
false
;
}
}
if
(
mojo
.
pluginName
.
version
.
compareTo
(
"2.4"
)
>=
0
)
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTests"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
}
else
if
(
mojo
.
is
(
"com.sun.maven"
,
"maven-junit-plugin"
,
"test"
))
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTests"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
else
if
(
mojo
.
is
(
"org.sonatype.flexmojos"
,
"flexmojos-maven-plugin"
,
"test-run"
))
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTest"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
else
if
(
mojo
.
is
(
"org.sonatype.tycho"
,
"maven-osgi-test-plugin"
,
"test"
))
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTest"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
else
if
(
mojo
.
is
(
"org.eclipse.tycho"
,
"tycho-surefire-plugin"
,
"test"
))
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTest"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
else
if
(
isAndroidMojo
(
mojo
))
{
if
(
mojo
.
pluginName
.
version
.
compareTo
(
"3.0.0-alpha-6"
)
<
0
)
{
// Earlier versions do not support tests
return
false
;
}
else
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skipTests"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
}
else
if
(
mojo
.
is
(
"org.codehaus.mojo"
,
"gwt-maven-plugin"
,
"test"
)
&&
mojo
.
pluginName
.
version
.
compareTo
(
"1.2"
)
<
0
)
{
// gwt-maven-plugin < 1.2 does not implement required Surefire option
return
false
;
}
else
if
(
isSoapUiMojo
(
mojo
))
{
Boolean
skipTests
=
mojo
.
getConfigurationValue
(
"skip"
,
Boolean
.
class
);
if
(((
skipTests
!=
null
)
&&
(
skipTests
)))
{
return
false
;
}
}
}
}
catch
(
ComponentConfigurationException
e
)
{
}
catch
(
ComponentConfigurationException
e
)
{
return
false
;
return
false
;
...
@@ -334,26 +323,11 @@ public class SurefireArchiver extends TestFailureDetector {
...
@@ -334,26 +323,11 @@ public class SurefireArchiver extends TestFailureDetector {
return
true
;
return
true
;
}
}
private
boolean
isAndroidMojo
(
MojoInfo
mojo
)
{
return
mojo
.
is
(
"com.jayway.maven.plugins.android.generation2"
,
"maven-android-plugin"
,
"internal-integration-test"
)
||
mojo
.
is
(
"com.jayway.maven.plugins.android.generation2"
,
"android-maven-plugin"
,
"internal-integration-test"
);
}
private
boolean
isSurefireOrFailsafeMojo
(
MojoInfo
mojo
)
{
return
mojo
.
is
(
"org.apache.maven.plugins"
,
"maven-surefire-plugin"
,
"test"
)
||
mojo
.
is
(
"org.apache.maven.plugins"
,
"maven-failsafe-plugin"
,
"verify"
);
}
private
boolean
isSoapUiMojo
(
MojoInfo
mojo
)
{
return
mojo
.
is
(
"eviware"
,
"maven-soapui-plugin"
,
"test"
)
||
mojo
.
is
(
"eviware"
,
"maven-soapui-pro-plugin"
,
"test"
);
}
// I'm not sure if SurefireArchiver is actually ever (de-)serialized,
// I'm not sure if SurefireArchiver is actually ever (de-)serialized,
// but just to be sure, set fileSets here
// but just to be sure, set fileSets here
protected
Object
readResolve
()
{
protected
Object
readResolve
()
{
fileSets
=
new
ConcurrentHashMap
<
File
,
FileSet
>();
parsedFiles
=
new
ConcurrentHashMap
<
File
,
File
>();
return
this
;
return
this
;
}
}
...
...
maven-plugin/src/main/java/hudson/maven/reporters/TestMojo.java
0 → 100644
浏览文件 @
79fbe28b
package
hudson.maven.reporters
;
import
hudson.Util
;
import
hudson.maven.MojoInfo
;
import
java.io.File
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
org.apache.maven.project.MavenProject
;
import
org.apache.tools.ant.types.FileSet
;
import
org.codehaus.plexus.component.configurator.ComponentConfigurationException
;
import
com.google.common.base.Function
;
import
com.google.common.collect.Iterators
;
/**
* Description of a mojo which can run tests.
*
* @author kutzi
*/
enum
TestMojo
{
/**
* Fallback to this if we have no exact match
*/
FALLBACK
(
""
,
""
,
""
,
"reportsDirectory"
)
{
@Override
protected
boolean
is
(
String
artifactId
,
String
groupId
,
String
goal
)
{
// never match anything implicitly
return
false
;
}
},
MAVEN_SUREFIRE
(
"org.apache.maven.plugins"
,
"maven-surefire-plugin"
,
"test"
,
"reportsDirectory"
),
MAVEN_FAILSAFE
(
"org.apache.maven.plugins"
,
"maven-failsafe-plugin"
,
"verify"
,
"reportsDirectory"
),
MAVEN_JUNIT
(
"com.sun.maven"
,
"maven-junit-plugin"
,
"test"
,
"reportsDirectory"
),
FLEXMOJOS
(
"org.sonatype.flexmojos"
,
"flexmojos-maven-plugin"
,
"test-run"
,
null
),
MAVEN_OSGI_TEST
(
"org.sonatype.tycho"
,
"maven-osgi-test-plugin"
,
"test"
,
"reportsDirectory"
),
TYCHO_SUREFIRE
(
"org.eclipse.tycho"
,
"tycho-surefire-plugin"
,
"test"
,
"reportsDirectory"
),
MAVEN_ANDROID_PLUGIN
(
"com.jayway.maven.plugins.android.generation2"
,
"maven-android-plugin"
,
"internal-integration-test"
,
null
,
"3.0.0-alpha-6"
),
ANDROID_MAVEN_PLUGIN
(
"com.jayway.maven.plugins.android.generation2"
,
"android-maven-plugin"
,
"internal-integration-test"
,
null
,
"3.0.0-alpha-6"
),
GWT_MAVEN_PLUGIN
(
"org.codehaus.mojo"
,
"gwt-maven-plugin"
,
"test"
,
"reportsDirectory"
,
"1.2"
),
MAVEN_SOAPUI_PLUGIN
(
"eviware"
,
"maven-soapui-plugin"
,
"test"
,
"outputFolder"
),
MAVEN_SOAPUI_PRO_PLUGIN
(
"eviware"
,
"maven-soapui-pro-plugin"
,
"test"
,
"outputFolder"
),
JASMINE
(
"com.github.searls"
,
"jasmine-maven-plugin"
,
"test"
,
null
)
{
@Override
public
Collection
<
File
>
getReportFiles
(
MavenProject
pom
,
MojoInfo
mojo
)
throws
ComponentConfigurationException
{
// jasmine just creates a single JUnit result file
File
reportsDir
=
mojo
.
getConfigurationValue
(
"jasmineTargetDir"
,
File
.
class
);
String
junitFileName
=
mojo
.
getConfigurationValue
(
"junitXmlReportFileName"
,
String
.
class
);
return
Collections
.
singleton
(
new
File
(
reportsDir
,
junitFileName
));
}
},
TOOLKIT_RESOLVER_PLUGIN
(
"org.terracotta.maven.plugins"
,
"toolkit-resolver-plugin"
,
"toolkit-resolve-test"
,
"reportsDirectory"
);
private
String
reportDirectoryConfigKey
;
private
Key
key
;
private
String
minimalRequiredVersion
;
private
TestMojo
(
String
artifactId
,
String
groupId
,
String
goal
,
String
reportDirectoryConfigKey
)
{
this
.
key
=
new
Key
(
artifactId
,
groupId
,
goal
);
this
.
reportDirectoryConfigKey
=
reportDirectoryConfigKey
;
}
private
TestMojo
(
String
artifactId
,
String
groupId
,
String
goal
,
String
reportDirectoryConfigKey
,
String
minimalRequiredVersion
)
{
this
.
key
=
new
Key
(
artifactId
,
groupId
,
goal
);
this
.
reportDirectoryConfigKey
=
reportDirectoryConfigKey
;
this
.
minimalRequiredVersion
=
minimalRequiredVersion
;
}
public
Key
getKey
()
{
return
this
.
key
;
}
/**
* Says if this mojo can run tests.
* Can e.g. return false if the version of the plugin is too old to create output in JUnit format.
*/
public
boolean
canRunTests
(
MojoInfo
mojo
)
{
if
(
this
.
minimalRequiredVersion
==
null
)
{
return
true
;
}
return
mojo
.
pluginName
.
version
.
compareTo
(
this
.
minimalRequiredVersion
)
>=
0
;
}
public
Iterable
<
File
>
getReportFiles
(
MavenProject
pom
,
MojoInfo
mojo
)
throws
ComponentConfigurationException
{
if
(
this
.
reportDirectoryConfigKey
!=
null
)
{
File
reportsDir
=
mojo
.
getConfigurationValue
(
this
.
reportDirectoryConfigKey
,
File
.
class
);
if
(
reportsDir
.
exists
())
{
return
getReportFiles
(
reportsDir
,
getFileSet
(
reportsDir
));
}
}
// some plugins just default to this:
File
reportsDir
=
new
File
(
pom
.
getBasedir
(),
pom
.
getBuild
().
getDirectory
()+
File
.
separator
+
"surefire-reports"
);
if
(
reportsDir
.
exists
())
{
return
getReportFiles
(
reportsDir
,
getFileSet
(
reportsDir
));
}
return
null
;
}
private
Iterable
<
File
>
getReportFiles
(
final
File
baseDir
,
FileSet
set
)
{
final
String
[]
includedFiles
=
set
.
getDirectoryScanner
().
getIncludedFiles
();
return
new
Iterable
<
File
>()
{
public
Iterator
<
File
>
iterator
()
{
return
Iterators
.
transform
(
Iterators
.
forArray
(
includedFiles
),
new
Function
<
String
,
File
>()
{
@Override
public
File
apply
(
String
file
)
{
return
new
File
(
baseDir
,
file
);
}
});
}
};
}
/**
* Returns the appropriate FileSet for the selected baseDir
* @param baseDir
* @return
*/
private
FileSet
getFileSet
(
File
baseDir
)
{
return
Util
.
createFileSet
(
baseDir
,
"*.xml"
,
"testng-results.xml,testng-failed.xml"
);
}
protected
boolean
is
(
String
artifactId
,
String
groupId
,
String
goal
)
{
return
key
.
artifactId
.
equals
(
artifactId
)
&&
key
.
groupId
.
equals
(
groupId
)
&&
key
.
goal
.
equals
(
goal
);
}
public
static
TestMojo
lookup
(
String
artifactId
,
String
groupId
,
String
goal
)
{
for
(
TestMojo
mojo
:
values
())
{
if
(
mojo
.
is
(
artifactId
,
groupId
,
goal
))
{
return
mojo
;
}
}
if
(
goal
.
equals
(
"test"
)
||
goal
.
equals
(
"test-run"
))
{
return
FALLBACK
;
}
return
null
;
}
public
static
TestMojo
lookup
(
MojoInfo
mojo
)
{
TestMojo
testMojo
=
lookup
(
mojo
.
pluginName
.
groupId
,
mojo
.
pluginName
.
artifactId
,
mojo
.
getGoal
());
if
(
testMojo
!=
null
&&
testMojo
.
canRunTests
(
mojo
))
{
return
testMojo
;
}
return
null
;
}
static
class
Key
{
private
String
artifactId
;
private
String
groupId
;
private
String
goal
;
public
Key
(
String
artifactId
,
String
groupId
,
String
goal
)
{
super
();
this
.
artifactId
=
artifactId
;
this
.
groupId
=
groupId
;
this
.
goal
=
goal
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
artifactId
==
null
)
?
0
:
artifactId
.
hashCode
());
result
=
prime
*
result
+
((
goal
==
null
)
?
0
:
goal
.
hashCode
());
result
=
prime
*
result
+
((
groupId
==
null
)
?
0
:
groupId
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Key
other
=
(
Key
)
obj
;
if
(
artifactId
==
null
)
{
if
(
other
.
artifactId
!=
null
)
return
false
;
}
else
if
(!
artifactId
.
equals
(
other
.
artifactId
))
return
false
;
if
(
goal
==
null
)
{
if
(
other
.
goal
!=
null
)
return
false
;
}
else
if
(!
goal
.
equals
(
other
.
goal
))
return
false
;
if
(
groupId
==
null
)
{
if
(
other
.
groupId
!=
null
)
return
false
;
}
else
if
(!
groupId
.
equals
(
other
.
groupId
))
return
false
;
return
true
;
}
}
}
maven-plugin/src/test/java/hudson/maven/ExecutedMojoTest.java
浏览文件 @
79fbe28b
...
@@ -53,7 +53,7 @@ public class ExecutedMojoTest {
...
@@ -53,7 +53,7 @@ public class ExecutedMojoTest {
// Faking JUnit's Assert to be the plugin class
// Faking JUnit's Assert to be the plugin class
this
.
mojoDescriptor
.
setImplementation
(
Assert
.
class
.
getName
());
this
.
mojoDescriptor
.
setImplementation
(
Assert
.
class
.
getName
());
MojoExecution
execution
=
new
MojoExecution
(
this
.
mojoDescriptor
);
MojoExecution
execution
=
new
MojoExecution
(
this
.
mojoDescriptor
);
MojoInfo
info
=
new
MojoInfo
(
execution
,
null
,
null
,
null
);
MojoInfo
info
=
new
MojoInfo
(
execution
,
null
,
null
,
null
,
-
1
);
ExecutedMojo
executedMojo
=
new
ExecutedMojo
(
info
,
1L
);
ExecutedMojo
executedMojo
=
new
ExecutedMojo
(
info
,
1L
);
...
@@ -66,7 +66,7 @@ public class ExecutedMojoTest {
...
@@ -66,7 +66,7 @@ public class ExecutedMojoTest {
// Faking this class as the mojo impl:
// Faking this class as the mojo impl:
this
.
mojoDescriptor
.
setImplementation
(
getClass
().
getName
());
this
.
mojoDescriptor
.
setImplementation
(
getClass
().
getName
());
MojoExecution
execution
=
new
MojoExecution
(
this
.
mojoDescriptor
);
MojoExecution
execution
=
new
MojoExecution
(
this
.
mojoDescriptor
);
MojoInfo
info
=
new
MojoInfo
(
execution
,
null
,
null
,
null
);
MojoInfo
info
=
new
MojoInfo
(
execution
,
null
,
null
,
null
,
-
1
);
ExecutedMojo
executedMojo
=
new
ExecutedMojo
(
info
,
1L
);
ExecutedMojo
executedMojo
=
new
ExecutedMojo
(
info
,
1L
);
...
...
maven-plugin/src/test/java/hudson/maven/MojoInfoBuilder.java
0 → 100644
浏览文件 @
79fbe28b
package
hudson.maven
;
import
hudson.maven.MojoInfo
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.maven.plugin.MojoExecution
;
import
org.apache.maven.plugin.descriptor.MojoDescriptor
;
import
org.apache.maven.plugin.descriptor.PluginDescriptor
;
import
org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator
;
import
org.codehaus.plexus.configuration.DefaultPlexusConfiguration
;
import
org.codehaus.plexus.configuration.PlexusConfiguration
;
public
class
MojoInfoBuilder
{
private
String
groupId
;
private
String
artifactId
;
private
String
goalName
;
private
String
version
=
"1.0"
;
private
Map
<
String
,
String
>
configValues
=
new
HashMap
<
String
,
String
>();
private
long
startTime
=
System
.
currentTimeMillis
();
public
static
MojoInfoBuilder
mojoBuilder
(
String
groupId
,
String
artifactId
,
String
goalName
)
{
return
new
MojoInfoBuilder
(
groupId
,
artifactId
,
goalName
);
}
private
MojoInfoBuilder
(
String
groupId
,
String
artifactId
,
String
goalName
)
{
this
.
groupId
=
groupId
;
this
.
artifactId
=
artifactId
;
this
.
goalName
=
goalName
;
}
public
MojoInfoBuilder
copy
()
{
MojoInfoBuilder
copy
=
new
MojoInfoBuilder
(
this
.
groupId
,
this
.
artifactId
,
this
.
goalName
)
.
version
(
this
.
version
);
copy
.
configValues
.
putAll
(
this
.
configValues
);
return
copy
;
}
public
MojoInfoBuilder
version
(
String
version
)
{
this
.
version
=
version
;
return
this
;
}
public
MojoInfoBuilder
startTime
(
long
startTime
)
{
this
.
startTime
=
startTime
;
return
this
;
}
public
MojoInfoBuilder
configValue
(
String
key
,
String
value
)
{
configValues
.
put
(
key
,
value
);
return
this
;
}
public
MojoInfo
build
()
{
PluginDescriptor
pluginDescriptor
=
new
PluginDescriptor
();
pluginDescriptor
.
setGroupId
(
groupId
);
pluginDescriptor
.
setArtifactId
(
artifactId
);
pluginDescriptor
.
setVersion
(
version
);
MojoDescriptor
mojoDescriptor
=
new
MojoDescriptor
();
mojoDescriptor
.
setPluginDescriptor
(
pluginDescriptor
);
mojoDescriptor
.
setGoal
(
goalName
);
MojoExecution
mojoExecution
=
new
MojoExecution
(
mojoDescriptor
);
PlexusConfiguration
configuration
=
new
DefaultPlexusConfiguration
(
"configuration"
);
for
(
Map
.
Entry
<
String
,
String
>
e
:
this
.
configValues
.
entrySet
())
{
configuration
.
addChild
(
e
.
getKey
(),
e
.
getValue
());
}
ExpressionEvaluator
evaluator
=
new
ExpressionEvaluator
()
{
@Override
public
Object
evaluate
(
String
expression
)
{
return
expression
;
}
@Override
public
File
alignToBaseDirectory
(
File
file
)
{
return
file
;
}
};
MojoInfo
info
=
new
MojoInfo
(
mojoExecution
,
null
,
configuration
,
evaluator
,
startTime
);
return
info
;
}
}
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverDetectTestMojosTest.java
0 → 100644
浏览文件 @
79fbe28b
package
hudson.maven.reporters
;
import
static
hudson
.
maven
.
MojoInfoBuilder
.
mojoBuilder
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
hudson.maven.MojoInfo
;
import
hudson.maven.MojoInfoBuilder
;
import
org.junit.Before
;
import
org.junit.Test
;
/**
* Regression test for the detection of test mojos in {@link SurefireArchiver}.
*
* @author kutzi
*/
public
class
SurefireArchiverDetectTestMojosTest
{
private
SurefireArchiver
surefireArchiver
;
@Before
public
void
before
()
{
this
.
surefireArchiver
=
new
SurefireArchiver
();
}
@Test
public
void
shouldDetectMavenSurefire
()
{
MojoInfo
mojo
=
mojoBuilder
(
"org.apache.maven.plugins"
,
"maven-surefire-plugin"
,
"test"
).
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectMavenFailsafe
()
{
MojoInfo
mojo
=
mojoBuilder
(
"org.apache.maven.plugins"
,
"maven-failsafe-plugin"
,
"verify"
).
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectMavenSurefireSkip
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.apache.maven.plugins"
,
"maven-surefire-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
copy
()
.
configValue
(
"skip"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
()
.
version
(
"2.4"
)
.
configValue
(
"skipTests"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
()
.
version
(
"2.3"
)
.
configValue
(
"skipExec"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
// That's not a valid skip property:
mojo
=
builder
.
copy
()
.
configValue
(
"skip--Exec"
,
"true"
).
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectMavenJunitPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"com.sun.maven"
,
"maven-junit-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
()
.
configValue
(
"skipTests"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectFlexMojoMavenPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.sonatype.flexmojos"
,
"flexmojos-maven-plugin"
,
"test-run"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
()
.
configValue
(
"skipTest"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectOsgiTestPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.sonatype.tycho"
,
"maven-osgi-test-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skipTest"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectTychoSurefirePlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.eclipse.tycho"
,
"tycho-surefire-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skipTest"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectMavenAndroidPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"com.jayway.maven.plugins.android.generation2"
,
"maven-android-plugin"
,
"internal-integration-test"
)
.
version
(
"3.0.0-alpha-6"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skipTests"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectAndroidMavenPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"com.jayway.maven.plugins.android.generation2"
,
"android-maven-plugin"
,
"internal-integration-test"
)
.
version
(
"3.0.0-alpha-6"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skipTests"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectGwtMavenPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.codehaus.mojo"
,
"gwt-maven-plugin"
,
"test"
)
.
version
(
"1.2"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
// that version of the plugin is too old
mojo
=
builder
.
copy
().
version
(
"1.1"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectSoapUiMavenPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"eviware"
,
"maven-soapui-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skip"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectSoapUiProMavenPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"eviware"
,
"maven-soapui-pro-plugin"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skip"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectToolkitResolverPlugin
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"org.terracotta.maven.plugins"
,
"toolkit-resolver-plugin"
,
"toolkit-resolve-test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
mojo
=
builder
.
copy
().
configValue
(
"skipTests"
,
"true"
).
build
();
assertFalse
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
@Test
public
void
shouldDetectAnyMojoWithATestGoal
()
{
MojoInfoBuilder
builder
=
mojoBuilder
(
"some.weird.internal"
,
"test-mojo"
,
"test"
);
MojoInfo
mojo
=
builder
.
build
();
assertTrue
(
this
.
surefireArchiver
.
isTestMojo
(
mojo
));
}
}
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverFilterReportsFileTest.java
0 → 100644
浏览文件 @
79fbe28b
package
hudson.maven.reporters
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
hudson.maven.reporters.SurefireArchiver.FilteredReportsFileIterable
;
import
java.io.File
;
import
java.util.Iterator
;
import
java.util.NoSuchElementException
;
import
org.junit.Test
;
public
class
SurefireArchiverFilterReportsFileTest
{
@Test
public
void
shouldIncludeAllReportFiles
()
{
File
reportsDir
=
new
File
(
"bla"
);
String
[]
reportFiles
=
{
"a"
,
"b"
,
"c"
};
FilteredReportsFileIterable
iterable
=
new
FilteredReportsFileIterable
(
reportsDir
,
reportFiles
,
0
,
1000
);
iterable
=
spy
(
iterable
);
File
file
=
mock
(
File
.
class
);
when
(
file
.
lastModified
()).
thenReturn
(
500L
);
when
(
iterable
.
getFile
(
any
(
File
.
class
),
anyString
())).
thenReturn
(
file
);
Iterator
<
File
>
iterator
=
iterable
.
iterator
();
iterator
.
next
();
iterator
.
next
();
iterator
.
next
();
try
{
iterator
.
next
();
fail
(
"Iterator should only have 3 elements"
);
}
catch
(
NoSuchElementException
e
)
{
// expected
}
}
@Test
public
void
shouldExcludeReportFileTooOld
()
{
File
reportsDir
=
new
File
(
"bla"
);
String
[]
reportFiles
=
{
"a"
,
"b"
,
"c"
};
FilteredReportsFileIterable
iterable
=
new
FilteredReportsFileIterable
(
reportsDir
,
reportFiles
,
5000
,
10000
);
iterable
=
spy
(
iterable
);
File
included
=
mock
(
File
.
class
);
when
(
included
.
lastModified
()).
thenReturn
(
6000L
);
File
tooOld
=
mock
(
File
.
class
);
when
(
tooOld
.
lastModified
()).
thenReturn
(
500L
);
when
(
iterable
.
getFile
(
any
(
File
.
class
),
anyString
())).
thenReturn
(
included
,
tooOld
,
included
);
Iterator
<
File
>
iterator
=
iterable
.
iterator
();
iterator
.
next
();
iterator
.
next
();
try
{
iterator
.
next
();
fail
(
"Iterator should only have 2 elements"
);
}
catch
(
NoSuchElementException
e
)
{
// expected
}
}
@Test
public
void
shouldExcludeReportFileTooYoung
()
{
File
reportsDir
=
new
File
(
"bla"
);
String
[]
reportFiles
=
{
"a"
,
"b"
,
"c"
};
FilteredReportsFileIterable
iterable
=
new
FilteredReportsFileIterable
(
reportsDir
,
reportFiles
,
5000
,
10000
);
iterable
=
spy
(
iterable
);
File
included
=
mock
(
File
.
class
);
when
(
included
.
lastModified
()).
thenReturn
(
5000L
);
File
tooYoung
=
mock
(
File
.
class
);
when
(
tooYoung
.
lastModified
()).
thenReturn
(
20000L
);
when
(
iterable
.
getFile
(
any
(
File
.
class
),
anyString
())).
thenReturn
(
included
,
included
,
tooYoung
);
Iterator
<
File
>
iterator
=
iterable
.
iterator
();
iterator
.
next
();
iterator
.
next
();
try
{
iterator
.
next
();
fail
(
"Iterator should only have 2 elements"
);
}
catch
(
NoSuchElementException
e
)
{
// expected
}
}
}
maven-plugin/src/test/java/hudson/maven/reporters/SurefireArchiverUnitTest.java
浏览文件 @
79fbe28b
package
hudson.maven.reporters
;
package
hudson.maven.reporters
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
spy
;
...
@@ -13,6 +14,7 @@ import hudson.maven.MavenBuildProxy;
...
@@ -13,6 +14,7 @@ import hudson.maven.MavenBuildProxy;
import
hudson.maven.MavenProjectActionBuilder
;
import
hudson.maven.MavenProjectActionBuilder
;
import
hudson.maven.MavenReporter
;
import
hudson.maven.MavenReporter
;
import
hudson.maven.MojoInfo
;
import
hudson.maven.MojoInfo
;
import
hudson.maven.MojoInfoBuilder
;
import
hudson.model.BuildListener
;
import
hudson.model.BuildListener
;
import
hudson.model.Cause
;
import
hudson.model.Cause
;
import
hudson.model.Result
;
import
hudson.model.Result
;
...
@@ -28,10 +30,6 @@ import java.util.Calendar;
...
@@ -28,10 +30,6 @@ import java.util.Calendar;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.io.output.NullOutputStream
;
import
org.apache.commons.io.output.NullOutputStream
;
import
org.apache.maven.plugin.MojoExecution
;
import
org.apache.maven.plugin.descriptor.MojoDescriptor
;
import
org.apache.maven.plugin.descriptor.PluginDescriptor
;
import
org.apache.tools.ant.types.FileSet
;
import
org.codehaus.plexus.component.configurator.ComponentConfigurationException
;
import
org.codehaus.plexus.component.configurator.ComponentConfigurationException
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Before
;
...
@@ -53,8 +51,6 @@ public class SurefireArchiverUnitTest {
...
@@ -53,8 +51,6 @@ public class SurefireArchiverUnitTest {
@Before
@Before
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
void
before
()
throws
ComponentConfigurationException
,
URISyntaxException
{
public
void
before
()
throws
ComponentConfigurationException
,
URISyntaxException
{
//suppress(constructor(MavenBuild.class, new Class[0]));
this
.
archiver
=
new
SurefireArchiver
();
this
.
archiver
=
new
SurefireArchiver
();
this
.
build
=
mock
(
MavenBuild
.
class
);
this
.
build
=
mock
(
MavenBuild
.
class
);
when
(
build
.
getAction
(
Matchers
.
any
(
Class
.
class
))).
thenCallRealMethod
();
when
(
build
.
getAction
(
Matchers
.
any
(
Class
.
class
))).
thenCallRealMethod
();
...
@@ -69,17 +65,8 @@ public class SurefireArchiverUnitTest {
...
@@ -69,17 +65,8 @@ public class SurefireArchiverUnitTest {
}
}
private
MojoInfo
createMojoInfo
()
throws
ComponentConfigurationException
{
private
MojoInfo
createMojoInfo
()
throws
ComponentConfigurationException
{
PluginDescriptor
pluginDescriptor
=
new
PluginDescriptor
();
MojoInfo
info
=
MojoInfoBuilder
.
mojoBuilder
(
"org.apache.maven.plugins"
,
"maven-surefire-plugin"
,
"test"
)
pluginDescriptor
.
setGroupId
(
"org.apache.maven.plugins"
);
.
version
(
"2.9"
).
build
();
pluginDescriptor
.
setArtifactId
(
"maven-surefire-plugin"
);
pluginDescriptor
.
setVersion
(
"2.9"
);
MojoDescriptor
mojoDescriptor
=
new
MojoDescriptor
();
mojoDescriptor
.
setPluginDescriptor
(
pluginDescriptor
);
mojoDescriptor
.
setGoal
(
"test"
);
MojoExecution
mojoExecution
=
new
MojoExecution
(
mojoDescriptor
);
MojoInfo
info
=
new
MojoInfo
(
mojoExecution
,
null
,
null
,
null
);
MojoInfo
spy
=
spy
(
info
);
MojoInfo
spy
=
spy
(
info
);
...
@@ -103,6 +90,7 @@ public class SurefireArchiverUnitTest {
...
@@ -103,6 +90,7 @@ public class SurefireArchiverUnitTest {
public
void
testArchiveResults
()
throws
InterruptedException
,
IOException
,
URISyntaxException
,
ComponentConfigurationException
{
public
void
testArchiveResults
()
throws
InterruptedException
,
IOException
,
URISyntaxException
,
ComponentConfigurationException
{
URL
resource
=
SurefireArchiverUnitTest
.
class
.
getResource
(
"/surefire-archiver-test2"
);
URL
resource
=
SurefireArchiverUnitTest
.
class
.
getResource
(
"/surefire-archiver-test2"
);
File
reportsDir
=
new
File
(
resource
.
toURI
().
getPath
());
File
reportsDir
=
new
File
(
resource
.
toURI
().
getPath
());
doReturn
(
reportsDir
).
when
(
this
.
mojoInfo
).
getConfigurationValue
(
"reportsDirectory"
,
File
.
class
);
doReturn
(
reportsDir
).
when
(
this
.
mojoInfo
).
getConfigurationValue
(
"reportsDirectory"
,
File
.
class
);
touchReportFiles
(
reportsDir
);
touchReportFiles
(
reportsDir
);
...
@@ -130,19 +118,22 @@ public class SurefireArchiverUnitTest {
...
@@ -130,19 +118,22 @@ public class SurefireArchiverUnitTest {
}
}
@Test
@Test
public
void
test
AlreadyCheckedFilesAreNotParsedAgain
()
throws
InterruptedException
,
IOException
,
URISyntaxException
,
ComponentConfigurationException
{
public
void
test
ResultsAreNotCountedTwice
()
throws
InterruptedException
,
IOException
,
URISyntaxException
,
ComponentConfigurationException
{
URL
resource
=
SurefireArchiverUnitTest
.
class
.
getResource
(
"/surefire-archiver-test2"
);
URL
resource
=
SurefireArchiverUnitTest
.
class
.
getResource
(
"/surefire-archiver-test2"
);
File
reportsDir
=
new
File
(
resource
.
toURI
().
getPath
());
File
reportsDir
=
new
File
(
resource
.
toURI
().
getPath
());
doReturn
(
reportsDir
).
when
(
this
.
mojoInfo
).
getConfigurationValue
(
"reportsDirectory"
,
File
.
class
);
doReturn
(
reportsDir
).
when
(
this
.
mojoInfo
).
getConfigurationValue
(
"reportsDirectory"
,
File
.
class
);
touchReportFiles
(
reportsDir
);
touchReportFiles
(
reportsDir
);
FileSet
fileSet
=
this
.
archiver
.
getFileSet
(
reportsDir
);
this
.
archiver
.
postExecute
(
buildProxy
,
null
,
this
.
mojoInfo
,
new
NullBuildListener
(),
null
);
Assert
.
assertEquals
(
2
,
fileSet
.
getDirectoryScanner
().
getIncludedFilesCount
());
SurefireReport
action
=
this
.
build
.
getAction
(
SurefireReport
.
class
);
TestResult
result
=
action
.
getResult
();
assertEquals
(
2658
,
result
.
getTotalCount
());
// result count shouldn't increase if mojo is called again
this
.
archiver
.
postExecute
(
buildProxy
,
null
,
this
.
mojoInfo
,
new
NullBuildListener
(),
null
);
this
.
archiver
.
postExecute
(
buildProxy
,
null
,
this
.
mojoInfo
,
new
NullBuildListener
(),
null
);
action
=
this
.
build
.
getAction
(
SurefireReport
.
class
);
fileSet
=
this
.
archiver
.
getFileSet
(
reportsDir
);
result
=
action
.
getResult
(
);
Assert
.
assertEquals
(
0
,
fileSet
.
getDirectoryScanner
().
getIncludedFiles
Count
());
assertEquals
(
2658
,
result
.
getTotal
Count
());
}
}
@Test
@Test
...
@@ -205,7 +196,7 @@ public class SurefireArchiverUnitTest {
...
@@ -205,7 +196,7 @@ public class SurefireArchiverUnitTest {
private
void
touchReportFiles
(
File
reportsDir
)
{
private
void
touchReportFiles
(
File
reportsDir
)
{
File
[]
files
=
reportsDir
.
listFiles
();
File
[]
files
=
reportsDir
.
listFiles
();
for
(
File
f
:
files
)
{
for
(
File
f
:
files
)
{
f
.
setLastModified
(
System
.
currentTimeMillis
());
f
.
setLastModified
(
this
.
mojoInfo
.
getStartTime
());
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录