generated from remal-gradle-plugins/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
234 lines (204 loc) · 9.32 KB
/
build.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import static org.objectweb.asm.ClassReader.SKIP_CODE
import static org.objectweb.asm.ClassReader.SKIP_DEBUG
import static org.objectweb.asm.ClassReader.SKIP_FRAMES
import com.github.fhermansson.gradle.assertj.plugin.GenerateAssertions
import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
buildscript {
String rootGroupId = project.ext.rootGroupId = "name.remal.gradle-plugins.${rootProject.name}"
String rootArtifactId = project.ext.rootArtifactId = rootProject.name
String rootSnapshotVersion = project.ext.rootSnapshotVersion = '0-SNAPSHOT'
dependencies {
//classpath("$rootGroupId:$rootArtifactId:$rootSnapshotVersion") { version { strictly(rootSnapshotVersion) } }
classpath 'name.remal.gradle-plugins.toolkit:build-logic:0.67.0'
classpath 'com.github.fhermansson:assertj-gradle-plugin:1.1.5'
}
repositories {
mavenCentral()
gradlePluginPortal()
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
allprojects {
group = project.rootGroupId
version = project.rootSnapshotVersion
}
apply plugin: 'name.remal.toolkit.build-logic'
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
apply plugin: 'java-gradle-plugin'
apply plugin: 'name.remal.generate-sources'
gradlePlugin {
plugins {
'name.remal.versions-retriever' {
id = 'name.remal.versions-retriever'
implementationClass = 'name.remal.gradle_plugins.versions_retriever.VersionsRetrieverPlugin'
displayName = 'Previous version retriever'
description = property('repository-description')
}
}
}
String jgitVersion = "6.10.0.202406032230-r"
configurations.create('jgit') { conf ->
conf.canBeResolved = true
conf.canBeConsumed = false
conf.description = "JGit dependencies"
configurations.optional.extendsFrom(conf)
}
dependencies {
jgit "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion"
jgit "org.eclipse.jgit:org.eclipse.jgit.ssh.apache:$jgitVersion"
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
apply plugin: 'java-test-fixtures'
apply plugin: 'com.github.fhermansson.assertj-generator'
dependencies {
testImplementation 'org.assertj:assertj-core'
testFixturesImplementation 'org.assertj:assertj-core'
}
assertjGenerator {
testSourceSet = sourceSets.testFixtures
outputDir = 'build/generated/assertj'
classOrPackageNames = [
'name.remal.gradle_plugins.versions_retriever.VersionInfo',
]
}
tasks.withType(GenerateAssertions).configureEach {
group = 'other'
doLast {
project.files(outputDir).asFileTree
.matching { include('**/*.java') }
.visit { FileVisitDetails details ->
if (details.directory) {
return
}
String content = details.file.getText('UTF-8')
content = content
.replaceAll(/@javax\.annotation\.Generated(\([^)]*\))?/, '@org.gradle.api.Generated')
.replaceAll(/(([\r\n]+)public class )/, '$2@SuppressWarnings("all")$1')
details.file.setText(content, 'UTF-8')
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
testSourceSets.create('integrationTest')
dependencies {
integrationTestImplementation "org.eclipse.jgit:org.eclipse.jgit.http.server:$jgitVersion"
integrationTestImplementation 'org.eclipse.jetty:jetty-servlet:10.0.24'
}
tasks.named('integrationTest', Test) { // TODO: remove it
exclude { FileTreeElement element ->
if (element.directory) return false
if (element.name.endsWith(".class")) {
ClassNode classNode = new ClassNode()
element.open().withCloseable {
new ClassReader(it).accept(classNode, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES)
}
Integer minSupportedJavaVersion = classNode.visibleAnnotations
?.find { it.desc == 'Lname/remal/gradle_plugins/toolkit/testkit/MinSupportedJavaVersion;' }
?.with {
for (int i = 0; i < it.values.size() - 1; i += 2) {
if (it.values[i] == 'value' && it.values[i + 1] instanceof Integer) {
return it.values[i + 1]
}
}
return null
}
if (minSupportedJavaVersion != null) {
if (project.javaRuntimeVersion.majorVersion.toInteger() < minSupportedJavaVersion) {
return true
}
}
Integer maxSupportedJavaVersion = classNode.visibleAnnotations
?.find { it.desc == 'Lname/remal/gradle_plugins/toolkit/testkit/MaxSupportedJavaVersion;' }
?.with {
for (int i = 0; i < it.values.size() - 1; i += 2) {
if (it.values[i] == 'value' && it.values[i + 1] instanceof Integer) {
return it.values[i + 1]
}
}
return null
}
if (maxSupportedJavaVersion != null) {
if (project.javaRuntimeVersion.majorVersion.toInteger() > maxSupportedJavaVersion) {
return true
}
}
}
return false
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Closure addDependenciesGenerator = { String packageName, String feature, Configuration configuration ->
tasks.named('generateJava') {
inputs.files(configuration).withNormalizer(ClasspathNormalizer).optional().withPropertyName("configuration:${configuration.name}")
classFile(packageName, "${feature}Dependency") {
it.writePackage()
it.println("")
it.writeImport("lombok.Builder")
it.writeImport("lombok.Value")
it.println("")
it.println("@Value")
it.println("@Builder")
it.writeBlock("public class ${it.simpleName}") {
it.println("String group;")
it.println("String name;")
it.println("String version;")
}
}
classFile(packageName, "${feature}Dependencies") {
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.writeBlock("public abstract class ${it.simpleName}") {
it.println("")
it.println("private static final Map<String, ${feature}Dependency> MAPPING = ImmutableMap.<String, ${feature}Dependency>builder()")
configuration.resolvedConfiguration.lenientConfiguration.firstLevelModuleDependencies
.findAll { !it.moduleArtifacts.isEmpty() }
.forEach { dep ->
it.println(" .put(\"${it.escapeJava(dep.moduleGroup)}:${it.escapeJava(dep.moduleName)}\", ${feature}Dependency.builder()")
it.println(" .group(\"${it.escapeJava(dep.moduleGroup)}\")")
it.println(" .name(\"${it.escapeJava(dep.moduleName)}\")")
it.println(" .version(\"${it.escapeJava(dep.moduleVersion)}\")")
it.println(" .build()")
it.println(" )")
}
it.println(" .build();")
it.println("")
it.writeBlock("public static Map<String, ${feature}Dependency> get${feature}Dependencies()") {
it.println("return MAPPING;")
}
it.println("")
it.writeBlock("public static ${feature}Dependency get${feature}Dependency(String id)") {
it.println("val dependency = get${feature}Dependencies().get(id);")
it.writeBlock("if (dependency == null)") {
it.println("throw new IllegalStateException(\"${feature} dependency is not registered: \" + id);")
}
it.println("return dependency;")
}
}
}
}
}
addDependenciesGenerator('name.remal.gradle_plugins.versions_retriever.git', 'JGit', configurations.jgit)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
List<Map<String, String>> loggingExclusions = [ // TODO: remove it
[group: 'org.slf4j', module: '*'],
]
sourceSets.configureEach { sourceSet ->
Collection<String> configurationNames = project.getSourceSetConfigurationNames(sourceSet)
configurations.matching { configurationNames.contains(it.name) }.configureEach { conf ->
conf.dependencies.withType(ExternalModuleDependency).configureEach { dep ->
if (dep.group != 'name.remal.gradle-api') {
loggingExclusions.forEach { dep.exclude(it) }
}
}
}
}