Skip to content

Commit c57c34f

Browse files
authored
feat: Support creating JavaFX projects (#581)
Signed-off-by: Sheng Chen <[email protected]>
1 parent 1d655a6 commit c57c34f

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

package-lock.json

Lines changed: 8 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@
613613
"copy-webpack-plugin": "^6.4.1",
614614
"glob": "^7.2.0",
615615
"mocha": "^8.3.1",
616-
"semver": "^7.3.5",
617616
"ts-loader": "^9.2.6",
618617
"tslint": "^5.20.1",
619618
"typescript": "^4.5.4",
@@ -628,6 +627,7 @@
628627
"globby": "^11.1.0",
629628
"lodash": "^4.17.21",
630629
"minimatch": "^3.0.4",
630+
"semver": "^7.3.5",
631631
"vscode-extension-telemetry-wrapper": "^0.11.0",
632632
"vscode-tas-client": "^0.1.27"
633633
}

src/controllers/projectController.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as fse from "fs-extra";
55
import * as _ from "lodash";
66
import * as path from "path";
7+
import * as semver from "semver";
78
import { commands, Disposable, Extension, ExtensionContext, extensions, QuickPickItem, Uri, window, workspace } from "vscode";
89
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
910
import { Commands } from "../commands";
@@ -58,6 +59,8 @@ export class ProjectController implements Disposable {
5859

5960
if (choice.metadata.type === ProjectType.NoBuildTool) {
6061
await scaffoldSimpleProject(this.context);
62+
} else if (choice.metadata.createCommandId && choice.metadata.createCommandArgs) {
63+
await commands.executeCommand(choice.metadata.createCommandId, ...choice.metadata.createCommandArgs);
6164
} else if (choice.metadata.createCommandId) {
6265
await commands.executeCommand(choice.metadata.createCommandId);
6366
}
@@ -75,7 +78,9 @@ interface IProjectTypeMetadata {
7578
type: ProjectType;
7679
extensionId: string;
7780
extensionName: string;
81+
leastExtensionVersion?: string;
7882
createCommandId: string;
83+
createCommandArgs?: any[];
7984
}
8085

8186
interface IProjectTypeQuickPick extends QuickPickItem {
@@ -88,6 +93,7 @@ enum ProjectType {
8893
SpringBoot = "SpringBoot",
8994
Quarkus = "Quarkus",
9095
MicroProfile = "MicroProfile",
96+
JavaFX = "JavaFX",
9197
}
9298

9399
async function ensureExtension(typeName: string, metaData: IProjectTypeMetadata): Promise<boolean> {
@@ -101,6 +107,11 @@ async function ensureExtension(typeName: string, metaData: IProjectTypeMetadata)
101107
return false;
102108
}
103109

110+
if (metaData.leastExtensionVersion && semver.lt(extension.packageJSON.version, metaData.leastExtensionVersion)) {
111+
await promptUpdateExtension(typeName, metaData);
112+
return false;
113+
}
114+
104115
await extension.activate();
105116
return true;
106117
}
@@ -112,6 +123,13 @@ async function promptInstallExtension(projectType: string, metaData: IProjectTyp
112123
}
113124
}
114125

126+
async function promptUpdateExtension(projectType: string, metaData: IProjectTypeMetadata): Promise<void> {
127+
const choice: string | undefined = await window.showInformationMessage(`${metaData.extensionName} needs to be updated to create ${projectType} projects. Please re-run the command 'Java: Create Java Project...' after the extension is updated.`, "Update");
128+
if (choice === "Update") {
129+
commands.executeCommand(Commands.INSTALL_EXTENSION, metaData.extensionId);
130+
}
131+
}
132+
115133
async function scaffoldSimpleProject(context: ExtensionContext): Promise<void> {
116134
const workspaceFolder = Utility.getDefaultWorkspaceFolder();
117135
const location: Uri[] | undefined = await window.showOpenDialog({
@@ -205,4 +223,20 @@ const projectTypes: IProjectType[] = [
205223
createCommandId: "extension.microProfileStarter",
206224
},
207225
},
226+
{
227+
displayName: "JavaFX",
228+
description: "create from archetype",
229+
metadata: {
230+
type: ProjectType.JavaFX,
231+
extensionId: "vscjava.vscode-maven",
232+
extensionName: "Maven for Java",
233+
leastExtensionVersion: "0.35.0",
234+
createCommandId: "maven.archetype.generate",
235+
createCommandArgs: [{
236+
archetypeGroupId: "org.openjfx",
237+
archetypeArtifactId: "javafx-archetype-fxml",
238+
archetypeVersion: "RELEASE",
239+
}],
240+
},
241+
},
208242
];

test/ui/command.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,8 @@ describe("Command Tests", function() {
282282
await new Workbench().executeCommand("java.project.create");
283283
let inputBox = await InputBox.create();
284284
const picks = await inputBox.getQuickPicks();
285-
for (const quickPick of picks) {
286-
if (await quickPick.getLabel() === "No build tools") {
287-
await quickPick.click();
288-
}
289-
}
285+
assert.equal("No build tools", await picks[0].getLabel());
286+
await picks[0].select();
290287
await sleep(3000);
291288
inputBox = await InputBox.create();
292289
await inputBox.setText(targetPath);

0 commit comments

Comments
 (0)