-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically register VMInstalls for the JDKs installed on the local…
… machine (#3251) * Automatically register VMInstalls for the JDKs installed on the local machine * disable jdt vm detection job by default Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
- Loading branch information
1 parent
5d224a5
commit 6cc071a
Showing
9 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
import { IJavaRuntime, findRuntimes, getSources } from 'jdk-utils'; | ||
|
||
let cachedJdks: IJavaRuntime[]; | ||
|
||
export async function listJdks(force?: boolean): Promise<IJavaRuntime[]> { | ||
if (force || !cachedJdks) { | ||
cachedJdks = await findRuntimes({ checkJavac: true, withVersion: true, withTags: true }); | ||
} | ||
|
||
return [].concat(cachedJdks); | ||
} | ||
|
||
/** | ||
* Sort by source where JDk is located. | ||
* The order is: | ||
* 1. JDK_HOME, JAVA_HOME, PATH | ||
* 2. JDK manager such as SDKMAN, jEnv, jabba, asdf | ||
* 3. Common places such as /usr/lib/jvm | ||
* 4. Others | ||
*/ | ||
export function sortJdksBySource(jdks: IJavaRuntime[]) { | ||
const rankedJdks = jdks as Array<IJavaRuntime & { rank: number }>; | ||
const env: string[] = ["JDK_HOME", "JAVA_HOME", "PATH"]; | ||
const jdkManagers: string[] = ["SDKMAN", "jEnv", "jabba", "asdf"]; | ||
for (const jdk of rankedJdks) { | ||
const detectedSources: string[] = getSources(jdk); | ||
for (const [index, source] of env.entries()) { | ||
if (detectedSources.includes(source)) { | ||
jdk.rank = index; // jdk from environment variables | ||
break; | ||
} | ||
} | ||
|
||
if (jdk.rank) { | ||
continue; | ||
} | ||
|
||
const fromManager: boolean = detectedSources.some(source => jdkManagers.includes(source)); | ||
if (fromManager) { | ||
jdk.rank = env.length + 1; // jdk from the jdk managers such as SDKMAN | ||
} else if (!detectedSources.length){ | ||
jdk.rank = env.length + 2; // jdk from common places | ||
} else { | ||
jdk.rank = env.length + 3; // jdk from other source such as ~/.gradle/jdks | ||
} | ||
} | ||
rankedJdks.sort((a, b) => a.rank - b.rank); | ||
} | ||
|
||
/** | ||
* Sort by major version in descend order. | ||
*/ | ||
export function sortJdksByVersion(jdks: IJavaRuntime[]) { | ||
jdks.sort((a, b) => (b.version?.major ?? 0) - (a.version?.major ?? 0)); | ||
} |
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
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