Skip to content

Commit c80980f

Browse files
committed
Accept resolvers in JavaScriptRewriteRpc and PythonRewriteRpc
Both RPC classes were calling the 2-arg RewriteRpc constructor which passes emptyList() for resolvers. When a JS/Python recipe's preconditions reference Java recipes bundled under the "maven" ecosystem, the PrepareRecipe callback fails with "No available resolver for 'maven' ecosystem". Add a resolvers field to both Builders (defaulting to emptyList() for backward compatibility) and pass them through to the 3-arg super constructor.
1 parent 79719fb commit c80980f

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc/JavaScriptRewriteRpc.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openrewrite.Parser;
2323
import org.openrewrite.SourceFile;
2424
import org.openrewrite.internal.StringUtils;
25+
import org.openrewrite.marketplace.RecipeBundleResolver;
2526
import org.openrewrite.marketplace.RecipeMarketplace;
2627
import org.openrewrite.rpc.RewriteRpc;
2728
import org.openrewrite.rpc.RewriteRpcProcess;
@@ -57,8 +58,8 @@ public class JavaScriptRewriteRpc extends RewriteRpc {
5758
private final Map<String, String> commandEnv;
5859
private final RewriteRpcProcess process;
5960

60-
JavaScriptRewriteRpc(RewriteRpcProcess process, RecipeMarketplace marketplace, String command, Map<String, String> commandEnv) {
61-
super(process.getRpcClient(), marketplace);
61+
JavaScriptRewriteRpc(RewriteRpcProcess process, RecipeMarketplace marketplace, List<RecipeBundleResolver> resolvers, String command, Map<String, String> commandEnv) {
62+
super(process.getRpcClient(), marketplace, resolvers);
6263
this.command = command;
6364
this.commandEnv = commandEnv;
6465
this.process = process;
@@ -199,6 +200,7 @@ public static Builder builder() {
199200
@RequiredArgsConstructor
200201
public static class Builder implements Supplier<JavaScriptRewriteRpc> {
201202
private RecipeMarketplace marketplace = new RecipeMarketplace();
203+
private List<RecipeBundleResolver> resolvers = Collections.emptyList();
202204
private final Map<String, String> environment = new HashMap<>();
203205
private Path npxPath = System.getProperty("os.name").toLowerCase().contains("windows") ? Paths.get("npx.cmd") : Paths.get("npx");
204206
private @Nullable Path log;
@@ -218,6 +220,11 @@ public Builder marketplace(RecipeMarketplace marketplace) {
218220
return this;
219221
}
220222

223+
public Builder resolvers(List<RecipeBundleResolver> resolvers) {
224+
this.resolvers = resolvers;
225+
return this;
226+
}
227+
221228
public Builder recipeInstallDir(@Nullable Path recipeInstallDir) {
222229
this.recipeInstallDir = recipeInstallDir;
223230
return this;
@@ -382,7 +389,7 @@ public JavaScriptRewriteRpc get() {
382389
process.start();
383390

384391
try {
385-
return (JavaScriptRewriteRpc) new JavaScriptRewriteRpc(process, marketplace,
392+
return (JavaScriptRewriteRpc) new JavaScriptRewriteRpc(process, marketplace, resolvers,
386393
String.join(" ", cmdArr), process.environment())
387394
.livenessCheck(process::getLivenessCheck)
388395
.timeout(timeout)

rewrite-python/src/main/java/org/openrewrite/python/rpc/PythonRewriteRpc.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.jspecify.annotations.Nullable;
2121
import org.openrewrite.ExecutionContext;
2222
import org.openrewrite.SourceFile;
23+
import org.openrewrite.marketplace.RecipeBundleResolver;
2324
import org.openrewrite.marketplace.RecipeMarketplace;
2425
import org.openrewrite.rpc.RewriteRpc;
2526
import org.openrewrite.rpc.RewriteRpcProcess;
@@ -54,8 +55,8 @@ public class PythonRewriteRpc extends RewriteRpc {
5455
private final Map<String, String> commandEnv;
5556
private final RewriteRpcProcess process;
5657

57-
PythonRewriteRpc(RewriteRpcProcess process, RecipeMarketplace marketplace, String command, Map<String, String> commandEnv) {
58-
super(process.getRpcClient(), marketplace);
58+
PythonRewriteRpc(RewriteRpcProcess process, RecipeMarketplace marketplace, List<RecipeBundleResolver> resolvers, String command, Map<String, String> commandEnv) {
59+
super(process.getRpcClient(), marketplace, resolvers);
5960
this.command = command;
6061
this.commandEnv = commandEnv;
6162
this.process = process;
@@ -223,6 +224,7 @@ public static Builder builder() {
223224
@RequiredArgsConstructor
224225
public static class Builder implements Supplier<PythonRewriteRpc> {
225226
private RecipeMarketplace marketplace = new RecipeMarketplace();
227+
private List<RecipeBundleResolver> resolvers = Collections.emptyList();
226228
private final Map<String, String> environment = new HashMap<>();
227229
// Default to looking for a venv python, falling back to system python
228230
private Path pythonPath = findDefaultPythonPath();
@@ -268,6 +270,11 @@ public Builder marketplace(RecipeMarketplace marketplace) {
268270
return this;
269271
}
270272

273+
public Builder resolvers(List<RecipeBundleResolver> resolvers) {
274+
this.resolvers = resolvers;
275+
return this;
276+
}
277+
271278
/**
272279
* Path to the Python executable.
273280
*
@@ -437,7 +444,7 @@ public PythonRewriteRpc get() {
437444
process.start();
438445

439446
try {
440-
return (PythonRewriteRpc) new PythonRewriteRpc(process, marketplace,
447+
return (PythonRewriteRpc) new PythonRewriteRpc(process, marketplace, resolvers,
441448
String.join(" ", cmdArr), process.environment())
442449
.livenessCheck(process::getLivenessCheck)
443450
.timeout(timeout)

0 commit comments

Comments
 (0)