-
Notifications
You must be signed in to change notification settings - Fork 5
/
sharedata.bat
687 lines (626 loc) · 25.2 KB
/
sharedata.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
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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
@echo off
setlocal enabledelayedexpansion
@rem only for interactive debugging !
set _DEBUG=0
@rem #########################################################################
@rem ## Environment setup
set _EXITCODE=0
call :env
if not %_EXITCODE%==0 goto end
call :args %*
if not %_EXITCODE%==0 goto end
@rem #########################################################################
@rem ## Main
if defined _HELP (
call :help
exit /b !_EXITCODE!
)
call :init
if not %_EXITCODE%==0 goto end
if defined _DUMP_ONLY (
call :dump
if not !_EXITCODE!==0 goto end
goto end
)
if defined _TEST_ONLY (
call :test
if not !_EXITCODE!==0 goto end
goto end
)
if defined _ACTIVATE (
call :dump
if not !_EXITCODE!==0 goto end
call :test
if not !_EXITCODE!==0 goto end
call :activate
if not !_EXITCODE!==0 goto end
) else if defined _RESET (
call :reset
if not !_EXITCODE!==0 goto end
)
goto end
@rem #########################################################################
@rem ## Subroutines
:env
set _BASENAME=%~n0
call :env_colors
set _DEBUG_LABEL=%_NORMAL_BG_CYAN%%_DEBUG_LABEL%%_RESET%
set _ERROR_LABEL=%_STRONG_FG_RED%Error%_RESET%:
set _WARNING_LABEL=%_STRONG_FG_YELLOW%Warning%_RESET%:
for /f "delims=" %%f in ("%~dp0..") do set "_ROOT_DIR=%%~sf"
set "_OUT_DIR=%_ROOT_DIR%\out\data-sharing"
if not exist "%_OUT_DIR%" mkdir "%_OUT_DIR%"
set "_LOG_DIR=%_OUT_DIR%\logs"
if not exist "%_LOG_DIR%" mkdir "%_LOG_DIR%"
set _CDS_NAME=dotty-cds
set _COMPILER_NAME=%_CDS_NAME%-compiler
set _COMPILER_CLASSLIST_FILE=%_OUT_DIR%\%_COMPILER_NAME%.classlist
set _COMPILER_CLASSLIST_LOG_FILE=%_LOG_DIR%\%_COMPILER_NAME%_classlist.log
set _COMPILER_JSA_FILE=%_OUT_DIR%\%_COMPILER_NAME%.jsa
set _COMPILER_JSA_LOG_FILE=%_LOG_DIR%\%_COMPILER_NAME%-jsa.log
set _REPL_NAME=%_CDS_NAME%-repl
set _REPL_CLASSLIST_FILE=%_OUT_DIR%\%_REPL_NAME%.classlist
set _REPL_CLASSLIST_LOG_FILE=%_LOG_DIR%\%_REPL_NAME%_classlist.log
set _REPL_JSA_FILE=%_OUT_DIR%\%_REPL_NAME%.jsa
set _REPL_JSA_LOG_FILE=%_LOG_DIR%\%_REPL_NAME%_jsa.log
set _REPL_SHARE_LOG_FILE=%_LOG_DIR%\%_REPL_NAME%-share.log
set _MAIN_CLASS_NAME=Main
set _MAIN_PKG_NAME=cds
set _APP_MAIN_CLASS=%_MAIN_PKG_NAME%.%_MAIN_CLASS_NAME%
set _APP_JAR_FILE=%_OUT_DIR%\%_CDS_NAME%.jar
goto :eof
:env_colors
@rem ANSI colors in standard Windows 10 shell
@rem see https://gist.github.com/mlocati/#file-win10colors-cmd
@rem normal foreground colors
set _NORMAL_FG_BLACK=[30m
set _NORMAL_FG_RED=[31m
set _NORMAL_FG_GREEN=[32m
set _NORMAL_FG_YELLOW=[33m
set _NORMAL_FG_BLUE=[34m
set _NORMAL_FG_MAGENTA=[35m
set _NORMAL_FG_CYAN=[36m
set _NORMAL_FG_WHITE=[37m
@rem normal background colors
set _NORMAL_BG_BLACK=[40m
set _NORMAL_BG_RED=[41m
set _NORMAL_BG_GREEN=[42m
set _NORMAL_BG_YELLOW=[43m
set _NORMAL_BG_BLUE=[44m
set _NORMAL_BG_MAGENTA=[45m
set _NORMAL_BG_CYAN=[46m
set _NORMAL_BG_WHITE=[47m
@rem strong foreground colors
set _STRONG_FG_BLACK=[90m
set _STRONG_FG_RED=[91m
set _STRONG_FG_GREEN=[92m
set _STRONG_FG_YELLOW=[93m
set _STRONG_FG_BLUE=[94m
set _STRONG_FG_MAGENTA=[95m
set _STRONG_FG_CYAN=[96m
set _STRONG_FG_WHITE=[97m
@rem strong background colors
set _STRONG_BG_BLACK=[100m
set _STRONG_BG_RED=[101m
set _STRONG_BG_GREEN=[102m
set _STRONG_BG_YELLOW=[103m
set _STRONG_BG_BLUE=[104m
@rem we define _RESET in last position to avoid crazy console output with type command
set _BOLD=[1m
set _UNDERSCORE=[4m
set _INVERSE=[7m
set _RESET=[0m
goto :eof
@rem input parameter: %*
@rem output parameters: _HELP, _VERBOSE, _SHARE_FLAG, _SHARE_TEXT
:args
set _HELP=
set _ACTIVATE=
set _DUMP_ONLY=
set _RESET=
set _SHARE_FLAG=off
set _TEST_ONLY=
set _VERBOSE=0
:args_loop
set __ARG=%~1
if not defined __ARG goto args_done
if /i "%__ARG%"=="help" ( set _HELP=1& goto :eof
) else if /i "%__ARG%"=="activate" ( set _ACTIVATE=1
) else if /i "%__ARG%"=="dump" ( set _DUMP_ONLY=1
) else if /i "%__ARG%"=="reset" ( set _RESET=1
) else if /i "%__ARG%"=="test" ( set _TEST_ONLY=1
) else if /i "%__ARG%"=="-debug" ( set _DEBUG=1
) else if /i "%__ARG%"=="-share" ( set _SHARE_FLAG=on
) else if /i "%__ARG%"=="-share:on" ( set _SHARE_FLAG=on
) else if /i "%__ARG%"=="-share:off" ( set _SHARE_FLAG=off
) else if /i "%__ARG%"=="-verbose" ( set _VERBOSE=1
) else (
echo %_ERROR_LABEL% Unknown subcommand %__ARG% 1>&2
set _EXITCODE=1
goto :eof
)
shift
goto args_loop
:args_done
if /i "%_SHARE_FLAG%"=="on" ( set _SHARE_TEXT=WITH
) else ( set _SHARE_TEXT=[41mWITHOUT[0m
)
goto :eof
:help
echo Usage: %_BASENAME% { options ^| subcommands }
echo Options:
echo -share[:on^|off] set the share flag (default:off)
echo -verbose print progress messages
echo Subcommands:
echo activate install the Java shared archive
echo dump create the Java shared archive
echo help print this help message
echo reset uninstall the Java share archive
echo test execute test application (depends on dump)
goto :eof
rem output parameters: _JAVAC_CMD, _JAVA_HOME, _JAVA_CLASSLIST_FILE, _DOTTY_HOME, _CDS_INSTALL_NAME
:init
where /q javac.exe
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Java compiler not found ^(run setenv.bat^) 1>&2
set _EXITCODE=1
goto :eof
)
set _JAVAC_CMD=javac.exe
set _JAR_CMD=jar.exe
where /q java.exe
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Java executable not found ^(run setenv.bat^) 1>&2
set _EXITCODE=1
goto :eof
)
set _JAVA_CMD=java.exe
for /f %%i in ('where "%_JAVA_CMD%" ^| findstr /v javapath') do (
for %%f in ("%%~dpi..") do set _JAVA_HOME=%%~sf
)
set __JAVA_11=
for /f "tokens=1,2,3,*" %%i in ('%_JAVA_CMD% -version 2^>^&1 ^| findstr version 2^>^&1') do (
set __JAVA_VERSION=%%~k
for /f %%j in ('echo %%~k ^| findstr "^1[1-9]\. ^1[1-9]-ea" 2^>NUL') do set __JAVA_11=1
)
if not defined __JAVA_11 (
echo %_ERROR_LABEL% Java 11 LTS or newer is required ^(found %__JAVA_VERSION%^) 1>&2
set _EXITCODE=1
goto :eof
)
set _JAVA_CLASSLIST_FILE=%_JAVA_HOME%\lib\classlist
if not exist "%_JAVA_CLASSLIST_FILE%" (
echo %_ERROR_LABEL% File not found ^(%_JAVA_CLASSLIST_FILE%^) 1>&2
set _EXITCODE=1
goto :eof
)
where /q dotc.bat
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Scala compiler not found ^(run setenv.bat^) 1>&2
set _EXITCODE=1
goto :eof
)
set _COMPILER_CMD=dotc.bat
set _REPL_CMD=dotr.bat
for /f "delims=" %%i in ('where "%_COMPILER_CMD%"') do (
for %%f in ("%%~dpi..") do set _DOTTY_HOME=%%~sf
)
for /f "delims=" %%i in ('dir /b /a-d "%_DOTTY_HOME%\lib\dotty-library*.jar"') do set _LIB_NAME=%%~ni
if not exist "%_DOTTY_HOME%\lib\%_LIB_NAME%.jar" (
echo %_ERROR_LABEL% Installation directory not found ^(%_DOTTY_HOME%\lib^) 1>&2
set _EXITCODE=1
goto :eof
)
set _CDS_INSTALL_NAME=%_LIB_NAME:library=cds%
goto :eof
rem globals: _COMPILER_CMD, _JAR_CMD, _REPL_CMD, _OUT_DIR, _COMPILER_JSA_FILE, _REPL_JSA_FILE
:dump
set "__SRC_DIR=%_OUT_DIR%\src\%_MAIN_PKG_NAME%"
if not exist "%__SRC_DIR%" mkdir "%__SRC_DIR%"
set "__SOURCE_FILE=%__SRC_DIR%\%_MAIN_CLASS_NAME%.scala"
(
echo package %_MAIN_PKG_NAME%
echo object %_MAIN_CLASS_NAME% {
echo def main(args: Array[String]^): Unit = {
echo println("Support files for Java class sharing:"^)
echo val jarUrl = getClass^(^).getProtectionDomain(^).getCodeSource(^).getLocation(^)
echo val libDir = java.nio.file.Paths.get(jarUrl.toURI(^)^).getParent(^).toFile(^)
echo val files = libDir.listFiles.filter^(_.getName.startsWith("%_CDS_NAME%"^)^)
echo files.foreach(f =^> println(" "+f.getName(^)+" ("+(f.length(^)/1024^)+" Kb)"^)^)
echo }
echo }
) > %__SOURCE_FILE%
set "__CLASSES_DIR=%_OUT_DIR%\classes"
if not exist "%__CLASSES_DIR%" mkdir "%__CLASSES_DIR%"
set __JAVA_TOOL_OPTS="-J-XX:DumpLoadedClassList=%_COMPILER_CLASSLIST_FILE%"
if %_DEBUG%==1 (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path=info"
) else if %_VERBOSE%==1 (
rem !!! Ignore drive letter (temporary hack, see JDK-8215398)
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path:file=%_COMPILER_CLASSLIST_LOG_FILE:~2%"
) else (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! -J-Xlog:disable
)
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% call "%_COMPILER_CMD%" %__JAVA_TOOL_OPTS% -d "%__CLASSES_DIR%" "%__SOURCE_FILE%" 1>&2
) else ( echo Create class list file "!_COMPILER_CLASSLIST_FILE:%_ROOT_DIR%\=!"
)
call "%_COMPILER_CMD%" %__JAVA_TOOL_OPTS% -d "%__CLASSES_DIR%" "%__SOURCE_FILE%"
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to compile source file "%__SOURCE_FILE%" 1>&2
set _EXITCODE=1
goto :eof
)
set __MANIFEST_FILE=%_OUT_DIR%\MANIFEST.MF
(
echo Manifest-Version: 1.0
echo Built-By: %USERNAME%
echo Build-Jdk: %_JAVA_VERSION%
echo Specification-Title: %_MAIN_PKG_NAME%
echo Specification-Version: 0.1-SNAPSHOT
echo Implementation-Title: %_MAIN_PKG_NAME%
echo Implementation-Version: 0.1-SNAPSHOT
echo Main-Class: %_APP_MAIN_CLASS%
) > %__MANIFEST_FILE%
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_JAR_CMD%" cfm %_APP_JAR_FILE% "%__MANIFEST_FILE%" -C "%__CLASSES_DIR%" . 1>&2
) else if %_VERBOSE%==1 ( echo Create Java archive "!_APP_JAR_FILE:%_ROOT_DIR%=!" 1>&2
)
call "%_JAR_CMD%" cfm %_APP_JAR_FILE% "%__MANIFEST_FILE%" -C "%__CLASSES_DIR%" .
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to generate Java archive "%_APP_JAR_FILE%" 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 ( set __REDIRECT_STDOUT=
) else ( set __REDIRECT_STDOUT=1^>NUL
)
set __JAVA_TOOL_OPTS=-J-Xshare:dump "-J-XX:SharedClassListFile=%_COMPILER_CLASSLIST_FILE%" -J-XX:+UnlockDiagnosticVMOptions "-J-XX:SharedArchiveFile=%_COMPILER_JSA_FILE%"
if %_DEBUG%==1 (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path=info"
) else if %_VERBOSE%==1 (
rem !!! We ignore drive letter in file path (temporary hack, see JDK-8215398)
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path:file=%_COMPILER_JSA_LOG_FILE:~2%"
) else (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! -J-Xlog:disable
)
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% call %_COMPILER_CMD% %__JAVA_TOOL_OPTS% -d %__CLASSES_DIR% %__SOURCE_FILE%
) else ( echo Create Java shared archive !_COMPILER_JSA_FILE:%_ROOT_DIR%\=!
)
call %_COMPILER_CMD% %__JAVA_TOOL_OPTS% -d %__CLASSES_DIR% %__SOURCE_FILE% %__REDIRECT_STDOUT%
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to compile source file %__SOURCE_FILE% 1>&2
set _EXITCODE=1
goto :eof
)
set __JAVA_TOOL_OPTS="-J-XX:DumpLoadedClassList=%_REPL_CLASSLIST_FILE%"
if %_DEBUG%==1 (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path=info"
) else if %_VERBOSE%==1 (
rem !!! We ignore drive letter in file path (temporary hack, see JDK-8215398)
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path:file=%_REPL_CLASSLIST_LOG_FILE:~2%"
) else (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! -J-Xlog:disable
)
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% call "%_REPL_CMD%" %__JAVA_TOOL_OPTS% -classpath "%__CLASSES_DIR%" %_APP_MAIN_CLASS% 1>&2
) else ( echo Create class list file "!_REPL_CLASSLIST_FILE:%_ROOT_DIR%\=!"
)
call "%_REPL_CMD%" %__JAVA_TOOL_OPTS% -classpath "%__CLASSES_DIR%" %_APP_MAIN_CLASS% %__REDIRECT_STDOUT%
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to execute Scala class "%_APP_MAIN_CLASS%" 1>&2
set _EXITCODE=1
goto :eof
)
set __JAVA_TOOL_OPTS=-J-Xshare:dump "-J-XX:SharedClassListFile=%_REPL_CLASSLIST_FILE%" -J-XX:+UnlockDiagnosticVMOptions "-J-XX:SharedArchiveFile=%_REPL_JSA_FILE%"
if %_DEBUG%==1 (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path=info"
) else if %_VERBOSE%==1 (
rem !!! We ignore drive letter in file path (temporary hack, see JDK-8215398)
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+path:file=%_REPL_JSA_LOG_FILE:~2%"
) else (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! -J-Xlog:disable
)
set "__CDS_JAR_FILE=%_DOTTY_HOME%\lib\%_CDS_INSTALL_NAME%.jar"
copy /y "%_APP_JAR_FILE%" "%__CDS_JAR_FILE%" 1>NUL
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% call "%_REPL_CMD%" %__JAVA_TOOL_OPTS% -classpath "%__CDS_JAR_FILE%" %_APP_MAIN_CLASS% 1>&2
) else ( echo Create Java shared archive "!_REPL_JSA_FILE:%_ROOT_DIR%\=!"
)
call "%_REPL_CMD%" %__JAVA_TOOL_OPTS% -classpath "%__CDS_JAR_FILE%" %_APP_MAIN_CLASS% %__REDIRECT_STDOUT%
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to execute Scala class "%_APP_MAIN_CLASS%" 1>&2
set _EXITCODE=1
goto :eof
)
rem Only subcommand 'activate' does modify Scala installation
del "%__CDS_JAR_FILE%" 1>NUL
goto :eof
:test
set __CDS_COPIED=0
set __CDS_JAR_FILE=%_DOTTY_HOME%\lib\%_CDS_INSTALL_NAME%.jar
if not exist "%__CDS_JAR_FILE%" (
if not exist "%_APP_JAR_FILE%" (
echo %_ERROR_LABEL% Java archive file %__CDS_JAR_FILE% not found 1>&2
echo ^(hint: run subcommand 'dump' first^)
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_APP_JAR_FILE%" "%__CDS_JAR_FILE%"
copy /y "%_APP_JAR_FILE%" "%__CDS_JAR_FILE%" 1>NUL
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_OUT_DIR%\%_CDS_NAME%-*" "%_DOTTY_HOME%\lib\"
copy /y "%_OUT_DIR%\%_CDS_NAME%*" "%_DOTTY_HOME%\lib\" 1>NUL
set __CDS_COPIED=1
)
set __JAVA_TOOL_OPTS=-J-Xshare:%_SHARE_FLAG% -J-XX:+UnlockDiagnosticVMOptions "-J-XX:SharedArchiveFile=%_DOTTY_HOME%\lib\%_REPL_NAME%.jsa"
if %_DEBUG%==1 (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+load=info"
) else if %_VERBOSE%==1 (
rem !!! We ignore drive letter in file path (temporary hack, see JDK-8215398)
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! "-J-Xlog:class+load:file=%_REPL_SHARE_LOG_FILE:~2%"
) else (
set __JAVA_TOOL_OPTS=!__JAVA_TOOL_OPTS! -J-Xlog:disable
)
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% call %_REPL_CMD% !__JAVA_TOOL_OPTS! -classpath %__CDS_JAR_FILE% %_APP_MAIN_CLASS%
) else if %_VERBOSE%==1 ( echo Execute test application with Scala REPL %_SHARE_TEXT% Java shared archive
)
call %_REPL_CMD% !__JAVA_TOOL_OPTS! -classpath %__CDS_JAR_FILE% %_APP_MAIN_CLASS%
if not %ERRORLEVEL%==0 (
if %__CDS_COPIED%==1 del "%_DOTTY_HOME%\lib\%_CDS_NAME%*"
rem Error message below is redundant
rem echo %_ERROR_LABEL% Failed to execute test application %_APP_MAIN_CLASS% 1>&2
set _EXITCODE=1
goto :eof
)
if %__CDS_COPIED%==1 del "%_DOTTY_HOME%\lib\%_CDS_NAME%*"
if %_VERBOSE%==1 (
if %_DEBUG%==1 echo %_DEBUG_LABEL% call :report "%_REPL_SHARE_LOG_FILE%"
call :report "%_REPL_SHARE_LOG_FILE%"
)
goto :eof
rem input parameter: %1=share log file
:report
set __SHARE_LOG_FILE=%~1
if not exist "%__SHARE_LOG_FILE%" (
echo %_ERROR_LABEL% Share log file %__SHARE_LOG_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
set __N_SHARED=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr shared "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr shared "%__SHARE_LOG_FILE%"') do (
set /a __N_SHARED+=1
if %_DEBUG%==1 echo %%i
)
set __N_FILE=0
set __FILE_URLS=
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"file:/" "%__SHARE_LOG_FILE%"
for /f "tokens=1,*" %%i in ('findstr /c:"file:/" "%__SHARE_LOG_FILE%"') do (
set /a __N_FILE+=1
if %_DEBUG%==1 echo %%j
if !__N_FILE! lss 2 ( set __FILE_URLS=!__FILE_URLS! %%j
) else if not "!__FILE_URLS:...=!"=="!__FILE_URLS!" ( set __FILE_URLS=!__FILE_URLS! ...
)
)
set __N_JRT=0
set __JRT_URLS=
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"jrt:/" "%__SHARE_LOG_FILE%"
for /f "tokens=1,*" %%i in ('findstr /c:"jrt:/" "%__SHARE_LOG_FILE%"') do (
set /a __N_JRT+=1
if %_DEBUG%==1 echo %%j
if !__N_JRT! lss 2 ( set __JRT_URLS=!__JRT_URLS! %%j
) else if not "!__JRT_URLS:...=!"=="!__JRT_URLS!" ( set __JRT_URLS=!__JRT_URLS! ...
)
)
set __N_MAIN=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] %_MAIN_PKG_NAME%." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] %_MAIN_PKG_NAME%." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: %_MAIN_PKG_NAME%."') do (
set /a __N_MAIN+=1
)
rem Java libraries
set __N_JAVA_IO=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.io." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.io." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.io."') do (
set /a __N_JAVA_IO+=1
)
set __N_JAVA_LANG=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.lang." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.lang." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.lang."') do (
set /a __N_JAVA_LANG+=1
)
set __N_JAVA_NET=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.net." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.net." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.net."') do (
set /a __N_JAVA_NET+=1
)
set __N_JAVA_NIO=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.nio." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.nio." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.nio."') do (
set /a __N_JAVA_NIO+=1
)
set __N_JAVA_SECURITY=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.security." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.security." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.security."') do (
set /a __N_JAVA_SECURITY+=1
)
set __N_JAVA_UTIL=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] java.util." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] java.util." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: java.util."') do (
set /a __N_JAVA_UTIL+=1
)
set __N_JDK=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] jdk." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] jdk." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: jdk."') do (
set /a __N_JDK+=1
)
set __N_SUN=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] sun." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] sun." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: sun."') do (
set /a __N_SUN+=1
)
rem Scala libraries
set __N_SCALA=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala." "%__SHARE_LOG_FILE%" ^| findstr /v "scala.collection scala.io scala.math scala.reflect scala.runtime scala.sys scala.util"') do (
set /a __N_SCALA+=1
)
set __N_SCALA_COLLECTION=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.collection." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.collection." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.collection."') do (
set /a __N_SCALA_COLLECTION+=1
)
set __N_SCALA_COMPAT=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.compat." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.compat." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.compat."') do (
set /a __N_SCALA_COMPAT+=1
)
set __N_SCALA_IO=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.io." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.io." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.io."') do (
set /a __N_SCALA_IO+=1
)
set __N_SCALA_MATH=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.math." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.math." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.math."') do (
set /a __N_SCALA_MATH+=1
)
set __N_SCALA_REFLECT=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.reflect." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.reflect." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.reflect."') do (
set /a __N_SCALA_REFLECT+=1
)
set __N_SCALA_RUNTIME=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.runtime." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.runtime." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.runtime."') do (
set /a __N_SCALA_RUNTIME+=1
)
set __N_SCALA_SYS=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.sys." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.sys." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.sys."') do (
set /a __N_SCALA_SYS+=1
)
set __N_SCALA_UTIL=0
if %_DEBUG%==1 echo %_DEBUG_LABEL% findstr /c:"] scala.util." "%__SHARE_LOG_FILE%"
for /f "delims=" %%i in ('findstr /c:"] scala.util." "%__SHARE_LOG_FILE%" ^| findstr /v /c:"source: scala.util."') do (
set /a __N_SCALA_UTIL+=1
)
set __LOAD_TIME=999.999s
for /f "delims=[]" %%i in ('powershell -c "Get-Content %__SHARE_LOG_FILE% | select -Last 1"') do (
set __LOAD_TIME=%%i
)
if "%_SHARE_FLAG%"=="off" ( set __FILE_TEXT=%__N_FILE%
) else if %__N_FILE% gtr 0 ( set __FILE_TEXT=%__N_FILE% ^(%__FILE_URLS:~1%^)
) else ( set __FILE_TEXT=%__N_FILE%
)
if "%_SHARE_FLAG%"=="off" ( set __JRT_TEXT=%__N_JRT%
) else if %__N_JRT% gtr 0 ( set __JRT_TEXT=%__N_JRT% ^(%__JRT_URLS:~1%^)
) else ( set __JRT_TEXT=%__N_JRT%
)
set /a __N_PACKAGES=__N_MAIN
rem Java libraries
set /a __N_PACKAGES=__N_PACKAGES+__N_JAVA_IO+__N_JAVA_LANG+__N_JAVA_NET+__N_JAVA_NIO
set /a __N_PACKAGES=__N_PACKAGES+__N_JAVA_SECURITY+__N_JAVA_UTIL+__N_JDK+__N_SUN
rem Scala libraries
set /a __N_PACKAGES=__N_PACKAGES+__N_SCALA+__N_SCALA_COLLECTION+__N_SCALA_COMPAT+__N_SCALA_IO
set /a __N_PACKAGES=__N_PACKAGES+__N_SCALA_MATH+__N_SCALA_REFLECT
set /a __N_PACKAGES=__N_PACKAGES+__N_SCALA_RUNTIME+__N_SCALA_SYS+__N_SCALA_UTIL
echo [96mExecution report:[0m
echo Share flag : %_SHARE_FLAG%
echo Shared archive : !_REPL_JSA_FILE:%_ROOT_DIR%\=!
echo Shared classes : %__N_SHARED%
echo File classes : %__FILE_TEXT%
echo jrt images : %__JRT_TEXT%
echo Load time : %__LOAD_TIME%
echo Execution logs : !__SHARE_LOG_FILE:%_ROOT_DIR%\=!
echo [96mClasses per package ^(!__N_PACKAGES!^):[0m
echo java.io.* ^(%__N_JAVA_IO%^), java.lang.* ^(%__N_JAVA_LANG%^), java.net.* ^(%__N_JAVA_NET%^), java.nio.* ^(%__N_JAVA_NIO%^)
echo java.security.* ^(%__N_JAVA_SECURITY%^), java.util.* ^(%__N_JAVA_UTIL%^), jdk.* ^(%__N_JDK%^), sun.* ^(%__N_SUN%^)
echo [APP] %_MAIN_PKG_NAME%.* ^(%__N_MAIN%^)
echo scala.* ^(%__N_SCALA%^), scala.collection.* ^(%__N_SCALA_COLLECTION%^), scala.compat.* ^(%__N_SCALA_COMPAT%^)
echo scala.io.* ^(%__N_SCALA_IO%^), scala.math.* ^(%__N_SCALA_MATH%^), scala.reflect.* ^(%__N_SCALA_REFLECT%^)
echo scala.runtime.* ^(%__N_SCALA_RUNTIME%^), scala.sys.* ^(%__N_SCALA_SYS%^), scala.util.* ^(%__N_SCALA_UTIL%^)
goto :eof
rem Add the Java shared archive to the Scala installation directory
rem globals: _APP_JAR_FILE, _COMPILER_CLASSLIST_FILE, _COMPILER_JSA_FILE, _REPL_CLASSLIST_FILE, _REPL_JSA_FILE
:activate
if not exist "%_APP_JAR_FILE%" (
echo %_ERROR_LABEL% Java archive file %_APP_JAR_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
set __CDS_JAR_FILE=%_DOTTY_HOME%\lib\%_CDS_INSTALL_NAME%.jar
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_APP_JAR_FILE%" "%__CDS_JAR_FILE%"
copy /y "%_APP_JAR_FILE%" "%__CDS_JAR_FILE%" 1>NUL
if not exist "%_COMPILER_CLASSLIST_FILE%" (
echo %_ERROR_LABEL% Classlist file %_COMPILER_CLASSLIST_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_COMPILER_CLASSLIST_FILE%" "%_DOTTY_HOME%\lib\"
copy /y "%_COMPILER_CLASSLIST_FILE%" "%_DOTTY_HOME%\lib\" 1>NUL
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy %_COMPILER_CLASSLIST_FILE% to %_DOTTY_HOME%\lib\ 1>&2
set _EXITCODE=1
goto :eof
)
if not exist "%_COMPILER_JSA_FILE%" (
echo %_ERROR_LABEL% Java shared archive %_COMPILER_JSA_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_COMPILER_JSA_FILE%" "%_DOTTY_HOME%\lib\"
copy /y "%_COMPILER_JSA_FILE%" "%_DOTTY_HOME%\lib\" 1>NUL
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy %_COMPILER_JSA_FILE% to %_DOTTY_HOME%\lib\ 1>&2
set _EXITCODE=1
goto :eof
)
if not exist "%_REPL_CLASSLIST_FILE%" (
echo %_ERROR_LABEL% Classlist file %_REPL_CLASSLIST_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_REPL_CLASSLIST_FILE%" "%_DOTTY_HOME%\lib\"
copy /y "%_REPL_CLASSLIST_FILE%" "%_DOTTY_HOME%\lib\" 1>NUL
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy classlist file %_REPL_CLASSLIST_FILE% to %_DOTTY_HOME%\lib\ 1>&2
set _EXITCODE=1
goto :eof
)
if not exist "%_REPL_JSA_FILE%" (
echo %_ERROR_LABEL% Java shared archive %_REPL_JSA_FILE% not found 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_REPL_JSA_FILE%" "%_DOTTY_HOME%\lib\"
copy /y "%_REPL_JSA_FILE%" "%_DOTTY_HOME%\lib\" 1>NUL
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy %_REPL_JSA_FILE% to %_DOTTY_HOME%\lib\ 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 echo %_DEBUG_LABEL% copy /y "%_APP_JAR_FILE%" "%_DOTTY_HOME%\lib\%_CDS_INSTALL_NAME%.jar"
copy /y "%_APP_JAR_FILE%" "%_DOTTY_HOME%\lib\%_CDS_INSTALL_NAME%.jar" 1>NUL
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy %_CDS_INSTALL_NAME%.jar% to %_DOTTY_HOME%\lib\ 1>&2
set _EXITCODE=1
goto :eof
)
goto :eof
:reset
set __N_REMOVED=0
for %%i in (%_COMPILER_NAME%.classlist %_COMPILER_NAME%.jsa %_REPL_NAME%.classlist %_REPL_NAME%.jsa %_CDS_INSTALL_NAME%.jar) do (
if exist "%_DOTTY_HOME%\lib\%%i" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% del "%_DOTTY_HOME%\lib\%%i"
del "%_DOTTY_HOME%\lib\%%i"
set /a __N_REMOVED+=1
)
)
if %_VERBOSE%==1 (
if %__N_REMOVED%==0 ( echo No file to delete in directory %_DOTTY_HOME%\lib
) else ( echo Deleted %__N_REMOVED% files in directory %_DOTTY_HOME%\lib
)
)
goto :eof
rem ##########################################################################
rem ## Cleanups
:end
if %_DEBUG%==1 echo %_DEBUG_LABEL% _EXITCODE=%_EXITCODE%
exit /b %_EXITCODE%
endlocal