Search in sources :

Example 21 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_11_2.

/**
     * Testing deleting a public/protected method when there is such a method in the superclass does not break binary compatibility.
     */
@Test
public void test_jdk_chap13_4_11_2() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
    cw.visitMethod(ACC_PUBLIC, "getBarLen", "(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.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());
}
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 22 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_6_2.

/**
     * Test changing the declared access of a method to permit less access, this should break compatibility.
     */
@Test
public void test_jdk_chap13_4_6_2() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
    cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "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.visitMethod(ACC_STATIC, "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);
    BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
    assertEquals("The method int convert(java.lang.Object) is less accessible.", bcs.get(0));
    assertTrue("Changing the declared access of a member or contructor to permit less access  , this should break binary 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 23 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_7_5.

/**
     * Change the signature of the field from Colllection<AA> to Collection<String>
     */
@Test
public void test_jdk_chap13_4_7_5() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "java/lang/Object", null);
    cw.visitField(ACC_PUBLIC, "more", "Ljava/util/Collection;", "Lcom/bim/AA;", 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.visitField(ACC_PROTECTED, "more", "Ljava/util/Collection;", "Ljava/lang/String;", 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 more becomes less accessible." })), new HashSet<String>(bcs));
    assertTrue("Changing the declared access of a field to permit less access  , this should break binary 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 24 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_4_2.

/**
     * 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.
     */
@Test
public void test_jdk_chap13_4_4_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, "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);
    BinaryCompatibilityStatus bcs = newCV.getClassDeclaration().getBinaryCompatibleStatus((oldCV.getClassDeclaration()));
    assertFalse("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());
    assertEquals(new HashSet<String>(Arrays.asList(new String[] { "The method int getFooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", "The method java.lang.String getFoo() has changed from non abstract to abstract.", "The method int getBarLen(java.lang.String) has been deleted or its return type or parameter list has changed.", "The method int getBooLen(java.lang.String) has been deleted or its return type or parameter list has changed.", "The superclasses or superinterfaces have stopped being super: [versioning/java/files/TestC, versioning/java/files/TestA].", "The protected field c has been deleted.", "The public field bar was not final but has been changed to be final.", "The public field bar was static but is changed to be non static or vice versa.", "The public field bar has changed its type." })), new HashSet<String>(bcs));
}
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 25 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_1_2.

/**
     * Test of binary compatibility where a class was abstract is changed to be declared non-abstract,
     */
@Test
public void test_jdk_chap13_4_1_2() {
    // construct original class
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC + ACC_ABSTRACT, "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 static to non-static, 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)

Aggregations

BinaryCompatibilityStatus (org.apache.aries.versioning.utils.BinaryCompatibilityStatus)33 SemanticVersioningClassVisitor (org.apache.aries.versioning.utils.SemanticVersioningClassVisitor)33 Test (org.junit.Test)32 ClassReader (org.objectweb.asm.ClassReader)32 ClassWriter (org.objectweb.asm.ClassWriter)32 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IFile (org.apache.aries.util.filesystem.IFile)1 ClassDeclaration (org.apache.aries.versioning.utils.ClassDeclaration)1 FieldDeclaration (org.apache.aries.versioning.utils.FieldDeclaration)1 MethodDeclaration (org.apache.aries.versioning.utils.MethodDeclaration)1