generated from remal-gradle-plugins/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-generate-LibrariesToTestCompatibility.gradle
38 lines (37 loc) · 1.89 KB
/
build-generate-LibrariesToTestCompatibility.gradle
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
tasks.named('generateFunctionalTestJava') { Task task ->
inputs.files(configurations.librariesToTestCompatibility).withPropertyName('librariesToTestCompatibility')
classFile(project.calculateBaseJavaPackage(), 'LibrariesToTestCompatibility') {
it.writePackage()
it.println("")
it.writeStaticImport("lombok.AccessLevel", "PRIVATE")
it.println("")
it.writeImport("com.google.common.collect.ImmutableMap")
it.writeImport("java.util.Map")
it.writeImport("lombok.NoArgsConstructor")
it.writeImport("lombok.val")
it.println("")
it.println("@NoArgsConstructor(access = PRIVATE)")
it.writeSuppressWarnings("checkstyle:LineLength", "checkstyle:RightCurlyAlone")
it.writeBlock("abstract class ${it.simpleName}") {
it.println("")
it.println("private static final Map<String, String> MAPPING = ImmutableMap.<String, String>builder()")
configurations.librariesToTestCompatibility.resolvedConfiguration
.getResolvedArtifacts()
.collect { it.id }
.collect { it.componentIdentifier }
.findAll { it instanceof ModuleComponentIdentifier }
.forEach { ModuleComponentIdentifier id ->
it.println(" .put(\"${it.escapeJava("${id.group}:${id.module}")}\", \"${it.escapeJava("${id.group}:${id.module}:${id.version}")}\")")
}
it.println(" .build();")
it.println("")
it.writeBlock("public static String getLibraryNotation(String id)") {
it.println("val notation = MAPPING.get(id);")
it.writeBlock("if (notation == null)") {
it.println("throw new IllegalStateException(\"Notation is not registered: \" + id);")
}
it.println("return notation;")
}
}
}
}