source: josm/trunk/tools/japicc/modules/Internals/RegTests.pm @ 12016

Last change on this file since 12016 was 11682, checked in by Don-vip, 3 years ago

update to japi-compliance-checker 2.1

File size: 52.8 KB
Line 
1###########################################################################
2# A module with regression test suite
3#
4# Copyright (C) 2016-2017 Andrey Ponomarenko's ABI Laboratory
5#
6# Written by Andrey Ponomarenko
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License or the GNU Lesser
10# General Public License as published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# and the GNU Lesser General Public License along with this program.
19# If not, see <http://www.gnu.org/licenses/>.
20###########################################################################
21use strict;
22use File::Copy qw(copy);
23
24sub testTool()
25{
26    printMsg("INFO", "\nVerifying detectable Java library changes");
27   
28    printMsg("INFO", "Creating test library ...");
29    my $LibName = "libsample_java";
30    if(-d $LibName) {
31        rmtree($LibName);
32    }
33   
34    my $PackageName = "TestPackage";
35    my $Path_v1 = "$LibName/$PackageName.v1/$PackageName";
36    mkpath($Path_v1);
37   
38    my $Path_v2 = "$LibName/$PackageName.v2/$PackageName";
39    mkpath($Path_v2);
40   
41    my $TestsPath = "$LibName/Tests";
42    mkpath($TestsPath);
43   
44    # FirstCheckedException
45    my $FirstCheckedException = "package $PackageName;
46    public class FirstCheckedException extends Exception {
47    }";
48    writeFile($Path_v1."/FirstCheckedException.java", $FirstCheckedException);
49    writeFile($Path_v2."/FirstCheckedException.java", $FirstCheckedException);
50   
51    # SecondCheckedException
52    my $SecondCheckedException = "package $PackageName;
53    public class SecondCheckedException extends Exception {
54    }";
55    writeFile($Path_v1."/SecondCheckedException.java", $SecondCheckedException);
56    writeFile($Path_v2."/SecondCheckedException.java", $SecondCheckedException);
57   
58    # FirstUncheckedException
59    my $FirstUncheckedException = "package $PackageName;
60    public class FirstUncheckedException extends RuntimeException {
61    }";
62    writeFile($Path_v1."/FirstUncheckedException.java", $FirstUncheckedException);
63    writeFile($Path_v2."/FirstUncheckedException.java", $FirstUncheckedException);
64   
65    # SecondUncheckedException
66    my $SecondUncheckedException = "package $PackageName;
67    public class SecondUncheckedException extends RuntimeException {
68    }";
69    writeFile($Path_v1."/SecondUncheckedException.java", $SecondUncheckedException);
70    writeFile($Path_v2."/SecondUncheckedException.java", $SecondUncheckedException);
71   
72    # BaseAbstractClass
73    my $BaseAbstractClass = "package $PackageName;
74    public abstract class BaseAbstractClass {
75        public Integer field;
76        public Integer someMethod(Integer param) { return param; }
77        public abstract Integer abstractMethod(Integer param);
78    }";
79    writeFile($Path_v1."/BaseAbstractClass.java", $BaseAbstractClass);
80    writeFile($Path_v2."/BaseAbstractClass.java", $BaseAbstractClass);
81   
82    # Removed_Annotation
83    writeFile($Path_v1."/RemovedAnnotation.java",
84    "package $PackageName;
85    public \@interface RemovedAnnotation {
86    }");
87   
88    # Beta Annotation
89    writeFile($Path_v1."/Beta.java",
90    "package $PackageName;
91    public \@interface Beta {
92    }");
93   
94    writeFile($Path_v2."/Beta.java",
95    "package $PackageName;
96    public \@interface Beta {
97    }");
98   
99    # BaseClass
100    my $BaseClass = "package $PackageName;
101    public class BaseClass {
102        public Integer field;
103        public Integer method(Integer param) { return param; }
104    }";
105    writeFile($Path_v1."/BaseClass.java", $BaseClass);
106    writeFile($Path_v2."/BaseClass.java", $BaseClass);
107   
108    # BaseClass2
109    my $BaseClass2 = "package $PackageName;
110    public class BaseClass2 {
111        public Integer field2;
112        public Integer method2(Integer param) { return param; }
113    }";
114    writeFile($Path_v1."/BaseClass2.java", $BaseClass2);
115    writeFile($Path_v2."/BaseClass2.java", $BaseClass2);
116   
117    # BaseInterface
118    my $BaseInterface = "package $PackageName;
119    public interface BaseInterface {
120        public Integer field = 100;
121        public Integer method(Integer param);
122    }";
123    writeFile($Path_v1."/BaseInterface.java", $BaseInterface);
124    writeFile($Path_v2."/BaseInterface.java", $BaseInterface);
125   
126    # BaseInterface2
127    my $BaseInterface2 = "package $PackageName;
128    public interface BaseInterface2 {
129        public Integer field2 = 100;
130        public Integer method2(Integer param);
131    }";
132    writeFile($Path_v1."/BaseInterface2.java", $BaseInterface2);
133    writeFile($Path_v2."/BaseInterface2.java", $BaseInterface2);
134   
135    # BaseConstantInterface
136    my $BaseConstantInterface = "package $PackageName;
137    public interface BaseConstantInterface {
138        public Integer CONSTANT = 10;
139        public Integer CONSTANT2 = 100;
140    }";
141    writeFile($Path_v1."/BaseConstantInterface.java", $BaseConstantInterface);
142    writeFile($Path_v2."/BaseConstantInterface.java", $BaseConstantInterface);
143   
144    # Removed_Method (Beta method)
145    writeFile($Path_v1."/RemovedBetaMethod.java",
146    "package $PackageName;
147    public class RemovedBetaMethod
148    {
149        \@Beta
150        public Integer someMethod() {
151            return 0;
152        }
153    }");
154    writeFile($Path_v2."/RemovedBetaMethod.java",
155    "package $PackageName;
156    public class RemovedBetaMethod {
157    }");
158   
159    # Removed_Method (from Beta class)
160    writeFile($Path_v1."/RemovedMethodFromBetaClass.java",
161    "package $PackageName;
162    \@Beta
163    public class RemovedMethodFromBetaClass
164    {
165        public Integer someMethod() {
166            return 0;
167        }
168    }");
169    writeFile($Path_v2."/RemovedMethodFromBetaClass.java",
170    "package $PackageName;
171    \@Beta
172    public class RemovedMethodFromBetaClass {
173    }");
174   
175    # Removed_Class (Beta)
176    writeFile($Path_v1."/RemovedBetaClass.java",
177    "package $PackageName;
178    \@Beta
179    public class RemovedBetaClass
180    {
181        public Integer someMethod() {
182            return 0;
183        }
184    }");
185   
186    # Abstract_Method_Added_Checked_Exception
187    writeFile($Path_v1."/AbstractMethodAddedCheckedException.java",
188    "package $PackageName;
189    public abstract class AbstractMethodAddedCheckedException {
190        public abstract Integer someMethod() throws FirstCheckedException;
191    }");
192    writeFile($Path_v2."/AbstractMethodAddedCheckedException.java",
193    "package $PackageName;
194    public abstract class AbstractMethodAddedCheckedException {
195        public abstract Integer someMethod() throws FirstCheckedException, SecondCheckedException;
196    }");
197   
198    # Abstract_Method_Removed_Checked_Exception
199    writeFile($Path_v1."/AbstractMethodRemovedCheckedException.java",
200    "package $PackageName;
201    public abstract class AbstractMethodRemovedCheckedException {
202        public abstract Integer someMethod() throws FirstCheckedException, SecondCheckedException;
203    }");
204    writeFile($Path_v2."/AbstractMethodRemovedCheckedException.java",
205    "package $PackageName;
206    public abstract class AbstractMethodRemovedCheckedException {
207        public abstract Integer someMethod() throws FirstCheckedException;
208    }");
209   
210    # NonAbstract_Method_Added_Checked_Exception
211    writeFile($Path_v1."/NonAbstractMethodAddedCheckedException.java",
212    "package $PackageName;
213    public class NonAbstractMethodAddedCheckedException {
214        public Integer someMethod() throws FirstCheckedException {
215            return 10;
216        }
217    }");
218    writeFile($Path_v2."/NonAbstractMethodAddedCheckedException.java",
219    "package $PackageName;
220    public class NonAbstractMethodAddedCheckedException {
221        public Integer someMethod() throws FirstCheckedException, SecondCheckedException {
222            return 10;
223        }
224    }");
225   
226    # NonAbstract_Method_Removed_Checked_Exception
227    writeFile($Path_v1."/NonAbstractMethodRemovedCheckedException.java",
228    "package $PackageName;
229    public class NonAbstractMethodRemovedCheckedException {
230        public Integer someMethod() throws FirstCheckedException, SecondCheckedException {
231            return 10;
232        }
233    }");
234    writeFile($Path_v2."/NonAbstractMethodRemovedCheckedException.java",
235    "package $PackageName;
236    public class NonAbstractMethodRemovedCheckedException {
237        public Integer someMethod() throws FirstCheckedException {
238            return 10;
239        }
240    }");
241   
242    # Added_Unchecked_Exception
243    writeFile($Path_v1."/AddedUncheckedException.java",
244    "package $PackageName;
245    public class AddedUncheckedException {
246        public Integer someMethod() throws FirstUncheckedException {
247            return 10;
248        }
249    }");
250    writeFile($Path_v2."/AddedUncheckedException.java",
251    "package $PackageName;
252    public class AddedUncheckedException {
253        public Integer someMethod() throws FirstUncheckedException, SecondUncheckedException, NullPointerException {
254            return 10;
255        }
256    }");
257   
258    # Removed_Unchecked_Exception
259    writeFile($Path_v1."/RemovedUncheckedException.java",
260    "package $PackageName;
261    public class RemovedUncheckedException {
262        public Integer someMethod() throws FirstUncheckedException, SecondUncheckedException, NullPointerException {
263            return 10;
264        }
265    }");
266    writeFile($Path_v2."/RemovedUncheckedException.java",
267    "package $PackageName;
268    public class RemovedUncheckedException {
269        public Integer someMethod() throws FirstUncheckedException {
270            return 10;
271        }
272    }");
273   
274    # Changed_Method_Return_From_Void
275    writeFile($Path_v1."/ChangedMethodReturnFromVoid.java",
276    "package $PackageName;
277    public class ChangedMethodReturnFromVoid {
278        public void changedMethod(Integer param1, String[] param2) { }
279    }");
280    writeFile($Path_v2."/ChangedMethodReturnFromVoid.java",
281    "package $PackageName;
282    public class ChangedMethodReturnFromVoid {
283        public Integer changedMethod(Integer param1, String[] param2){
284            return param1;
285        }
286    }");
287   
288    # Added_Method
289    writeFile($Path_v1."/AddedMethod.java",
290    "package $PackageName;
291    public class AddedMethod {
292        public Integer field = 100;
293    }");
294    writeFile($Path_v2."/AddedMethod.java",
295    "package $PackageName;
296    public class AddedMethod {
297        public Integer field = 100;
298        public Integer addedMethod(Integer param1, String[] param2) { return param1; }
299        public static String[] addedStaticMethod(String[] param) { return param; }
300    }");
301   
302    # Added_Method (Constructor)
303    writeFile($Path_v1."/AddedConstructor.java",
304    "package $PackageName;
305    public class AddedConstructor {
306        public Integer field = 100;
307    }");
308    writeFile($Path_v2."/AddedConstructor.java",
309    "package $PackageName;
310    public class AddedConstructor {
311        public Integer field = 100;
312        public AddedConstructor() { }
313        public AddedConstructor(Integer x, String y) { }
314    }");
315   
316    # Class_Added_Field
317    writeFile($Path_v1."/ClassAddedField.java",
318    "package $PackageName;
319    public class ClassAddedField {
320        public Integer otherField;
321    }");
322    writeFile($Path_v2."/ClassAddedField.java",
323    "package $PackageName;
324    public class ClassAddedField {
325        public Integer addedField;
326        public Integer otherField;
327    }");
328   
329    # Interface_Added_Field
330    writeFile($Path_v1."/InterfaceAddedField.java",
331    "package $PackageName;
332    public interface InterfaceAddedField {
333        public Integer method();
334    }");
335    writeFile($Path_v2."/InterfaceAddedField.java",
336    "package $PackageName;
337    public interface InterfaceAddedField {
338        public Integer addedField = 100;
339        public Integer method();
340    }");
341   
342    # Removed_NonConstant_Field (Class)
343    writeFile($Path_v1."/ClassRemovedField.java",
344    "package $PackageName;
345    public class ClassRemovedField {
346        public Integer removedField;
347        public Integer otherField;
348    }");
349    writeFile($Path_v2."/ClassRemovedField.java",
350    "package $PackageName;
351    public class ClassRemovedField {
352        public Integer otherField;
353    }");
354   
355    writeFile($TestsPath."/Test_ClassRemovedField.java",
356    "import $PackageName.*;
357    public class Test_ClassRemovedField {
358        public static void main(String[] args) {
359            ClassRemovedField X = new ClassRemovedField();
360            Integer Copy = X.removedField;
361        }
362    }");
363   
364    writeFile($TestsPath."/Test_RemovedAnnotation.java",
365    "import $PackageName.*;
366    public class Test_RemovedAnnotation {
367        public static void main(String[] args) {
368            testMethod();
369        }
370       
371        \@RemovedAnnotation
372        static void testMethod() {
373        }
374    }");
375   
376    # Removed_Constant_Field (Interface)
377    writeFile($Path_v1."/InterfaceRemovedConstantField.java",
378    "package $PackageName;
379    public interface InterfaceRemovedConstantField {
380        public String someMethod();
381        public int removedField_Int = 1000;
382        public String removedField_Str = \"Value\";
383    }");
384    writeFile($Path_v2."/InterfaceRemovedConstantField.java",
385    "package $PackageName;
386    public interface InterfaceRemovedConstantField {
387        public String someMethod();
388    }");
389   
390    # Removed_NonConstant_Field (Interface)
391    writeFile($Path_v1."/InterfaceRemovedField.java",
392    "package $PackageName;
393    public interface InterfaceRemovedField {
394        public String someMethod();
395        public BaseClass removedField = new BaseClass();
396    }");
397    writeFile($Path_v2."/InterfaceRemovedField.java",
398    "package $PackageName;
399    public interface InterfaceRemovedField {
400        public String someMethod();
401    }");
402   
403    # Renamed_Field
404    writeFile($Path_v1."/RenamedField.java",
405    "package $PackageName;
406    public class RenamedField {
407        public String oldName;
408    }");
409    writeFile($Path_v2."/RenamedField.java",
410    "package $PackageName;
411    public class RenamedField {
412        public String newName;
413    }");
414   
415    # Renamed_Constant_Field
416    writeFile($Path_v1."/RenamedConstantField.java",
417    "package $PackageName;
418    public class RenamedConstantField {
419        public final String oldName = \"Value\";
420    }");
421    writeFile($Path_v2."/RenamedConstantField.java",
422    "package $PackageName;
423    public class RenamedConstantField {
424        public final String newName = \"Value\";
425    }");
426   
427    # Changed_Field_Type
428    writeFile($Path_v1."/ChangedFieldType.java",
429    "package $PackageName;
430    public class ChangedFieldType {
431        public String fieldName;
432    }");
433    writeFile($Path_v2."/ChangedFieldType.java",
434    "package $PackageName;
435    public class ChangedFieldType {
436        public Integer fieldName;
437    }");
438   
439    # Changed_Field_Access
440    writeFile($Path_v1."/ChangedFieldAccess.java",
441    "package $PackageName;
442    public class ChangedFieldAccess {
443        public String fieldName;
444    }");
445    writeFile($Path_v2."/ChangedFieldAccess.java",
446    "package $PackageName;
447    public class ChangedFieldAccess {
448        private String fieldName;
449    }");
450   
451    # Changed_Final_Field_Value
452    writeFile($Path_v1."/ChangedFinalFieldValue.java",
453    "package $PackageName;
454    public class ChangedFinalFieldValue {
455        public final int field = 1;
456        public final String field2 = \" \";
457    }");
458    writeFile($Path_v2."/ChangedFinalFieldValue.java",
459    "package $PackageName;
460    public class ChangedFinalFieldValue {
461        public final int field = 2;
462        public final String field2 = \"newValue\";
463    }");
464   
465    # NonConstant_Field_Became_Static
466    writeFile($Path_v1."/NonConstantFieldBecameStatic.java",
467    "package $PackageName;
468    public class NonConstantFieldBecameStatic {
469        public String fieldName;
470    }");
471    writeFile($Path_v2."/NonConstantFieldBecameStatic.java",
472    "package $PackageName;
473    public class NonConstantFieldBecameStatic {
474        public static String fieldName;
475    }");
476   
477    # NonConstant_Field_Became_NonStatic
478    writeFile($Path_v1."/NonConstantFieldBecameNonStatic.java",
479    "package $PackageName;
480    public class NonConstantFieldBecameNonStatic {
481        public static String fieldName;
482    }");
483    writeFile($Path_v2."/NonConstantFieldBecameNonStatic.java",
484    "package $PackageName;
485    public class NonConstantFieldBecameNonStatic {
486        public String fieldName;
487    }");
488   
489    # Constant_Field_Became_NonStatic
490    writeFile($Path_v1."/ConstantFieldBecameNonStatic.java",
491    "package $PackageName;
492    public class ConstantFieldBecameNonStatic {
493        public final static String fieldName = \"Value\";
494    }");
495    writeFile($Path_v2."/ConstantFieldBecameNonStatic.java",
496    "package $PackageName;
497    public class ConstantFieldBecameNonStatic {
498        public final String fieldName = \"Value\";
499    }");
500   
501    # Field_Became_Final
502    writeFile($Path_v1."/FieldBecameFinal.java",
503    "package $PackageName;
504    public class FieldBecameFinal {
505        public String fieldName;
506    }");
507    writeFile($Path_v2."/FieldBecameFinal.java",
508    "package $PackageName;
509    public class FieldBecameFinal {
510        public final String fieldName = \"Value\";
511    }");
512   
513    # Field_Became_NonFinal
514    writeFile($Path_v1."/FieldBecameNonFinal.java",
515    "package $PackageName;
516    public class FieldBecameNonFinal {
517        public final String fieldName = \"Value\";
518    }");
519    writeFile($Path_v2."/FieldBecameNonFinal.java",
520    "package $PackageName;
521    public class FieldBecameNonFinal {
522        public String fieldName;
523    }");
524   
525    # Removed_Method
526    writeFile($Path_v1."/RemovedMethod.java",
527    "package $PackageName;
528    public class RemovedMethod {
529        public Integer field = 100;
530        public Integer removedMethod(Integer param1, String param2) { return param1; }
531        public static Integer removedStaticMethod(Integer param) { return param; }
532    }");
533    writeFile($Path_v2."/RemovedMethod.java",
534    "package $PackageName;
535    public class RemovedMethod {
536        public Integer field = 100;
537    }");
538   
539    # Removed_Method (move up to java.lang.Object)
540    writeFile($Path_v1."/MoveUpToJavaLangObject.java",
541    "package $PackageName;
542    public class MoveUpToJavaLangObject extends java.lang.Object {
543        public int hashCode() { return 0; }
544    }");
545    writeFile($Path_v2."/MoveUpToJavaLangObject.java",
546    "package $PackageName;
547    public class MoveUpToJavaLangObject extends java.lang.Object {
548    }");
549   
550    writeFile($TestsPath."/Test_MoveUpToJavaLangObject.java",
551    "import $PackageName.*;
552    public class Test_MoveUpToJavaLangObject {
553        public static void main(String[] args) {
554            MoveUpToJavaLangObject X = new MoveUpToJavaLangObject();
555            int R = X.hashCode();
556        }
557    }");
558   
559    # Removed_Method (Deprecated)
560    writeFile($Path_v1."/RemovedDeprecatedMethod.java",
561    "package $PackageName;
562    public class RemovedDeprecatedMethod {
563        public Integer field = 100;
564        public Integer otherMethod(Integer param) { return param; }
565        \@Deprecated
566        public Integer removedMethod(Integer param1, String param2) { return param1; }
567    }");
568    writeFile($Path_v2."/RemovedDeprecatedMethod.java",
569    "package $PackageName;
570    public class RemovedDeprecatedMethod {
571        public Integer field = 100;
572        public Integer otherMethod(Integer param) { return param; }
573    }");
574   
575    # Interface_Removed_Abstract_Method
576    writeFile($Path_v1."/InterfaceRemovedAbstractMethod.java",
577    "package $PackageName;
578    public interface InterfaceRemovedAbstractMethod extends BaseInterface, BaseInterface2 {
579        public void removedMethod(Integer param1, java.io.ObjectOutput param2);
580        public void someMethod(Integer param);
581    }");
582    writeFile($Path_v2."/InterfaceRemovedAbstractMethod.java",
583    "package $PackageName;
584    public interface InterfaceRemovedAbstractMethod extends BaseInterface, BaseInterface2 {
585        public void someMethod(Integer param);
586    }");
587   
588    # Interface_Added_Abstract_Method
589    writeFile($Path_v1."/InterfaceAddedAbstractMethod.java",
590    "package $PackageName;
591    public interface InterfaceAddedAbstractMethod extends BaseInterface, BaseInterface2 {
592        public void someMethod(Integer param);
593    }");
594    writeFile($Path_v2."/InterfaceAddedAbstractMethod.java",
595    "package $PackageName;
596    public interface InterfaceAddedAbstractMethod extends BaseInterface, BaseInterface2 {
597        public void someMethod(Integer param);
598        public Integer addedMethod(Integer param);
599    }");
600   
601    # Interface_Added_Default_Method
602    writeFile($Path_v1."/InterfaceAddedDefaultMethod.java",
603    "package $PackageName;
604    public interface InterfaceAddedDefaultMethod {
605        public void someMethod(Integer param);
606    }");
607    writeFile($Path_v2."/InterfaceAddedDefaultMethod.java",
608    "package $PackageName;
609    public interface InterfaceAddedDefaultMethod {
610        public void someMethod(Integer param);
611        default Integer addedMethod(Integer param) { return 0; }
612    }");
613   
614    # Method_Became_NonDefault
615    writeFile($Path_v1."/MethodBecameNonDefault.java",
616    "package $PackageName;
617    public interface MethodBecameNonDefault {
618        default Integer someMethod(Integer param) { return 0; }
619    }");
620    writeFile($Path_v2."/MethodBecameNonDefault.java",
621    "package $PackageName;
622    public interface MethodBecameNonDefault {
623        public Integer someMethod(Integer param);
624    }");
625   
626    writeFile($TestsPath."/Test_MethodBecameNonDefault.java",
627    "import $PackageName.*;
628    class Class_MethodBecameNonDefault implements MethodBecameNonDefault {
629    };
630   
631    public class Test_MethodBecameNonDefault
632    {
633        public static void main(String[] args)
634        {
635            Class_MethodBecameNonDefault Obj = new Class_MethodBecameNonDefault();
636            Integer Res = Obj.someMethod(0);
637        }
638    }");
639   
640    # Variable_Arity_To_Array
641    writeFile($Path_v1."/VariableArityToArray.java",
642    "package $PackageName;
643    public class VariableArityToArray {
644        public void someMethod(Integer x, String... y) { };
645    }");
646    writeFile($Path_v2."/VariableArityToArray.java",
647    "package $PackageName;
648    public class VariableArityToArray {
649        public void someMethod(Integer x, String[] y) { };
650    }");
651   
652    # Class_Became_Interface
653    writeFile($Path_v1."/ClassBecameInterface.java",
654    "package $PackageName;
655    public class ClassBecameInterface extends BaseClass {
656        public Integer someMethod(Integer param) {
657            return param;
658        }
659    }");
660    writeFile($Path_v2."/ClassBecameInterface.java",
661    "package $PackageName;
662    public interface ClassBecameInterface extends BaseInterface, BaseInterface2 {
663        public Integer someMethod(Integer param);
664    }");
665   
666    # Added_Super_Class
667    writeFile($Path_v1."/AddedSuperClass.java",
668    "package $PackageName;
669    public class AddedSuperClass {
670        public Integer someMethod(Integer param) {
671            return param;
672        }
673    }");
674    writeFile($Path_v2."/AddedSuperClass.java",
675    "package $PackageName;
676    public class AddedSuperClass extends BaseClass {
677        public Integer someMethod(Integer param) {
678            return param;
679        }
680    }");
681   
682    # Abstract_Class_Added_Super_Abstract_Class
683    writeFile($Path_v1."/AbstractClassAddedSuperAbstractClass.java",
684    "package $PackageName;
685    public abstract class AbstractClassAddedSuperAbstractClass {
686        public Integer someMethod(Integer param) {
687            return param;
688        }
689    }");
690    writeFile($Path_v2."/AbstractClassAddedSuperAbstractClass.java",
691    "package $PackageName;
692    public abstract class AbstractClassAddedSuperAbstractClass extends BaseAbstractClass {
693        public Integer someMethod(Integer param) {
694            return param;
695        }
696    }");
697   
698    # Removed_Super_Class
699    writeFile($Path_v1."/RemovedSuperClass.java",
700    "package $PackageName;
701    public class RemovedSuperClass extends BaseClass {
702        public Integer someMethod(Integer param) {
703            return param;
704        }
705    }");
706    writeFile($Path_v2."/RemovedSuperClass.java",
707    "package $PackageName;
708    public class RemovedSuperClass {
709        public Integer someMethod(Integer param) {
710            return param;
711        }
712    }");
713   
714    # Changed_Super_Class
715    writeFile($Path_v1."/ChangedSuperClass.java",
716    "package $PackageName;
717    public class ChangedSuperClass extends BaseClass {
718        public Integer someMethod(Integer param) {
719            return param;
720        }
721    }");
722    writeFile($Path_v2."/ChangedSuperClass.java",
723    "package $PackageName;
724    public class ChangedSuperClass extends BaseClass2 {
725        public Integer someMethod(Integer param) {
726            return param;
727        }
728    }");
729   
730    # Abstract_Class_Added_Super_Interface
731    writeFile($Path_v1."/AbstractClassAddedSuperInterface.java",
732    "package $PackageName;
733    public abstract class AbstractClassAddedSuperInterface implements BaseInterface {
734        public Integer method(Integer param) {
735            return param;
736        }
737    }");
738    writeFile($Path_v2."/AbstractClassAddedSuperInterface.java",
739    "package $PackageName;
740    public abstract class AbstractClassAddedSuperInterface implements BaseInterface, BaseInterface2 {
741        public Integer method(Integer param) {
742            return param;
743        }
744    }");
745   
746    # Abstract_Class_Added_Super_Interface_With_Implemented_Methods
747    writeFile($Path_v1."/AbstractClassAddedSuperInterfaceWithImplementedMethods.java",
748    "package $PackageName;
749    public abstract class AbstractClassAddedSuperInterfaceWithImplementedMethods implements BaseInterface {
750        public Integer method(Integer param) {
751            return param;
752        }
753        public Integer method2(Integer param) {
754            return param;
755        }
756    }");
757    writeFile($Path_v2."/AbstractClassAddedSuperInterfaceWithImplementedMethods.java",
758    "package $PackageName;
759    public abstract class AbstractClassAddedSuperInterfaceWithImplementedMethods implements BaseInterface, BaseInterface2 {
760        public Integer method(Integer param) {
761            return param;
762        }
763        public Integer method2(Integer param) {
764            return param;
765        }
766    }");
767   
768    # Class_Removed_Super_Interface
769    writeFile($Path_v1."/ClassRemovedSuperInterface.java",
770    "package $PackageName;
771    public class ClassRemovedSuperInterface implements BaseInterface, BaseInterface2 {
772        public Integer method(Integer param) {
773            return param;
774        }
775        public Integer method2(Integer param) {
776            return param;
777        }
778    }");
779    writeFile($Path_v2."/ClassRemovedSuperInterface.java",
780    "package $PackageName;
781    public class ClassRemovedSuperInterface implements BaseInterface {
782        public Integer method(Integer param) {
783            return param;
784        }
785        public Integer method2(Integer param) {
786            return param;
787        }
788    }");
789   
790    writeFile($TestsPath."/Test_ClassRemovedSuperInterface.java",
791    "import $PackageName.*;
792    public class Test_ClassRemovedSuperInterface
793    {
794        public static void main(String[] args)
795        {
796            ClassRemovedSuperInterface Obj = new ClassRemovedSuperInterface();
797            Integer Res = Obj.method2(0);
798        }
799    }");
800   
801    # Interface_Added_Super_Interface
802    writeFile($Path_v1."/InterfaceAddedSuperInterface.java",
803    "package $PackageName;
804    public interface InterfaceAddedSuperInterface extends BaseInterface {
805        public Integer someMethod(Integer param);
806    }");
807    writeFile($Path_v2."/InterfaceAddedSuperInterface.java",
808    "package $PackageName;
809    public interface InterfaceAddedSuperInterface extends BaseInterface, BaseInterface2 {
810        public Integer someMethod(Integer param);
811    }");
812   
813    # Interface_Added_Super_Constant_Interface
814    writeFile($Path_v1."/InterfaceAddedSuperConstantInterface.java",
815    "package $PackageName;
816    public interface InterfaceAddedSuperConstantInterface extends BaseInterface {
817        public Integer someMethod(Integer param);
818    }");
819    writeFile($Path_v2."/InterfaceAddedSuperConstantInterface.java",
820    "package $PackageName;
821    public interface InterfaceAddedSuperConstantInterface extends BaseInterface, BaseConstantInterface {
822        public Integer someMethod(Integer param);
823    }");
824   
825    # Interface_Removed_Super_Interface
826    writeFile($Path_v1."/InterfaceRemovedSuperInterface.java",
827    "package $PackageName;
828    public interface InterfaceRemovedSuperInterface extends BaseInterface, BaseInterface2 {
829        public Integer someMethod(Integer param);
830    }");
831    writeFile($Path_v2."/InterfaceRemovedSuperInterface.java",
832    "package $PackageName;
833    public interface InterfaceRemovedSuperInterface extends BaseInterface {
834        public Integer someMethod(Integer param);
835    }");
836   
837    # Interface_Removed_Super_Constant_Interface
838    writeFile($Path_v1."/InterfaceRemovedSuperConstantInterface.java",
839    "package $PackageName;
840    public interface InterfaceRemovedSuperConstantInterface extends BaseInterface, BaseConstantInterface {
841        public Integer someMethod(Integer param);
842    }");
843    writeFile($Path_v2."/InterfaceRemovedSuperConstantInterface.java",
844    "package $PackageName;
845    public interface InterfaceRemovedSuperConstantInterface extends BaseInterface {
846        public Integer someMethod(Integer param);
847    }");
848   
849    # Interface_Became_Class
850    writeFile($Path_v1."/InterfaceBecameClass.java",
851    "package $PackageName;
852    public interface InterfaceBecameClass extends BaseInterface, BaseInterface2 {
853        public Integer someMethod(Integer param);
854    }");
855    writeFile($Path_v2."/InterfaceBecameClass.java",
856    "package $PackageName;
857    public class InterfaceBecameClass extends BaseClass {
858        public Integer someMethod(Integer param) {
859            return param;
860        }
861    }");
862   
863    # Removed_Class
864    writeFile($Path_v1."/RemovedClass.java",
865    "package $PackageName;
866    public class RemovedClass extends BaseClass {
867        public Integer someMethod(Integer param){
868            return param;
869        }
870    }");
871   
872    # Removed_Class (w/o methods)
873    writeFile($Path_v1."/RemovedFieldClass.java",
874    "package $PackageName;
875    public class RemovedFieldClass {
876        public Integer field;
877    }");
878   
879    writeFile($TestsPath."/Test_RemovedFieldClass.java",
880    "import $PackageName.*;
881    public class Test_RemovedFieldClass extends RemovedFieldClass
882    {
883        public static void main(String[] args)
884        {
885            RemovedFieldClass X = new RemovedFieldClass();
886            Integer Copy = X.field;
887        }
888    }");
889   
890    # Removed_Class (with static fields, private constructor)
891    writeFile($Path_v1."/RemovedClassWithStaticField.java",
892    "package $PackageName;
893    public class RemovedClassWithStaticField
894    {
895        private RemovedClassWithStaticField(){}
896        public static Integer cnt = 0;
897    }");
898   
899    writeFile($TestsPath."/Test_RemovedClassWithStaticField.java",
900    "import $PackageName.*;
901    public class Test_RemovedClassWithStaticField
902    {
903        public static void main(String[] args)
904        {
905            Integer Copy = RemovedClassWithStaticField.cnt;
906        }
907    }");
908   
909    # Removed_Field (static field, private constructor)
910    writeFile($Path_v1."/RemovedStaticFieldFromClassWithPrivateCtor.java",
911    "package $PackageName;
912    public class RemovedStaticFieldFromClassWithPrivateCtor
913    {
914        private RemovedStaticFieldFromClassWithPrivateCtor(){}
915        public static Integer cnt = 0;
916    }");
917   
918    writeFile($Path_v2."/RemovedStaticFieldFromClassWithPrivateCtor.java",
919    "package $PackageName;
920    public class RemovedStaticFieldFromClassWithPrivateCtor
921    {
922        private RemovedStaticFieldFromClassWithPrivateCtor(){}
923    }");
924   
925    writeFile($TestsPath."/Test_RemovedStaticFieldFromClassWithPrivateCtor.java",
926    "import $PackageName.*;
927    public class Test_RemovedStaticFieldFromClassWithPrivateCtor
928    {
929        public static void main(String[] args)
930        {
931            Integer Copy = RemovedStaticFieldFromClassWithPrivateCtor.cnt;
932        }
933    }");
934   
935    # Removed_Constant_Field
936    writeFile($Path_v1."/ClassRemovedStaticConstantField.java",
937    "package $PackageName;
938    public class ClassRemovedStaticConstantField
939    {
940        public static int removedField_Int = 1000;
941        public static String removedField_Str = \"Value\";
942    }");
943    writeFile($Path_v2."/ClassRemovedStaticConstantField.java",
944    "package $PackageName;
945    public class ClassRemovedStaticConstantField {
946    }");
947   
948    writeFile($TestsPath."/Test_ClassRemovedStaticConstantField.java",
949    "import $PackageName.*;
950    public class Test_ClassRemovedStaticConstantField
951    {
952        public static void main(String[] args)
953        {
954            Integer Copy = ClassRemovedStaticConstantField.removedField_Int;
955        }
956    }");
957   
958    # Removed_Class (Deprecated)
959    writeFile($Path_v1."/RemovedDeprecatedClass.java",
960    "package $PackageName;
961    \@Deprecated
962    public class RemovedDeprecatedClass {
963        public Integer someMethod(Integer param){
964            return param;
965        }
966    }");
967   
968    # Removed_Interface
969    writeFile($Path_v1."/RemovedInterface.java",
970    "package $PackageName;
971    public interface RemovedInterface extends BaseInterface, BaseInterface2 {
972        public Integer someMethod(Integer param);
973    }");
974   
975    # NonAbstract_Class_Added_Abstract_Method
976    writeFile($Path_v1."/NonAbstractClassAddedAbstractMethod.java",
977    "package $PackageName;
978    public class NonAbstractClassAddedAbstractMethod {
979        public Integer someMethod(Integer param1, String[] param2) {
980            return param1;
981        };
982    }");
983    writeFile($Path_v2."/NonAbstractClassAddedAbstractMethod.java",
984    "package $PackageName;
985    public abstract class NonAbstractClassAddedAbstractMethod {
986        public Integer someMethod(Integer param1, String[] param2) {
987            return param1;
988        };
989        public abstract Integer addedMethod(Integer param);
990    }");
991   
992    # Abstract_Class_Added_Abstract_Method
993    writeFile($Path_v1."/AbstractClassAddedAbstractMethod.java",
994    "package $PackageName;
995    public abstract class AbstractClassAddedAbstractMethod {
996        public Integer someMethod(Integer param1, String[] param2) {
997            return param1;
998        };
999    }");
1000    writeFile($Path_v2."/AbstractClassAddedAbstractMethod.java",
1001    "package $PackageName;
1002    public abstract class AbstractClassAddedAbstractMethod {
1003        public Integer someMethod(Integer param1, String[] param2) {
1004            return param1;
1005        };
1006        public abstract Integer addedMethod(Integer param);
1007    }");
1008   
1009    # Class_Became_Abstract
1010    writeFile($Path_v1."/ClassBecameAbstract.java",
1011    "package $PackageName;
1012    public class ClassBecameAbstract {
1013        public Integer someMethod(Integer param1, String[] param2) {
1014            return param1;
1015        };
1016    }");
1017    writeFile($Path_v2."/ClassBecameAbstract.java",
1018    "package $PackageName;
1019    public abstract class ClassBecameAbstract {
1020        public Integer someMethod(Integer param1, String[] param2) {
1021            return param1;
1022        };
1023        public abstract Integer addedMethod(Integer param);
1024    }");
1025   
1026    # Class_Became_Final
1027    writeFile($Path_v1."/ClassBecameFinal.java",
1028    "package $PackageName;
1029    public class ClassBecameFinal {
1030        public Integer someMethod(Integer param1, String[] param2) {
1031            return param1;
1032        };
1033    }");
1034    writeFile($Path_v2."/ClassBecameFinal.java",
1035    "package $PackageName;
1036    public final class ClassBecameFinal {
1037        public Integer someMethod(Integer param1, String[] param2) {
1038            return param1;
1039        };
1040    }");
1041   
1042    # Class_Removed_Abstract_Method
1043    writeFile($Path_v1."/ClassRemovedAbstractMethod.java",
1044    "package $PackageName;
1045    public abstract class ClassRemovedAbstractMethod {
1046        public Integer someMethod(Integer param1, String[] param2) {
1047            return param1;
1048        };
1049        public abstract Integer removedMethod(Integer param);
1050    }");
1051    writeFile($Path_v2."/ClassRemovedAbstractMethod.java",
1052    "package $PackageName;
1053    public abstract class ClassRemovedAbstractMethod {
1054        public Integer someMethod(Integer param1, String[] param2) {
1055            return param1;
1056        };
1057    }");
1058   
1059    # Class_Method_Became_Abstract
1060    writeFile($Path_v1."/ClassMethodBecameAbstract.java",
1061    "package $PackageName;
1062    public abstract class ClassMethodBecameAbstract {
1063        public Integer someMethod(Integer param1, String[] param2) {
1064            return param1;
1065        };
1066        public Integer someMethod(Integer param){
1067            return param;
1068        };
1069    }");
1070    writeFile($Path_v2."/ClassMethodBecameAbstract.java",
1071    "package $PackageName;
1072    public abstract class ClassMethodBecameAbstract {
1073        public Integer someMethod(Integer param1, String[] param2) {
1074            return param1;
1075        };
1076        public abstract Integer someMethod(Integer param);
1077    }");
1078   
1079    # Class_Method_Became_NonAbstract
1080    writeFile($Path_v1."/ClassMethodBecameNonAbstract.java",
1081    "package $PackageName;
1082    public abstract class ClassMethodBecameNonAbstract {
1083        public Integer someMethod(Integer param1, String[] param2) {
1084            return param1;
1085        };
1086        public abstract Integer someMethod(Integer param);
1087    }");
1088    writeFile($Path_v2."/ClassMethodBecameNonAbstract.java",
1089    "package $PackageName;
1090    public abstract class ClassMethodBecameNonAbstract {
1091        public Integer someMethod(Integer param1, String[] param2) {
1092            return param1;
1093        };
1094        public Integer someMethod(Integer param){
1095            return param;
1096        };
1097    }");
1098   
1099    # Method_Became_Static
1100    writeFile($Path_v1."/MethodBecameStatic.java",
1101    "package $PackageName;
1102    public class MethodBecameStatic {
1103        public Integer someMethod(Integer param) {
1104            return param;
1105        };
1106    }");
1107    writeFile($Path_v2."/MethodBecameStatic.java",
1108    "package $PackageName;
1109    public class MethodBecameStatic {
1110        public static Integer someMethod(Integer param) {
1111            return param;
1112        };
1113    }");
1114   
1115    # Method_Became_NonStatic
1116    writeFile($Path_v1."/MethodBecameNonStatic.java",
1117    "package $PackageName;
1118    public class MethodBecameNonStatic {
1119        public static Integer someMethod(Integer param) {
1120            return param;
1121        };
1122    }");
1123    writeFile($Path_v2."/MethodBecameNonStatic.java",
1124    "package $PackageName;
1125    public class MethodBecameNonStatic {
1126        public Integer someMethod(Integer param) {
1127            return param;
1128        };
1129    }");
1130   
1131    # Static_Method_Became_Final
1132    writeFile($Path_v1."/StaticMethodBecameFinal.java",
1133    "package $PackageName;
1134    public class StaticMethodBecameFinal {
1135        public static Integer someMethod(Integer param) {
1136            return param;
1137        };
1138    }");
1139    writeFile($Path_v2."/StaticMethodBecameFinal.java",
1140    "package $PackageName;
1141    public class StaticMethodBecameFinal {
1142        public static final Integer someMethod(Integer param) {
1143            return param;
1144        };
1145    }");
1146   
1147    # NonStatic_Method_Became_Final
1148    writeFile($Path_v1."/NonStaticMethodBecameFinal.java",
1149    "package $PackageName;
1150    public class NonStaticMethodBecameFinal {
1151        public Integer someMethod(Integer param) {
1152            return param;
1153        };
1154    }");
1155    writeFile($Path_v2."/NonStaticMethodBecameFinal.java",
1156    "package $PackageName;
1157    public class NonStaticMethodBecameFinal {
1158        public final Integer someMethod(Integer param) {
1159            return param;
1160        };
1161    }");
1162   
1163    # Method_Became_Abstract
1164    writeFile($Path_v1."/MethodBecameAbstract.java",
1165    "package $PackageName;
1166    public abstract class MethodBecameAbstract {
1167        public Integer someMethod(Integer param) {
1168            return param;
1169        };
1170    }");
1171    writeFile($Path_v2."/MethodBecameAbstract.java",
1172    "package $PackageName;
1173    public abstract class MethodBecameAbstract {
1174        public abstract Integer someMethod(Integer param);
1175    }");
1176   
1177    # Method_Became_NonAbstract
1178    writeFile($Path_v1."/MethodBecameNonAbstract.java",
1179    "package $PackageName;
1180    public abstract class MethodBecameNonAbstract {
1181        public abstract Integer someMethod(Integer param);
1182    }");
1183    writeFile($Path_v2."/MethodBecameNonAbstract.java",
1184    "package $PackageName;
1185    public abstract class MethodBecameNonAbstract {
1186        public Integer someMethod(Integer param) {
1187            return param;
1188        };
1189    }");
1190   
1191    # Changed_Method_Access
1192    writeFile($Path_v1."/ChangedMethodAccess.java",
1193    "package $PackageName;
1194    public class ChangedMethodAccess {
1195        public Integer someMethod(Integer param) {
1196            return param;
1197        };
1198    }");
1199    writeFile($Path_v2."/ChangedMethodAccess.java",
1200    "package $PackageName;
1201    public class ChangedMethodAccess {
1202        protected Integer someMethod(Integer param) {
1203            return param;
1204        };
1205    }");
1206   
1207    # Method_Became_Synchronized
1208    writeFile($Path_v1."/MethodBecameSynchronized.java",
1209    "package $PackageName;
1210    public class MethodBecameSynchronized {
1211        public Integer someMethod(Integer param) {
1212            return param;
1213        };
1214    }");
1215    writeFile($Path_v2."/MethodBecameSynchronized.java",
1216    "package $PackageName;
1217    public class MethodBecameSynchronized {
1218        public synchronized Integer someMethod(Integer param) {
1219            return param;
1220        };
1221    }");
1222   
1223    # Method_Became_NonSynchronized
1224    writeFile($Path_v1."/MethodBecameNonSynchronized.java",
1225    "package $PackageName;
1226    public class MethodBecameNonSynchronized {
1227        public synchronized Integer someMethod(Integer param) {
1228            return param;
1229        };
1230    }");
1231    writeFile($Path_v2."/MethodBecameNonSynchronized.java",
1232    "package $PackageName;
1233    public class MethodBecameNonSynchronized {
1234        public Integer someMethod(Integer param) {
1235            return param;
1236        };
1237    }");
1238   
1239    # Class_Overridden_Method
1240    writeFile($Path_v1."/OverriddenMethod.java",
1241    "package $PackageName;
1242    public class OverriddenMethod extends BaseClass {
1243        public Integer someMethod(Integer param) { return param; }
1244    }");
1245    writeFile($Path_v2."/OverriddenMethod.java",
1246    "package $PackageName;
1247    public class OverriddenMethod extends BaseClass {
1248        public Integer someMethod(Integer param) { return param; }
1249        public Integer method(Integer param) { return 2*param; }
1250    }");
1251   
1252    # Class_Method_Moved_Up_Hierarchy
1253    writeFile($Path_v1."/ClassMethodMovedUpHierarchy.java",
1254    "package $PackageName;
1255    public class ClassMethodMovedUpHierarchy extends BaseClass {
1256        public Integer someMethod(Integer param) { return param; }
1257        public Integer method(Integer param) { return 2*param; }
1258    }");
1259    writeFile($Path_v2."/ClassMethodMovedUpHierarchy.java",
1260    "package $PackageName;
1261    public class ClassMethodMovedUpHierarchy extends BaseClass {
1262        public Integer someMethod(Integer param) { return param; }
1263    }");
1264   
1265    # Class_Method_Moved_Up_Hierarchy (Interface Method) - should not be reported
1266    writeFile($Path_v1."/InterfaceMethodMovedUpHierarchy.java",
1267    "package $PackageName;
1268    public interface InterfaceMethodMovedUpHierarchy extends BaseInterface {
1269        public Integer method(Integer param);
1270        public Integer method2(Integer param);
1271    }");
1272    writeFile($Path_v2."/InterfaceMethodMovedUpHierarchy.java",
1273    "package $PackageName;
1274    public interface InterfaceMethodMovedUpHierarchy extends BaseInterface {
1275        public Integer method2(Integer param);
1276    }");
1277   
1278    # Class_Method_Moved_Up_Hierarchy (Abstract Method) - should not be reported
1279    writeFile($Path_v1."/AbstractMethodMovedUpHierarchy.java",
1280    "package $PackageName;
1281    public abstract class AbstractMethodMovedUpHierarchy implements BaseInterface {
1282        public abstract Integer method(Integer param);
1283        public abstract Integer method2(Integer param);
1284    }");
1285    writeFile($Path_v2."/AbstractMethodMovedUpHierarchy.java",
1286    "package $PackageName;
1287    public abstract class AbstractMethodMovedUpHierarchy implements BaseInterface {
1288        public abstract Integer method2(Integer param);
1289    }");
1290   
1291    # Use
1292    writeFile($Path_v1."/Use.java",
1293    "package $PackageName;
1294    public class Use
1295    {
1296        public FieldBecameFinal field;
1297        public void someMethod(FieldBecameFinal[] param) { };
1298        public void someMethod(Use param) { };
1299        public Integer someMethod(AbstractClassAddedSuperAbstractClass param) {
1300            return 0;
1301        }
1302        public Integer someMethod(AbstractClassAddedAbstractMethod param) {
1303            return 0;
1304        }
1305        public Integer someMethod(InterfaceAddedAbstractMethod param) {
1306            return 0;
1307        }
1308        public Integer someMethod(InterfaceAddedSuperInterface param) {
1309            return 0;
1310        }
1311        public Integer someMethod(AbstractClassAddedSuperInterface param) {
1312            return 0;
1313        }
1314        public Integer someMethod(AbstractClassAddedSuperInterfaceWithImplementedMethods param) {
1315            return 0;
1316        }
1317    }");
1318    writeFile($Path_v2."/Use.java",
1319    "package $PackageName;
1320    public class Use
1321    {
1322        public FieldBecameFinal field;
1323        public void someMethod(FieldBecameFinal[] param) { };
1324        public void someMethod(Use param) { };
1325        public Integer someMethod(AbstractClassAddedSuperAbstractClass param) {
1326            return param.abstractMethod(100)+param.field;
1327        }
1328        public Integer someMethod(AbstractClassAddedAbstractMethod param) {
1329            return param.addedMethod(100);
1330        }
1331        public Integer someMethod(InterfaceAddedAbstractMethod param) {
1332            return param.addedMethod(100);
1333        }
1334        public Integer someMethod(InterfaceAddedSuperInterface param) {
1335            return param.method2(100);
1336        }
1337        public Integer someMethod(AbstractClassAddedSuperInterface param) {
1338            return param.method2(100);
1339        }
1340        public Integer someMethod(AbstractClassAddedSuperInterfaceWithImplementedMethods param) {
1341            return param.method2(100);
1342        }
1343    }");
1344   
1345    # Added_Package
1346    writeFile($Path_v2."/AddedPackage/AddedPackageClass.java",
1347    "package $PackageName.AddedPackage;
1348    public class AddedPackageClass {
1349        public Integer field;
1350        public void someMethod(Integer param) { };
1351    }");
1352   
1353    # Removed_Package
1354    writeFile($Path_v1."/RemovedPackage/RemovedPackageClass.java",
1355    "package $PackageName.RemovedPackage;
1356    public class RemovedPackageClass {
1357        public Integer field;
1358        public void someMethod(Integer param) { };
1359    }");
1360    my $BuildRoot1 = getDirname($Path_v1);
1361    my $BuildRoot2 = getDirname($Path_v2);
1362    if(compileJavaLib($LibName, $BuildRoot1, $BuildRoot2))
1363    {
1364        runTests($TestsPath, $PackageName, getAbsPath($BuildRoot1), getAbsPath($BuildRoot2));
1365        runChecker($LibName, $BuildRoot1, $BuildRoot2);
1366    }
1367}
1368
1369sub checkJavaCompiler($)
1370{ # check javac: compile simple program
1371    my $Cmd = $_[0];
1372   
1373    if(not $Cmd) {
1374        return;
1375    }
1376   
1377    my $TmpDir = $In::Opt{"Tmp"};
1378   
1379    writeFile($TmpDir."/test_javac/Simple.java",
1380    "public class Simple {
1381        public Integer f;
1382        public void method(Integer p) { };
1383    }");
1384    chdir($TmpDir."/test_javac");
1385    system("$Cmd Simple.java 2>errors.txt");
1386    chdir($In::Opt{"OrigDir"});
1387    if($?)
1388    {
1389        my $Msg = "something is going wrong with the Java compiler (javac):\n";
1390        my $Err = readFile($TmpDir."/test_javac/errors.txt");
1391        $Msg .= $Err;
1392        if($Err=~/elf\/start\.S/ and $Err=~/undefined\s+reference\s+to/)
1393        { # /usr/lib/gcc/i586-suse-linux/4.5/../../../crt1.o: In function _start:
1394          # /usr/src/packages/BUILD/glibc-2.11.3/csu/../sysdeps/i386/elf/start.S:115: undefined reference to main
1395            $Msg .= "\nDid you install a JDK-devel package?";
1396        }
1397        exitStatus("Error", $Msg);
1398    }
1399}
1400
1401sub runTests($$$$)
1402{
1403    my ($TestsPath, $PackageName, $Path_v1, $Path_v2) = @_;
1404   
1405    # compile with old version of package
1406    my $JavacCmd = getCmdPath("javac");
1407    if(not $JavacCmd) {
1408        exitStatus("Not_Found", "can't find \"javac\" compiler");
1409    }
1410   
1411    my $JavaCmd = getCmdPath("java");
1412    if(not $JavaCmd) {
1413        exitStatus("Not_Found", "can't find \"java\" command");
1414    }
1415   
1416    chdir($TestsPath);
1417    system($JavacCmd." -classpath \"".$Path_v1."\" -g *.java");
1418    chdir($In::Opt{"OrigDir"});
1419   
1420    foreach my $TestSrc (cmdFind($TestsPath, "", "*\\.java"))
1421    { # remove test source
1422        unlink($TestSrc);
1423    }
1424   
1425    my $TEST_REPORT = "";
1426   
1427    foreach my $TestPath (cmdFind($TestsPath, "", "*\\.class", 1))
1428    { # run tests
1429        my $Name = getFilename($TestPath);
1430        $Name=~s/\.class\Z//g;
1431       
1432        chdir($TestsPath);
1433        system($JavaCmd." -classpath \"".join_A($Path_v2, ".")."\" $Name >result.txt 2>&1");
1434        chdir($In::Opt{"OrigDir"});
1435       
1436        my $Result = readFile($TestsPath."/result.txt");
1437        unlink($TestsPath."/result.txt");
1438        $TEST_REPORT .= "TEST CASE: $Name\n";
1439        if($Result) {
1440            $TEST_REPORT .= "RESULT: FAILED\n";
1441            $TEST_REPORT .= "OUTPUT:\n$Result\n";
1442        }
1443        else {
1444            $TEST_REPORT .= "RESULT: SUCCESS\n";
1445        }
1446        $TEST_REPORT .= "\n";
1447    }
1448   
1449    writeFile("$TestsPath/Journal.txt", $TEST_REPORT);
1450}
1451
1452sub compileJavaLib($$$)
1453{
1454    my ($LibName, $BuildRoot1, $BuildRoot2) = @_;
1455   
1456    my $JavacCmd = getCmdPath("javac");
1457    if(not $JavacCmd) {
1458        exitStatus("Not_Found", "can't find \"javac\" compiler");
1459    }
1460   
1461    checkJavaCompiler($JavacCmd);
1462   
1463    my $JarCmd = getCmdPath("jar");
1464    if(not $JarCmd) {
1465        exitStatus("Not_Found", "can't find \"jar\" command");
1466    }
1467   
1468    # space before value, new line
1469    writeFile("$BuildRoot1/MANIFEST.MF", "Implementation-Version: 1.0\n");
1470    writeFile("$BuildRoot2/MANIFEST.MF", "Implementation-Version: 2.0\n");
1471   
1472    my (%SrcDir1, %SrcDir2) = ();
1473    foreach my $Path (cmdFind($BuildRoot1, "f", "*\\.java")) {
1474        $SrcDir1{getDirname($Path)} = 1;
1475    }
1476    foreach my $Path (cmdFind($BuildRoot2, "f", "*\\.java")) {
1477        $SrcDir2{getDirname($Path)} = 1;
1478    }
1479    # build classes v.1
1480    foreach my $Dir (keys(%SrcDir1))
1481    {
1482        chdir($Dir);
1483        system("$JavacCmd -g *.java");
1484        chdir($In::Opt{"OrigDir"});
1485        if($?) {
1486            exitStatus("Error", "can't compile classes v.1");
1487        }
1488    }
1489    # create java archive v.1
1490    chdir($BuildRoot1);
1491    system("$JarCmd -cmf MANIFEST.MF $LibName.jar TestPackage");
1492    chdir($In::Opt{"OrigDir"});
1493   
1494    # build classes v.2
1495    foreach my $Dir (keys(%SrcDir2))
1496    {
1497        chdir($Dir);
1498        system("$JavacCmd -g *.java");
1499        chdir($In::Opt{"OrigDir"});
1500        if($?) {
1501            exitStatus("Error", "can't compile classes v.2");
1502        }
1503    }
1504    # create java archive v.2
1505    chdir($BuildRoot2);
1506    system("$JarCmd -cmf MANIFEST.MF $LibName.jar TestPackage");
1507    chdir($In::Opt{"OrigDir"});
1508   
1509    foreach my $SrcPath (cmdFind($BuildRoot1, "", "*\\.java")) {
1510        unlink($SrcPath);
1511    }
1512    foreach my $SrcPath (cmdFind($BuildRoot2, "", "*\\.java")) {
1513        unlink($SrcPath);
1514    }
1515    return 1;
1516}
1517
1518sub runChecker($$$)
1519{
1520    my ($LibName, $Path1, $Path2) = @_;
1521   
1522    writeFile("$LibName/v1.xml", "
1523        <version>
1524            1.0
1525        </version>
1526        <archives>
1527            ".getAbsPath($Path1)."
1528        </archives>\n");
1529   
1530    writeFile("$LibName/v2.xml", "
1531        <version>
1532            2.0
1533        </version>
1534        <archives>
1535            ".getAbsPath($Path2)."
1536        </archives>\n");
1537   
1538    my $Cmd = "perl $0 -l $LibName $LibName/v1.xml $LibName/v2.xml";
1539    if($In::Opt{"Quick"}) {
1540        $Cmd .= " -quick";
1541    }
1542    if(defined $In::Opt{"SkipDeprecated"}) {
1543        $Cmd .= " -skip-deprecated";
1544    }
1545    if(defined $In::Opt{"OldStyle"}) {
1546        $Cmd .= " -old-style";
1547    }
1548   
1549    my $TmpDir = $In::Opt{"Tmp"};
1550   
1551    writeFile($TmpDir."/skip-annotations.list", "TestPackage.Beta");
1552    $Cmd .= " -skip-annotations-list ".$TmpDir."/skip-annotations.list";
1553    if($In::Opt{"Debug"})
1554    {
1555        $Cmd .= " -debug";
1556        printMsg("INFO", "Executing $Cmd");
1557    }
1558   
1559    my $Report = "compat_reports/$LibName/1.0_to_2.0/compat_report.html";
1560   
1561    if(-f $Report) {
1562        unlink($Report);
1563    }
1564   
1565    system($Cmd);
1566   
1567    if(not -f $Report) {
1568        exitStatus("Error", "analysis has failed");
1569    }
1570   
1571    # Binary
1572    my $BReport = readAttributes($Report, 0);
1573    my $NProblems = $BReport->{"type_problems_high"}+$BReport->{"type_problems_medium"};
1574    $NProblems += $BReport->{"method_problems_high"}+$BReport->{"method_problems_medium"};
1575    $NProblems += $BReport->{"removed"};
1576   
1577    # Source
1578    my $SReport = readAttributes($Report, 1);
1579    $NProblems += $SReport->{"type_problems_high"}+$SReport->{"type_problems_medium"};
1580    $NProblems += $SReport->{"method_problems_high"}+$SReport->{"method_problems_medium"};
1581    $NProblems += $SReport->{"removed"};
1582   
1583    if($NProblems>=100) {
1584        printMsg("INFO", "Test result: SUCCESS ($NProblems breaks found)\n");
1585    }
1586    else {
1587        printMsg("ERROR", "Test result: FAILED ($NProblems breaks found)\n");
1588    }
1589}
1590
1591return 1;
Note: See TracBrowser for help on using the repository browser.