use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_7_2.
/**
* If a field is added but is less accessible than the old one or change to static from non-static or from non-static to static.
*/
@Test
public void test_jdk_chap13_4_7_2() {
ClassWriter cw = new ClassWriter(0);
cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
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_PROTECTED, "bar", "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 bar becomes less accessible.", bcs.get(0));
assertTrue("The new field conflicts with a field in the super class. Check chapter 13.4.7 java spec for more info.", bcs.size() == 1);
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_not_cotaining_more_abstract_methods.
/**
* Check not containing more abstract methods
*/
@Test
public void test_not_cotaining_more_abstract_methods() {
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.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "getFoo", "(I)I", null, null).visitEnd();
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", new String[] { "versioning/java/files/TestB" });
cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "getFoo", "(I)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);
assertTrue("No change should not break compatibility.", newCV.getClassDeclaration().getBinaryCompatibleStatus(oldCV.getClassDeclaration()).isCompatible());
assertEquals("Containing more abstract methods should return false.", 0, newCV.getClassDeclaration().getExtraMethods(oldCV.getClassDeclaration()).size());
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_2_1.
/**
* Test a binary incompatibility where a class was not final is changed to be final.
*/
@Test
public void test_jdk_chap13_4_2_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_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);
BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
assertTrue("When a class is changed from non final to final, this should break binary compatibility.", bcs.size() == 1);
assertEquals(" The class pkg/Test was not final but is changed to be final.", bcs.get(0));
}
use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.
the class BinaryCompatibilityTest method test_jdk_chap13_4_18_2.
/**
* Deleting a synchronized modifier of a method does not break compatibility.
*/
@Test
public void test_jdk_chap13_4_18_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_SYNCHRONIZED, "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, "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);
assertTrue("Adding a synchronized modifier of a method does not break 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_5_3.
/**
* Test adding a class member or constructor should not break binary compatibility.
*/
@Test
public void test_jdk_chap13_4_5_3() {
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, "pkg/Test", null, "java/lang/Object", null);
cw.visitMethod(ACC_PROTECTED, "convert", "(Ljava/lang/Object;)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);
assertTrue("Adding a class member or constructor should not break binary compatibility.", newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration())).isCompatible());
}
Aggregations