-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli/java): resolve latest lts version
- #1384
- Loading branch information
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import { HttpService } from '../services'; | ||
import { EnvService, HttpService } from '../services'; | ||
|
||
export const TOOL_VERSION_RESOLVER = Symbol('TOOL_VERSION_RESOLVER'); | ||
|
||
@injectable() | ||
export abstract class ToolVersionResolver { | ||
abstract readonly tool: string; | ||
|
||
constructor(@inject(HttpService) protected readonly http: HttpService) {} | ||
constructor( | ||
@inject(HttpService) protected readonly http: HttpService, | ||
@inject(EnvService) protected readonly env: EnvService, | ||
) {} | ||
|
||
abstract resolve(version: string | undefined): Promise<string | undefined>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import is from '@sindresorhus/is'; | ||
import { injectable } from 'inversify'; | ||
import { ToolVersionResolver } from '../../install-tool/tool-version-resolver'; | ||
import { resolveLatestJavaLtsVersion } from './utils'; | ||
|
||
@injectable() | ||
export class JavaVersionResolver extends ToolVersionResolver { | ||
readonly tool: string = 'java'; | ||
|
||
async resolve(version: string | undefined): Promise<string | undefined> { | ||
if (!is.nonEmptyStringAndNotWhitespace(version) || version === 'latest') { | ||
// we know that the latest version is the first entry, so search for first lts | ||
return await resolveLatestJavaLtsVersion( | ||
this.http, | ||
this.tool === 'java-jre' ? 'jre' : 'jdk', | ||
this.env.arch, | ||
); | ||
} | ||
return version; | ||
} | ||
} | ||
|
||
@injectable() | ||
export class JavaJreVersionResolver extends JavaVersionResolver { | ||
override readonly tool = 'java-jre'; | ||
} | ||
|
||
@injectable() | ||
export class JavaJdkVersionResolver extends JavaVersionResolver { | ||
override readonly tool = 'java-jdk'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters