-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support java 17 runtime when create function project #3311
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c7b7bf9
Support create java 17 function project
Flanker32 dd460df
Force to use latest maven archetype when create maven function project
Flanker32 ec8fe90
Fix validation issue in `verifyAppSettings`
Flanker32 f09587a
Add validation for local java runtime
Flanker32 e939fd6
Resolve issues in test cases
Flanker32 9a9ecdc
Fix wording and migrate to `AzExtFsExtra`
Flanker32 66eeac6
Update version for gradle plugin and java library
Flanker32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,69 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils'; | ||
import { localize } from '../../../localize'; | ||
import { cpUtils } from "../../../utils/cpUtils"; | ||
|
||
import * as path from 'path'; | ||
|
||
export async function getJavaVersion(): Promise<number> { | ||
const javaHome: string | undefined = process.env['JAVA_HOME']; | ||
let javaVersion = javaHome ? await checkVersionInReleaseFile(javaHome) : undefined; | ||
if (!javaVersion) { | ||
javaVersion = await checkVersionByCLI(javaHome ? path.join(javaHome, 'bin', 'java') : 'java'); | ||
} | ||
if (!javaVersion) { | ||
const message: string = localize('javaNotFound', 'Failed to get Java version. Please ensure that Java is installed and JAVA_HOME environment variable is set.'); | ||
throw new Error(message); | ||
} | ||
return javaVersion; | ||
} | ||
|
||
async function checkVersionInReleaseFile(javaHome: string): Promise<number | undefined> { | ||
if (!javaHome) { | ||
return undefined; | ||
} | ||
const releaseFile = path.join(javaHome, "release"); | ||
if (!await AzExtFsExtra.pathExists(releaseFile)) { | ||
return undefined; | ||
} | ||
|
||
try { | ||
const content = await AzExtFsExtra.readFile(releaseFile); | ||
const regexp = /^JAVA_VERSION="(.*)"/gm; | ||
const match = regexp.exec(content.toString()); | ||
return match ? flattenMajorVersion(match[1]) : undefined; | ||
} catch (error) { | ||
// ignore | ||
return undefined; | ||
} | ||
} | ||
|
||
async function checkVersionByCLI(javaExec: string): Promise<number | undefined> { | ||
if (!javaExec) { | ||
return undefined; | ||
} | ||
const result: cpUtils.ICommandResult = await cpUtils.tryExecuteCommand(undefined, undefined, javaExec, '-version'); | ||
const output: string = result.cmdOutputIncludingStderr; | ||
const regexp = /version "(.*)"/g; | ||
const match = regexp.exec(output); | ||
return match ? flattenMajorVersion(match[1]) : undefined; | ||
} | ||
|
||
function flattenMajorVersion(version: string): number { | ||
// Ignore '1.' prefix for legacy Java versions | ||
if (version.startsWith("1.")) { | ||
version = version.substring(2); | ||
} | ||
|
||
const regexp = /\d+/g; | ||
const match = regexp.exec(version); | ||
let javaVersion = 0; | ||
if (match) { | ||
javaVersion = parseInt(match[0], 10); | ||
} | ||
|
||
return javaVersion; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this get changed to an earlier version of Java?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As some of the test environment uses java 8 as default java version, we add java version validation in this pr and will not provide java 11 as an option in this case