forked from eclipse-buildship/buildship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
336 lines (296 loc) · 12.1 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
import eclipsebuild.*
import eclipsebuild.testing.EclipseTestTask
import java.util.regex.*
plugins {
id "org.ajoberstar.grgit" version "4.1.1"
}
apply plugin: eclipsebuild.BuildDefinitionPlugin
ext.toolingApiBundleVersion = getBundleVersion(toolingApiVersion)
// define version mapping for the 3rd-party dependencies that are not specific to a particular Eclipse version
def eclipseVersionAgnosticDependencies = [
'org.gradle.toolingapi' : toolingApiBundleVersion,
'org.slf4j.api' : '1.7.30',
'org.slf4j.simple' : '1.7.30',
'com.google.guava' : '30.1.0',
'com.google.gson' : '2.7.0',
'org.eclipse.swtbot.eclipse.finder' : '2.2.1',
'org.eclipse.swtbot.junit4_x' : '2.2.1',
'org.jetbrains.kotlin.bundled-compiler': '0.8.7',
'org.jetbrains.kotlin.core' : '0.8.7'
]
def targetPlatformIds = [
'48',
'49',
'410',
'411',
'412',
'413',
'414',
'415',
'416',
'417',
'418',
'419',
'420',
'421',
'422',
'423',
'424',
'425',
'426',
'427'
]
// target platform definition for all major Eclipse releases between version 4.3 and 4.8
// the default version is 48 which can be overridden through -Peclipse.version=<version>
// also the target platforms contain 1) the Eclipse SDK 2) the latest junit 3) SWTBot 2.2.1
eclipseBuild {
defaultEclipseVersion = '423'
// TODO make the default targetPlatformIds.last() after adding support for running builds on Java 17. e424+ builds should run on Java 17.
final def swtPluginId = "org.eclipse.swt.${ECLIPSE_WS}.${ECLIPSE_OS}.${ECLIPSE_ARCH}"
targetPlatformIds.each { id ->
targetPlatform {
eclipseVersion = id
targetDefinition = file("target-platforms/${id}.target")
versionMapping = readVersionMapping(file("target-platforms/${id}-version.properties"), swtPluginId) + eclipseVersionAgnosticDependencies
}
}
scmRepo = "https://github.com/eclipse/buildship.git"
commitId = currentCommitId()
}
// read the current version from an external file and add a timestamp suffix if requested by the caller
ext.baseVersion = file('version.txt').text.trim()
ext.versionQualifier = getVersionQualifier()
version = baseVersion + '.' + versionQualifier
// ensure that the assembleTargetPlatform is executed when the gradle.properties file is changed
project.assembleTargetPlatform.inputs.file file('gradle.properties')
// delete the org.eclipse.core.runtime.compatibility.registry plugin from the target platform
// it causes classpath issues when the the Spock tests are running with Groovy 2.4; only
// contains files to provide 2.x compatibility hence it's safe to remove
project.assembleTargetPlatform.doLast {
def config = Config.on(project)
if (config.targetPlatform.eclipseVersion in ['43', '44', '45']) {
def registryPluginId = 'org.eclipse.core.runtime.compatibility.registry'
project.exec {
// redirect the external process output to the logging
standardOutput = new LogOutputStream(project.logger, LogLevel.INFO)
errorOutput = new LogOutputStream(project.logger, LogLevel.INFO)
commandLine(config.eclipseSdkExe.path,
'-application', 'org.eclipse.equinox.p2.director',
'-uninstallIU', registryPluginId,
'-tag', 'target-platform-2',
'-destination', config.nonMavenizedTargetPlatformDir.path,
'-profile', 'SDKProfile',
'-bundlepool', config.nonMavenizedTargetPlatformDir.path,
'-p2.os', Constants.os,
'-p2.ws', Constants.ws,
'-p2.arch', Constants.arch,
'-roaming',
'-nosplash')
}
def bundlesInfo = new File(config.nonMavenizedTargetPlatformDir, 'configuration/org.eclipse.equinox.simpleconfigurator/bundles.info')
def updatedInfo = ''
bundlesInfo.withReader { reader ->
def line
while (line = reader.readLine()) {
if (!line.contains(registryPluginId)) {
updatedInfo += line + '\n'
}
}
}
bundlesInfo.text = updatedInfo
}
}
subprojects {
// set the calculated version on all projects in the hierarchy
version = rootProject.version
plugins.withType(JavaPlugin) {
def config = Config.on(project)
if (project.name.endsWith(".compat") || config.targetPlatform.eclipseVersion in ['43', '44', '45', '46', '47', '48', '49', '410', '411', '412', '413', '414', '415', '416']) {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
} else {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
}
tasks.matching { it instanceof JavaCompile || it instanceof GroovyCompile }.all {
// enable all warnings except for different sourceCompatibility and targetCompatibility value
options.compilerArgs << '-Xlint:all'
options.compilerArgs << '-Xlint:-options'
}
}
// use common bundled testing depenendencies for all test plugins
plugins.withType(eclipsebuild.TestBundlePlugin) {
dependencies {
implementation "org.codehaus.groovy:groovy-all:$groovyLibVersion"
bundled "org.codehaus.groovy:groovy-all:$groovyLibVersion"
bundled "org.objenesis:objenesis:$objenesisLibVersion"
bundled "org.spockframework:spock-core:$spockLibVersion"
bundled "cglib:cglib-nodep:$cglibLibVersion"
bundled "org.slf4j:slf4j-simple:$slf4jLibVersion"
}
if (project.hasProperty('eclipse.test.java.version')) {
tasks.withType(EclipseTestTask) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(project.getProperty('eclipse.test.java.version') as Integer)
}
}
}
}
// apply Checkstyle plugin, mainly to ensure license/copyright and javadoc is present
apply plugin: 'checkstyle'
// share checkstyle config across all sub-projects
def checkstyleConfigDir = "$rootDir/gradle/config/checkstyle"
tasks.withType(Checkstyle).all {
configFile = "$checkstyleConfigDir/checkstyle.xml" as File
configProperties = ['checkstyleConfigDir': checkstyleConfigDir]
inputs.file "$checkstyleConfigDir/suppressions.xml" as File
}
tasks.withType(Test).all {
def java8 = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(8) }
def java11 = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(11) }
jvmArgs "-Djdk8.location=${java8.get().metadata.installationPath.asFile}"
jvmArgs "-Djdk11.location=${java11.get().metadata.installationPath.asFile}"
// TODO re-enable html test reporting on Windows
if (org.gradle.internal.os.OperatingSystem.current().windows) {
reports.html.enabled = false
}
}
// configure the repositories where the external dependencies can be found
repositories {
maven {
name = 'mavenized-target-platform'
url "${eclipsebuild.Config.on(project).mavenizedTargetPlatformDir}"
}
mavenCentral()
maven {
name = 'gradle-snapshots'
url gradleSnapshotsRepositoryUrl
}
maven {
name = 'gradle-releases'
url gradleReleasesRepositoryUrl
}
maven {
name = 'gradle-remote'
url gradleRemoteRepositoryUrl
}
}
}
// tag the HEAD of the current branch and push the new tag
task tag {
doLast {
def githubAccessKey = findProperty("githubAccessKey")
if (!githubAccessKey) {
throw new IllegalStateException("Cannot tag commit: define GitHub access key with -PgithubAccessKey=<access_key> project property")
} else {
// set access token
System.setProperty("org.ajoberstar.grgit.auth.username", githubAccessKey)
// tag current state
grgit.tag.add {
def tagVersion = file('version.txt').text.trim()
name = "REL_$tagVersion"
message = "Create tag REL_$tagVersion"
}
// push changes
grgit.push(tags: true)
}
}
}
// increment the service segment in the version number and push it to master
task incrementVersion {
doLast {
def oldVersion = file('version.txt').text.trim()
def newVersion = ""
def matcher = version =~ "^(\\d+)\\.(\\d+).(\\d+)"
if (matcher.find()) {
def serviceSegment = Integer.parseInt(matcher.group(3)) + 1
newVersion = matcher.group(1) + "." + matcher.group(2) + "." + serviceSegment
file('version.txt').text = newVersion
Pattern bundleVersionPattern = Pattern.compile('(?<=Bundle-Version: )\\d+\\.\\d+\\.\\d+(?=\\.qualifier)')
file('.').eachFileRecurse { file ->
if (file.name == 'MANIFEST.MF') {
replacePatternsInFile(file, [(bundleVersionPattern): newVersion])
}
}
} else {
throw new IllegalStateException("Unparseable version: $oldVersion.")
}
exec { commandLine 'git', 'commit', '-a', '-m', "Increment version from $oldVersion to $newVersion" }
exec { commandLine 'git', 'push', githubAuthenticatedHost, 'master' }
}
}
void replacePatternsInFile(File file, Map<Pattern, String> patternAndReplacement) {
String fileText = file.text
patternAndReplacement.each { Pattern pattern, String replacement ->
fileText = pattern.matcher(fileText).replaceAll(replacement)
}
file.text = fileText
}
String getVersionQualifier() {
def config = BuildshipConfig.on(project)
// determine suffix for snapshot and milestone builds
String suffix = getVersionSuffix(config)
// use full timestamp on CI vs. date-only for local builds
if (project.hasProperty('qualifier')) {
'v' + project.getProperty('qualifier')
} else if (project.hasProperty('build.invoker') && project.property('build.invoker') == 'ci') {
// note that for Eclipse plugin versions, the '-' and '.' character are invalid in front of the build id
'v' + new Date().format('yyyyMMdd-kkmm', TimeZone.getTimeZone('GMT')) + suffix
} else {
'v' + new Date().format('yyyyMMdd', TimeZone.getTimeZone('GMT')) + suffix
}
}
private getVersionSuffix(BuildshipConfig config) {
if (config.isRelease()) {
return ''
}
if (config.isMilestone()) {
return '-m'
}
if (config.isSnapshot()) {
return '-s'
}
throw new IllegalStateException("BuildshipConfig must either be a release, milestone, or snapshot.")
}
String getBundleVersion(String version) {
def matcher = version =~ /(\d+)\.(\d+)(?:-.*|\.(\d+)(?:-.*)?)?/
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid bundle version: $version")
}
def major = matcher.group(1)
def minor = matcher.group(2)
def service = matcher.group(3) ?: '0'
"$major.$minor.$service"
}
def currentCommitId() {
def result = new ByteArrayOutputStream()
exec {
standardOutput = result
commandLine('git', 'rev-parse', '--verify', 'HEAD')
}
return result.toString().trim()
}
def readVersionMapping(File propertiesFile, String swtPluginId) {
if (!propertiesFile.exists()) {
return [:]
}
Properties properties = new Properties()
propertiesFile.withInputStream {
properties.load(it)
}
Map result = [:]
properties.each { k, v ->
if (k == '$swtPluginId') {
result[swtPluginId] = v
} else {
result[(k)] = v
}
}
return result
}