-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.gradle
More file actions
430 lines (374 loc) · 11.7 KB
/
Copy pathbuild.gradle
File metadata and controls
430 lines (374 loc) · 11.7 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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.sonatype.plexus:plexus-sec-dispatcher:1.4'
classpath 'org.codehaus.plexus:plexus-container-default:2.1.1'
classpath 'org.sonatype.plexus:plexus-cipher:1.7'
}
}
import org.gradle.internal.os.OperatingSystem
import org.apache.tools.ant.filters.ReplaceTokens
import groovy.xml.XmlParser
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher
plugins {
id 'java-library'
id 'eclipse'
id 'maven-publish'
id 'jacoco'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'pl.allegro.tech.build.axion-release' version '1.21.1'
}
group = 'com.nordstrom.ui-tools'
description = 'Selenium Foundation'
ext.profile = project.findProperty('profile') ?: 'selenium4'
assert ['selenium3', 'selenium4'].contains(profile)
/* Repositories */
repositories {
mavenLocal()
mavenCentral()
maven { url "${projectDir}/repo" }
}
def getMavenServer(String serverId) {
def settingsFile = new File(System.getProperty("user.home"), ".m2/settings.xml")
if (!settingsFile.exists()) return null
def settings = new XmlParser().parse(settingsFile)
def server = settings.servers.server.find { it.id.text() == serverId }
if (server) {
def dispatcher = new DefaultSecDispatcher()
dispatcher._cipher = new DefaultPlexusCipher()
def securityFile = new File(System.getProperty("user.home"), ".m2/settings-security.xml")
System.setProperty("settings.security", securityFile.absolutePath)
def decrypt = { String val ->
if (val == null) return null
return dispatcher._cipher.isEncryptedString(val) ? dispatcher.decrypt(val) : val
}
return [
username: server.username?.text(),
password: decrypt(server.password?.text()),
passphrase: decrypt(server.passphrase?.text())
]
}
return null
}
scmVersion {
branchVersionCreator.putAll([
'.*': { version, position -> version }
])
repository {
def githubNode = getMavenServer('github')
if (githubNode) {
customUsername.set(githubNode.username)
customPassword.set(githubNode.password)
}
}
}
/* Version logic */
def resolvedVersion = project.hasProperty('artifactVersion')
? project.property('artifactVersion').toString()
: scmVersion.version
def verBits = resolvedVersion.split('-')
def seleniumApi = "s${profile.charAt(8)}"
ext.baseVersion = verBits[0]
ext.isSnapshot = !resolvedVersion.matches('\\d+\\.\\d+\\.\\d+')
ext.archiveVer = "${baseVersion}-${seleniumApi}" + (isSnapshot ? '-SNAPSHOT' : '')
ext.archiveBase = "${rootProject.name}-${archiveVer}"
version = archiveVer
task updateReadme {
def base = project.ext.baseVersion
doLast {
def version = resolvedVersion
if (version.endsWith('-SNAPSHOT')) return
ant.replaceregexp(file: 'README.md',
match: /\d+\.\d+\.\d+-s3/,
replace: "${base}-s3",
flags: 'g')
ant.replaceregexp(file: 'README.md',
match: /\d+\.\d+\.\d+-s4/,
replace: "${base}-s4",
flags: 'g')
}
}
task checkSincePlaceholders {
description = 'Fails non-SNAPSHOT release builds if any [next-major] placeholders remain unreplaced in source.'
doLast {
def version = project.version.toString()
if (version.endsWith('-SNAPSHOT')) return
def violations = []
def sourceRoots = ['src/main/java', 'src/selenium3/java', 'src/selenium4/java']
.collect { project.file(it) }
.findAll { it.exists() }
sourceRoots.each { root ->
fileTree(root).matching {
include '**/*.java'
}.each { file ->
file.readLines().eachWithIndex { line, idx ->
if (line.contains('[next-major]')) {
violations << "${file.path}:${idx + 1}"
}
}
}
}
if (violations) {
throw new GradleException(
"\n*** RELEASE BUILD FAILED ***\n"
+ "Unreplaced [next-major] placeholders found in release ${ext.baseVersion}:\n"
+ violations.join('\n')
+ "\nEnsure all placeholders were replaced before publishing.\n")
}
}
}
task updateSinceAnnotations {
description = 'Replaces [next-major] placeholders in source with the current project version.'
def base = project.ext.baseVersion
doLast {
def version = project.version.toString()
if (version.endsWith('-SNAPSHOT')) return
def sinceVersion = base
def sourceRoots = ['src/main/java', 'src/selenium3/java', 'src/selenium4/java']
.collect { project.file(it) }
.findAll { it.exists() }
sourceRoots.each { root ->
fileTree(root).matching {
include '**/*.java'
}.each { file ->
ant.replaceregexp(
file: file,
match: '\\[next-major\\]',
replace: sinceVersion,
flags: 'g'
)
}
}
}
}
checkSincePlaceholders.mustRunAfter(updateSinceAnnotations)
checkSincePlaceholders.mustRunAfter(updateReadme)
publish.dependsOn(checkSincePlaceholders)
compileJava.dependsOn(updateSinceAnnotations, updateReadme, checkSincePlaceholders)
apply from: "${profile}Deps.gradle"
if (project.hasProperty('browsers')) {
project.browsers.split(',').each { browser ->
browser = browser.trim()
if (browser) {
apply from: "${browser}Deps.gradle"
}
}
}
/* personality injection */
if (project.hasProperty('personality')) {
System.setProperty('injected.selenium.browser.name', personality)
if ([".chrome", ".safari"].any { personality.endsWith(it) }) {
System.setProperty('injected.selenium.context.platform', 'web-app')
System.setProperty('injected.selenium.grid.examples', 'true')
}
}
java {
withJavadocJar()
withSourcesJar()
}
/* Clean */
tasks.named('clean') {
delete 'logs', 'target', buildRoot
delete fileTree('.') {
include 'hubConfig*.json'
include 'nodeConfig*.json'
}
}
/* JaCoCo */
jacoco {
toolVersion = '0.8.13'
reportsDirectory = layout.buildDirectory.dir("jacoco")
}
jacocoTestReport {
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
/* Shared libs dir */
def libsDirProvider = layout.buildDirectory.dir("libs")
/* Main JAR */
tasks.named('jar', Jar) {
group = 'Build'
description = "Assembles a jar archive containing the '${profile}' classes, POM and Maven properties."
def destPath = "META-INF/maven/${project.group}/${rootProject.name}"
def timestamp = System.currentTimeMillis().toString()
from('.') {
include 'pom.xml'
into destPath
filter ReplaceTokens, tokens: [
projectVersion : archiveVer,
projectTimestamp: timestamp,
seleniumApi : seleniumApi
]
}
from('.') {
include 'pom.properties'
into destPath
filter ReplaceTokens, tokens: [
projectVersion : archiveVer,
projectGroupId : project.group,
projectArtifactId: rootProject.name
]
}
archiveFileName.set("${archiveBase}.jar")
destinationDirectory.set(libsDirProvider)
}
/* Sources JAR */
tasks.named('sourcesJar', Jar) {
group = 'Build'
archiveClassifier.set('sources')
archiveFileName.set("${archiveBase}-sources.jar")
destinationDirectory.set(libsDirProvider)
}
/* Javadoc JAR */
tasks.named('javadocJar', Jar) {
group = 'Build'
archiveClassifier.set('javadoc')
archiveFileName.set("${archiveBase}-javadoc.jar")
destinationDirectory.set(libsDirProvider)
}
/* Test system property propagation */
tasks.withType(Test).configureEach {
systemProperties.putAll(
System.properties.findAll { k, _ ->
k.endsWith('.binary.path') ||
['injected.', 'selenium.', 'appium.', 'testng.', 'junit.']
.any { k.startsWith(it) }
}.collectEntries { k, v ->
if (OperatingSystem.current().isWindows() && k.endsWith('selenium.browser.caps')) {
[(k): v.replace('"', '\\\"')]
} else {
[(k): v]
}
}
)
reports.html.outputLocation.set(
layout.buildDirectory.dir("reports/${name}")
)
}
/* TestNG */
tasks.register('testNG', Test) {
dependsOn tasks.named('jar')
useTestNG()
testLogging.showStandardStreams = true
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
if (project.findProperty('debugTestNG') == 'true') {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
maxParallelForks = 1
forkEvery = 0
}
}
/* JUnit */
tasks.named('test', Test) {
dependsOn tasks.named('testNG')
testLogging.showStandardStreams = true
if (project.findProperty('debugJUnit') == 'true') {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006'
maxParallelForks = 1
forkEvery = 0
}
doFirst {
jvmArgs "-javaagent:${classpath.find { it.name.contains('junit-foundation') }}"
}
}
/* Publishing */
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'Selenium Foundation'
groupId = project.group
artifactId = rootProject.name
version = archiveVer
packaging = 'jar'
description = 'Selenium Foundation is an automation framework designed to extend and enhance the capabilities provided by Selenium (WebDriver).'
url = 'https://github.com/sbabcoc/Selenium-Foundation'
scm {
connection = 'scm:git:https://github.com/sbabcoc/Selenium-Foundation.git'
developerConnection = 'scm:git:https://github.com/sbabcoc/Selenium-Foundation.git'
url = 'https://github.com/sbabcoc/Selenium-Foundation/tree/master'
tag = 'HEAD'
}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'scoba'
name = 'Scott Babcock'
email = 'scoba@hotmail.com'
organization = 'Nordstrom'
organizationUrl = 'https://shop.nordstrom.com'
}
}
}
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
}
/* Signing */
signing {
if (project.hasProperty('signing.keyId')) {
def keyId = project.getProperty('signing.keyId')
def gpgNode = getMavenServer(keyId)
def secret = gpgNode?.passphrase
if (secret) {
useGpgCmd()
project.ext.set("signing.gnupg.passphrase", secret)
project.ext.set("signing.gnupg.arguments", "--batch,--pinentry-mode,loopback")
}
}
sign publishing.publications.mavenJava
}
/* Install alias */
tasks.register('install') {
dependsOn tasks.named('publishToMavenLocal')
group = tasks.named('publishToMavenLocal').get().group
description = "[alias] publish to Maven Local"
}
/* Nexus publishing */
nexusPublishing {
packageGroup = 'com.nordstrom'
repositories {
ossrh {
def ossrhNode = getMavenServer('ossrh')
username = ossrhNode?.username
password = ossrhNode?.password
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/content/repositories/snapshots/"))
if (project.hasProperty('ossrhStagingProfileId')) {
stagingProfileId = ossrhStagingProfileId
}
}
}
}
/* Dependencies */
dependencies {
api platform("com.nordstrom.ui-tools:selenium-bom-${seleniumApi}:${baseVersion}${isSnapshot ? '-SNAPSHOT' : ''}")
api 'com.nordstrom.tools:java-utils'
api 'com.nordstrom.tools:settings'
api 'com.nordstrom.tools:junit-foundation'
api('com.github.sbabcoc:logback-testng') {
exclude group: 'org.testng', module: 'testng'
}
api 'org.hamcrest:hamcrest-core'
api 'org.yaml:snakeyaml'
}