-
Notifications
You must be signed in to change notification settings - Fork 62
/
build.gradle.sample
266 lines (225 loc) · 8.59 KB
/
build.gradle.sample
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
import java.text.SimpleDateFormat
buildscript {
ext {
gradleVersion = '8.12'
teswizVersion = '1.0.12'
}
repositories {
mavenLocal()
}
}
plugins {
id "java"
id "idea"
id "maven-publish"
}
version '0.0.1'
project.ext.log4jProperties = "src/test/resources/log4j2.properties"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenLocal()
flatDir {
dirs 'libs'
}
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
// Define the libs directory in the project root
ext.libsDir = file("$projectDir/libs")
def downloadDependency(String name, String type, Map<String, String> params) {
if (!libsDir.exists()) {
libsDir.mkdirs()
}
println "Download dependency: ${name} from ${type}"
def jarFile = new File(libsDir, "${name}-${params.version}.jar")
if (jarFile.exists()) {
println "\tDependency $name already exists at: $jarFile. No need to redownload it"
return jarFile
}
def jarUrl
if (type == "github") {
println "\tFetching latest GitHub release information for ${params.repoUrl}..."
def jsonResponse = new URL(params.repoUrl).text
def jsonSlurper = new groovy.json.JsonSlurper()
def releaseInfo = jsonSlurper.parseText(jsonResponse)
// Ensure assets field is a list and each asset is a Map
def assets = releaseInfo.assets
if (!(assets instanceof List)) {
throw new GradleException("Assets field is not a list: $assets")
}
def jarAsset = releaseInfo.assets.find { it.name.matches(/${name}-\d+\.\d+\.\d+\.jar/) }
if (!jarAsset) {
throw new GradleException("No ${name} JAR file found in the latest GitHub release.")
}
jarUrl = jarAsset.browser_download_url
} else if (type == "jitpack") {
jarUrl = "https://jitpack.io/${params.group.replace('.', '/')}/${params.artifact}/${params.version}/${params.artifact}-${params.version}${params.fileNameSuffix}.jar"
} else {
throw new GradleException("Unknown type: $type")
}
println "\tDownloading ${name} JAR from ${jarUrl}"
def downloadCommand
if (System.getProperty("os.name").toLowerCase().contains("win")) {
downloadCommand = ["cmd", "/c", "curl", "-o", jarFile.absolutePath, jarUrl]
} else {
downloadCommand = ["wget", "-O", jarFile.absolutePath, jarUrl]
}
// Explicitly convert all elements to String
downloadCommand = downloadCommand.collect { it.toString() }
println "\tDownloading using command: ${downloadCommand}"
def process = new ProcessBuilder(downloadCommand).redirectErrorStream(true).start()
process.inputStream.eachLine { println it }
process.waitFor()
if (process.exitValue() != 0) {
throw new GradleException("Failed to download ${name} JAR.")
}
println "${name} JAR downloaded to $jarFile"
return jarFile
}
// Define a custom task to download dependencies
task downloadDependencies {
doLast {
println "Downloading required dependencies..."
def dependencies = [
[
name : "teswiz",
type : "github",
params: [
repoUrl: "https://api.github.com/repos/znsio/teswiz/releases/latest",
version : "$project.teswizVersion" ]
]
]
println "\n---------------------------------------------"
dependencies.each { dep ->
println "Processing dependency: ${dep.name}"
downloadDependency(dep.name, dep.type, dep.params)
println "\n---------------------------------------------"
}
}
}
// Ensure dependencies are downloaded before compiling
tasks.compileJava {
dependsOn downloadDependencies
}
// Ensure dependencies are downloaded before compiling
tasks.compileJava {
dependsOn downloadDependencies
options.encoding = "UTF-8"
}
dependencies {
implementation fileTree(dir: "$project.projectDir/libs", include: ['*.jar'])
}
static def getCurrentDatestamp() {
Date today = new Date()
SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy")
return df.format(today)
}
static def getMonth() {
Date today = new Date()
SimpleDateFormat df = new SimpleDateFormat("MMM-yyyy")
return df.format(today)
}
static def getCurrentTimestamp() {
Date today = new Date()
SimpleDateFormat df = new SimpleDateFormat("HH-mm-ss")
return df.format(today)
}
project.ext.logDir = "./target/" + getMonth() + "/" + getCurrentDatestamp() + "/" + getCurrentTimestamp()
def copyRpPropertiesIfMissing() {
def rpFile = file('src/test/resources/reportportal.properties')
def rpTemplateFile = file('src/test/resources/reportportal.properties.template')
if (!rpFile.exists() && rpTemplateFile.exists()) {
println "Copying $rpTemplateFile to $rpFile"
rpFile.text = rpTemplateFile.text
} else if (!rpTemplateFile.exists()) {
println "$rpTemplateFile does not exist. Please create it."
} else {
println "$rpFile already exists."
}
System.setProperty("reportportal.properties.file", rpFile.absolutePath)
}
task copyRpPropertiesIfMissing {
doLast {
copyRpPropertiesIfMissing()
}
}
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':build') || taskGraph.hasTask(':run')) {
copyRpPropertiesIfMissing()
}
}
tasks.register('run', JavaExec) {
doFirst {
println "Using LOG_DIR: ${project.logDir}"
System.setProperty "LOG_DIR", "${project.logDir}"
environment "APPLITOOLS_LOG_DIR", "${project.logDir}/applitools_logs"
def configFile = System.getenv("CONFIG")
if (null == configFile || !file(configFile).exists()) {
println("CONFIG file not provided, or does not exist")
println("Run the test by providing the CONFIG file not provided, or does not exist")
assert file(configFile).exists()
}
def hostname = InetAddress.getLocalHost().getHostName()
println "Hostname: $hostname"
def ipAddress = InetAddress.getAllByName(hostname)
.find { it.hostAddress.startsWith("192") || it.hostAddress.startsWith("172") || it.hostAddress.startsWith("10") }
?.hostAddress
println "IP Address of this machine: $ipAddress"
if (null == ipAddress) {
println "Unable to get local IP address. NOT updating BASE_URL and REMOTE_WEBDRIVER_GRID_HOST_NAME"
} else {
// println "Updating BASE_URL ('http://$ipAddress:3000') and REMOTE_WEBDRIVER_GRID_HOST_NAME ('$ipAddress')"
// environment "BASE_URL", "http://$ipAddress:3000"
environment "REMOTE_WEBDRIVER_GRID_HOST_NAME", "$ipAddress"
}
// You can also specify which config file to use based on the value of RUN_IN_CI as shown below
//
// def isRunInCI = Boolean.parseBoolean(System.getenv("RUN_IN_CI"))
// println "isRunningInCI: $isRunInCI"
// def configFile = isRunInCI
// ? "./configs/theapp/theapp_pcloudy_config.properties"
// : "./configs/theapp/theapp_local_android_config.properties"
// configFile = System.getenv("CONFIG") ? System.getenv("CONFIG") : configFile
systemProperties = System.properties as Map<String, ?>
def runnerArgs = [
"${configFile}",
"com/znsio/teswiz/steps",
"./src/test/resources/com/znsio/teswiz/features"
]
args = runnerArgs
println("Debug mode: " + System.getProperty('debug', 'false'))
// attach debugger
// example: ./gradlew run -Ddebug=true
if (System.getProperty('debug', 'false') == 'true') {
println("In debug mode")
jvmArgs '-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,' +
'address=*:5005'
}
}
mainClass = "com.znsio.teswiz.runner.Runner"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
}
wrapper {
gradleVersion = project.gradleVersion // version from gradle.properties
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += ['--release', '17']
}
tasks.withType(JavaExec).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}