@@ -16,7 +16,6 @@ import {
1616 workspace
1717} from 'vscode' ;
1818import * as Path from 'path' ;
19- import * as Crypto from 'crypto' ;
2019import PortFinder from 'portfinder' ;
2120import * as Net from 'net' ;
2221import * as CommonsCommands from './commands' ;
@@ -27,13 +26,13 @@ import * as P2C from 'vscode-languageclient/lib/common/protocolConverter';
2726import { HighlightService , HighlightParams } from './highlight-service' ;
2827import { JVM , findJvm , findJdk } from '@pivotal-tools/jvm-launch-utils' ;
2928import { HighlightCodeLensProvider } from "./code-lens-service" ;
29+ import { CdsSupport , CdsResult } from './cds' ;
3030
3131const p2c = P2C . createConverter ( undefined , false , false ) ;
3232
3333PortFinder . basePort = 45556 ;
3434
3535const LOG_RESOLVE_VM_ARG_PREFIX = '-Xlog:jni+resolve=' ;
36- const LOG_AOT_VM_ARG_PREFIX = '-Xlog:aot' ;
3736const DEBUG_ARG = '-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y' ;
3837
3938async function fileExists ( filePath : string ) : Promise < boolean > {
@@ -154,56 +153,12 @@ async function findJdtEmbeddedJRE(): Promise<string | undefined> {
154153 }
155154}
156155
157- function hashString ( value : string ) : string {
158- return Crypto . createHash ( 'sha256' ) . update ( value ) . digest ( 'hex' ) . substring ( 0 , 12 ) ;
159- }
160-
161- function getAotCachePath ( extensionPath : string , jvm : JVM ) : string {
162- const javaHomeHash = hashString ( jvm . getJavaHome ( ) ) ;
163- return Path . join ( extensionPath , 'language-server' , `spring-boot-ls_${ javaHomeHash } .aot` ) ;
164- }
165-
166- async function prepareCdsArgs ( options : ActivatorOptions , context : ExtensionContext , jvm : JVM , useSocket : boolean ) : Promise < CdsResult > {
167- if ( ! options . workspaceOptions . get ( "cds.enabled" ) ) {
168- return { cdsArgs : [ ] } ;
169- }
170-
171- if ( jvm . getMajorVersion ( ) < 25 ) {
172- window . showInformationMessage (
173- 'Spring Boot Language Server: CDS is enabled but requires Java 25+. ' +
174- `Current Java version is ${ jvm . getMajorVersion ( ) } . Starting without CDS.`
175- ) ;
176- return { cdsArgs : [ ] } ;
177- }
178-
179- const aotCachePath = getAotCachePath ( context . extensionPath , jvm ) ;
180- const cdsArgs : string [ ] = [ ] ;
181-
182- if ( await fileExists ( aotCachePath ) ) {
183- options . clientOptions . outputChannel . appendLine ( `CDS: Using existing AOT cache: ${ aotCachePath } ` ) ;
184- cdsArgs . push ( `-XX:AOTCache=${ aotCachePath } ` ) ;
185- } else {
186- options . clientOptions . outputChannel . appendLine ( `CDS: No AOT cache found, will record cache on this run: ${ aotCachePath } ` ) ;
187- cdsArgs . push ( `-XX:AOTCacheOutput=${ aotCachePath } ` ) ;
188- }
189-
190- if ( ! useSocket ) {
191- cdsArgs . push ( `${ LOG_AOT_VM_ARG_PREFIX } *=off` ) ;
192- }
193-
194- return { cdsArgs } ;
195- }
196-
197- interface CdsResult {
198- cdsArgs : string [ ] ;
199- }
200-
201156function addCdsArgs ( vmArgs : string [ ] , cdsResult ?: CdsResult ) : void {
202157 if ( ! cdsResult ?. cdsArgs . length ) {
203158 return ;
204159 }
205160 for ( const arg of cdsResult . cdsArgs ) {
206- if ( arg . startsWith ( LOG_AOT_VM_ARG_PREFIX ) && hasVmArg ( LOG_AOT_VM_ARG_PREFIX , vmArgs ) ) {
161+ if ( arg . startsWith ( '-Xlog:aot' ) && hasVmArg ( '-Xlog:aot' , vmArgs ) ) {
207162 continue ;
208163 }
209164 vmArgs . push ( arg ) ;
@@ -246,13 +201,21 @@ export async function activate(options: ActivatorOptions, context: ExtensionCont
246201 clientOptions . outputChannel . appendLine ( "isJavaEightOrHigher => true" ) ;
247202
248203 const useSocket = ! ! process . env [ 'SPRING_LS_USE_SOCKET' ] ;
249- const cdsResult = await prepareCdsArgs ( options , context , jvm , useSocket ) ;
204+ const cds = new CdsSupport ( options , context , jvm , useSocket ) ;
205+ const cdsResult = await cds . prepareArgs ( ) ;
250206
207+ let client : LanguageClient ;
251208 if ( useSocket ) {
252- return setupLanguageClient ( context , await createServerOptionsForPortComm ( options , context , jvm , cdsResult ) , options ) ;
209+ client = await setupLanguageClient ( context , await createServerOptionsForPortComm ( options , context , jvm , cdsResult ) , options ) ;
253210 } else {
254- return setupLanguageClient ( context , await createServerOptions ( options , context , jvm , undefined , cdsResult ) , options ) ;
211+ client = await setupLanguageClient ( context , await createServerOptions ( options , context , jvm , undefined , cdsResult ) , options ) ;
255212 }
213+
214+ if ( cdsResult . isTrainingRun ) {
215+ cds . handleTrainingRun ( client ) ;
216+ }
217+
218+ return client ;
256219}
257220
258221async function createServerOptions ( options : ActivatorOptions , context : ExtensionContext , jvm : JVM , port ?: number , cdsResult ?: CdsResult ) : Promise < Executable > {
@@ -385,8 +348,8 @@ async function addCpAndLauncherToJvmArgs(args: string[], options: ActivatorOptio
385348 }
386349}
387350
388- function hasHeapArg ( _vmargs ?: string [ ] ) : boolean {
389- return hasVmArg ( '-Xmx' ) ;
351+ function hasHeapArg ( vmargs ?: string [ ] ) : boolean {
352+ return hasVmArg ( '-Xmx' , vmargs ) ;
390353}
391354
392355function hasVmArg ( argPrefix : string , vmargs ?: string [ ] ) : boolean {
0 commit comments