-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.bat
115 lines (111 loc) · 3.37 KB
/
build.bat
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
@echo off
setlocal EnableDelayedExpansion
echo.
:: Modify these parameters when necessary
set "WebCTRL=C:\WebCTRL9.0"
set "mainClass=TerminalUnitTest"
set "package=aces\webctrl\scripts\terminalunits\"
set "jdk=%JAVA_HOME%\bin"
set "release=11"
if not exist "%~dp0lib" mkdir "%~dp0lib" >nul 2>nul
call :collect "%~dp0DEPENDENCIES" "%~dp0lib"
if %ERRORLEVEL% NEQ 0 (
echo Failed to collect necessary dependencies.
echo Press any key to exit.
pause >nul
exit
)
set "classes=%~dp0classes"
if exist "%classes%" rmdir /S /Q "%classes%" >nul
if exist "%~dp0%mainClass%.jar" del /F "%~dp0%mainClass%.jar" >nul
mkdir "%classes%" >nul
echo Compiling...
"%jdk%\javac.exe" --release %release% -d "%classes%" --class-path "%~dp0src;%~dp0lib\*" "%~dp0src\%package%%mainClass%.java"
if %ERRORLEVEL% NEQ 0 (
rmdir /S /Q "%classes%" >nul
echo.
echo Compilation failed.
echo Press any key to exit.
pause >nul
exit
)
echo Packing...
robocopy /E "%~dp0src" "%classes%" /XF "*.java" >nul 2>nul
if exist "%~dp0%mainClass%.jar" del /F "%~dp0%mainClass%.jar" >nul 2>nul
"%jdk%\jar.exe" --create --verbose --file "%~dp0%mainClass%.jar" --main-class "%package:\=.%%mainClass%" -C "%classes%" . >nul
if %ERRORLEVEL% NEQ 0 (
rmdir /S /Q "%classes%" >nul
echo.
echo Jar creation failed.
echo Press any key to exit.
pause >nul
exit
)
rmdir /S /Q "%classes%" >nul
echo Copying to CommissioningScripts repository...
copy /y "%~dp0%mainClass%.jar" "%~dp0..\commissioning-scripts\src\aces\webctrl\scripts\commissioning\fixed\%mainClass%.jar" >nul
if %ERRORLEVEL% NEQ 0 (
echo.
echo Copy task failed.
echo Press any key to exit.
pause >nul
exit
)
echo Build successful.
echo Press any key to exit.
pause >nul
exit
:: Collect dependencies from the WebCTRL installation or from external websites
:: Parameters: <dependency-file> <output-folder>
:collect
setlocal
set "tmp1=%~dp0tmp1"
set "tmp2=%~dp0tmp2"
set "err=0"
set "msg=0"
dir "%~f2\*.jar" /B /A-D 2>nul >"%tmp1%"
for /F "usebackq tokens=1,2,* delims=:" %%i in ("%~f1") do (
set "findString=%%j"
if "!findString:~-4!" NEQ ".jar" set "findString=%%j-[0-9].*"
set "exists=0"
for /F %%a in ('findstr /R /X "!findString!" "%tmp1%"') do (
set "exists=1"
)
if "!exists!" EQU "0" (
set "msg=1"
if /I "%%i" EQU "url" (
curl --location --fail --silent --output-dir "%~f2" --remote-name %%k
if !ErrorLevel! EQU 0 (
echo Collected: %%j
) else (
set "err=1"
echo Failed to collect: %%j
)
) else if /I "%%i" EQU "file" (
set "file="
dir "%WebCTRL%\%%k\*.jar" /B /A-D 2>nul >"%tmp2%"
for /F %%a in ('findstr /R /X "!findString!" "%tmp2%"') do (
set "file=%%a"
)
if "!file!" EQU "" (
set "err=1"
echo Failed to collect: %%j
) else (
copy /Y "%WebCTRL%\%%k\!file!" "%~f2\!file!" >nul
if !ErrorLevel!==0 (
echo Collected: %%j
) else (
set "err=1"
echo Failed to collect: %%j
)
)
) else (
set "err=1"
echo Failed to collect: %%j
)
)
)
if "%msg%" EQU "1" echo.
if exist "%tmp1%" del /F "%tmp1%" >nul 2>nul
if exist "%tmp2%" del /F "%tmp2%" >nul 2>nul
endlocal & exit /b %err%