@@ -13,7 +13,7 @@ import { LibertyProject } from "./libertyProject";
1313import { ProjectRegistry } from "./projectRegistry" ;
1414import { ProjectTreeProvider } from "./projectTreeProvider" ;
1515import { getReport } from "../util/helperUtil" ;
16- import { COMMAND_TITLES , LIBERTY_SERVER_ENV_PORT_REGEX , isMaven , isGradle , isContainer } from "../definitions/constants" ;
16+ import { COMMAND_TITLES , LIBERTY_SERVER_ENV_PORT_REGEX , isMaven , isGradle , MAVEN_GOAL_DEV , MAVEN_GOAL_DEVC , GRADLE_TASK_DEV , GRADLE_TASK_DEVC } from "../definitions/constants" ;
1717import { getGradleTestReport } from "../util/gradleUtil" ;
1818import { DashboardData } from "./dashboard" ;
1919import { ProjectStartCmdParam } from "./projectStartCmdParam" ;
@@ -80,6 +80,43 @@ export async function listAllCommands(): Promise<void> {
8080}
8181
8282
83+ /**
84+ * Ensures a terminal exists for the project, creates one if needed, shows it,
85+ * and registers it. Returns the terminal, or undefined if creation failed.
86+ */
87+ function ensureTerminal ( project : LibertyProject ) : vscode . Terminal | undefined {
88+ let terminal = project . getTerminal ( ) ;
89+ if ( terminal === undefined ) {
90+ const terminalPath = project . parent
91+ ? Path . dirname ( project . parent . getPath ( ) )
92+ : Path . dirname ( project . getPath ( ) ) ;
93+ terminal = createTerminalforLiberty ( project , terminal , terminalPath ) ;
94+ }
95+ if ( terminal !== undefined ) {
96+ terminal . show ( ) ;
97+ project . setTerminal ( terminal ) ;
98+ }
99+ return terminal ;
100+ }
101+
102+ async function sendDevModeCommand (
103+ terminal : vscode . Terminal ,
104+ project : LibertyProject ,
105+ mavenGoal : string ,
106+ gradleTask : string ,
107+ customCommand ?: string
108+ ) : Promise < void > {
109+ if ( isMaven ( project . getContextValue ( ) ) ) {
110+ const pomPath = project . parent ? project . parent . getPath ( ) : project . getPath ( ) ;
111+ const artifactId = project . parent ? project . artifactId : undefined ;
112+ const cmd = await getCommandForMaven ( pomPath , mavenGoal , project . getTerminalType ( ) , customCommand , artifactId ) ;
113+ terminal . sendText ( cmd ) ;
114+ } else if ( isGradle ( project . getContextValue ( ) ) ) {
115+ const cmd = await getCommandForGradle ( project . getPath ( ) , gradleTask , project . getTerminalType ( ) , customCommand ) ;
116+ terminal . sendText ( cmd ) ;
117+ }
118+ }
119+
83120// start dev mode
84121export async function startDevMode ( libProject ?: LibertyProject | undefined ) : Promise < void > {
85122 const projectProvider : ProjectTreeProvider = ProjectTreeProvider . getInstance ( ) ;
@@ -94,32 +131,10 @@ export async function startDevMode(libProject?: LibertyProject | undefined): Pro
94131 return ;
95132 }
96133
97- // Check if user selected a child from an aggregator
98- const originalIsAggregator = libProject ?. isAggregator ?? false ;
99- const clickedDirectlyOnChild = ! originalIsAggregator && targetProject . parent ;
100-
101134 console . log ( localize ( "starting.liberty.dev.on" , targetProject . getLabel ( ) ) ) ;
102- let terminal = targetProject . getTerminal ( ) ;
103- if ( terminal === undefined ) {
104- const terminalPath = targetProject . parent
105- ? Path . dirname ( targetProject . parent . getPath ( ) )
106- : Path . dirname ( targetProject . getPath ( ) ) ;
107- terminal = createTerminalforLiberty ( targetProject , terminal , terminalPath ) ;
108- }
135+ const terminal = ensureTerminal ( targetProject ) ;
109136 if ( terminal !== undefined ) {
110- terminal . show ( ) ;
111- targetProject . setTerminal ( terminal ) ;
112- if ( isMaven ( targetProject . getContextValue ( ) ) ) {
113- const pomPath = targetProject . parent ? targetProject . parent . getPath ( ) : targetProject . getPath ( ) ;
114- const artifactId = ( targetProject . parent && ( clickedDirectlyOnChild || ProjectRegistry . getInstance ( ) . findLibertyDescendants ( targetProject . parent ) . length > 1 ) )
115- ? targetProject . artifactId
116- : undefined ;
117- const cmd = await getCommandForMaven ( pomPath , "io.openliberty.tools:liberty-maven-plugin:dev" , targetProject . getTerminalType ( ) , undefined , artifactId ) ;
118- terminal . sendText ( cmd ) ;
119- } else if ( isGradle ( targetProject . getContextValue ( ) ) ) {
120- const cmd = await getCommandForGradle ( targetProject . getPath ( ) , "libertyDev" , targetProject . getTerminalType ( ) ) ;
121- terminal . sendText ( cmd ) ;
122- }
137+ await sendDevModeCommand ( terminal , targetProject , MAVEN_GOAL_DEV , GRADLE_TASK_DEV ) ;
123138 targetProject . isDevMode = true ;
124139 projectProvider . notifyDevModeChanged ( targetProject ) ;
125140 }
@@ -374,19 +389,8 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
374389 const registry = ProjectRegistry . getInstance ( ) ;
375390 const targetProject = libProject ;
376391
377- // Check if this is a child of an aggregator
378- const clickedDirectlyOnChild = targetProject . parent !== undefined ;
379-
380- let terminal = targetProject . getTerminal ( ) ;
381- if ( terminal === undefined ) {
382- const terminalPath = targetProject . parent
383- ? Path . dirname ( targetProject . parent . getPath ( ) )
384- : Path . dirname ( targetProject . getPath ( ) ) ;
385- terminal = createTerminalforLiberty ( targetProject , terminal , terminalPath ) ;
386- }
392+ const terminal = ensureTerminal ( targetProject ) ;
387393 if ( terminal !== undefined ) {
388- terminal . show ( ) ;
389- targetProject . setTerminal ( terminal ) ;
390394
391395 let placeHolderStr = "" ;
392396 let promptString = localize ( "specify.custom.parms.maven" ) ;
@@ -425,17 +429,7 @@ export async function customDevMode(libProject?: LibertyProject | undefined, par
425429 await helperUtil . saveStorageData ( registry . getContext ( ) , dashboardData ) ;
426430 }
427431
428- if ( isMaven ( targetProject . getContextValue ( ) ) ) {
429- const pomPath = targetProject . parent ? targetProject . parent . getPath ( ) : targetProject . getPath ( ) ;
430- const artifactId = ( targetProject . parent && ( clickedDirectlyOnChild || registry . findLibertyDescendants ( targetProject . parent ) . length > 1 ) )
431- ? targetProject . artifactId
432- : undefined ;
433- const cmd = await getCommandForMaven ( pomPath , "io.openliberty.tools:liberty-maven-plugin:dev" , targetProject . getTerminalType ( ) , customCommand , artifactId ) ;
434- terminal . sendText ( cmd ) ;
435- } else if ( isGradle ( targetProject . getContextValue ( ) ) ) {
436- const cmd = await getCommandForGradle ( targetProject . getPath ( ) , "libertyDev" , targetProject . getTerminalType ( ) , customCommand ) ;
437- terminal . sendText ( cmd ) ;
438- }
432+ await sendDevModeCommand ( terminal , targetProject , MAVEN_GOAL_DEV , GRADLE_TASK_DEV , customCommand ) ;
439433 targetProject . isDevMode = true ;
440434 projectProvider . notifyDevModeChanged ( targetProject ) ;
441435 }
@@ -456,29 +450,9 @@ export async function startContainerDevMode(libProject?: LibertyProject | undefi
456450 return ;
457451 }
458452
459- const clickedDirectlyOnChild = ! ( libProject ?. isAggregator ?? false ) && targetProject . parent ;
460-
461- let terminal = targetProject . getTerminal ( ) ;
462- if ( terminal === undefined ) {
463- const terminalPath = targetProject . parent
464- ? Path . dirname ( targetProject . parent . getPath ( ) )
465- : Path . dirname ( targetProject . getPath ( ) ) ;
466- terminal = createTerminalforLiberty ( targetProject , terminal , terminalPath ) ;
467- }
453+ const terminal = ensureTerminal ( targetProject ) ;
468454 if ( terminal !== undefined ) {
469- terminal . show ( ) ;
470- targetProject . setTerminal ( terminal ) ;
471- if ( isContainer ( targetProject . getContextValue ( ) ) && isMaven ( targetProject . getContextValue ( ) ) ) {
472- const pomPath = targetProject . parent ? targetProject . parent . getPath ( ) : targetProject . getPath ( ) ;
473- const artifactId = ( targetProject . parent && ( clickedDirectlyOnChild || ProjectRegistry . getInstance ( ) . findLibertyDescendants ( targetProject . parent ) . length > 1 ) )
474- ? targetProject . artifactId
475- : undefined ;
476- const cmd = await getCommandForMaven ( pomPath , "io.openliberty.tools:liberty-maven-plugin:devc" , targetProject . getTerminalType ( ) , undefined , artifactId ) ;
477- terminal . sendText ( cmd ) ;
478- } else if ( isContainer ( targetProject . getContextValue ( ) ) && isGradle ( targetProject . getContextValue ( ) ) ) {
479- const cmd = await getCommandForGradle ( targetProject . getPath ( ) , "libertyDevc" , targetProject . getTerminalType ( ) ) ;
480- terminal . sendText ( cmd ) ;
481- }
455+ await sendDevModeCommand ( terminal , targetProject , MAVEN_GOAL_DEVC , GRADLE_TASK_DEVC ) ;
482456 targetProject . isDevMode = true ;
483457 projectProvider . notifyDevModeChanged ( targetProject ) ;
484458 }
0 commit comments