-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
154 lines (128 loc) · 3.75 KB
/
build.ps1
File metadata and controls
154 lines (128 loc) · 3.75 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
<#
.SYNOPSIS
Build script for Java Chess Application (Windows PowerShell)
.DESCRIPTION
Provides compilation, execution, and cleanup functionality for the Chess project
on Windows systems without requiring GNU Make.
.PARAMETER Action
The build action to perform: compile, run, test, clean, help
.EXAMPLE
.\build.ps1 compile
.\build.ps1 run
.\build.ps1 test
.\build.ps1 clean
#>
param(
[Parameter(Position=0)]
[ValidateSet("compile", "run", "test", "clean", "help", "all")]
[string]$Action = "help"
)
# Configuration
$SrcDir = "src"
$OutDir = "out"
$LibDir = "lib"
$JsonLib = Join-Path $LibDir "json-simple-1.1.1.jar"
$MainClass = "main_package.Main"
$TestClass = "Testare.ChessTestRunner"
$JavacFlags = @("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation")
# Verify Java installation
function Test-JavaInstalled {
try {
$null = & javac -version 2>&1
return $true
} catch {
Write-Error "ERROR: 'javac' not found. Please install JDK 8 or higher."
return $false
}
}
# Compile all Java sources
function Invoke-Compile {
Write-Host "[COMPILE] Building Java sources..." -ForegroundColor Cyan
if (-not (Test-Path $JsonLib)) {
Write-Error "ERROR: Missing dependency: $JsonLib"
exit 1
}
# Create output directory
if (-not (Test-Path $OutDir)) {
New-Item -ItemType Directory -Path $OutDir | Out-Null
}
# Find all Java files
$sources = Get-ChildItem -Path $SrcDir -Recurse -Filter "*.java" | Select-Object -ExpandProperty FullName
if ($sources.Count -eq 0) {
Write-Error "ERROR: No .java files found in $SrcDir"
exit 1
}
Write-Host " Found $($sources.Count) source files"
# Compile
$compileArgs = $JavacFlags + @(
"-d", $OutDir,
"-cp", $JsonLib,
"-sourcepath", $SrcDir
) + $sources
& javac @compileArgs
if ($LASTEXITCODE -eq 0) {
Write-Host "[COMPILE] Done. Output: $OutDir/" -ForegroundColor Green
} else {
Write-Error "[COMPILE] Compilation failed!"
exit 1
}
}
# Run the GUI application
function Invoke-Run {
Invoke-Compile
Write-Host "[RUN] Starting Chess GUI..." -ForegroundColor Cyan
$classpath = "$OutDir;$JsonLib"
& java -cp $classpath $MainClass
}
# Run the test harness
function Invoke-Test {
Invoke-Compile
Write-Host "[TEST] Starting Console Test Runner..." -ForegroundColor Cyan
$classpath = "$OutDir;$JsonLib"
& java -cp $classpath $TestClass
}
# Clean build artifacts
function Invoke-Clean {
Write-Host "[CLEAN] Removing compiled artifacts..." -ForegroundColor Cyan
if (Test-Path $OutDir) {
Remove-Item -Recurse -Force $OutDir
Write-Host "[CLEAN] Done." -ForegroundColor Green
} else {
Write-Host "[CLEAN] Nothing to clean." -ForegroundColor Yellow
}
}
# Display help
function Show-Help {
Write-Host @"
==========================================
Chess Application - Build Script
==========================================
Usage: .\build.ps1 <action>
Actions:
compile Compile all Java sources to out/
run Compile and launch the GUI application
test Compile and run the console test harness
clean Remove compiled artifacts
help Show this message
Examples:
.\build.ps1 compile
.\build.ps1 run
.\build.ps1 test
.\build.ps1 clean
Requirements:
- JDK 8 or higher (javac, java in PATH)
"@ -ForegroundColor White
}
# Main execution
if (-not (Test-JavaInstalled)) {
exit 1
}
switch ($Action) {
"compile" { Invoke-Compile }
"all" { Invoke-Compile }
"run" { Invoke-Run }
"test" { Invoke-Test }
"clean" { Invoke-Clean }
"help" { Show-Help }
default { Show-Help }
}