Skip to content

Commit

Permalink
Support create java 17 function project
Browse files Browse the repository at this point in the history
  • Loading branch information
Flanker32 committed Sep 4, 2022
1 parent 3a908b0 commit c7b7bf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { Progress } from 'vscode';
import { buildGradleFileName, JavaBuildTool, settingsGradleFileName } from '../../../constants';
import { localize } from '../../../localize';
import { confirmOverwriteFile } from '../../../utils/fs';
import { gradleUtils } from '../../../utils/gradleUtils';
import { javaUtils } from '../../../utils/javaUtils';
import { nonNullProp } from '../../../utils/nonNull';
import { IJavaProjectWizardContext } from '../javaSteps/IJavaProjectWizardContext';
import { java11, java8 } from '../javaSteps/JavaVersionStep';
import { java8 } from '../javaSteps/JavaVersionStep';
import { ScriptProjectCreateStep } from './ScriptProjectCreateStep';

const backupGradlePluginVersion = "1.8.2";
Expand Down Expand Up @@ -54,14 +54,9 @@ export class GradleProjectCreateStep extends ScriptProjectCreateStep {
return `rootProject.name = "${context.javaArtifactId}"`;
}

getCompatibilityVersion(javaVersion: string | undefined): string {
if (javaVersion === java8) {
return "1.8";
} else if (javaVersion === java11) {
return "11";
} else {
throw new Error(localize('invalidJavaVersion', 'Invalid Java version "{0}".', javaVersion));
}
getCompatibilityVersion(context: IJavaProjectWizardContext): string {
const javaVersion: string = nonNullProp(context, 'javaVersion');
return javaVersion === java8 ? "1.8" : javaVersion;
}

async getBuildGradleContent(context: IJavaProjectWizardContext): Promise<string> {
Expand All @@ -80,8 +75,8 @@ dependencies {
testImplementation 'org.mockito:mockito-core:3.3.3'
}
sourceCompatibility = '${this.getCompatibilityVersion(context.javaVersion)}'
targetCompatibility = '${this.getCompatibilityVersion(context.javaVersion)}'
sourceCompatibility = '${this.getCompatibilityVersion(context)}'
targetCompatibility = '${this.getCompatibilityVersion(context)}'
compileJava.options.encoding = 'UTF-8'
Expand Down
25 changes: 21 additions & 4 deletions src/commands/createNewProject/javaSteps/JavaVersionStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,46 @@
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { previewDescription } from "../../../constants";
import { hasMinFuncCliVersion } from "../../../funcCoreTools/hasMinFuncCliVersion";
import { localize } from "../../../localize";
import { IJavaProjectWizardContext } from "./IJavaProjectWizardContext";

export const java8: string = '8';
export const java11: string = '11';
export const java17: string = '17';

const versionInfo: [string, string, string, string?][] = [
[java8, 'Java 8', '1.0.0'],
[java11, 'Java 11', '3.0.2630'],
[java17, 'Java 17', '4.0.0', previewDescription]
];

export class JavaVersionStep extends AzureWizardPromptStep<IJavaProjectWizardContext> {

public static async setDefaultVersion(context: IJavaProjectWizardContext): Promise<void> {
if (!await hasMinFuncCliVersion(context, '3.0.2630', context.version)) {
context.javaVersion = java8;
}
}

public async prompt(context: IJavaProjectWizardContext): Promise<void> {
const picks: IAzureQuickPickItem<string>[] = [
{ label: 'Java 8', data: java8 },
{ label: 'Java 11', data: java11 },
];
const picks: IAzureQuickPickItem<string>[] = await this.getPicks(context);
const placeHolder: string = localize('selectJavaVersion', 'Select a version of Java');
context.javaVersion = (await context.ui.showQuickPick(picks, { placeHolder })).data;
}

// todo: get runtime from Get Function App Stacks API and validate local java version
async getPicks(context: IJavaProjectWizardContext): Promise<IAzureQuickPickItem<string>[]> {
const result: IAzureQuickPickItem<string>[] = [];
for (const [javaVersion, displayName, miniFunc, description] of versionInfo) {
if (await hasMinFuncCliVersion(context, miniFunc, context.version)) {
result.push({ label: displayName, data: javaVersion, description: description });
}
}
return result;
}

public shouldPrompt(context: IJavaProjectWizardContext): boolean {
return !context.javaVersion;
}
Expand Down

0 comments on commit c7b7bf9

Please sign in to comment.