Search in sources :

Example 51 with SemanticVersioningClassVisitor

use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.

the class BinaryCompatibilityTest method test_jdk_chap13_4_2_2.

/**
     * Test a binary compatibility where a class was final is changed to not final.
     */
@Test
public void test_jdk_chap13_4_2_2() {
    // construct original class
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC + 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, "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 final to not final, this should not break binary compatibility.", bcs.isCompatible());
}
Also used : BinaryCompatibilityStatus(org.apache.aries.versioning.utils.BinaryCompatibilityStatus) ClassReader(org.objectweb.asm.ClassReader) SemanticVersioningClassVisitor(org.apache.aries.versioning.utils.SemanticVersioningClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 52 with SemanticVersioningClassVisitor

use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.

the class BinaryCompatibilityTest method test_jdk_chap13_5_5_1.

/**
     * Changing a method return type in an interface should  break compatibility.
     */
@Test
public void test_jdk_chap13_5_5_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.visitMethod(ACC_PUBLIC, "getFoo", "()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, "getFoo", "(I)I", null, null).visitEnd();
    cw.visitMethod(ACC_PUBLIC, "getMoo", "()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 getFoo() has been deleted or its return type or parameter list has changed.", bcs.get(0));
    assertTrue("Changing a method return type in an interface should  break compatibility.", bcs.size() == 1);
}
Also used : BinaryCompatibilityStatus(org.apache.aries.versioning.utils.BinaryCompatibilityStatus) ClassReader(org.objectweb.asm.ClassReader) SemanticVersioningClassVisitor(org.apache.aries.versioning.utils.SemanticVersioningClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 53 with SemanticVersioningClassVisitor

use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.

the class BinaryCompatibilityTest method test_ignore_clinit.

@Test
public void test_ignore_clinit() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", new String[] { "versioning/java/files/TestB" });
    cw.visitField(ACC_PUBLIC, "foo", "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", new String[] { "versioning/java/files/TestB" });
    cw.visitField(ACC_PUBLIC + ACC_STATIC, "bar", "I", null, null).visitEnd();
    cw.visitField(ACC_PUBLIC, "foo", "I", null, null).visitEnd();
    cw.visitMethod(ACC_PUBLIC, "<clinit>", "()V", 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());
}
Also used : ClassReader(org.objectweb.asm.ClassReader) SemanticVersioningClassVisitor(org.apache.aries.versioning.utils.SemanticVersioningClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 54 with SemanticVersioningClassVisitor

use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.

the class BinaryCompatibilityTest method test_jdk_chap13_4_16_1.

/**
     * Adding a native modifier of a method does not break compatibility.
     */
@Test
public void test_jdk_chap13_4_16_1() {
    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 + ACC_STATIC + ACC_NATIVE, "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 native modifier of a method does not break compatibility.", newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration())).isCompatible());
}
Also used : ClassReader(org.objectweb.asm.ClassReader) SemanticVersioningClassVisitor(org.apache.aries.versioning.utils.SemanticVersioningClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 55 with SemanticVersioningClassVisitor

use of org.apache.aries.versioning.utils.SemanticVersioningClassVisitor in project aries by apache.

the class BinaryCompatibilityTest method test_jdk_chap13_4_7_1.

/**
     * Test deleting a private/default field, this should not break compatibility.
     */
@Test
public void test_jdk_chap13_4_7_1() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
    cw.visitField(ACC_PRIVATE, "lESS", "I", null, new Integer(-1)).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.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("Deleting a private field should not break binary compatibility.", newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration())).isCompatible());
}
Also used : ClassReader(org.objectweb.asm.ClassReader) SemanticVersioningClassVisitor(org.apache.aries.versioning.utils.SemanticVersioningClassVisitor) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Aggregations

SemanticVersioningClassVisitor (org.apache.aries.versioning.utils.SemanticVersioningClassVisitor)55 ClassReader (org.objectweb.asm.ClassReader)53 Test (org.junit.Test)52 ClassWriter (org.objectweb.asm.ClassWriter)52 BinaryCompatibilityStatus (org.apache.aries.versioning.utils.BinaryCompatibilityStatus)33 IFile (org.apache.aries.util.filesystem.IFile)2 MethodDeclaration (org.apache.aries.versioning.utils.MethodDeclaration)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClassDeclaration (org.apache.aries.versioning.utils.ClassDeclaration)1 FieldDeclaration (org.apache.aries.versioning.utils.FieldDeclaration)1 SerialVersionClassVisitor (org.apache.aries.versioning.utils.SerialVersionClassVisitor)1