use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_17_2.
/**
* If a method is not private was declared static and is changed to not be declared static, this breaks compatibility.
*/
@Test
public void test_jdk_chap13_4_17_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "getCooLen", "(Ljava/lang/String;)I", null, null).visitEnd();
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC + ACC_TRANSIENT, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/lang/String;)I", null, null).visitEnd();
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
ClassReader newCR = new ClassReader(newBytes);
ClassReader oldCR = new ClassReader(oldBytes);
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertEquals("The method int getCooLen(java.lang.String) has changed from static to non-static or vice versa.", bcs.get(0));
assertTrue("If a method is not private was declared static and is changed to not be decalared static, this should break compatibility.", bcs.size() == 1);
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_3_2.
/**
* Test a binary incompatibility where a class was not public is changed to public.
*/
@Test
public void test_jdk_chap13_4_3_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_FINAL, "pkg/Test", null, "java/lang/Object", null);
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC + ACC_FINAL, "pkg/Test", null, "java/lang/Object", null);
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
ClassReader newCR = new ClassReader(newBytes);
ClassReader oldCR = new ClassReader(oldBytes);
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
assertTrue("When a class is changed from non-public to public, this should break binary compatibility.", newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration())).isCompatible());
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_10_2.
/**
* If a field was non-transient is changed to transient, then it will not break compatibility.
*/
@Test
public void test_jdk_chap13_4_10_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC + ACC_TRANSIENT, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
ClassReader newCR = new ClassReader(newBytes);
ClassReader oldCR = new ClassReader(oldBytes);
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertTrue("If a change to the direct superclass or the set of direct superinterfaces results in any class or interface no longer being a superclass or superinterface, respectively, it will break binary compatibility.", bcs.isCompatible());
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_9_2.
/**
* If a field was non-static is changed to be static, then it will break compatibility.
*/
@Test
public void test_jdk_chap13_4_9_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC + ACC_STATIC, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
ClassReader newCR = new ClassReader(newBytes);
ClassReader oldCR = new ClassReader(oldBytes);
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertEquals("The public field aa was static but is changed to be non static or vice versa.", bcs.get(0));
assertTrue("If a field was non-static is changed to be static, then it will break compatibility.", bcs.size() == 1);
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_13_1.
/**
* Changing a method return type is a binary compatibility change.
*/
@Test
public void test_jdk_chap13_4_13_1() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/lang/String;)I", null, null).visitEnd();
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
cw.visitField(ACC_PUBLIC + ACC_TRANSIENT, "aa", "Ljava/lang/String;", null, new String("newBar")).visitEnd();
cw.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/lang/String;)[I", null, null).visitEnd();
cw.visitEnd();
byte[] newBytes = cw.toByteArray();
SemanticVersioningClassVisitor oldCV = new SemanticVersioningClassVisitor(loader);
SemanticVersioningClassVisitor newCV = new SemanticVersioningClassVisitor(loader);
ClassReader newCR = new ClassReader(newBytes);
ClassReader oldCR = new ClassReader(oldBytes);
newCR.accept(newCV, 0);
oldCR.accept(oldCV, 0);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertEquals("The method int getCooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", bcs.get(0));
assertTrue("Changing a method return type will break binary compatibility.", bcs.size() == 1);
}
Aggregations