-
Notifications
You must be signed in to change notification settings - Fork 220
/
CompileJar.bat
422 lines (322 loc) · 15 KB
/
CompileJar.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
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
@echo off
SETLOCAL
REM ----------------
REM Init Environment
REM ----------------
if "%ALBaseDir%"=="" (
Set Standalone=1
call "%~dp0InitEnvironment.bat"
IF ERRORLEVEL 1 goto ERROR
)
REM --------------
REM Security check
REM --------------
if not exist "%ALBaseDir%\Source\Alcinoe.inc" goto ERROR
REM -------------------------
REM Ask with library to build
REM -------------------------
set LibraryToBuild=
if NOT "%Standalone%"=="1" GOTO SKIP_INTERACTION
echo.
echo 1) alcinoe-common
echo 2) alcinoe-datepicker
echo 3) alcinoe-edittext
echo 4) alcinoe-facebook-share
echo 5) alcinoe-firebase-messaging
echo 6) alcinoe-installreferrer
echo 7) alcinoe-webrtc
set /P LibraryToBuild=Enter number to select a library (Empty for all): %=%
more < nul > nul & REM This instruction to clear the ERRORLEVEL because previous instruction set ERRORLEVEL to 1 if empty input
echo.
:SKIP_INTERACTION
REM -----------------
REM Update local vars
REM -----------------
FOR /F "usebackq tokens=3*" %%A IN (`reg query "HKCU\Software\Embarcadero\BDS\%ALDelphiVersion%" /v RootDir`) DO set DelphiRootDirFromReg=%%A %%B
set FMXJAR=%DelphiRootDirFromReg%lib\android\release\fmx.jar
FOR /F "usebackq tokens=3*" %%A IN (`reg query "HKCU\Software\Embarcadero\BDS\%ALDelphiVersion%\PlatformSDKs" /v Default_Android`) DO set Default_Android=%%A
FOR /F "usebackq tokens=3*" %%A IN (`reg query "HKCU\Software\Embarcadero\BDS\%ALDelphiVersion%\PlatformSDKs" /v Default_Android64`) DO set Default_Android64=%%A
set PlatformSDK=%Default_Android64%
if "%PlatformSDK%" == "" set PlatformSDK=%Default_Android%
FOR /F "usebackq tokens=3*" %%A IN (`reg query "HKCU\Software\Embarcadero\BDS\%ALDelphiVersion%\PlatformSDKs\%PlatformSDK%" /v SDKApiLevelPath`) DO set SDKApiLevelPath=%%A
FOR /F "usebackq tokens=3*" %%A IN (`reg query "HKCU\Software\Embarcadero\BDS\%ALDelphiVersion%\PlatformSDKs\%PlatformSDK%" /v JDKPath`) DO set JDKPath=%%A %%B
set JDKBinPath="%JDKPath%\bin"
echo FMXJAR=%FMXJAR%
echo PlatformSDK=%PlatformSDK%
echo SDKApiLevelPath=%SDKApiLevelPath%
echo JDKBinPath=%JDKBinPath%
echo.
REM ---------------
REM clean Libraries
REM ---------------
if NOT "%LibraryToBuild%"=="" GOTO SKIP_clean_Libraries
SET FileName=%ALBaseDir%\Libraries\jar\io\magicfoundation\alcinoe
IF EXIST "%FileName%" rmdir /s /q "%FileName%"
IF EXIST "%FileName%" goto ERROR
mkdir "%FileName%"
:SKIP_clean_Libraries
REM --------------
REM Create Tmp dir
REM --------------
SET TMPDir=%ALBaseDir%\Tmp
IF EXIST "%TMPDir%" rmdir /s /q "%TMPDir%"
IF EXIST "%TMPDir%" goto ERROR
mkdir "%TMPDir%"
SET TMPLibrariesDir=%TMPDir%\Libraries
SET TMPOutputDir=%TMPDir%\Output
SET TMPDependenciesFile=%TMPDir%\Dependencies.txt
REM ----------------------------------
REM Go to the library we want to build
REM ----------------------------------
if "%LibraryToBuild%"=="" goto ALL_LIBRARIES
if "%LibraryToBuild%"=="1" goto alcinoe_common
if "%LibraryToBuild%"=="2" goto alcinoe_datepicker
if "%LibraryToBuild%"=="3" goto alcinoe_edittext
if "%LibraryToBuild%"=="4" goto alcinoe_facebook_share
if "%LibraryToBuild%"=="5" goto alcinoe_firebase_messaging
if "%LibraryToBuild%"=="6" goto alcinoe_installreferrer
if "%LibraryToBuild%"=="7" goto alcinoe_webrtc
goto FINISHED
:ALL_LIBRARIES
REM ------------------------
REM Build alcinoe-common.jar
REM ------------------------
:alcinoe_common
echo [36mBuild alcinoe-common[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\util\*.java
SET SourceFiles=%SourceFiles% %ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\content\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-common" "1.0.1"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM ----------------------------
REM Build alcinoe-datepicker.jar
REM ----------------------------
:alcinoe_datepicker
echo [36mBuild alcinoe-datepicker[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\datepicker\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-datepicker" "1.0.0"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM --------------------------
REM Build alcinoe-edittext.jar
REM --------------------------
:alcinoe_edittext
echo [36mBuild alcinoe-edittext[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\edittext\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-edittext" "1.0.0"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM ------------------------
REM Build alcinoe-webrtc.jar
REM ------------------------
:alcinoe_webrtc
echo [36mBuild alcinoe-webrtc[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "androidx.annotation" "annotation" "1.3.0"
Call :UPDATE_ClASSPATH "https://artifactory.wetransform.to/artifactory/libs-snapshot" "org.webrtc" "google-webrtc" "1.0.25331"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\webrtc\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-webrtc" "1.0.0"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM ------------------------------------
REM Build alcinoe-firebase-messaging.jar
REM ------------------------------------
:alcinoe_firebase_messaging
echo [36mBuild alcinoe-firebase-messaging[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "com.google.firebase" "firebase-messaging" "23.2.0"
REM Mandatory dependencies of com.google.firebase:firebase-messaging:23.2.0 required to build the JAR
REM Use Tools\AndroidLibScanner\AndroidLibScanner.bat to determine the required versions of those dependencies
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "androidx.lifecycle" "lifecycle-livedata-core" "2.0.0"
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "com.google.android.gms" "play-services-basement" "18.1.0"
@echo androidx.appcompat:appcompat:1.6.1>> %TMPDependenciesFile%
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\firebase\messaging\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-firebase-messaging" "1.0.1"
SET FirebaseMessagingDir=%ALBaseDir%\Libraries\jar\io\magicfoundation\alcinoe\alcinoe-firebase-messaging\1.0.1\
SET FirebaseMessagingFilename=alcinoe-firebase-messaging-1.0.1
SET AndroidManifestFilename=%FirebaseMessagingDir%\AndroidManifest.xml
IF EXIST "%AndroidManifestFilename%" del "%AndroidManifestFilename%" /s > nul
IF EXIST "%AndroidManifestFilename%" goto ERROR
@echo ^<?xml version="1.0" encoding="utf-8"?^>> %AndroidManifestFilename%
@echo ^<manifest xmlns:android="http://schemas.android.com/apk/res/android">> %AndroidManifestFilename%
@echo package="io.magicfoundation.alcinoe.alcinoe-firebase-messaging" ^>>> %AndroidManifestFilename%
@echo ^<application^>>> %AndroidManifestFilename%
@echo ^<service android:name="io.magicfoundation.alcinoe.firebase.messaging.ALFirebaseMessagingService">> %AndroidManifestFilename%
@echo android:directBootAware="true">> %AndroidManifestFilename%
@echo android:exported="true"^>>> %AndroidManifestFilename%
@echo ^<intent-filter^>>> %AndroidManifestFilename%
@echo ^<action android:name="com.google.firebase.MESSAGING_EVENT"/^>>> %AndroidManifestFilename%
@echo ^</intent-filter^>>> %AndroidManifestFilename%
@echo ^</service^>>> %AndroidManifestFilename%
@echo ^</application^>>> %AndroidManifestFilename%
@echo ^</manifest^>>> %AndroidManifestFilename%
IF EXIST "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.zip" del "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.zip" /s >nul
IF EXIST "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.zip" goto ERROR
IF EXIST "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.aar" del "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.aar" /s >nul
IF EXIST "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.aar" goto ERROR
rename "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.jar" classes.jar
powershell -command "Compress-Archive -Path '%FirebaseMessagingDir%\AndroidManifest.xml','%FirebaseMessagingDir%\classes.jar' -DestinationPath '%FirebaseMessagingDir%\%FirebaseMessagingFilename%.zip'"
rename "%FirebaseMessagingDir%\%FirebaseMessagingFilename%.zip" %FirebaseMessagingFilename%.aar
del "%AndroidManifestFilename%" /s > nul
del "%FirebaseMessagingDir%\classes.jar" /s > nul
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM --------------------------------
REM Build alcinoe-facebook-share.jar
REM --------------------------------
:alcinoe_facebook_share
echo [36mBuild alcinoe-facebook-share[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
Call :UPDATE_ClASSPATH "https://repo1.maven.org/maven2" "com.facebook.android" "facebook-common" "15.2.0"
REM Mandatory dependencies of com.facebook.android:facebook-common:15.2.0 required to build the JAR
REM Use Tools\AndroidLibScanner\AndroidLibScanner.bat to determine the required versions of those dependencies
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "androidx.fragment" "fragment" "1.3.0"
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "androidx.annotation" "annotation" "1.1.0"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\facebook\share\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-facebook-share" "1.0.1"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM ---------------------------------
REM Build alcinoe-installreferrer.jar
REM ---------------------------------
:alcinoe_installreferrer
echo [36mBuild alcinoe-installreferrer[0m
type nul > %TMPDependenciesFile%
SET ClassPath="%SDKApiLevelPath%\android.jar"
Call :UPDATE_ClASSPATH "https://dl.google.com/android/maven2" "com.android.installreferrer" "installreferrer" "2.2"
SET SourceFiles=%ALBaseDir%\Source\Java\io\magicfoundation\alcinoe\installreferrer\*.java
Call :BUILD_JAR "io.magicfoundation.alcinoe" "alcinoe-installreferrer" "1.0.0"
if NOT "%LibraryToBuild%"=="" GOTO FINISHED
REM -------------
REM Goto Finished
REM -------------
GOTO FINISHED
REM ------------------
REM Function BUILD_JAR
REM ------------------
:UPDATE_ClASSPATH
REM %~2 the groupId (io.magicfoundation.alcinoe)
REM %~3 the artifactId (alcinoe-facebook)
REM %~4 the version (1.0.0)
Call :DOWNLOAD_LIBRARY "%~1" "%~2" "%~3" "%~4"
Set groupID4DIR=%~2
Set groupID4DIR=%groupID4DIR:.=\%
Set PartialPath=%groupID4DIR%\%~3\%~4\%~3-%~4
if exist "%ALBaseDir%\Libraries\jar\%PartialPath%.aar" (
Call :UNZIP "%PartialPath%"
SET ClassPath=%ClassPath%;"%TMPLibrariesDir%\%PartialPath%\classes.jar"
) else (
SET ClassPath=%ClassPath%;"%ALBaseDir%\Libraries\jar\%PartialPath%.jar"
)
@echo %~2:%~3:%~4>> %TMPDependenciesFile%
EXIT /B 0
REM -------------------------
REM Function DOWNLOAD_LIBRARY
REM -------------------------
:DOWNLOAD_LIBRARY
REM %~1 the maven base url (https://repo1.maven.org/maven2)
REM %~2 the groupID (androidx.annotation)
REM %~3 the artifactID (annotation)
REM %~4 the version (1.0.0)
Set groupID4URL=%~2
Set groupID4URL=%groupID4URL:.=/%
Set SrcUrl=%~1/%groupID4URL%/%~3/%~4/%~3-%~4
Set groupID4DIR=%~2
Set groupID4DIR=%groupID4DIR:.=\%
Set DestDIR=%ALBaseDir%\Libraries\jar\%groupID4DIR%\%~3\%~4\
IF EXIST "%DestDIR%\%~3-%~4.pom" (
EXIT /B 0
)
IF EXIST "%DestDIR%" rmdir /s /q "%DestDIR%"
IF EXIST "%DestDIR%" goto ERROR
mkdir "%DestDIR%"
echo [33mDownload %~2:%~3:%~4[0m
curl --fail --location "%SrcUrl%.aar" --output "%DestDIR%\%~3-%~4.aar"
IF ERRORLEVEL 1 (
curl --fail --location "%SrcUrl%.jar" --output "%DestDIR%\%~3-%~4.jar"
IF ERRORLEVEL 1 goto ERROR
)
curl --fail --location "%SrcUrl%.pom" --output "%DestDIR%\%~3-%~4.pom"
IF ERRORLEVEL 1 goto ERROR
EXIT /B 0
REM --------------
REM Function UNZIP
REM --------------
:UNZIP
REM %~1 the partial path of the library (androidx\core\core\1.2.0\core-1.2.0)
Set ArchiveFilename=%ALBaseDir%\Libraries\jar\%~1.aar
Set OutPutPath=%TMPLibrariesDir%\%~1
IF EXIST "%OutPutPath%\tmp.zip" EXIT /B 0
xcopy "%ArchiveFilename%" "%OutPutPath%\tmp.zip*" /Q > nul
IF ERRORLEVEL 1 goto ERROR
powershell -command "Expand-Archive -Force '%OutPutPath%\tmp.zip' '%OutPutPath%'"
IF ERRORLEVEL 1 goto ERROR
del "%OutPutPath%\tmp.zip"
IF EXIST "%OutPutPath%\tmp.zip" goto ERROR
EXIT /B 0
REM ------------------
REM Function BUILD_JAR
REM ------------------
:BUILD_JAR
REM %~1 the groupId (io.magicfoundation.alcinoe)
REM %~2 the artifactId (alcinoe-facebook)
REM %~3 the version (1.0.0)
SET GroupId4Directory=%~1
SET GroupId4Directory=%GroupId4Directory:.=\%
SET JARDirectory=%ALBaseDir%\Libraries\jar\%GroupId4Directory%\%~2\%~3\
SET JARFilename=%JARDirectory%\%~2-%~3.jar
IF EXIST "%JARFilename%" del "%JARFilename%" /s >nul
IF EXIST "%JARFilename%" goto ERROR
SET POMFilename=%JARDirectory%\%~2-%~3.pom
IF EXIST "%POMFilename%" del "%POMFilename%" /s >nul
IF EXIST "%POMFilename%" goto ERROR
IF EXIST "%TMPOutputDir%" rmdir /s /q "%TMPOutputDir%"
IF EXIST "%TMPOutputDir%" goto ERROR
mkdir "%TMPOutputDir%"
%JDKBinPath%\javac^
-Xlint:unchecked^
-Xlint:deprecation^
-cp %ClassPath%^
-d %TMPOutputDir%^
%SourceFiles%
IF ERRORLEVEL 1 goto ERROR
IF EXIST "%JARDirectory%" rmdir /s /q "%JARDirectory%"
IF EXIST "%JARDirectory%" goto ERROR
MKDIR "%JARDirectory%"
%JDKBinPath%\jar cf "%JARFilename%" -C "%TMPOutputDir%" %GroupId4Directory%
IF ERRORLEVEL 1 goto ERROR
@echo ^<project xmlns="http://maven.apache.org/POM/4.0.0"> %POMFilename%
@echo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">> %POMFilename%
@echo xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"^>>> %POMFilename%
@echo ^<modelVersion^>4.0.0^</modelVersion^>>> %POMFilename%
@echo ^<groupId^>%~1^</groupId^>>> %POMFilename%
@echo ^<artifactId^>%~2^</artifactId^>>> %POMFilename%
@echo ^<version^>%~3^</version^>>> %POMFilename%
@echo ^<dependencies^>>> %POMFilename%
for /f "tokens=1-3 delims=:" %%i in (%TMPDependenciesFile%) do (
@echo ^<dependency^>>> %POMFilename%
@echo ^<groupId^>%%i^</groupId^>>> %POMFilename%
@echo ^<artifactId^>%%j^</artifactId^>>> %POMFilename%
@echo ^<version^>%%k^</version^>>> %POMFilename%
@echo ^</dependency^>>> %POMFilename%
)
@echo ^</dependencies^>>> %POMFilename%
@echo ^</project^>>> %POMFilename%
EXIT /B 0
REM -------------------
REM FINISHED/ERROR/EXIT
REM -------------------
:FINISHED
IF EXIST "%TMPDir%" rmdir /s /q "%TMPDir%"
IF EXIST "%TMPDir%" goto ERROR
echo.
echo Jars created successfully
if "%Standalone%"=="1" PAUSE
goto EXIT
:ERROR
PAUSE
EXIT 1 & REM without /B to Close CMD.exe in case this batch is a subroutine and the caller forget to catch the ERRORLEVEL
:EXIT