forked from RAF-SI-2022/Banka-2-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.cmd
131 lines (111 loc) · 3.78 KB
/
run.cmd
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
@echo off
rem This script is used for manipulating all projects in this repository, on
rem a per-project and global level (all projects at once).
goto :main
rem Initializes the JDK, Git repo settings/hooks, etc. Sets up the development
rem environemnt.
:init
setlocal
rem Disable auto-modification of CR/LF endings
echo Disabling git config core.autocrlf (this repo)...
call git config core.autocrlf false
echo Done
echo Cleaning old !jdk! folder...
call rmdir %jdk% /s /q >NUL 2>&1
call del lib\sha_comp_0.txt >NUL 2>&1
call del lib\sha_comp_1.txt >NUL 2>&1
if not exist "lib" mkdir lib
echo Done
rem Download the package
echo Downloading Amazon Corretto JDK and checksum...
call curl -Lo ./lib/%targetJdk% %sourceJdk%
rem Download the checksum
call curl -Lo ./lib/%targetSha% %sourceSha%
echo Done
rem Check SHA256
cd lib
echo Verifying JDK checksum...
set /p sha_dl=<%targetSha%
rem Calculate hashes
>sha_comp_0.txt (
certutil -hashfile %targetJdk% SHA256
)
>sha_comp_1.txt (
findstr /r /c:"^[a-z0-9]*$" sha_comp_0.txt
)
rem Set EOF after 64 chars and read into var
call fsutil file seteof sha_comp_1.txt 64 1> NUL
set /p sha_comp=<sha_comp_1.txt
rem Compare checksums
if "!sha_dl!" NEQ "!sha_comp!" (
echo Bad SHA, do ./run init again:
echo SHA downloaded: !sha_dl!
echo SHA computed: !sha_comp!
exit 1
)
echo Done
rem Delete checksum files
call del sha_comp_0.txt >NUL 2>&1
call del sha_comp_1.txt >NUL 2>&1
rem Unpack
echo Unpacking JDK...
call tar -xf %targetJdk%
rem Remove residue
del %targetJdk%
del %targetSha%
cd ..
rem Move files directly into jdk dir
move /y lib\jdk* %jdk%
echo Init complete
endlocal
exit /B 0
rem Compiles the .build project.
:compileBuild
setlocal
%bin%\javac -cp .build\src ^
-d .build\out ^
.build\src\rs\edu\raf\si\bank2\Main.java
endlocal
exit /B 0
rem Runs any commands other than init through the Java build script with JDK.
:run
setlocal
set JAVA_HOME="%projectHome%\%jdk%"
%bin%\java -cp .build\out rs.edu.raf.si.bank2.Main %*
endlocal
exit /B 0
rem Main script logic.
:main
setlocal enableextensions enabledelayedexpansion
set projectHome=%cd%
set targetJdk=amazon-corretto-17-x64-windows-jdk.zip
set sourceJdk=https://corretto.aws/downloads/latest/%targetJdk%
set targetSha=amazon-corretto-17-x64-windows-jdk.zip.checksum
set sourceSha=https://corretto.aws/downloads/latest_sha256/%targetJdk%
set jdk=lib\jdk
set bin="%cd%\%jdk%\bin"
if "%~1" == "init" (
call :init
) else (
if "%~1" == "compileBuild" (
call :compileBuild
exit 0
)
if exist %jdk%\bin (
call :run %* ^
"--shellCommand" "cmd" "--shellStartTokenCount" "1" ^
"--shellStartTokens" "/c" "--platform" "windows"
) else (
call java --version >NUL
if %errorlevel% == 0 (
call java -cp .build\out rs.edu.raf.si.bank2.Main %* ^
"--shellCommand" "cmd" "--shellStartTokenCount" "1" ^
"--shellStartTokens" "/c" "--platform" "windows"
) else (
echo Java not installed! Run init or install Java first
exit 1
)
)
)
endlocal
exit /B 0