Skip to content

Commit

Permalink
[GR-26965] Clarify to user GraalVM supports less Java versions than M…
Browse files Browse the repository at this point in the history
…icronaut.

PullRequest: graal/7519
  • Loading branch information
dbalek committed Nov 4, 2020
2 parents 333917a + a40e054 commit b8ec287
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 103 deletions.
24 changes: 11 additions & 13 deletions vscode/graalvm/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ import { onClientNotification, startLanguageServer, stopLanguageServer } from '.
import { installRPackage, R_LANGUAGE_SERVER_PACKAGE_NAME } from './graalVMR';
import { installRubyGem, RUBY_LANGUAGE_SERVER_GEM_NAME } from './graalVMRuby';
import { addNativeImageToPOM } from './graalVMNativeImage';
import { getGVMHome, configureGraalVMHome, setupProxy } from './graalVMConfiguration';
import { getGVMHome, setupProxy } from './graalVMConfiguration';
import { runVisualVMForPID } from './graalVMVisualVM';

const INSTALL_GRAALVM: string = 'Install GraalVM';
const SELECT_EXISTING_GRAALVM: string = 'Select Existing GraalVM';
const SELECT_ACTIVE_GRAALVM: string = 'Set Active GraalVM';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.selectGraalVMHome', (installation?: Installation) => {
selectInstalledGraalVM(installation ? installation.home : undefined);
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.selectGraalVMHome', (installation?: string | Installation, nonInteractive?: boolean) => {
selectInstalledGraalVM(installation instanceof Installation ? installation.home : installation, nonInteractive);
}));
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.installGraalVM', () => {
installGraalVM(context.extensionPath);
}));
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.addExistingGraalVM', () => {
addExistingGraalVM();
}));
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.findGraalVMs', async () => {
const graalVMHome = getGVMHome();
return (await findGraalVMs()).map(item => ({name: item.name, path: item.path, active: item.path === graalVMHome}));
}));
context.subscriptions.push(vscode.commands.registerCommand('extension.graalvm.installGraalVMComponent', (component: string | Component, homeFolder?: string) => {
installGraalVMComponent(component, homeFolder, context.extensionPath);
}));
Expand Down Expand Up @@ -78,7 +82,10 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('graalvm.home')) {
vscode.commands.executeCommand('extension.graalvm.refreshInstallations');
config();
const graalVMHome = getGVMHome();
if (!graalVMHome) {
setupGraalVM();
}
stopLanguageServer().then(() => startLanguageServer(getGVMHome()));
} else if (e.affectsConfiguration('graalvm.installations')) {
vscode.commands.executeCommand('extension.graalvm.refreshInstallations');
Expand Down Expand Up @@ -122,12 +129,3 @@ function setupGraalVM(){
});
});
}

function config() {
const graalVMHome = getGVMHome();
if (graalVMHome) {
configureGraalVMHome(graalVMHome);
} else {
setupGraalVM();
}
}
43 changes: 22 additions & 21 deletions vscode/graalvm/src/graalVMConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,31 @@ export function setupProxy() {
});
}

export async function configureGraalVMHome(graalVMHome: string) {
gatherConfigurations();
export async function configureGraalVMHome(graalVMHome: string, nonInteractive?: boolean) {
const gr = getGVMConfig();
if (graalVMHome !== getGVMHome(gr)) {
await setGVMHome(graalVMHome, gr);
checkForMissingComponents(graalVMHome);
return;
}

await defaultConfig(graalVMHome, gr);

const toShow = configurations.filter(conf => conf.show(graalVMHome));
if (toShow.length > 0) {
const selected: ConfigurationPickItem[] = await vscode.window.showQuickPick(
toShow, {
canPickMany: true,
placeHolder: 'Configure active GraalVM'
}) || [];

for (const select of selected) {
try {
await select.set(graalVMHome);
} catch (error) {
vscode.window.showErrorMessage(error?.message);
if (!nonInteractive) {
checkForMissingComponents(graalVMHome);

gatherConfigurations();
await defaultConfig(graalVMHome, gr);

const toShow = configurations.filter(conf => conf.show(graalVMHome));
if (toShow.length > 0) {
const selected: ConfigurationPickItem[] = await vscode.window.showQuickPick(
toShow, {
canPickMany: true,
placeHolder: 'Configure active GraalVM'
}) || [];

for (const select of selected) {
try {
await select.set(graalVMHome);
} catch (error) {
vscode.window.showErrorMessage(error?.message);
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vscode/graalvm/src/graalVMInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export async function addExistingGraalVM(): Promise<void> {
}
}

export async function selectInstalledGraalVM(graalVMHome?: string): Promise<void> {
export async function selectInstalledGraalVM(graalVMHome?: string, nonInteractive?: boolean): Promise<void> {
graalVMHome = graalVMHome || await _selectInstalledGraalVM();
if (graalVMHome) {
const graalVMVersion = await getGraalVMVersion(graalVMHome);
if (graalVMVersion) {
configureGraalVMHome(graalVMHome);
configureGraalVMHome(graalVMHome, nonInteractive);
}
}
}
Expand Down
110 changes: 43 additions & 67 deletions vscode/micronaut/src/projectCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ export async function createProject() {
const uri = vscode.Uri.file(options.target);
updateGitIgnore(options);
if (vscode.workspace.workspaceFolders) {
vscode.window.showInformationMessage('New Micronaut project created', OPEN_IN_NEW_WINDOW, ADD_TO_CURRENT_WORKSPACE).then(value => {
if (value === OPEN_IN_NEW_WINDOW) {
vscode.commands.executeCommand('vscode.openFolder', uri, true);
} else if (value === ADD_TO_CURRENT_WORKSPACE) {
vscode.workspace.updateWorkspaceFolders(vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders.length : 0, undefined, { uri });
}
});
const value = await vscode.window.showInformationMessage('New Micronaut project created', OPEN_IN_NEW_WINDOW, ADD_TO_CURRENT_WORKSPACE);
if (value === OPEN_IN_NEW_WINDOW) {
await vscode.commands.executeCommand('vscode.openFolder', uri, true);
} else if (value === ADD_TO_CURRENT_WORKSPACE) {
vscode.workspace.updateWorkspaceFolders(vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders.length : 0, undefined, { uri });
}
} else if (vscode.window.visibleTextEditors.length > 0) {
vscode.window.showInformationMessage('New Micronaut project created', OPEN_IN_NEW_WINDOW, OPEN_IN_CURRENT_WINDOW).then(value => {
if (value) {
vscode.commands.executeCommand('vscode.openFolder', uri, OPEN_IN_NEW_WINDOW === value);
}
});
const value = await vscode.window.showInformationMessage('New Micronaut project created', OPEN_IN_NEW_WINDOW, OPEN_IN_CURRENT_WINDOW);
if (value) {
await vscode.commands.executeCommand('vscode.openFolder', uri, OPEN_IN_NEW_WINDOW === value);
}
} else {
vscode.commands.executeCommand('vscode.openFolder', uri, false);
await vscode.commands.executeCommand('vscode.openFolder', uri, false);
}
if (options.java) {
const commands: string[] = await vscode.commands.getCommands();
if (commands.includes('extension.graalvm.selectGraalVMHome')) {
await vscode.commands.executeCommand('extension.graalvm.selectGraalVMHome', options.java, true);
}
}
}
}
Expand All @@ -61,18 +65,21 @@ function updateGitIgnore(options: {url: string, name: string, target: string, bu
if (options.buildTool !== 'GRADLE') {
return;
}
const filePath = path.join(options.target, '.gitignore')
const filePath = path.join(options.target, '.gitignore');
let content = fs.readFileSync(filePath).toString();
if (!content.includes(GRADLE_JAR)) {
content = `${content.trim()}\n${GRADLE_JAR}`
content = `${content.trim()}\n${GRADLE_JAR}`;
}
if (!content.includes(GRADLE_PROPERTIES)) {
content = `${content.trim()}\n${GRADLE_PROPERTIES}`
content = `${content.trim()}\n${GRADLE_PROPERTIES}`;
}
fs.writeFileSync(filePath, content);
}

async function selectCreateOptions(): Promise<{url: string, name: string, target: string, buildTool: string} | undefined> {
async function selectCreateOptions(): Promise<{url: string, name: string, target: string, buildTool: string, java?: string} | undefined> {

const commands: string[] = await vscode.commands.getCommands();
const graalVMs: {name: string, path: string, active: boolean}[] = commands.includes('extension.graalvm.findGraalVMs') ? await vscode.commands.executeCommand('extension.graalvm.findGraalVMs') || [] : [];

interface State {
micronautVersion: {label: string, serviceUrl: string};
Expand All @@ -93,7 +100,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
}

const title = 'Create Micronaut Project';
const totalSteps = 9;
const totalSteps = graalVMs.length > 0 ? 9 : 8;

async function pickMicronautVersion(input: utils.MultiStepInput, state: Partial<State>) {
const selected: any = await input.showQuickPick({
Expand All @@ -120,16 +127,18 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
shouldResume: () => Promise.resolve(false)
});
state.applicationType = selected;
return (input: utils.MultiStepInput) => pickJavaVersion(input, state);
return (input: utils.MultiStepInput) => graalVMs.length > 0 ? pickJavaVersion(input, state) : projectName(input, state);
}

async function pickJavaVersion(input: utils.MultiStepInput, state: Partial<State>) {
const items: {label: string, value: string, description?: string}[] = graalVMs.map(item => ({label: item.name, value: item.path, description: item.active ? '(active)' : undefined}));
items.push({label: 'Other Java', value: '', description: '(manual configuration)'});
const selected: any = await input.showQuickPick({
title,
step: 3,
totalSteps,
placeholder: 'Pick Java version',
items: getJavaVersions(),
placeholder: 'Pick project Java',
items,
activeItems: state.javaVersion,
shouldResume: () => Promise.resolve(false)
});
Expand All @@ -140,7 +149,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function projectName(input: utils.MultiStepInput, state: Partial<State>) {
state.projectName = await input.showInputBox({
title,
step: 4,
step: graalVMs.length > 0 ? 4 : 3,
totalSteps,
value: state.projectName || 'demo',
prompt: 'Provide project name',
Expand All @@ -153,7 +162,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function basePackage(input: utils.MultiStepInput, state: Partial<State>) {
state.basePackage = await input.showInputBox({
title,
step: 5,
step: graalVMs.length > 0 ? 5 : 4,
totalSteps,
value: state.basePackage || 'com.example',
prompt: 'Provide base package',
Expand All @@ -166,7 +175,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function pickLanguage(input: utils.MultiStepInput, state: Partial<State>) {
const selected: any = await input.showQuickPick({
title,
step: 6,
step: graalVMs.length > 0 ? 6 : 5,
totalSteps,
placeholder: 'Pick project language',
items: getLanguages(),
Expand All @@ -180,7 +189,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function pickFeatures(input: utils.MultiStepInput, state: Partial<State>) {
const selected: any = await input.showQuickPick({
title,
step: 7,
step: graalVMs.length > 0 ? 7 : 6,
totalSteps,
placeholder: 'Pick project features',
items: state.micronautVersion && state.applicationType ? await getFeatures(state.micronautVersion, state.applicationType) : [],
Expand All @@ -195,7 +204,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function pickBuildTool(input: utils.MultiStepInput, state: Partial<State>) {
const selected: any = await input.showQuickPick({
title,
step: 8,
step: graalVMs.length > 0 ? 8 : 7,
totalSteps,
placeholder: 'Pick build tool',
items: getBuildTools(),
Expand All @@ -209,7 +218,7 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
async function pickTestFramework(input: utils.MultiStepInput, state: Partial<State>) {
const selected: any = await input.showQuickPick({
title,
step: 9,
step: graalVMs.length > 0 ? 9 : 8,
totalSteps,
placeholder: 'Pick test framework',
items: getTestFrameworks(),
Expand All @@ -230,42 +239,19 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
openLabel: 'Select'
});
if (location && location.length > 0) {
let query = '';
if (state.javaVersion) {
if (query) {
query += '&javaVersion=' + state.javaVersion.value;
} else {
query = '?javaVersion=' + state.javaVersion.value;
}
}
let query = '?javaVersion=JDK_8';
if (state.language) {
if (query) {
query += '&lang=' + state.language.value;
} else {
query = '?lang=' + state.language.value;
}
query += '&lang=' + state.language.value;
}
if (state.buildTool) {
if (query) {
query += '&build=' + state.buildTool.value;
} else {
query = '?build=' + state.buildTool.value;
}
query += '&build=' + state.buildTool.value;
}
if (state.testFramework) {
if (query) {
query += '&test=' + state.testFramework.value;
} else {
query = '?test=' + state.testFramework.value;
}
query += '&test=' + state.testFramework.value;
}
if (state.features) {
state.features.forEach((feature: {label: string, detail: string, name: string}) => {
if (query) {
query += '&feature=' + feature.name;
} else {
query = '?feature=' + feature.name;
}
query += '&features=' + feature.name;
});
}
let appName = state.basePackage;
Expand All @@ -278,7 +264,8 @@ async function selectCreateOptions(): Promise<{url: string, name: string, target
url: state.micronautVersion.serviceUrl + CREATE + '/' + state.applicationType.name + '/' + appName + query,
name: state.projectName,
target: path.join(location[0].fsPath, state.projectName),
buildTool: state.buildTool.value
buildTool: state.buildTool.value,
java: state.javaVersion && state.javaVersion.value.length > 0 ? state.javaVersion.value : undefined
};
}
}
Expand All @@ -303,17 +290,6 @@ async function getApplicationTypes(micronautVersion: {label: string, serviceUrl:
});
}

function getJavaVersions(): {label: string, value: string}[] {
return [
{ label: '8', value: 'JDK_8'},
{ label: '9', value: 'JDK_9'},
{ label: '11', value: 'JDK_11'},
{ label: '12', value: 'JDK_12'},
{ label: '13', value: 'JDK_13'},
{ label: '14', value: 'JDK_14'},
];
}

function getLanguages(): {label: string, value: string}[] {
return [
{ label: 'Java', value: 'JAVA'},
Expand Down

0 comments on commit b8ec287

Please sign in to comment.