Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ static void register(Project project, ProjectLayout layout, SourceSet main, Code
"Opens the Code Visualizer on this project; -Pcodevisualizer.base=<rev> also shows the branch's changes");
}

/// The Gradle property that names the port a tool serves its MCP tools on, the
/// `-P` twin of the `-D` property `cn1:guibuilder` and `cn1:visualize` forward,
/// or null for a tool that serves none.
static String mcpPortProperty(DesktopTool tool) {
if (tool == DesktopTool.GUI_BUILDER) {
return "guibuilder.mcp.port";
}
if (tool == DesktopTool.CODE_VISUALIZER) {
return "codevisualizer.mcp.port";
}
return null;
}

/// The main source set's Java and Kotlin directories as the build resolved
/// them, a `sourceSets { }` block included. Settings treats the descriptor's
/// roots as the whole compiled-source set, so the conventional layout's alone
Expand Down Expand Up @@ -198,7 +211,10 @@ private static void register(Project project, ProjectLayout layout, CodenameOneE
.orElse(Boolean.TRUE));
t.getInitialForm().set(project.getProviders().gradleProperty("className"));
t.getBase().set(project.getProviders().gradleProperty("codevisualizer.base"));
t.getMcpPort().set(project.getProviders().gradleProperty("codevisualizer.mcp.port"));
String portProperty = mcpPortProperty(tool);
if (portProperty != null) {
t.getMcpPort().set(project.getProviders().gradleProperty(portProperty));
}
t.getToken().set(project.getProviders().gradleProperty("token"));
t.getUser().set(project.getProviders().gradleProperty("user"));
t.getBaseUrl().set(project.getProviders().gradleProperty("baseUrl")
Expand Down Expand Up @@ -244,8 +260,9 @@ public abstract static class ToolTask extends Cn1Task {
@Optional
public abstract Property<String> getBase();

/// `-Pcodevisualizer.mcp.port`: the port the visualizer's assistant tools are served
/// on; 8766, or a free one, when unset.
/// The port the tool's assistant tools are served on: `-Pcodevisualizer.mcp.port` for
/// the Code Visualizer (8766, or a free one, when unset) and `-Pguibuilder.mcp.port`
/// for the GUI Builder (no server when unset); see [ToolSupport#mcpPortProperty].
@Input
@Optional
public abstract Property<String> getMcpPort();
Expand Down Expand Up @@ -299,6 +316,9 @@ public void open() {
binding.set("sourceDir", getJavaSourceDir().get());
binding.set("cssFile", layout.themeCss().getAbsolutePath());
binding.set("initialForm", getInitialForm().getOrNull());
if (getMcpPort().isPresent()) {
extra.add("-Dguibuilder.mcp.port=" + getMcpPort().get());
}
} else if (tool == DesktopTool.GAME_BUILDER) {
ensureDir(layout.gamesDir());
binding.set("gamesDir", layout.gamesDir().getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,13 @@ void eachPlatformHasItsOwnCn1libConfiguration() {
assertEquals("cn1libIos", Cn1libs.configurationName("ios"));
assertEquals("cn1libJavascript", Cn1libs.configurationName("javascript"));
}

@Test
void eachToolReadsItsOwnMcpPortProperty() {
assertEquals("guibuilder.mcp.port", ToolSupport.mcpPortProperty(com.codename1.maven.DesktopTool.GUI_BUILDER));
assertEquals("codevisualizer.mcp.port",
ToolSupport.mcpPortProperty(com.codename1.maven.DesktopTool.CODE_VISUALIZER));
assertNull(ToolSupport.mcpPortProperty(com.codename1.maven.DesktopTool.SETTINGS));
assertNull(ToolSupport.mcpPortProperty(com.codename1.maven.DesktopTool.GAME_BUILDER));
}
}
Loading