-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow transforming the DB2 JDBC driver to Jakarta APIs during Augmentation #27910
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
82 changes: 82 additions & 0 deletions
82
...c/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JakartaEnablement.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,82 @@ | ||
package io.quarkus.jdbc.db2.deployment; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.transformer.action.ActionContext; | ||
import org.eclipse.transformer.action.ByteData; | ||
import org.eclipse.transformer.action.impl.ActionContextImpl; | ||
import org.eclipse.transformer.action.impl.ByteDataImpl; | ||
import org.eclipse.transformer.action.impl.ClassActionImpl; | ||
import org.eclipse.transformer.action.impl.SelectionRuleImpl; | ||
import org.eclipse.transformer.action.impl.SignatureRuleImpl; | ||
import org.eclipse.transformer.util.FileUtils; | ||
import org.objectweb.asm.ClassReader; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.quarkus.bootstrap.classloading.QuarkusClassLoader; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem; | ||
|
||
/** | ||
* The DB2 driver is compiled using references to classes in the javax.transaction | ||
* package; we need to transform these to fix compatibility with jakarta.transaction. | ||
* We do this by leveraging the Eclipse Transformer project during Augmentation, so | ||
* that end users don't need to bother. | ||
*/ | ||
public class JakartaEnablement { | ||
|
||
private static final List<String> CLASSES_NEEDING_TRANSFORMATION = List.of( | ||
"com.ibm.db2.jcc.t2zos.ab", | ||
"com.ibm.db2.jcc.t2zos.T2zosConnection", | ||
"com.ibm.db2.jcc.t2zos.T2zosConfiguration"); | ||
|
||
@BuildStep | ||
void transformToJakarta(BuildProducer<BytecodeTransformerBuildItem> transformers) { | ||
if (QuarkusClassLoader.isClassPresentAtRuntime("jakarta.transaction.Transaction")) { | ||
JakartaTransformer tr = new JakartaTransformer(); | ||
for (String classname : CLASSES_NEEDING_TRANSFORMATION) { | ||
final BytecodeTransformerBuildItem item = new BytecodeTransformerBuildItem.Builder() | ||
.setCacheable(true) | ||
.setContinueOnFailure(false) | ||
.setClassToTransform(classname) | ||
.setClassReaderOptions(ClassReader.SKIP_DEBUG) | ||
.setInputTransformer(tr::transform) | ||
.build(); | ||
transformers.produce(item); | ||
} | ||
} | ||
} | ||
|
||
private static class JakartaTransformer { | ||
|
||
private final Logger logger; | ||
private final ActionContext ctx; | ||
|
||
JakartaTransformer() { | ||
logger = LoggerFactory.getLogger("JakartaTransformer"); | ||
Map<String, String> renames = new HashMap<>(); | ||
//N.B. we enable only this transformation, not the full set of capabilities of Eclipse Transformer; | ||
//this might need tailoring if the same idea gets applied to a different context. | ||
renames.put("javax.transaction", "jakarta.transaction"); | ||
ctx = new ActionContextImpl(logger, | ||
new SelectionRuleImpl(logger, Collections.emptyMap(), Collections.emptyMap()), | ||
new SignatureRuleImpl(logger, renames, null, null, null, null, null, Collections.emptyMap())); | ||
} | ||
|
||
byte[] transform(final String name, final byte[] bytes) { | ||
logger.info("Jakarta EE compatibility enhancer for Quarkus: transforming " + name); | ||
final ClassActionImpl classTransformer = new ClassActionImpl(ctx); | ||
final ByteBuffer input = ByteBuffer.wrap(bytes); | ||
final ByteData inputData = new ByteDataImpl(name, input, FileUtils.DEFAULT_CHARSET); | ||
final ByteData outputData = classTransformer.apply(inputData); | ||
return outputData.buffer().array(); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the artifact version to our BOM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would rather not enforce it for now. We can revisit if we have more modules using it but I would rather let projects use the version they want given we only use a small capability of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was in doubt about this and leaning for the less disruptive approach keeping it here. Happy to revisit when there's any need.