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

feat: Support create JavaFX projects #581

Merged
merged 1 commit into from
Jan 13, 2022
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
19 changes: 8 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@
"copy-webpack-plugin": "^6.4.1",
"glob": "^7.2.0",
"mocha": "^8.3.1",
"semver": "^7.3.5",
"ts-loader": "^9.2.6",
"tslint": "^5.20.1",
"typescript": "^4.5.4",
Expand All @@ -628,6 +627,7 @@
"globby": "^11.1.0",
"lodash": "^4.17.21",
"minimatch": "^3.0.4",
"semver": "^7.3.5",
"vscode-extension-telemetry-wrapper": "^0.11.0",
"vscode-tas-client": "^0.1.27"
}
Expand Down
34 changes: 34 additions & 0 deletions src/controllers/projectController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as fse from "fs-extra";
import * as _ from "lodash";
import * as path from "path";
import * as semver from "semver";
import { commands, Disposable, Extension, ExtensionContext, extensions, QuickPickItem, Uri, window, workspace } from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
Expand Down Expand Up @@ -58,6 +59,8 @@ export class ProjectController implements Disposable {

if (choice.metadata.type === ProjectType.NoBuildTool) {
await scaffoldSimpleProject(this.context);
} else if (choice.metadata.createCommandId && choice.metadata.createCommandArgs) {
await commands.executeCommand(choice.metadata.createCommandId, ...choice.metadata.createCommandArgs);
} else if (choice.metadata.createCommandId) {
await commands.executeCommand(choice.metadata.createCommandId);
}
Expand All @@ -75,7 +78,9 @@ interface IProjectTypeMetadata {
type: ProjectType;
extensionId: string;
extensionName: string;
leastExtensionVersion?: string;
createCommandId: string;
createCommandArgs?: any[];
}

interface IProjectTypeQuickPick extends QuickPickItem {
Expand All @@ -88,6 +93,7 @@ enum ProjectType {
SpringBoot = "SpringBoot",
Quarkus = "Quarkus",
MicroProfile = "MicroProfile",
JavaFX = "JavaFX",
}

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

if (metaData.leastExtensionVersion && semver.lt(extension.packageJSON.version, metaData.leastExtensionVersion)) {
await promptUpdateExtension(typeName, metaData);
return false;
}

await extension.activate();
return true;
}
Expand All @@ -112,6 +123,13 @@ async function promptInstallExtension(projectType: string, metaData: IProjectTyp
}
}

async function promptUpdateExtension(projectType: string, metaData: IProjectTypeMetadata): Promise<void> {
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");
if (choice === "Update") {
commands.executeCommand(Commands.INSTALL_EXTENSION, metaData.extensionId);
}
}

async function scaffoldSimpleProject(context: ExtensionContext): Promise<void> {
const workspaceFolder = Utility.getDefaultWorkspaceFolder();
const location: Uri[] | undefined = await window.showOpenDialog({
Expand Down Expand Up @@ -205,4 +223,20 @@ const projectTypes: IProjectType[] = [
createCommandId: "extension.microProfileStarter",
},
},
{
displayName: "JavaFX",
description: "create from archetype",
metadata: {
type: ProjectType.JavaFX,
extensionId: "vscjava.vscode-maven",
extensionName: "Maven for Java",
leastExtensionVersion: "0.35.0",
createCommandId: "maven.archetype.generate",
createCommandArgs: [{
archetypeGroupId: "org.openjfx",
archetypeArtifactId: "javafx-archetype-fxml",
archetypeVersion: "RELEASE",
}],
},
},
];
7 changes: 2 additions & 5 deletions test/ui/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,8 @@ describe("Command Tests", function() {
await new Workbench().executeCommand("java.project.create");
let inputBox = await InputBox.create();
const picks = await inputBox.getQuickPicks();
for (const quickPick of picks) {
if (await quickPick.getLabel() === "No build tools") {
await quickPick.click();
}
}
assert.equal("No build tools", await picks[0].getLabel());
await picks[0].select();
await sleep(3000);
inputBox = await InputBox.create();
await inputBox.setText(targetPath);
Expand Down