Search in sources :

Example 41 with SemanticVersioningClassVisitor

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

the class BinaryCompatibilityTest method test_jdk_chap13_5_5_2.

/**
     * Changing a method parameter in an interface should  break compatibility.
     */
@Test
public void test_jdk_chap13_5_5_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.visitMethod(ACC_PUBLIC, "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, "getFoo", "(IZ)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(int) has been deleted or its return type or parameter list has changed.", bcs.get(0));
    assertTrue("Changing a method parameter 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 42 with SemanticVersioningClassVisitor

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_14_2.

/**
     * Changing a method to not to be abstract is not a binary compatibility change.
     */
@Test
public void test_jdk_chap13_4_14_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_ABASTRACT, "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, "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("Changing a method not to be abstract will 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)

Example 43 with SemanticVersioningClassVisitor

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_4_1.

/**
     * Changing the direct superclass or the set of direct superinterfaces of a class type will not break compatibility
     * with pre-existing binaries, provided that the total set of superclasses or superinterfaces, respectively, of the class type loses no members.
     */
@Test
public void test_jdk_chap13_4_4_1() 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/TestBChild", 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("Changing the direct superclass or the set of direct superinterfaces of a class type will not breake binary compatibility if not losing any members.", 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 44 with SemanticVersioningClassVisitor

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_11_1.

/**
     * Testing deleting a public/protected method when there is no such a method in the superclass breaks binary compatibility.
     */
@Test
public void test_jdk_chap13_4_11_1() {
    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) has been deleted or its return type or parameter list has changed.", bcs.get(0));
    assertTrue("Deleting a public/protected method when there is no such a method in the superclass breaks 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 45 with SemanticVersioningClassVisitor

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

the class BinaryCompatibilityTest method test_jdk_chap13_4_12_3.

/**
     * Changing a method formal type parameter is not a binary compatibility change.
     */
@Test
public void test_jdk_chap13_4_12_3() {
    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/util/List;)I", "Ljava/lang/String;", 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.visitMethod(ACC_PUBLIC, "getCooLen", "(Ljava/util/List;)I", "Lcome/ibm/blah;", 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()));
    assertTrue("Changing a method formal type parameter 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

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