Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
9956c73a
Commit
9956c73a
authored
6 years ago
by
Sergei Vorobyov
Committed by
Sergei Vorobyov
6 years ago
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-169795 added more intelligence test task finding
parent
30a9ffae
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/tests/DefaultExternalTestsModel.java
+33
-0
...plugins/gradle/model/tests/DefaultExternalTestsModel.java
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalTestsModelBuilderImpl.groovy
+85
-0
...adle/tooling/builder/ExternalTestsModelBuilderImpl.groovy
with
118 additions
and
0 deletions
+118
-0
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/model/tests/DefaultExternalTestsModel.java
0 → 100644
+
33
-
0
View file @
9956c73a
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.gradle.model.tests
;
import
org.jetbrains.annotations.NotNull
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
DefaultExternalTestsModel
implements
ExternalTestsModel
{
@NotNull
private
List
<
ExternalTestSourceMapping
>
sourceTestMappings
=
Collections
.
emptyList
();
public
DefaultExternalTestsModel
()
{}
public
DefaultExternalTestsModel
(
ExternalTestsModel
model
)
{
sourceTestMappings
=
new
ArrayList
<
ExternalTestSourceMapping
>();
for
(
ExternalTestSourceMapping
sourceMapping
:
model
.
getTestSourceMappings
())
{
sourceTestMappings
.
add
(
new
DefaultExternalTestSourceMapping
(
sourceMapping
));
}
}
@Override
@NotNull
public
List
<
ExternalTestSourceMapping
>
getTestSourceMappings
()
{
return
Collections
.
unmodifiableList
(
sourceTestMappings
);
}
public
void
setSourceTestMappings
(
@NotNull
List
<
ExternalTestSourceMapping
>
sourceTestMappings
)
{
this
.
sourceTestMappings
=
sourceTestMappings
;
}
}
This diff is collapsed.
Click to expand it.
plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalTestsModelBuilderImpl.groovy
0 → 100644
+
85
-
0
View file @
9956c73a
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.gradle.tooling.builder
import
groovy.transform.CompileStatic
import
org.gradle.api.Project
import
org.gradle.api.file.FileCollection
import
org.gradle.api.tasks.SourceSetContainer
import
org.gradle.api.tasks.testing.Test
import
org.jetbrains.annotations.NotNull
import
org.jetbrains.plugins.gradle.model.tests.DefaultExternalTestSourceMapping
import
org.jetbrains.plugins.gradle.model.tests.DefaultExternalTestsModel
import
org.jetbrains.plugins.gradle.model.tests.ExternalTestSourceMapping
import
org.jetbrains.plugins.gradle.model.tests.ExternalTestsModel
import
org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import
org.jetbrains.plugins.gradle.tooling.ModelBuilderService
@CompileStatic
class
ExternalTestsModelBuilderImpl
implements
ModelBuilderService
{
@Override
boolean
canBuild
(
String
modelName
)
{
return
ExternalTestsModel
.
name
==
modelName
}
@Override
Object
buildAll
(
String
modelName
,
Project
project
)
{
def
defaultTestsModel
=
new
DefaultExternalTestsModel
()
defaultTestsModel
.
sourceTestMappings
=
getMapping
(
project
)
return
defaultTestsModel
}
private
static
List
<
ExternalTestSourceMapping
>
getMapping
(
Project
project
)
{
def
taskToClassesDirs
=
new
LinkedHashMap
<
Test
,
Set
<
String
>>()
for
(
def
task
:
project
.
tasks
)
{
if
(
task
instanceof
Test
)
{
def
test
=
(
Test
)
task
def
classFiles
=
getPaths
(
test
.
testClassesDirs
)
taskToClassesDirs
[
test
]
=
classFiles
}
}
def
sourceSetContainer
=
project
.
findProperty
(
"sourceSets"
)
as
SourceSetContainer
if
(
sourceSetContainer
==
null
)
return
Collections
.
emptyList
()
def
classesDirToSourceDirs
=
new
LinkedHashMap
<
String
,
Set
<
String
>>()
for
(
def
sourceSet
:
sourceSetContainer
)
{
def
sourceFolders
=
getPaths
(
sourceSet
.
allSource
.
sourceDirectories
)
for
(
def
classDirectory
:
getPaths
(
sourceSet
.
output
))
{
def
storedSourceFolders
=
classesDirToSourceDirs
.
getOrDefault
(
classDirectory
,
new
LinkedHashSet
<>())
storedSourceFolders
.
addAll
(
sourceFolders
)
classesDirToSourceDirs
.
put
(
classDirectory
,
storedSourceFolders
)
}
}
def
testSourceMappings
=
new
ArrayList
<
ExternalTestSourceMapping
>()
for
(
def
entry
:
taskToClassesDirs
.
entrySet
())
{
def
sourceFolders
=
new
LinkedHashSet
<
String
>()
for
(
def
classDirectory
:
entry
.
value
)
{
def
storedSourceFolders
=
classesDirToSourceDirs
[
classDirectory
]
if
(
storedSourceFolders
==
null
)
continue
sourceFolders
.
addAll
(
storedSourceFolders
)
}
def
task
=
entry
.
key
def
taskProjectPath
=
task
.
project
.
path
==
":"
?
""
:
task
.
project
.
path
def
cleanTestTaskName
=
"clean"
+
task
.
name
.
capitalize
()
def
defaultExternalTestSourceMapping
=
new
DefaultExternalTestSourceMapping
()
defaultExternalTestSourceMapping
.
testName
=
task
.
name
defaultExternalTestSourceMapping
.
testTaskPath
=
task
.
path
defaultExternalTestSourceMapping
.
cleanTestTaskPath
=
taskProjectPath
+
":"
+
cleanTestTaskName
defaultExternalTestSourceMapping
.
sourceFolders
=
sourceFolders
testSourceMappings
.
add
(
defaultExternalTestSourceMapping
)
}
return
testSourceMappings
}
private
static
Set
<
String
>
getPaths
(
FileCollection
files
)
{
def
paths
=
new
LinkedHashSet
<
String
>()
for
(
def
file
:
files
.
files
)
{
paths
.
add
(
file
.
absolutePath
)
}
return
paths
}
@NotNull
@Override
ErrorMessageBuilder
getErrorMessageBuilder
(
@NotNull
Project
project
,
@NotNull
Exception
e
)
{
return
ErrorMessageBuilder
.
create
(
project
,
e
,
"Tests model errors"
)
}
}
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment