Search in sources :

Example 6 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_9_1.

/**
     * If a field was static is changed to be non-static, then it will break compatibility.
     */
@Test
public void test_jdk_chap13_4_9_1() {
    ClassWriter 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[] 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.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 static is changed to be non-static, then it will 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 7 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_7_4.

/**
     * Changing field type breaks binary compatibility
     * with pre-existing binaries, provided that the total set of superclasses or superinterfaces, respectively, of the class type loses no members but the one of the fields has changed type.
     */
@Test
public void test_jdk_chap13_4_7_4() throws IOException {
    ClassWriter 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[] oldBytes = cw.toByteArray();
    cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", 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("Changing the direct superclass or the set of direct superinterfaces of a class type results fields changes. This should breake binary compatibility if not losing any members.", bcs.size() == 2);
    assertEquals(new HashSet<String>(Arrays.asList(new String[] { "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 8 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_5_3_1.

/**
     * Deleting a method in an interface should break compatibility.
     */
@Test
public void test_jdk_chap13_5_3_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.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("Deleting a method 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 9 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_11_3.

/**
     * Testing deleting a public/protected method when there is less accessible method in the superclass does break binary compatibility.
     */
@Test
public void test_jdk_chap13_4_11_3() {
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_5, ACC_PUBLIC, "pkg/Test", null, "versioning/java/files/TestA", null);
    cw.visitMethod(ACC_PUBLIC, "getFooLen", "(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()));
    assertEquals("The method int getFooLen(java.lang.String) is less accessible.", bcs.get(0));
    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.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 10 with BinaryCompatibilityStatus

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_17_1.

/**
     * If a method is not private was not declared static and is changed to be declared static, this breaks compatibility.
     */
@Test
public void test_jdk_chap13_4_17_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_STATIC, "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 not declared static and is changed to be decalared static, this 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)

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