Skip to content

Commit

Permalink
[WFLY-xxxx] Transform classes to replace deprecated API method call
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Mar 13, 2018
1 parent 3c5b725 commit 080ac76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module name="org.wildfly.clustering.infinispan.spi"/>
<module name="org.wildfly.clustering.service"/>
<module name="org.wildfly.transaction.client"/>
<module name="asm.asm"/>

<!-- TODO WFLY-5966 validate the need for these and remove if not needed.
Prior to WFLY-5922 they were exported by javax.ejb.api. -->
Expand Down
4 changes: 4 additions & 0 deletions jpa/subsystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,9 @@
<artifactId>wildfly-weld-common</artifactId>
</dependency>

<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.as.jpa;

import java.lang.instrument.ClassFileTransformer;
import java.security.ProtectionDomain;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
* A class file transformer which makes deployment classes written for Hibernate 5.1 be compatible with Hibernate 5.3.
*/
public class Hibernate51CompatibilityTransformer implements ClassFileTransformer {
public Hibernate51CompatibilityTransformer() {
}

public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) {
final ClassReader classReader = new ClassReader(classfileBuffer);
final ClassWriter cv = new ClassWriter(classReader, 0);
classReader.accept(new ClassVisitor(Opcodes.ASM6, cv) {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(Opcodes.ASM6, super.visitMethod(access, name, desc, signature, exceptions)) {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == Opcodes.INVOKEINTERFACE && owner.equals("org/hibernate/Session") && name.equals("getFlushMode") && desc.equals("()Lorg/hibernate/FlushMode;")) {
name = "getHibernateFlushMode";
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
};
}
}, 0);
return cv.toByteArray();
}
}

0 comments on commit 080ac76

Please sign in to comment.