forked from lvc/japi-compliance-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
japi-compliance-checker.pl
executable file
·7384 lines (7034 loc) · 269 KB
/
japi-compliance-checker.pl
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
###########################################################################
# Java API Compliance Checker (Java ACC) 1.3.1
# A tool for checking backward compatibility of a Java library API
#
# Copyright (C) 2011 Institute for System Programming, RAS
# Copyright (C) 2011 Russian Linux Verification Center
# Copyright (C) 2011-2012 ROSA Lab
#
# Written by Andrey Ponomarenko
#
# PLATFORMS
# =========
# Linux, FreeBSD, Mac OS X, MS Windows
#
# REQUIREMENTS
# ============
# Linux, FreeBSD, Mac OS X
# - JDK (javap, javac)
# - Perl 5 (5.8 or newer)
#
# MS Windows
# - JDK (javap, javac)
# - Active Perl 5 (5.8 or newer)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License or the GNU Lesser
# General Public License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# and the GNU Lesser General Public License along with this program.
# If not, see <http://www.gnu.org/licenses/>.
###########################################################################
use Getopt::Long;
Getopt::Long::Configure ("posix_default", "no_ignore_case", "permute");
use File::Path qw(mkpath rmtree);
use File::Temp qw(tempdir);
use File::Copy qw(copy);
use Cwd qw(abs_path cwd);
use Data::Dumper;
use Config;
my $TOOL_VERSION = "1.3.1";
my $API_DUMP_VERSION = "1.0";
my $API_DUMP_MAJOR = majorVersion($API_DUMP_VERSION);
my ($Help, $ShowVersion, %Descriptor, $TargetLibraryName, $CheckSeparately,
$GenerateDescriptor, $TestSystem, $DumpAPI, $ClassListPath, $ClientPath,
$StrictCompat, $DumpVersion, $BinaryOnly, $TargetLibraryFullName, $CheckImpl,
%TargetVersion, $SourceOnly, $ShortMode, $KeepInternal, $OutputReportPath,
$BinaryReportPath, $SourceReportPath, $Browse, $Debug, $Quick, $SortDump,
$OpenReport, $SkipDeprecated, $SkipClasses, $ShowAccess);
my $CmdName = get_filename($0);
my $OSgroup = get_OSgroup();
my $ORIG_DIR = cwd();
my $TMP_DIR = tempdir(CLEANUP=>1);
my $MAX_ARGS = ($OSgroup eq "windows")?100:1200;
my %OS_Archive = (
"windows"=>"zip",
"default"=>"tar.gz"
);
my %ERROR_CODE = (
# Compatible verdict
"Compatible"=>0,
"Success"=>0,
# Incompatible verdict
"Incompatible"=>1,
# Undifferentiated error code
"Error"=>2,
# System command is not found
"Not_Found"=>3,
# Cannot access input files
"Access_Error"=>4,
# Invalid input API dump
"Invalid_Dump"=>7,
# Incompatible version of API dump
"Dump_Version"=>8,
# Cannot find a module
"Module_Error"=>9
);
my %HomePage = (
"Wiki"=>"http://ispras.linuxbase.org/index.php/Java_API_Compliance_Checker",
"Dev"=>"https://github.com/lvc/japi-compliance-checker"
);
my $ShortUsage = "Java API Compliance Checker (Java ACC) $TOOL_VERSION
A tool for checking backward compatibility of a Java library API
Copyright (C) 2012 ROSA Lab
License: GNU LGPL or GNU GPL
Usage: $CmdName [options]
Example: $CmdName OLD.jar NEW.jar
More info: $CmdName --help";
if($#ARGV==-1)
{
printMsg("INFO", $ShortUsage);
exit(0);
}
foreach (2 .. $#ARGV)
{ # correct comma separated options
if($ARGV[$_-1] eq ",")
{
$ARGV[$_-2].=",".$ARGV[$_];
splice(@ARGV, $_-1, 2);
}
elsif($ARGV[$_-1]=~/,\Z/)
{
$ARGV[$_-1].=$ARGV[$_];
splice(@ARGV, $_, 1);
}
elsif($ARGV[$_]=~/\A,/
and $ARGV[$_] ne ",")
{
$ARGV[$_-1].=$ARGV[$_];
splice(@ARGV, $_, 1);
}
}
GetOptions("h|help!" => \$Help,
"v|version!" => \$ShowVersion,
"dumpversion!" => \$DumpVersion,
# general options
"l|lib|library=s" => \$TargetLibraryName,
"d1|old|o=s" => \$Descriptor{1}{"Path"},
"d2|new|n=s" => \$Descriptor{2}{"Path"},
# extra options
"client|app=s" => \$ClientPath,
"binary!" => \$BinaryOnly,
"source!" => \$SourceOnly,
"check-impl|check-implementation!" => \$CheckImpl,
"v1|version1=s" => \$TargetVersion{1},
"v2|version2=s" => \$TargetVersion{2},
"s|strict!" => \$StrictCompat,
"keep-internal!" => \$KeepInternal,
"dump|dump-api=s" => \$DumpAPI,
"classes-list=s" => \$ClassListPath,
"skip-deprecated!" => \$SkipDeprecated,
"skip-classes=s" => \$SkipClasses,
"short" => \$ShortMode,
"d|template!" => \$GenerateDescriptor,
"report-path=s" => \$OutputReportPath,
"bin-report-path=s" => \$BinaryReportPath,
"src-report-path=s" => \$SourceReportPath,
"quick!" => \$Quick,
"sort!" => \$SortDump,
"show-access!" => \$ShowAccess,
# other options
"test!" => \$TestSystem,
"debug!" => \$Debug,
"l-full|lib-full=s" => \$TargetLibraryFullName,
"b|browse=s" => \$Browse,
"open!" => \$OpenReport
) or ERR_MESSAGE();
if(@ARGV)
{
if($#ARGV==1)
{ # japi-compliance-checker OLD.jar NEW.jar
$Descriptor{1}{"Path"} = $ARGV[0];
$Descriptor{2}{"Path"} = $ARGV[1];
}
else {
ERR_MESSAGE();
}
}
sub ERR_MESSAGE()
{
printMsg("INFO", "\n".$ShortUsage);
exit($ERROR_CODE{"Error"});
}
my $AR_EXT = getAR_EXT($OSgroup);
my $HelpMessage="
NAME:
Java API Compliance Checker ($CmdName)
Check backward compatibility of a Java library API
DESCRIPTION:
Java API Compliance Checker (Java ACC) is a tool for checking backward
binary/source compatibility of a Java library API. The tool checks classes
declarations of old and new versions and analyzes changes that may break
compatibility: removed class members, added abstract methods, etc. Breakage
of the binary compatibility may result in crashing or incorrect behavior of
existing clients built with an old version of a library if they run with a
new one. Breakage of the source compatibility may result in recompilation
errors with a new library version.
Java ACC is intended for library developers and operating system maintainers
who are interested in ensuring backward compatibility (i.e. allow old clients
to run or to be recompiled with a new version of a library).
This tool is free software: you can redistribute it and/or modify it
under the terms of the GNU LGPL or GNU GPL.
USAGE:
$CmdName [options]
EXAMPLE:
$CmdName OLD.jar NEW.jar
OR
$CmdName -lib NAME -old OLD.xml -new NEW.xml
OLD.xml and NEW.xml are XML-descriptors:
<version>
1.0
</version>
<archives>
/path1/to/JAR(s)/
/path2/to/JAR(s)/
...
</archives>
INFORMATION OPTIONS:
-h|-help
Print this help.
-v|-version
Print version information.
-dumpversion
Print the tool version ($TOOL_VERSION) and don't do anything else.
GENERAL OPTIONS:
-l|-lib|-library NAME
Library name (without version).
-d1|-old|-o PATH
Descriptor of 1st (old) library version.
It may be one of the following:
1. Java ARchive (*.jar)
2. XML-descriptor (VERSION.xml file):
<version>
1.0
</version>
<archives>
/path1/to/JAR(s)/
/path2/to/JAR(s)/
...
</archives>
... (XML-descriptor template
may be generated by -d option)
3. API dump generated by -dump option
4. Directory with Java ARchives
5. Comma separated list of Java ARchives
6. Comma separated list of directories with Java ARchives
If you are using 1, 4-6 descriptor types then you should
specify version numbers with -v1 and -v2 options too.
If you are using *.jar as a descriptor then the tool will try to
get implementation version from MANIFEST.MF file.
-d2|-new|-n PATH
Descriptor of 2nd (new) library version.
EXTRA OPTIONS:
-client|-app PATH
This option allows to specify the client Java ARchive that should be
checked for portability to the new library version.
-binary
Show \"Binary\" compatibility problems only.
Generate report to \"bin_compat_report.html\".
-source
Show \"Source\" compatibility problems only.
Generate report to \"src_compat_report.html\".
-check-impl|-check-implementation
Compare implementation code (method\'s body) of Java classes.
Add \'Problems with Implementation\' section to the report.
-v1|-version1 NUM
Specify 1st API version outside the descriptor. This option is needed
if you have prefered an alternative descriptor type (see -d1 option).
In general case you should specify it in the XML descriptor:
<version>
VERSION
</version>
-v2|-version2 NUM
Specify 2nd library version outside the descriptor.
-s|-strict
Treat all API compatibility warnings as problems.
-dump|-dump-api PATH
Dump library API to gzipped TXT format file. You can transfer it
anywhere and pass instead of the descriptor. Also it may be used
for debugging the tool. Compatible dump versions: $API_DUMP_MAJOR.0<=V<=$API_DUMP_VERSION
-classes-list PATH
This option allows to specify a file with a list
of classes that should be checked, other classes will not be checked.
-skip-deprecated
Skip analysis of deprecated methods and classes.
-skip-classes PATH
This option allows to specify a file with a list
of classes that should not be checked.
-short PATH
Generate short report without 'Added Methods' section.
-d|-template
Create XML descriptor template ./VERSION.xml
-report-path PATH
Path to compatibility report.
Default:
compat_reports/LIB_NAME/V1_to_V2/compat_report.html
-bin-report-path PATH
Path to \"Binary\" compatibility report.
Default:
compat_reports/LIB_NAME/V1_to_V2/bin_compat_report.html
-src-report-path PATH
Path to \"Source\" compatibility report.
Default:
compat_reports/LIB_NAME/V1_to_V2/src_compat_report.html
-quick
Quick analysis.
Disabled:
- analysis of method parameter names
- analysis of class field values
- analysis of usage of added abstract methods
- distinction of deprecated methods and classes
-sort
Enable sorting of data in API dumps.
-show-access
Show access level of non-public methods listed in the report.
OTHER OPTIONS:
-test
Run internal tests. Create two incompatible versions of a sample library
and run the tool to check them for compatibility. This option allows to
check if the tool works correctly in the current environment.
-debug
Debugging mode. Print debug info on the screen. Save intermediate
analysis stages in the debug directory:
debug/LIB_NAME/VER/
Also consider using --dump option for debugging the tool.
-l-full|-lib-full NAME
Change library name in the report title to NAME. By default
will be displayed a name specified by -l option.
-b|-browse PROGRAM
Open report(s) in the browser (firefox, opera, etc.).
-open
Open report(s) in the default browser.
REPORT:
Compatibility report will be generated to:
compat_reports/LIB_NAME/V1_to_V2/compat_report.html
EXIT CODES:
0 - Compatible. The tool has run without any errors.
non-zero - Incompatible or the tool has run with errors.
REPORT BUGS TO:
Andrey Ponomarenko <aponomarenko\@rosalab.ru>
MORE INFORMATION:
".$HomePage{"Wiki"}."
".$HomePage{"Dev"}."\n\n";
sub HELP_MESSAGE()
{ # -help
printMsg("INFO", $HelpMessage."\n");
}
my $Descriptor_Template = "
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<descriptor>
/* Primary sections */
<version>
/* Version of the library */
</version>
<archives>
/* The list of paths to Java ARchives and/or
directories with archives, one per line */
</archives>
/* Optional sections */
<skip_packages>
/* The list of packages, that
should not be checked, one per line */
</skip_packages>
<packages>
/* The list of packages, that
should be checked, one per line.
Other packages will not be checked. */
</packages>
</descriptor>";
my %TypeProblems_Kind=(
"Binary"=>{
"NonAbstract_Class_Added_Abstract_Method"=>"High",
"Abstract_Class_Added_Abstract_Method"=>"Medium",
"Class_Removed_Abstract_Method"=>"High",
"Interface_Added_Abstract_Method"=>"Medium",
"Interface_Removed_Abstract_Method"=>"High",
"Removed_Class"=>"High",
"Removed_Interface"=>"High",
"Class_Method_Became_Abstract"=>"High",
"Class_Method_Became_NonAbstract"=>"Low",
"Added_Super_Class"=>"Low",
"Abstract_Class_Added_Super_Abstract_Class"=>"Medium",
"Removed_Super_Class"=>"Medium",
"Changed_Super_Class"=>"Medium",
"Abstract_Class_Added_Super_Interface"=>"Medium",
"Class_Removed_Super_Interface"=>"High",
"Interface_Added_Super_Interface"=>"Medium",
"Interface_Added_Super_Constant_Interface"=>"Low",
"Interface_Removed_Super_Interface"=>"High",
"Class_Became_Interface"=>"High",
"Interface_Became_Class"=>"High",
"Class_Became_Final"=>"High",
"Class_Became_Abstract"=>"High",
"Class_Added_Field"=>"Safe",
"Interface_Added_Field"=>"Safe",
"Removed_NonConstant_Field"=>"High",
"Removed_Constant_Field"=>"Low",
"Renamed_Field"=>"High",
"Renamed_Constant_Field"=>"Low",
"Changed_Field_Type"=>"High",
"Changed_Field_Access"=>"High",
"Changed_Final_Field_Value"=>"Medium",
"Field_Became_Final"=>"Medium",
"Field_Became_NonFinal"=>"Low",
"NonConstant_Field_Became_Static"=>"High",
"NonConstant_Field_Became_NonStatic"=>"High",
"Class_Overridden_Method"=>"Low",
"Class_Method_Moved_Up_Hierarchy"=>"Low"
},
"Source"=>{
"NonAbstract_Class_Added_Abstract_Method"=>"High",
"Abstract_Class_Added_Abstract_Method"=>"High",
"Interface_Added_Abstract_Method"=>"High",
"Class_Removed_Abstract_Method"=>"High",
"Interface_Removed_Abstract_Method"=>"High",
"Removed_Class"=>"High",
"Removed_Interface"=>"High",
"Class_Method_Became_Abstract"=>"High",
"Added_Super_Class"=>"Low",
"Abstract_Class_Added_Super_Abstract_Class"=>"High",
"Removed_Super_Class"=>"Medium",
"Changed_Super_Class"=>"Medium",
"Abstract_Class_Added_Super_Interface"=>"High",
"Class_Removed_Super_Interface"=>"High",
"Interface_Added_Super_Interface"=>"High",
"Interface_Added_Super_Constant_Interface"=>"Low",
"Interface_Removed_Super_Interface"=>"High",
"Interface_Removed_Super_Constant_Interface"=>"High",
"Class_Became_Interface"=>"High",
"Interface_Became_Class"=>"High",
"Class_Became_Final"=>"High",
"Class_Became_Abstract"=>"High",
"Class_Added_Field"=>"Safe",
"Interface_Added_Field"=>"Safe",
"Removed_NonConstant_Field"=>"High",
"Removed_Constant_Field"=>"High",
"Renamed_Field"=>"High",
"Renamed_Constant_Field"=>"High",
"Changed_Field_Type"=>"High",
"Changed_Field_Access"=>"High",
"Field_Became_Final"=>"Medium",
"Constant_Field_Became_NonStatic"=>"High",
"NonConstant_Field_Became_NonStatic"=>"High"
}
);
my %MethodProblems_Kind=(
"Binary"=>{
"Added_Method"=>"Safe",
"Removed_Method"=>"High",
"Method_Became_Static"=>"High",
"Method_Became_NonStatic"=>"High",
"NonStatic_Method_Became_Final"=>"Medium",
"Changed_Method_Access"=>"High",
"Method_Became_Synchronized"=>"Low",
"Method_Became_NonSynchronized"=>"Low",
"Method_Became_Abstract"=>"High",
"Method_Became_NonAbstract"=>"Low",
"NonAbstract_Method_Added_Checked_Exception"=>"Low",
"NonAbstract_Method_Removed_Checked_Exception"=>"Low",
"Added_Unchecked_Exception"=>"Low",
"Removed_Unchecked_Exception"=>"Low",
"Variable_Arity_To_Array"=>"Low",# not implemented yet
"Changed_Method_Return_From_Void"=>"High"
},
"Source"=>{
"Added_Method"=>"Safe",
"Removed_Method"=>"High",
"Method_Became_Static"=>"Low",
"Method_Became_NonStatic"=>"High",
"Static_Method_Became_Final"=>"Medium",
"NonStatic_Method_Became_Final"=>"Medium",
"Changed_Method_Access"=>"High",
"Method_Became_Abstract"=>"High",
"Abstract_Method_Added_Checked_Exception"=>"Medium",
"NonAbstract_Method_Added_Checked_Exception"=>"Medium",
"Abstract_Method_Removed_Checked_Exception"=>"Medium",
"NonAbstract_Method_Removed_Checked_Exception"=>"Medium"
}
);
my %KnownRuntimeExceptions= map {$_=>1} (
# To separate checked- and unchecked- exceptions
"java.lang.AnnotationTypeMismatchException",
"java.lang.ArithmeticException",
"java.lang.ArrayStoreException",
"java.lang.BufferOverflowException",
"java.lang.BufferUnderflowException",
"java.lang.CannotRedoException",
"java.lang.CannotUndoException",
"java.lang.ClassCastException",
"java.lang.CMMException",
"java.lang.ConcurrentModificationException",
"java.lang.DataBindingException",
"java.lang.DOMException",
"java.lang.EmptyStackException",
"java.lang.EnumConstantNotPresentException",
"java.lang.EventException",
"java.lang.IllegalArgumentException",
"java.lang.IllegalMonitorStateException",
"java.lang.IllegalPathStateException",
"java.lang.IllegalStateException",
"java.lang.ImagingOpException",
"java.lang.IncompleteAnnotationException",
"java.lang.IndexOutOfBoundsException",
"java.lang.JMRuntimeException",
"java.lang.LSException",
"java.lang.MalformedParameterizedTypeException",
"java.lang.MirroredTypeException",
"java.lang.MirroredTypesException",
"java.lang.MissingResourceException",
"java.lang.NegativeArraySizeException",
"java.lang.NoSuchElementException",
"java.lang.NoSuchMechanismException",
"java.lang.NullPointerException",
"java.lang.ProfileDataException",
"java.lang.ProviderException",
"java.lang.RasterFormatException",
"java.lang.RejectedExecutionException",
"java.lang.SecurityException",
"java.lang.SystemException",
"java.lang.TypeConstraintException",
"java.lang.TypeNotPresentException",
"java.lang.UndeclaredThrowableException",
"java.lang.UnknownAnnotationValueException",
"java.lang.UnknownElementException",
"java.lang.UnknownEntityException",
"java.lang.UnknownTypeException",
"java.lang.UnmodifiableSetException",
"java.lang.UnsupportedOperationException",
"java.lang.WebServiceException",
"java.lang.WrongMethodTypeException"
);
my %Slash_Type=(
"default"=>"/",
"windows"=>"\\"
);
my $SLASH = $Slash_Type{$OSgroup}?$Slash_Type{$OSgroup}:$Slash_Type{"default"};
my %OS_AddPath=(
# this data needed if tool can't detect it automatically
"macos"=>{
"bin"=>{"/Developer/usr/bin"=>1}},
"beos"=>{
"bin"=>{"/boot/common/bin"=>1,"/boot/system/bin"=>1,"/boot/develop/abi"=>1}}
);
#Global variables
my %RESULT;
my $ExtractCounter = 0;
my %Cache;
my $TOP_REF = "<a style='font-size:11px;' href='#Top'>to the top</a>";
my %DEBUG_PATH;
#Types
my %TypeInfo;
my $TypeID = 0;
my %CheckedTypes;
my %TName_Tid;
my %Class_Constructed;
#Classes
my %ClassList_User;
my %SkipClass_User;
my %UsedMethods_Client;
my %UsedFields_Client;
my %LibClasses;
my %LibArchives;
my %Class_Methods;
my %Class_AbstractMethods;
my %Class_Fields;
my %MethodInvoked;
my %ClassMethod_AddedInvoked;
my %FieldUsed;
#Methods
my %CheckedMethods;
my %MethodBody;
my %tr_name;
#Merging
my %MethodInfo;
my $Version;
my %AddedMethod_Abstract;
my %RemovedMethod_Abstract;
my %ChangedReturnFromVoid;
my %SkipPackages;
my %KeepPackages;
#Report
my %Type_MaxPriority;
#Recursion locks
my @RecurSymlink;
my @RecurTypes;
#System
my %SystemPaths;
my %DefaultBinPaths;
#Problem descriptions
my %CompatProblems;
my %ImplProblems;
my %TotalAffected;
#Rerort
my $ContentID = 1;
my $ContentSpanStart = "<span class=\"section\" onclick=\"javascript:showContent(this, 'CONTENT_ID')\">\n";
my $ContentSpanStart_Affected = "<span class=\"section_affected\" onclick=\"javascript:showContent(this, 'CONTENT_ID')\">\n";
my $ContentSpanEnd = "</span>\n";
my $ContentDivStart = "<div id=\"CONTENT_ID\" style=\"display:none;\">\n";
my $ContentDivEnd = "</div>\n";
my $Content_Counter = 0;
#Modes
my $JoinReport = 1;
my $DoubleReport = 0;
sub get_CmdPath($)
{
my $Name = $_[0];
return "" if(not $Name);
if(defined $Cache{"get_CmdPath"}{$Name}) {
return $Cache{"get_CmdPath"}{$Name};
}
my $Path = search_Cmd($Name);
if(not $Path and $OSgroup eq "windows")
{ # search for *.exe file
$Path=search_Cmd($Name.".exe");
}
if($Path=~/\s/) {
$Path = "\"".$Path."\"";
}
return ($Cache{"get_CmdPath"}{$Name} = $Path);
}
sub search_Cmd($)
{
my $Name = $_[0];
return "" if(not $Name);
if(defined $Cache{"search_Cmd"}{$Name}) {
return $Cache{"search_Cmd"}{$Name};
}
if(my $DefaultPath = get_CmdPath_Default($Name)) {
return ($Cache{"search_Cmd"}{$Name} = $DefaultPath);
}
foreach my $Path (sort {length($a)<=>length($b)} keys(%{$SystemPaths{"bin"}}))
{
if(-f $Path."/".$Name or -f $Path."/".$Name.".exe") {
return ($Cache{"search_Cmd"}{$Name} = joinPath($Path,$Name));
}
}
return ($Cache{"search_Cmd"}{$Name} = "");
}
sub get_CmdPath_Default($)
{ # search in PATH
return "" if(not $_[0]);
if(defined $Cache{"get_CmdPath_Default"}{$_[0]}) {
return $Cache{"get_CmdPath_Default"}{$_[0]};
}
return ($Cache{"get_CmdPath_Default"}{$_[0]} = get_CmdPath_Default_I($_[0]));
}
sub get_CmdPath_Default_I($)
{ # search in PATH
my $Name = $_[0];
if($Name=~/find/)
{ # special case: search for "find" utility
if(`find \"$TMP_DIR\" -maxdepth 0 2>\"$TMP_DIR/null\"`) {
return "find";
}
}
if(get_version($Name)) {
return $Name;
}
if($OSgroup eq "windows")
{
if(`$Name /? 2>\"$TMP_DIR/null\"`) {
return $Name;
}
}
if($Name!~/which/)
{
if(my $WhichCmd = get_CmdPath("which"))
{
if(`$WhichCmd $Name 2>\"$TMP_DIR/null\"`) {
return $Name;
}
}
}
foreach my $Path (sort {length($a)<=>length($b)} keys(%DefaultBinPaths))
{
if(-f $Path."/".$Name) {
return joinPath($Path,$Name);
}
}
return "";
}
sub showPos($)
{
my $Number = $_[0];
if(not $Number) {
$Number = 1;
}
else {
$Number = int($Number)+1;
}
if($Number>3) {
return $Number."th";
}
elsif($Number==1) {
return "1st";
}
elsif($Number==2) {
return "2nd";
}
elsif($Number==3) {
return "3rd";
}
else {
return $Number;
}
}
sub getAR_EXT($)
{
my $Target = $_[0];
if(my $Ext = $OS_Archive{$Target}) {
return $Ext;
}
return $OS_Archive{"default"};
}
sub readDescriptor($$)
{
my ($LibVersion, $Content) = @_;
return if(not $LibVersion);
my $DName = $DumpAPI?"descriptor":"descriptor \"d$LibVersion\"";
if(not $Content) {
exitStatus("Error", "$DName is empty");
}
if($Content!~/\</) {
exitStatus("Error", "descriptor should be one of the following:\n Java ARchive, XML descriptor, gzipped API dump or directory with Java ARchives.");
}
$Content=~s/\/\*(.|\n)+?\*\///g;
$Content=~s/<\!--(.|\n)+?-->//g;
$Descriptor{$LibVersion}{"Version"} = parseTag(\$Content, "version");
$Descriptor{$LibVersion}{"Version"} = $TargetVersion{$LibVersion} if($TargetVersion{$LibVersion});
if(not $Descriptor{$LibVersion}{"Version"}) {
exitStatus("Error", "version in the $DName is not specified (<version> section)");
}
my $DArchives = parseTag(\$Content, "archives");
if(not $DArchives){
exitStatus("Error", "Java ARchives in the $DName are not specified (<archive> section)");
}
else
{# append the descriptor Java ARchives list
if($Descriptor{$LibVersion}{"Archives"}) {
$Descriptor{$LibVersion}{"Archives"} .= "\n".$DArchives;
}
else {
$Descriptor{$LibVersion}{"Archives"} = $DArchives;
}
foreach my $Path (split(/\s*\n\s*/, $DArchives))
{
if(not -e $Path) {
exitStatus("Access_Error", "can't access \'$Path\'");
}
}
}
foreach my $Package (split(/\s*\n\s*/, parseTag(\$Content, "skip_packages"))) {
$SkipPackages{$LibVersion}{$Package} = 1;
}
foreach my $Package (split(/\s*\n\s*/, parseTag(\$Content, "packages"))) {
$KeepPackages{$LibVersion}{$Package} = 1;
}
}
sub parseTag($$)
{
my ($CodeRef, $Tag) = @_;
return "" if(not $CodeRef or not ${$CodeRef} or not $Tag);
if(${$CodeRef}=~s/\<\Q$Tag\E\>((.|\n)+?)\<\/\Q$Tag\E\>//)
{
my $Content = $1;
$Content=~s/(\A\s+|\s+\Z)//g;
return $Content;
}
else {
return "";
}
}
sub ignore_path($$)
{
my ($Path, $Prefix) = @_;
return 1 if(not $Path or not -e $Path
or not $Prefix or not -e $Prefix);
return 1 if($Path=~/\~\Z/);# skipping system backup files
# skipping hidden .svn, .git, .bzr, .hg and CVS directories
return 1 if(cut_path_prefix($Path, $Prefix)=~/(\A|[\/\\]+)(\.(svn|git|bzr|hg)|CVS)([\/\\]+|\Z)/);
return 0;
}
sub cut_path_prefix($$)
{
my ($Path, $Prefix) = @_;
$Prefix=~s/[\/\\]+\Z//;
$Path=~s/\A\Q$Prefix\E([\/\\]+|\Z)//;
return $Path;
}
sub get_filename($)
{ # much faster than basename() from File::Basename module
if(defined $Cache{"get_filename"}{$_[0]}) {
return $Cache{"get_filename"}{$_[0]};
}
if($_[0] and $_[0]=~/([^\/\\]+)[\/\\]*\Z/) {
return ($Cache{"get_filename"}{$_[0]}=$1);
}
return ($Cache{"get_filename"}{$_[0]}="");
}
sub get_dirname($)
{ # much faster than dirname() from File::Basename module
if(defined $Cache{"get_dirname"}{$_[0]}) {
return $Cache{"get_dirname"}{$_[0]};
}
if($_[0] and $_[0]=~/\A(.*?)[\/\\]+[^\/\\]*[\/\\]*\Z/) {
return ($Cache{"get_dirname"}{$_[0]}=$1);
}
return ($Cache{"get_dirname"}{$_[0]}="");
}
sub separate_path($) {
return (get_dirname($_[0]), get_filename($_[0]));
}
sub esc($)
{
my $Str = $_[0];
$Str=~s/([()\[\]{}$ &'"`;,<>\+])/\\$1/g;
return $Str;
}
sub get_Signature($$$)
{
my ($Method, $LibVersion, $Kind) = @_;
if(defined $Cache{"get_Signature"}{$LibVersion}{$Method}{$Kind}) {
return $Cache{"get_Signature"}{$LibVersion}{$Method}{$Kind};
}
my $Signature = $MethodInfo{$LibVersion}{$Method}{"ShortName"};
if($Kind eq "Full") {
$Signature = get_TypeName($MethodInfo{$LibVersion}{$Method}{"Class"}, $LibVersion).".".$Signature;
}
my @Params = ();
foreach my $PPos (sort {int($a)<=>int($b)}
keys(%{$MethodInfo{$LibVersion}{$Method}{"Param"}}))
{
my $PTid = $MethodInfo{$LibVersion}{$Method}{"Param"}{$PPos}{"Type"};
if(my $PTName = get_TypeName($PTid, $LibVersion))
{
if($Kind eq "Full")
{
my $PName = $MethodInfo{$LibVersion}{$Method}{"Param"}{$PPos}{"Name"};
push(@Params, $PTName." ".$PName);
}
else {
push(@Params, $PTName);
}
}
}
$Signature .= "(".join(", ", @Params).")";
if($Kind eq "Full")
{
if($MethodInfo{$LibVersion}{$Method}{"Static"}) {
$Signature .= " [static]";
}
elsif($MethodInfo{$LibVersion}{$Method}{"Abstract"}) {
$Signature .= " [abstract]";
}
if($ShowAccess)
{
if(my $Access = $MethodInfo{$LibVersion}{$Method}{"Access"})
{
if($Access ne "public") {
$Signature .= " [".$Access."]";
}
}
}
if(my $ReturnId = $MethodInfo{$LibVersion}{$Method}{"Return"}) {
$Signature .= " :".get_TypeName($ReturnId, $LibVersion);
}
$Signature=~s/java\.lang\.//g;
}
$Cache{"get_Signature"}{$LibVersion}{$Method}{$Kind} = $Signature;
return $Cache{"get_Signature"}{$LibVersion}{$Method}{$Kind};
}
sub joinPath($$)
{
return join($SLASH, @_);
}
sub get_abs_path($)
{ # abs_path() should NOT be called for absolute inputs
# because it can change them
my $Path = $_[0];
if(not is_abs($Path)) {
$Path = abs_path($Path);
}
return $Path;
}
sub is_abs($) {
return ($_[0]=~/\A(\/|\w+:[\/\\])/);
}
sub cmd_find($$$$)
{
my ($Path, $Type, $Name, $MaxDepth) = @_;
return () if(not $Path or not -e $Path);
if($OSgroup eq "windows")
{
my $DirCmd = get_CmdPath("dir");
if(not $DirCmd) {
exitStatus("Not_Found", "can't find \"dir\" command");
}
$Path=~s/[\\]+\Z//;
$Path = get_abs_path($Path);
my $Cmd = $DirCmd." \"$Path\" /B /O";
if($MaxDepth!=1) {