use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_5_1_2.
/**
* Changing an interface that is declared public to not be declared public should break compatibility.
*/
@Test
public void test_jdk_chap13_5_1_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, "pkg/Test", null, "java/lang/Object", new String[] { "versioning/java/files/TestB" });
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_ABSTRACT + ACC_INTERFACE, "pkg/Test", null, "java/lang/Object", new String[] { "versioning/java/files/TestB" });
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);
assertNull("Changing an interface that is declared public to not be declared public should break compatibility.", newCV.getClassDeclaration());
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_5_2_1.
/**
* Changes to the interface hierarchy resulting an interface not being a super interface should break compatibility.
*/
@Test
public void test_jdk_chap13_5_2_1() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, "pkg/Test", null, "java/lang/Object", new String[] { "versioning/java/files/TestB" });
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, "pkg/Test", null, "java/lang/Object", null);
cw.visitMethod(ACC_PUBLIC, "getFoo", "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(new HashSet<String>(Arrays.asList(new String[] { "The public field bar has been deleted.", "The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestB].", "The method java.lang.String getFoo() has been deleted or its return type or parameter list has changed." })), new HashSet<String>(bcs));
assertFalse("Changes to the interface hierarchy resulting an interface not being a super interface should break compatibility.", bcs.isCompatible());
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_1_1.
/**
* Test of binary incompatibility where a class was not abstract is changed to be declared abstract,
*/
@Test
public void test_jdk_chap13_4_1_1() {
// construct original class
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT, "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);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertTrue("When a class is changed from non abstract to abstract, this should break binary compatibility.", bcs.size() == 1);
assertEquals(" The class pkg/Test was not abstract but is changed to be abstract.", bcs.get(0));
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_5_2.
/**
* Test deleting a class member or constructor that is declared private should not break binary compatibility.
*/
@Test
public void test_jdk_chap13_4_5_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
cw.visitMethod(ACC_PRIVATE, "convert", "(Ljava/lang/Object;)I", null, null).visitEnd();
cw.visitEnd();
byte[] oldBytes = cw.toByteArray();
cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "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("Deleting a class member or constructor that is declared private should not 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_15_1.
/**
* Changing an instance method that is not final to be final is a binary compatibility change.
*/
@Test
public void test_jdk_chap13_4_15_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 + ACC_FINAL, "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) was not final but has been changed to be final.", bcs.get(0));
assertTrue("Changing an instance method from non-final to final will break binary compatibility.", bcs.size() == 1);
}
Aggregations