-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgrouping.gradle
More file actions
139 lines (120 loc) · 4.21 KB
/
Copy pathgrouping.gradle
File metadata and controls
139 lines (120 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def addDependency = { TaskProvider taskProvider, String dependency ->
taskProvider.configure { Task task -> task.dependsOn(dependency) }
}
def getProjectFullName = { Project pj ->
def fullName = pj.name
def parent = pj.parent
while (parent != null && parent.name != rootProject.name) {
fullName = parent.name + ":" + fullName
parent = parent.parent
}
return fullName
}
def groupedCollections = [
"examples",
"guides",
]
def moduleGroups = [
"database",
"graalvm",
"server",
"client",
"kafka",
"other",
]
def getCollectionName = { Project pj ->
def collectionName = groupedCollections.find { pj.path.startsWith(":${it}:") }
return collectionName
}
def getModuleLanguage = { Project pj ->
def collectionName = getCollectionName(pj)
if (collectionName == null) {
return null
}
if (pj.path.startsWith(":${collectionName}:kotlin:")) {
return "kotlin"
}
if (pj.path.startsWith(":${collectionName}:java:") || pj.path.startsWith(":${collectionName}:graalvm:")) {
return "java"
}
return null
}
def getModuleGroup = { Project pj ->
def collectionName = getCollectionName(pj)
if (collectionName == null) {
return null
}
if (pj.path.startsWith(":${collectionName}:graalvm:") || pj.name.contains("graalvm")) {
return "graalvm"
}
def matchedGroup = moduleGroups.find { it != "other" && pj.name.contains(it) }
return matchedGroup ?: "other"
}
def addDependencyByModuleGroup = { TaskProvider taskProvider, String collectionName, String language, String groupName, String taskName ->
rootProject.allprojects.forEach { Project pj ->
if (!pj.childProjects.isEmpty()) {
return
}
if (getCollectionName(pj) != collectionName) {
return
}
if (getModuleLanguage(pj) != language) {
return
}
if (getModuleGroup(pj) != groupName) {
return
}
def fullName = getProjectFullName(pj)
addDependency(taskProvider, ":${fullName}:${taskName}")
}
}
def groupModules = { String collectionName, String language, String groupName ->
def capitalizedLanguage = language.capitalize()
def capitalizedGroup = groupName.capitalize()
def capitalizedCollection = collectionName.capitalize()
def taskSuffix = "${capitalizedCollection}${capitalizedLanguage}${capitalizedGroup}"
def descriptionSuffix = "${collectionName} ${language} ${groupName}"
def testByType = tasks.register("test${taskSuffix}") {
group("verification")
description("Run tests for ${descriptionSuffix}")
}
addDependencyByModuleGroup(testByType, collectionName, language, groupName, "test")
def classesByType = tasks.register("classes${taskSuffix}") {
group("build")
description("Build classes for ${descriptionSuffix}")
}
addDependencyByModuleGroup(classesByType, collectionName, language, groupName, "classes")
def testClassesByType = tasks.register("testClasses${taskSuffix}") {
group("build")
description("Build testClasses for ${descriptionSuffix}")
}
addDependencyByModuleGroup(testClassesByType, collectionName, language, groupName, "testClasses")
}
groupedCollections.forEach { collectionName ->
["java", "kotlin"].forEach { language ->
moduleGroups.forEach { groupName ->
groupModules(collectionName, language, groupName)
}
}
}
def jacocoRootReport = tasks.register("jacocoRootReport", JacocoReport) {
group = 'verification'
executionData project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')
reports {
xml.required.set(true)
xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/test/jacocoTestReport.xml"))
csv.required.set(false)
html.required.set(false)
}
}
subprojects {
tasks.configureEach { task ->
if (task.name == "jacocoTestReport") {
def report = (JacocoReport) task
jacocoRootReport.configure { root ->
root.additionalClassDirs report.allClassDirs
root.additionalSourceDirs report.allSourceDirs
}
}
}
}