forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFLY-xxxx] Transform classes to replace deprecated API method call
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
jpa/subsystem/src/main/java/org/jboss/as/jpa/Hibernate51CompatibilityTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |