|
1 | 1 | plugins {
|
2 |
| - id("de.jjohannes.java-ecosystem-capabilities") |
| 2 | + `kotlin-dsl` |
3 | 3 | }
|
4 | 4 |
|
5 |
| -buildscript { |
6 |
| - dependencies { |
7 |
| - classpath("org.reflections:reflections:0.10.2") |
8 |
| - } |
9 |
| -} |
10 |
| - |
11 |
| -fun String.asRepoLink() = "[$this](https://mvnrepository.com/artifact/${replace(":", "/")})" |
12 |
| - |
13 |
| -val updateReadme = tasks.register("updateReadme") { |
14 |
| - doLast { |
15 |
| - val readme = layout.projectDirectory.file("../README.MD").asFile |
16 |
| - |
17 |
| - val reflections = org.reflections.Reflections("de.jjohannes.gradle.javaecosystem.capabilities.rules") |
18 |
| - val allClasses = reflections.getSubTypesOf(ComponentMetadataRule::class.java) |
19 |
| - val allCapabilities = allClasses.map { ruleClass -> |
20 |
| - val capabilityGroup = ruleClass.getDeclaredField("CAPABILITY_GROUP").get(null) as String |
21 |
| - var capability = ""; |
22 |
| - ruleClass.declaredFields.filter { it.name.startsWith("CAPABILITY_NAME") }.forEach { field -> |
23 |
| - if (capability.isNotEmpty()) { |
24 |
| - capability += " / " |
25 |
| - } |
26 |
| - val capabilityName = field.get(null) as String |
27 |
| - capability += "$capabilityGroup:${capabilityName}".asRepoLink() |
28 |
| - } |
29 |
| - capability += " ([${ruleClass.simpleName}](plugin/src/main/java/de/jjohannes/gradle/javaecosystem/capabilities/rules/${ruleClass.simpleName}.java))" |
30 |
| - |
31 |
| - val modules = ruleClass.getDeclaredField("MODULES").get(null) as Array<*> |
32 |
| - Pair(capability, modules) |
33 |
| - }.sortedBy { it.first } |
34 |
| - |
35 |
| - val capabilityList = allCapabilities.joinToString("") { c -> |
36 |
| - "* ${c.first}\n${c.second.joinToString("") { " * ${(it as String).asRepoLink()}\n" }}" |
37 |
| - } |
38 |
| - |
39 |
| - readme.writeText( |
40 |
| - readme.readText().replace( |
41 |
| - Regex("<!-- START_GENERATED -->(.*\\n)+<!-- END_GENERATED -->"), |
42 |
| - "<!-- START_GENERATED -->\n$capabilityList\n<!-- END_GENERATED -->" |
43 |
| - ) |
44 |
| - ) |
45 |
| - } |
46 |
| -} |
47 |
| - |
48 |
| -val checkAllSample = tasks.register("checkAllSample") { |
49 |
| - doLast { |
50 |
| - val buildFile = layout.projectDirectory.file("../samples/sample-all/build.gradle.kts").asFile.readText() |
51 |
| - |
52 |
| - val reflections = org.reflections.Reflections("de.jjohannes.gradle.javaecosystem.capabilities.rules") |
53 |
| - val allClasses = reflections.getSubTypesOf(ComponentMetadataRule::class.java) |
54 |
| - |
55 |
| - val missing = allClasses.map { ruleClass -> |
56 |
| - val capabilityGroup = ruleClass.getDeclaredField("CAPABILITY_GROUP").get(null) |
57 |
| - val capabilityName = ruleClass.getDeclaredField("CAPABILITY_NAME").get(null) |
58 |
| - val capability = ruleClass.getDeclaredField("CAPABILITY").get(null) |
59 |
| - if (capability != "$capabilityGroup:$capabilityName") { |
60 |
| - throw RuntimeException("Inconsistent fields in ${ruleClass.simpleName}: $capabilityGroup:$capabilityName | $capability") |
61 |
| - } |
62 |
| - ((ruleClass.getDeclaredField("MODULES").get(null) as Array<*>).toList() + capability).filter { |
63 |
| - module -> !buildFile.contains(module as String) } |
64 |
| - }.flatten() |
65 |
| - |
66 |
| - if (missing.isNotEmpty()) { |
67 |
| - throw RuntimeException(missing.joinToString("\n") { "implementation(\"$it:+\")" }) |
68 |
| - } |
69 |
| - } |
70 |
| -} |
71 |
| - |
72 |
| -tasks.register("checkAndUpdate") { |
73 |
| - dependsOn(updateReadme) |
74 |
| - dependsOn(checkAllSample) |
| 5 | +dependencies { |
| 6 | + implementation("de.jjohannes.gradle:java-ecosystem-capabilities") |
| 7 | + implementation("org.reflections:reflections:0.10.2") |
75 | 8 | }
|
0 commit comments