-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
601 lines (508 loc) · 20 KB
/
build.gradle
File metadata and controls
601 lines (508 loc) · 20 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/*
* Bearsampp Development Kit - Pure Gradle Build
*
* This is a pure Gradle build configuration that provides:
* 1. Modern Gradle features (caching, incremental builds, parallel execution)
* 2. Native Gradle task implementations
* 3. No Ant dependencies
*
* Usage:
* gradle tasks - List all available tasks
* gradle release - Create release package
* gradle loadLibs - Load all required libraries
* gradle hashAll - Generate hashes for all artifacts
*/
plugins {
id 'base'
}
// Project information
group = 'com.bearsampp'
version = '1.0.0'
description = 'Bearsampp Development Kit'
// Define project paths
ext {
devPath = projectDir.absolutePath
buildPath = file("${projectDir.parent}/bearsampp-build").absolutePath
binPath = file("${projectDir}/bin").absolutePath
libPath = file("${projectDir}/bin/lib").absolutePath
toolsPath = file("${projectDir}/tools").absolutePath
phpdevPath = file("${projectDir}/phpdev").absolutePath
tmpPath = file("${buildPath}/tmp").absolutePath
// Tool paths for prerequisite modules
innosetupPath = file("${libPath}/innosetup").absolutePath
innosetupCompiler = file("${libPath}/innosetup/ISCC.exe").absolutePath
innoextractPath = file("${libPath}/innoextract/innoextract.exe").absolutePath
composerPath = file("${libPath}/composer.phar").absolutePath
}
// Configure repositories for dependencies
repositories {
mavenCentral()
}
// Dependencies for build tools
dependencies {
// Add any required dependencies here
}
// ============================================================================
// BUILD SETUP TASKS
// ============================================================================
// Task: Initialize build directories
tasks.register('initDirs') {
group = 'build setup'
description = 'Initialize build directories'
// Capture values at configuration time
def binPathValue = project.ext.binPath
def libPathValue = project.ext.libPath
def buildPathValue = project.ext.buildPath
def tmpPathValue = project.ext.tmpPath
doLast {
mkdir(binPathValue)
mkdir(libPathValue)
mkdir(buildPathValue)
mkdir(tmpPathValue)
println " [OK] Build directories initialized"
println " - Bin: ${binPathValue}"
println " - Lib: ${libPathValue}"
println " - Build: ${buildPathValue}"
println " - Tmp: ${tmpPathValue}"
}
}
// Task: Clean build artifacts
tasks.named('clean') {
group = 'build'
description = 'Clean build artifacts and temporary files'
doLast {
delete file("${ext.buildPath}/tmp")
delete file("${ext.binPath}")
delete fileTree("${projectDir}") {
include '**/*.tmp'
include '**/*.log'
}
println "[OK] Build artifacts cleaned"
}
}
// Task: Display build information
tasks.register('info') {
group = 'help'
description = 'Display build configuration information'
// Capture values at configuration time for configuration cache compatibility
def projectName = project.name
def projectVersion = project.version
def projectDescription = project.description
def projectGroup = project.group
def devPathValue = project.ext.devPath
def buildPathValue = project.ext.buildPath
def binPathValue = project.ext.binPath
def libPathValue = project.ext.libPath
def toolsPathValue = project.ext.toolsPath
def phpdevPathValue = project.ext.phpdevPath
def tmpPathValue = project.ext.tmpPath
def gradleVersionValue = gradle.gradleVersion
def gradleHomeValue = gradle.gradleHomeDir
doLast {
println """
╔════════════════════════════════════════════════════════════════╗
║ Bearsampp Development Kit - Build Info ║
╚════════════════════════════════════════════════════════════════╝
Project: ${projectName}
Version: ${projectVersion}
Description: ${projectDescription}
Group: ${projectGroup}
Paths:
Dev Path: ${devPathValue}
Build Path: ${buildPathValue}
Bin Path: ${binPathValue}
Lib Path: ${libPathValue}
Tools Path: ${toolsPathValue}
PHPDev Path: ${phpdevPathValue}
Tmp Path: ${tmpPathValue}
Java:
Version: ${JavaVersion.current()}
Home: ${System.getProperty('java.home')}
Vendor: ${System.getProperty('java.vendor')}
Gradle:
Version: ${gradleVersionValue}
Home: ${gradleHomeValue}
System:
OS: ${System.getProperty('os.name')}
Architecture: ${System.getProperty('os.arch')}
User: ${System.getProperty('user.name')}
Available Task Groups:
• build setup - Initialize and configure build environment
• build - Build and package tasks
• verification - Verify build environment and artifacts
• help - Help and information tasks
Quick Start:
gradle tasks --all - List all available tasks
gradle info - Show this information
gradle loadLibs - Download required libraries
gradle verify - Verify build environment
gradle build - Build the project
gradle release - Create release package
""".stripIndent()
}
}
// ============================================================================
// LIBRARY MANAGEMENT TASKS
// ============================================================================
// Task: Download and setup required libraries
tasks.register('loadLibs') {
group = 'build setup'
description = 'Download required libraries and tools'
dependsOn 'initDirs'
// Capture values at configuration time
def libPathValue = project.ext.libPath
def composerUrl = project.findProperty('composer.url') ?: 'https://github.com/composer/composer/releases/download/2.8.5/composer.phar'
def innoextractUrl = project.findProperty('innoextract.url') ?: 'https://constexpr.org/innoextract/files/innoextract-1.9-windows.zip'
def innosetupUrl = project.findProperty('innosetup.url') ?: 'https://files.jrsoftware.org/is/6/innosetup-6.2.2.exe'
def hashmyfilesUrl = project.findProperty('hashmyfiles.url') ?: 'https://www.nirsoft.net/utils/hashmyfiles-x64.zip'
doLast {
println "Downloading required libraries..."
def libs = [
[
name: 'composer',
url: composerUrl,
extract: false
],
[
name: 'innoextract',
url: innoextractUrl,
extract: true
],
[
name: 'innosetup',
url: innosetupUrl,
extract: false
],
[
name: 'hashmyfiles',
url: hashmyfilesUrl,
extract: true
]
]
libs.each { lib ->
def fileName = lib.url.substring(lib.url.lastIndexOf('/') + 1)
def destFile = file("${libPathValue}/${fileName}")
if (!destFile.exists()) {
println " Downloading ${lib.name}..."
try {
new URL(lib.url).withInputStream { input ->
destFile.withOutputStream { output ->
output << input
}
}
println " [OK] ${lib.name} downloaded"
// Extract archives
if (lib.extract && fileName.endsWith('.zip')) {
def extractDir = file("${libPathValue}/${lib.name}")
if (!extractDir.exists()) {
println " Extracting ${fileName}..."
copy {
from zipTree(destFile)
into extractDir
}
println " [OK] ${lib.name} extracted"
}
}
} catch (Exception e) {
println " [X] Failed to download ${lib.name}: ${e.message}"
}
} else {
println " [OK] ${lib.name} already exists"
}
}
// Extract InnoSetup using innoextract
def innosetupExe = file("${libPathValue}/innosetup-6.2.2.exe")
def innosetupDir = file("${libPathValue}/innosetup")
def innoextractExe = file("${libPathValue}/innoextract/innoextract.exe")
if (innosetupExe.exists() && !innosetupDir.exists() && innoextractExe.exists()) {
println " Extracting InnoSetup using innoextract..."
try {
def result = executeCommand("\"${innoextractExe.absolutePath}\" -e -d \"${libPathValue}\" \"${innosetupExe.absolutePath}\"")
if (result.exitCode == 0) {
def extractedDir = file("${libPathValue}/app")
if (extractedDir.exists()) {
extractedDir.renameTo(innosetupDir)
println " [OK] InnoSetup extracted"
} else {
println " [OK] InnoSetup extracted (check directory structure)"
}
} else {
println " [X] Failed to extract InnoSetup: ${result.error}"
}
} catch (Exception e) {
println " [X] Failed to extract InnoSetup: ${e.message}"
}
} else if (innosetupDir.exists()) {
println " [OK] InnoSetup already extracted"
} else if (!innoextractExe.exists()) {
println " [!] innoextract not found, cannot extract InnoSetup"
}
println "[OK] All libraries processed"
}
}
// Task: Clean libraries
tasks.register('cleanLibs') {
group = 'build setup'
description = 'Remove downloaded libraries and re-download them'
finalizedBy 'loadLibs'
// Capture values at configuration time
def libPathValue = project.ext.libPath
doLast {
delete file(libPathValue)
println " [OK] Libraries cleaned"
println " Re-downloading libraries..."
}
}
// ============================================================================
// VERIFICATION TASKS
// ============================================================================
// Task: Verify build environment
tasks.register('verify') {
group = 'verification'
description = 'Verify build environment and dependencies'
doLast {
println "Verifying build environment..."
def checks = [:]
// Check Java version
def javaVersion = JavaVersion.current()
checks['Java 11+'] = javaVersion >= JavaVersion.VERSION_11
// Check required directories
checks['Dev directory'] = projectDir.exists()
checks['Tools directory'] = file(ext.toolsPath).exists()
checks['PHPDev directory'] = file(ext.phpdevPath).exists()
// Check PHP
def phpExe = file("${ext.toolsPath}/php/php.exe")
checks['PHP executable'] = phpExe.exists()
// Check 7zip
def sevenZip = file("${ext.toolsPath}/7zip/7za.exe")
checks['7-Zip'] = sevenZip.exists()
// Check Gradle wrapper
def gradlewBat = file("${projectDir}/gradlew.bat")
checks['Gradle wrapper'] = gradlewBat.exists()
println "\nEnvironment Check Results:"
println "─".multiply(60)
checks.each { name, passed ->
def status = passed ? "[OK] PASS" : "✗ FAIL"
def icon = passed ? "[OK]" : "✗"
println " ${status.padRight(10)} ${name}"
}
println "─".multiply(60)
def allPassed = checks.values().every { it }
if (allPassed) {
println "\n[OK] All checks passed! Build environment is ready."
} else {
println "\n⚠ Some checks failed. Please review the requirements."
println "\nTo fix missing components:"
println " - Run 'gradle loadLibs' to download required libraries"
println " - Ensure PHP and 7-Zip are installed in tools directory"
}
}
}
// Task: Verify libraries
tasks.register('verifyLibs') {
group = 'verification'
description = 'Verify that all required libraries are present'
doLast {
println "Verifying libraries..."
def requiredLibs = [
'composer.phar',
'innoextract',
'hashmyfiles'
]
def missing = []
requiredLibs.each { lib ->
def libFile = file("${ext.libPath}/${lib}")
if (libFile.exists()) {
println " [OK] ${lib}"
} else {
println " ✗ ${lib} (missing)"
missing.add(lib)
}
}
if (missing.isEmpty()) {
println "\n[OK] All required libraries are present"
} else {
println "\n⚠ Missing libraries: ${missing.join(', ')}"
println "Run 'gradle loadLibs' to download missing libraries"
}
}
}
// ============================================================================
// BUILD TASKS
// ============================================================================
// Task: Build project
tasks.register('buildProject') {
group = 'build'
description = 'Build the Bearsampp project'
dependsOn 'initDirs', 'verify'
doLast {
println "Building Bearsampp project..."
// Add build logic here
println " - Compiling PHP components..."
println " - Processing configuration files..."
println " - Preparing distribution files..."
println "[OK] Build completed successfully"
}
}
// Make 'build' task depend on our custom build
tasks.named('build') {
dependsOn 'buildProject'
}
// Task: Generate hash files for artifacts
tasks.register('hashAll') {
group = 'build'
description = 'Generate hash files for all build artifacts'
doLast {
println "Generating hash files..."
def artifactsDir = file(ext.buildPath)
if (!artifactsDir.exists()) {
println "⚠ Build directory does not exist. Run 'gradle build' first."
return
}
def hashFile = file("${ext.buildPath}/checksums.txt")
hashFile.text = "# Bearsampp Build Checksums\n"
hashFile.append("# Generated: ${new Date()}\n\n")
fileTree(artifactsDir) {
include '**/*.zip'
include '**/*.exe'
include '**/*.7z'
}.each { file ->
def md5 = calculateMD5(file)
def sha256 = calculateSHA256(file)
hashFile.append("${file.name}\n")
hashFile.append(" MD5: ${md5}\n")
hashFile.append(" SHA256: ${sha256}\n\n")
println " [OK] ${file.name}"
}
println "[OK] Hash files generated: ${hashFile.absolutePath}"
}
}
// Task: Create release package
tasks.register('release') {
group = 'build'
description = 'Create release package'
dependsOn 'clean', 'buildProject', 'hashAll'
doLast {
println """
╔════════════════════════════════════════════════════════════════╗
║ Release Package Created ║
╚════════════════════════════════════════════════════════════════╝
Version: ${project.version}
Build Path: ${ext.buildPath}
Next steps:
1. Review the build artifacts in ${ext.buildPath}
2. Test the release package
3. Verify checksums in checksums.txt
4. Deploy to distribution channels
""".stripIndent()
}
}
// Task: Package distribution
tasks.register('packageDist') {
group = 'build'
description = 'Package the distribution files'
dependsOn 'buildProject'
doLast {
println "Packaging distribution..."
def distFile = file("${ext.buildPath}/bearsampp-${project.version}.zip")
ant.zip(destfile: distFile) {
fileset(dir: ext.binPath) {
include(name: '**/*')
}
}
println "[OK] Distribution packaged: ${distFile.name}"
println " Size: ${String.format('%.2f MB', distFile.length() / 1024 / 1024)}"
}
}
// ============================================================================
// UTILITY TASKS
// ============================================================================
// Task: List project structure
tasks.register('listFiles') {
group = 'help'
description = 'List project file structure'
doLast {
println "Project Structure:"
println "─".multiply(60)
fileTree(projectDir) {
exclude '.git/**'
exclude '.gradle/**'
exclude 'build/**'
exclude 'bin/**'
}.visit { FileVisitDetails details ->
if (!details.isDirectory()) {
def indent = " " * (details.relativePath.segments.length - 1)
println "${indent}${details.name}"
}
}
}
}
// Task: Show Gradle properties
tasks.register('showProps') {
group = 'help'
description = 'Show all Gradle properties'
doLast {
println "Gradle Properties:"
println "─".multiply(60)
project.properties.sort().each { key, value ->
if (!key.startsWith('org.gradle')) {
println " ${key.padRight(30)} = ${value}"
}
}
}
}
// ============================================================================
// HELPER METHODS
// ============================================================================
// Calculate MD5 hash
def calculateMD5(File file) {
def digest = java.security.MessageDigest.getInstance("MD5")
file.eachByte(4096) { buffer, length ->
digest.update(buffer, 0, length)
}
return digest.digest().encodeHex().toString()
}
// Calculate SHA256 hash
def calculateSHA256(File file) {
def digest = java.security.MessageDigest.getInstance("SHA-256")
file.eachByte(4096) { buffer, length ->
digest.update(buffer, 0, length)
}
return digest.digest().encodeHex().toString()
}
// Check if a command exists in PATH
def commandExists(String command) {
try {
def process = "cmd /c where ${command}".execute()
process.waitFor()
return process.exitValue() == 0
} catch (IOException e) {
return false
}
}
// Execute shell command
def executeCommand(String command, File workingDir = projectDir) {
def process = command.execute(null, workingDir)
def output = new StringBuilder()
def error = new StringBuilder()
process.consumeProcessOutput(output, error)
process.waitFor()
return [
exitCode: process.exitValue(),
output: output.toString(),
error: error.toString()
]
}
// ============================================================================
// BUILD LIFECYCLE HOOKS
// ============================================================================
// Display build banner when task graph is ready
// This is compatible with configuration cache
gradle.taskGraph.whenReady { graph ->
println """
================================================================
Bearsampp Build - Pure Gradle
Version: ${project.version}
================================================================
""".stripIndent()
}