Remove hard dependency of redhat.java (#617)
* Remove hard dependency of redhat.java Signed-off-by: Yan Zhang <yanzh@microsoft.com> * move helper method to utility Signed-off-by: Yan Zhang <yanzh@microsoft.com> * guide to install redhat.java directly Signed-off-by: Yan Zhang <yanzh@microsoft.com> * Prompt to reload window after installing redhat.java Signed-off-by: Yan Zhang <yanzh@microsoft.com> * address comments: check redhat.java enabled status instead of activated Signed-off-by: Yan Zhang <yanzh@microsoft.com> * Fix potential NPE. Signed-off-by: Yan Zhang <yanzh@microsoft.com> * fix travis linux build
This commit is contained in:
parent
50c981186a
commit
fa49caa25a
55
.travis.yml
55
.travis.yml
|
@ -1,27 +1,28 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
|
|
||||||
node_js:
|
node_js:
|
||||||
- '--lts'
|
- '--lts'
|
||||||
|
|
||||||
os:
|
os:
|
||||||
- linux
|
- linux
|
||||||
- osx
|
- osx
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- |
|
- |
|
||||||
if [ $TRAVIS_OS_NAME == "linux" ]; then
|
if [ $TRAVIS_OS_NAME == "linux" ]; then
|
||||||
export CXX="g++-4.9" CC="gcc-4.9"
|
export CXX="g++-4.9" CC="gcc-4.9"
|
||||||
export DISPLAY=':99.0'
|
export DISPLAY=':99.0'
|
||||||
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
|
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
|
||||||
sleep 3
|
sleep 3
|
||||||
fi
|
fi
|
||||||
install:
|
|
||||||
- npm install -g vsce
|
install:
|
||||||
- npm install -g typescript
|
- npm install -g vsce
|
||||||
- npm install -g gulp
|
- npm install -g typescript
|
||||||
- npm install
|
- npm install -g gulp
|
||||||
|
- npm install
|
||||||
script:
|
|
||||||
- gulp tslint
|
script:
|
||||||
- vsce package
|
- gulp tslint
|
||||||
- npm test
|
- vsce package
|
||||||
|
- npm test
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
import * as utility from "./utility";
|
||||||
|
|
||||||
export const VSCODE_STARTDEBUG = "vscode.startDebug";
|
export const VSCODE_STARTDEBUG = "vscode.startDebug";
|
||||||
|
|
||||||
|
@ -31,5 +32,16 @@ export const JAVA_CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings";
|
||||||
|
|
||||||
export function executeJavaLanguageServerCommand(...rest) {
|
export function executeJavaLanguageServerCommand(...rest) {
|
||||||
// TODO: need to handle error and trace telemetry
|
// TODO: need to handle error and trace telemetry
|
||||||
|
if (!utility.isJavaExtEnabled()) {
|
||||||
|
throw new utility.JavaExtensionNotActivatedError(
|
||||||
|
`Cannot execute command ${JAVA_EXECUTE_WORKSPACE_COMMAND}, VS Code Java Extension is not enabled.`);
|
||||||
|
}
|
||||||
return vscode.commands.executeCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
|
return vscode.commands.executeCommand(JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function executeJavaExtensionCommand(commandName: string, ...rest) {
|
||||||
|
if (!utility.isJavaExtEnabled()) {
|
||||||
|
throw new utility.JavaExtensionNotActivatedError(`Cannot execute command ${commandName}, VS Code Java Extension is not enabled.`);
|
||||||
|
}
|
||||||
|
return vscode.commands.executeCommand(commandName, ...rest);
|
||||||
|
}
|
||||||
|
|
|
@ -59,19 +59,20 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
||||||
|
|
||||||
private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) {
|
private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) {
|
||||||
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => {
|
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
p.report({ message: "Auto generating configuration..." });
|
p.report({ message: "Auto generating configuration..." });
|
||||||
lsPlugin.resolveMainClass(folder ? folder.uri : undefined).then((res: lsPlugin.IMainClassOption[]) => {
|
const defaultLaunchConfig = {
|
||||||
|
type: "java",
|
||||||
|
name: "Debug (Launch) - Current File",
|
||||||
|
request: "launch",
|
||||||
|
// tslint:disable-next-line
|
||||||
|
mainClass: "${file}",
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const mainClasses = await lsPlugin.resolveMainClass(folder ? folder.uri : undefined);
|
||||||
let cache;
|
let cache;
|
||||||
cache = {};
|
cache = {};
|
||||||
const defaultLaunchConfig = {
|
const launchConfigs = mainClasses.map((item) => {
|
||||||
type: "java",
|
|
||||||
name: "Debug (Launch) - Current File",
|
|
||||||
request: "launch",
|
|
||||||
// tslint:disable-next-line
|
|
||||||
mainClass: "${file}",
|
|
||||||
};
|
|
||||||
const launchConfigs = res.map((item) => {
|
|
||||||
return {
|
return {
|
||||||
...defaultLaunchConfig,
|
...defaultLaunchConfig,
|
||||||
name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache),
|
name: this.constructLaunchConfigName(item.mainClass, item.projectName, cache),
|
||||||
|
@ -80,10 +81,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
resolve([defaultLaunchConfig, ...launchConfigs]);
|
resolve([defaultLaunchConfig, ...launchConfigs]);
|
||||||
}, (ex) => {
|
} catch (ex) {
|
||||||
|
if (ex instanceof utility.JavaExtensionNotActivatedError) {
|
||||||
|
utility.guideToInstallJavaExtension();
|
||||||
|
}
|
||||||
p.report({ message: `failed to generate configuration. ${ex}` });
|
p.report({ message: `failed to generate configuration. ${ex}` });
|
||||||
reject(ex);
|
resolve(defaultLaunchConfig);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -160,8 +164,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
||||||
|
|
||||||
if (needsBuildWorkspace()) {
|
if (needsBuildWorkspace()) {
|
||||||
try {
|
try {
|
||||||
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
|
const buildResult = await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err instanceof utility.JavaExtensionNotActivatedError) {
|
||||||
|
utility.guideToInstallJavaExtension();
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const ans = await utility.showErrorMessageWithTroubleshooting({
|
const ans = await utility.showErrorMessageWithTroubleshooting({
|
||||||
message: "Build failed, do you want to continue?",
|
message: "Build failed, do you want to continue?",
|
||||||
type: Type.USAGEERROR,
|
type: Type.USAGEERROR,
|
||||||
|
@ -238,6 +247,10 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
|
||||||
throw new Error("Failed to start debug server.");
|
throw new Error("Failed to start debug server.");
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
if (ex instanceof utility.JavaExtensionNotActivatedError) {
|
||||||
|
utility.guideToInstallJavaExtension();
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
if (ex instanceof utility.UserError) {
|
if (ex instanceof utility.UserError) {
|
||||||
utility.showErrorMessageWithTroubleshooting(ex.context);
|
utility.showErrorMessageWithTroubleshooting(ex.context);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -61,7 +61,7 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte
|
||||||
await autobuildConfig.update("enabled", true);
|
await autobuildConfig.update("enabled", true);
|
||||||
// Force an incremental build to avoid auto build is not finishing during HCR.
|
// Force an incremental build to avoid auto build is not finishing during HCR.
|
||||||
try {
|
try {
|
||||||
await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false)
|
await commands.executeJavaExtensionCommand(commands.JAVA_BUILD_WORKSPACE, false)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// do nothing.
|
// do nothing.
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
|
import { setUserError } from "vscode-extension-telemetry-wrapper";
|
||||||
import { logger, Type } from "./logger";
|
import { logger, Type } from "./logger";
|
||||||
|
|
||||||
const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
|
const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md";
|
||||||
const LEARN_MORE = "Learn More";
|
const LEARN_MORE = "Learn More";
|
||||||
|
const JAVA_EXTENSION_ID = "redhat.java";
|
||||||
|
|
||||||
export class UserError extends Error {
|
export class UserError extends Error {
|
||||||
public context: ITroubleshootingMessage;
|
public context: ITroubleshootingMessage;
|
||||||
|
@ -13,6 +15,14 @@ export class UserError extends Error {
|
||||||
constructor(context: ITroubleshootingMessage) {
|
constructor(context: ITroubleshootingMessage) {
|
||||||
super(context.message);
|
super(context.message);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
setUserError(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class JavaExtensionNotActivatedError extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
setUserError(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +95,27 @@ function handleTroubleshooting(choice: string, message: string, anchor: string):
|
||||||
return choice;
|
return choice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function guideToInstallJavaExtension() {
|
||||||
|
const MESSAGE = "Language Support for Java is required. Please install and enable it.";
|
||||||
|
const INSTALL = "Install";
|
||||||
|
const choice = await vscode.window.showWarningMessage(MESSAGE, INSTALL);
|
||||||
|
if (choice === INSTALL) {
|
||||||
|
await installJavaExtension();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installJavaExtension() {
|
||||||
|
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (p) => {
|
||||||
|
p.report({ message: "Installing Language Support for Java ..." });
|
||||||
|
await vscode.commands.executeCommand("workbench.extensions.installExtension", JAVA_EXTENSION_ID);
|
||||||
|
});
|
||||||
|
const RELOAD = "Reload Window";
|
||||||
|
const choice = await vscode.window.showInformationMessage("Please reload window to activate Language Support for Java.", RELOAD);
|
||||||
|
if (choice === RELOAD) {
|
||||||
|
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function formatErrorProperties(ex: any): IProperties {
|
export function formatErrorProperties(ex: any): IProperties {
|
||||||
const exception = (ex && ex.data && ex.data.cause)
|
const exception = (ex && ex.data && ex.data.cause)
|
||||||
|| { stackTrace: (ex && ex.stack), detailMessage: String((ex && ex.message) || ex || "Unknown exception") };
|
|| { stackTrace: (ex && ex.stack), detailMessage: String((ex && ex.message) || ex || "Unknown exception") };
|
||||||
|
@ -106,7 +137,10 @@ export function formatErrorProperties(ex: any): IProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getJavaHome(): Promise<string> {
|
export async function getJavaHome(): Promise<string> {
|
||||||
const extension = vscode.extensions.getExtension("redhat.java");
|
const extension = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
|
||||||
|
if (!extension) {
|
||||||
|
throw new JavaExtensionNotActivatedError("VS Code Java Extension is not enabled.");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const extensionApi = await extension.activate();
|
const extensionApi = await extension.activate();
|
||||||
if (extensionApi && extensionApi.javaRequirement) {
|
if (extensionApi && extensionApi.javaRequirement) {
|
||||||
|
@ -117,3 +151,8 @@ export async function getJavaHome(): Promise<string> {
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isJavaExtEnabled() {
|
||||||
|
const javaExt = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
|
||||||
|
return !!javaExt;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue