44import * as fse from "fs-extra" ;
55import * as _ from "lodash" ;
66import * as path from "path" ;
7+ import * as semver from "semver" ;
78import { commands , Disposable , Extension , ExtensionContext , extensions , QuickPickItem , Uri , window , workspace } from "vscode" ;
89import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper" ;
910import { 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
8186interface IProjectTypeQuickPick extends QuickPickItem {
@@ -88,6 +93,7 @@ enum ProjectType {
8893 SpringBoot = "SpringBoot" ,
8994 Quarkus = "Quarkus" ,
9095 MicroProfile = "MicroProfile" ,
96+ JavaFX = "JavaFX" ,
9197}
9298
9399async 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+
115133async 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] ;
0 commit comments