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

Apache HttpClient5 recipes should load classpath from resources #480

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ recipeDependencies {

parserClasspath("com.nimbusds:nimbus-jose-jwt:9.13")
parserClasspath("net.minidev:json-smart:2.4.+")

parserClasspath("org.apache.httpcomponents.core5:httpcore5:5.1.+")
parserClasspath("org.apache.httpcomponents.client5:httpclient5:5.1.+")
}

val rewriteVersion = rewriteRecipe.rewriteVersion.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
JavaTemplate template = JavaTemplate
.builder(StringUtils.repeat("#{any()}, ", m.getArguments().size()) + "TimeUnit.#{}")
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion().classpath("httpclient5", "httpcore5"))
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "httpclient5", "httpcore5"))
.imports("java.util.concurrent.TimeUnit")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public String getDescription() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaVisitor<ExecutionContext>() {
final MethodMatcher matcher = new MethodMatcher("org.apache.hc.core5.http.HttpResponse getStatusLine()");
final JavaTemplate template = JavaTemplate.builder("new StatusLine(#{any(org.apache.hc.core5.http.HttpResponse)})")
.javaParser(JavaParser.fromJavaVersion().classpath("httpcore5"))
.imports("org.apache.hc.core5.http.message.StatusLine")
.build();

@Override
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx);
if (matcher.matches(m)) {
maybeAddImport("org.apache.hc.core5.http.message.StatusLine");
return template.apply(updateCursor(m), m.getCoordinates().replace(), m.getSelect());
return JavaTemplate.builder("new StatusLine(#{any(org.apache.hc.core5.http.HttpResponse)})")
.imports("org.apache.hc.core5.http.message.StatusLine")
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "httpcore5"))
.build()
.apply(updateCursor(m), m.getCoordinates().replace(), m.getSelect());
}
return m;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void defaults(RecipeSpec spec) {
}

@Test
void testCookieConstantsMapping() {
void cookieConstantsMapping() {
rewriteRun(
//language=java
java(
Expand Down
Loading