Skip to content
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

Avoid letting our transformation rules getting transformed #28140

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -57,18 +56,25 @@ private static class JakartaTransformer {

private final Logger logger;
private final ActionContext ctx;
private static final Map<String, String> renames = Collections.singletonMap(forbiddenName(), "jakarta.transaction");

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;
//N.B. we enable only this single transformation of package renames, 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()));
}

//Need to prevent the Eclipse Transformer - which is run on this whole code base - to actually replace this name:
private static String forbiddenName() {
StringBuilder sb = new StringBuilder("java")
.append("x.")
.append("transaction");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, I just fixed it by doing a "javax." + "transaction" where I faced the issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But given you're transforming the bytecode and not the source, maybe it wouldn't work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, pretty sure that would have worked too. But didn't want to take chances - spent enough on this :)

return sb.toString();
}

byte[] transform(final String name, final byte[] bytes) {
logger.info("Jakarta EE compatibility enhancer for Quarkus: transforming " + name);
final ClassActionImpl classTransformer = new ClassActionImpl(ctx);
Expand Down