PT #156854852: Bosh extension for Theia

This commit is contained in:
BoykoAlex
2018-05-18 14:07:40 -04:00
parent 40f615e339
commit 34f340a462
23 changed files with 9003 additions and 33 deletions

View File

@@ -0,0 +1,7 @@
node_modules
.browser_modules
lib
jars
*.log
*-app/*
!*-app/package.json

View File

@@ -0,0 +1,60 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Start Browser Backend",
"program": "${workspaceRoot}/browser-app/src-gen/backend/main.js",
"args": [
"--loglevel=debug",
"--port=3000",
"--no-cluster"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/node_modules/@theia/*/lib/**/*.js",
"${workspaceRoot}/browser-app/lib/**/*.js",
"${workspaceRoot}/browser-app/src-gen/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
"name": "Start Electron Backend",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"program": "${workspaceRoot}/electron-app/src-gen/frontend/electron-main.js",
"protocol": "inspector",
"args": [
"--loglevel=debug",
"--hostname=localhost",
"--no-cluster"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/electron-app/src-gen/frontend/electron-main.js",
"${workspaceRoot}/electron-app/src-gen/backend/main.js",
"${workspaceRoot}/electron-app/lib/**/*.js",
"${workspaceRoot}/node_modules/@theia/*/lib/**/*.js"
],
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outputCapture": "std"
}
]
}

View File

@@ -0,0 +1,81 @@
# Bosh Extension for Theia IDE
Bosh deployment YAML editor support
## Getting started
Install [nvm](https://github.com/creationix/nvm#install-script).
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
Install npm and node.
nvm install 8
nvm use 8
Install yarn.
npm install -g yarn
## Install dependencies and server JARs
Install dependencies and compile the code.
./build.sh
Note: it is also running `yarn rebuild:browser` and `yarn rebuild:electron`, thus one could navigate to the proper folder and launch it
## Running the browser example
yarn rebuild:browser
cd browser-app
yarn start
Open http://localhost:3000 in the browser.
## Running the Electron example
yarn rebuild:electron
cd electron-app
yarn start
## Developing with the browser example
Start watching of the Bosh extension.
cd bosh
yarn watch
Start watching of the browser example.
yarn rebuild:browser
cd browser-app
yarn watch
Launch `Start Browser Backend` configuration from VS code.
Open http://localhost:3000 in the browser.
## Developing with the Electron example
Start watching of the Bosh extension.
cd bosh
yarn watch
Start watching of the electron example.
yarn rebuild:electron
cd electron-app
yarn watch
Launch `Start Electron Backend` configuration from VS code.
## Publishing Bosh extension
Create a npm user and login to the npm registry, [more on npm publishing](https://docs.npmjs.com/getting-started/publishing-npm-packages).
npm login
Publish packages with lerna to update versions properly across local packages, [more on publishing with lerna](https://github.com/lerna/lerna#publish).
npx lerna publish

View File

@@ -0,0 +1,34 @@
{
"name": "@theia/bosh",
"keywords": [
"theia-extension"
],
"version": "0.0.0",
"files": [
"lib",
"src"
],
"dependencies": {
"@theia/core": "latest",
"@theia/languages": "latest",
"@pivotal-tools/jvm-launch-utils": "0.0.11",
"@types/glob": "^5.0.30",
"glob": "^7.1.2"
},
"devDependencies": {
"rimraf": "latest",
"typescript": "latest"
},
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib",
"build": "tsc",
"watch": "tsc -w"
},
"theiaExtensions": [
{
"frontend": "lib/browser/bosh-frontend-module",
"backend": "lib/node/bosh-backend-module"
}
]
}

View File

@@ -0,0 +1,14 @@
import { ContainerModule } from 'inversify';
import { LanguageClientContribution } from '@theia/languages/lib/browser';
import { BoshClientContribution } from './language-client-contribution';
import { bindBoshPreferences } from './bosh-preferences';
// Contribute monaco-editor languages for deployment and cloud-config yaml
import './deployment-yaml-monaco-contribution';
import './cloudconfig-yaml-monaco-contribution';
export default new ContainerModule(bind => {
// add your contribution bindings here
bindBoshPreferences(bind);
bind(LanguageClientContribution).to(BoshClientContribution).inSingletonScope();
});

View File

@@ -0,0 +1,47 @@
import { interfaces } from 'inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
// tslint:disable:max-line-length
export const BoshConfigSchema: PreferenceSchema = {
'type': 'object',
'title': 'Bosh CLI Configuration',
properties: {
'boot-bosh.cli.command': {
type: 'string',
description: 'Path to an executable to launch the bosh cli V2. A V2 cli is required! Set this to null to completely disable all editor features that require access to the bosh director.',
default: 'bosh'
},
'bosh.cli.target': {
type: 'string',
description: `Specifies the director/environment to target when executing bosh cli commands. I.e. this value is passed to the CLI via \`-e\` parameter.`,
default: null
},
'bosh.cli.timeout': {
type: 'integer',
description: `Number of seconds before CLI commands are terminated with a timeout.`,
default: 3
}
}
};
export interface BoshConfiguration {
'boot-bosh.cli.command': string | null;
'bosh.cli.target': string | null;
'bosh.cli.timeout': number;
}
export const BoshPreferences = Symbol('BoshPreferences');
export type BoshPreferences = PreferenceProxy<BoshConfiguration>;
export function createBootPreferences(preferences: PreferenceService): BoshPreferences {
return createPreferenceProxy(preferences, BoshConfigSchema);
}
export function bindBoshPreferences(bind: interfaces.Bind): void {
bind(BoshPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createBootPreferences(preferences);
});
bind(PreferenceContribution).toConstantValue({ schema: BoshConfigSchema });
}

View File

@@ -0,0 +1,25 @@
/// <reference types='monaco-editor-core/monaco'/>
import {
BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID,
BOSH_CLOUDCONFIG__YAML_LANGUAGE_NAME
} from '../common';
// Task .yml file language registration
let YAML_LANG_MODULE_PROMISE: monaco.Promise<any>;
monaco.languages.register({
id: BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID,
filenamePatterns: ['*cloud-config*.yml'],
aliases: [BOSH_CLOUDCONFIG__YAML_LANGUAGE_NAME]
});
monaco.languages.onLanguage(BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID, () => {
if (!YAML_LANG_MODULE_PROMISE) {
YAML_LANG_MODULE_PROMISE = (<any>monaco.languages.getLanguages().find(ext => ext.id === 'yaml')).loader();
}
return YAML_LANG_MODULE_PROMISE.then(mod => {
monaco.languages.setLanguageConfiguration(BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID, mod.conf);
monaco.languages.setMonarchTokensProvider(BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID, mod.language);
})
});

View File

@@ -0,0 +1,25 @@
/// <reference types='monaco-editor-core/monaco'/>
import {
BOSH_DEPLOYMENT_YAML_LANGUAGE_ID,
BOSH_DEPLOYMENT_YAML_LANGUAGE_NAME
} from '../common';
// Deployment .yml file language registration
let YAML_LANG_MODULE_PROMISE: monaco.Promise<any>;
monaco.languages.register({
id: BOSH_DEPLOYMENT_YAML_LANGUAGE_ID,
filenamePatterns: ['*deployment*.yml'],
aliases: [BOSH_DEPLOYMENT_YAML_LANGUAGE_NAME]
});
monaco.languages.onLanguage(BOSH_DEPLOYMENT_YAML_LANGUAGE_ID, () => {
if (!YAML_LANG_MODULE_PROMISE) {
YAML_LANG_MODULE_PROMISE = (<any>monaco.languages.getLanguages().find(ext => ext.id === 'yaml')).loader();
}
return YAML_LANG_MODULE_PROMISE.then(mod => {
monaco.languages.setLanguageConfiguration(BOSH_DEPLOYMENT_YAML_LANGUAGE_ID, mod.conf);
monaco.languages.setMonarchTokensProvider(BOSH_DEPLOYMENT_YAML_LANGUAGE_ID, mod.language);
})
});

View File

@@ -0,0 +1,58 @@
import { injectable, inject, postConstruct } from 'inversify';
import { BaseLanguageClientContribution, Workspace, Languages, LanguageClientFactory } from '@theia/languages/lib/browser';
import { NotificationType } from 'vscode-jsonrpc';
import { DidChangeConfigurationParams } from 'vscode-base-languageclient/lib/base';
import {
BOSH_DEPLOYMENT_YAML_LANGUAGE_ID,
BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID,
BOSH_SERVER_ID,
BOSH_SERVER_NAME
} from '../common';
import { BoshPreferences } from './bosh-preferences';
import { Utils } from './utils';
const CONFIG_CHANGED_NOTIFICATION_TYPE = new NotificationType<DidChangeConfigurationParams,void>('workspace/didChangeConfiguration');
@injectable()
export class BoshClientContribution extends BaseLanguageClientContribution {
readonly id = BOSH_SERVER_ID;
readonly name = BOSH_SERVER_NAME;
constructor(
@inject(Workspace) protected readonly workspace: Workspace,
@inject(Languages) protected readonly languages: Languages,
@inject(LanguageClientFactory) protected readonly languageClientFactory: LanguageClientFactory,
@inject(BoshPreferences) protected readonly preferences: BoshPreferences
) {
super(workspace, languages, languageClientFactory);
}
@postConstruct()
protected async init() {
await this.preferences.ready;
// Send settings to LS
this.sendConfig();
this.preferences.onPreferenceChanged(() => this.sendConfig());
}
private sendConfig() {
return this.languageClient.then(client => {
const params = Utils.convertDotToNested(Object.assign({}, this.preferences));
return client.sendNotification(CONFIG_CHANGED_NOTIFICATION_TYPE, {
settings: params
});
})
}
protected get documentSelector() {
return [BOSH_DEPLOYMENT_YAML_LANGUAGE_ID, BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID];
}
protected get globPatterns() {
return [
'*deployment*.yml',
'*cloud-config*.yml'
];
}
}

View File

@@ -0,0 +1,27 @@
export class Utils {
private static setNestedValue(properties: string[], value: any, obj: any){
if (properties.length > 1) {
// The property doesn't exists OR is not an object (and so we overwritte it) so we create it
if (!obj.hasOwnProperty(properties[0]) || typeof obj[properties[0]] !== 'object') {
obj[properties[0]] = {};
}
Utils.setNestedValue(properties.slice(1), value, obj[properties[0]]);
} else {
obj[properties[0]] = value;
}
}
public static convertDotToNested(source: any): any {
const result = {};
Object.keys(source).forEach(property => {
const properties = property.split('.');
if (source[property] && typeof source[property] === 'object') {
Utils.setNestedValue(properties, Utils.convertDotToNested(source[property]), result);
} else {
Utils.setNestedValue(properties, source[property], result);
}
});
return result;
}
}

View File

@@ -0,0 +1,8 @@
export const BOSH_SERVER_ID = 'bosh-yaml';
export const BOSH_SERVER_NAME = 'Bosh YAML';
export const BOSH_DEPLOYMENT_YAML_LANGUAGE_ID = 'bosh-deployment-manifest';
export const BOSH_DEPLOYMENT_YAML_LANGUAGE_NAME = 'Bosh Deployment Manifest';
export const BOSH_CLOUDCONFIG_YAML_LANGUAGE_ID = 'bosh-cloud-config';
export const BOSH_CLOUDCONFIG__YAML_LANGUAGE_NAME = 'Bosh Cloud Config';

View File

@@ -0,0 +1,7 @@
import { ContainerModule } from "inversify";
import { LanguageServerContribution } from "@theia/languages/lib/node";
import { BoshLanguageContribution } from './bosh-language-contribution';
export default new ContainerModule(bind => {
bind(LanguageServerContribution).to(BoshLanguageContribution).inSingletonScope();
});

View File

@@ -0,0 +1,72 @@
import * as path from 'path';
import * as glob from 'glob';
import { injectable } from 'inversify';
// import { DEBUG_MODE } from '@theia/core/lib/node';
import { IConnection, BaseLanguageServerContribution } from '@theia/languages/lib/node';
import { BOSH_SERVER_ID, BOSH_SERVER_NAME } from '../common';
import { findJvm } from '@pivotal-tools/jvm-launch-utils';
@injectable()
export class BoshLanguageContribution extends BaseLanguageServerContribution {
readonly id = BOSH_SERVER_ID;
readonly name = BOSH_SERVER_NAME;
start(clientConnection: IConnection): void {
const serverPath = path.resolve(__dirname, '../../jars');
const jarPaths = glob.sync('bosh-language-server*.jar', { cwd: serverPath });
if (jarPaths.length === 0) {
throw new Error(`The ${this.name} server launcher is not found.`);
}
const jarPath = path.resolve(serverPath, jarPaths[0]);
findJvm()
.catch(error => {
throw new Error('Error trying to find JVM');
})
.then(jvm => {
if (!jvm) {
throw new Error("Couldn't locate java in $JAVA_HOME or $PATH");
}
this.startSocketServer().then(server => {
const socket = this.accept(server);
// this.logInfo('logs at ' + path.resolve(workspacePath, '.metadata', '.log'));
const env = Object.create(process.env);
const addressInfo = server.address();
if (typeof addressInfo === 'string') {
throw new Error(`Address info was string ${addressInfo}`);
}
env.CLIENT_HOST = addressInfo.address;
env.CLIENT_PORT = addressInfo.port;
const command = jvm.getJavaExecutable();
const args = [
'-Dsts.lsp.client=theia',
'-Dlsp.completions.indentation.enable=true',
'-Dlsp.yaml.completions.errors.disable=true',
'-Dorg.slf4j.simpleLogger.logFile=concourse-yaml.log',
`-Dserver.port=${env.CLIENT_PORT}`
];
// if (DEBUG_MODE) {
args.push(
'-Xdebug',
'-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7999',
'-Dlog.level=ALL'
);
// }
args.push(
'-jar', jarPath,
);
this.createProcessSocketConnection(socket, socket, command, args, { env })
.then(serverConnection => this.forward(clientConnection, serverConnection));
});
});
}
}

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"strict": true,
"experimentalDecorators": true,
"noUnusedLocals": true,
"emitDecoratorMetadata": true,
"downlevelIteration": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"lib": [
"es6",
"dom"
],
"sourceMap": true,
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}

View File

@@ -0,0 +1,32 @@
{
"private": true,
"name": "browser-app",
"version": "0.0.0",
"dependencies": {
"@theia/core": "latest",
"@theia/filesystem": "latest",
"@theia/workspace": "latest",
"@theia/preferences": "latest",
"@theia/navigator": "latest",
"@theia/process": "latest",
"@theia/terminal": "latest",
"@theia/editor": "latest",
"@theia/languages": "latest",
"@theia/markers": "latest",
"@theia/monaco": "latest",
"@theia/typescript": "latest",
"@theia/messages": "latest",
"@theia/bosh": "0.0.0"
},
"devDependencies": {
"@theia/cli": "latest"
},
"scripts": {
"prepare": "theia build",
"start": "theia start",
"watch": "theia build --watch"
},
"theia": {
"target": "browser"
}
}

View File

@@ -0,0 +1,17 @@
#!/bin/bash
set -e
workdir=`pwd`/bosh
cd ${workdir}
# Use maven to build fat jar of the language server
cd ../../../headless-services/bosh-language-server
./build.sh
rm -fr ${workdir}/jars
mkdir -p ${workdir}/jars
cp target/*.jar ${workdir}/jars
cd ${workdir}/..
yarn

View File

@@ -0,0 +1,32 @@
{
"private": true,
"name": "electron-app",
"version": "0.0.0",
"dependencies": {
"@theia/core": "latest",
"@theia/filesystem": "latest",
"@theia/workspace": "latest",
"@theia/preferences": "latest",
"@theia/navigator": "latest",
"@theia/process": "latest",
"@theia/terminal": "latest",
"@theia/editor": "latest",
"@theia/languages": "latest",
"@theia/markers": "latest",
"@theia/monaco": "latest",
"@theia/typescript": "latest",
"@theia/messages": "latest",
"@theia/bosh": "0.0.0"
},
"devDependencies": {
"@theia/cli": "latest"
},
"scripts": {
"prepare": "theia build",
"start": "theia start",
"watch": "theia build --watch"
},
"theia": {
"target": "electron"
}
}

View File

@@ -0,0 +1,11 @@
{
"lerna": "2.4.0",
"version": "0.0.0",
"useWorkspaces": true,
"npmClient": "yarn",
"command": {
"run": {
"stream": true
}
}
}

View File

@@ -0,0 +1,14 @@
{
"private": true,
"scripts": {
"prepare": "lerna run prepare",
"rebuild:browser": "theia rebuild:browser",
"rebuild:electron": "theia rebuild:electron"
},
"devDependencies": {
"lerna": "2.4.0"
},
"workspaces": [
"bosh", "browser-app", "electron-app"
]
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
# Concourse Extension for Theia IDE
The example of how to build the Theia-based applications with the concourse-extension.
Concouse pipelines and task YAML editor support
## Getting started
@@ -40,9 +40,9 @@ Open http://localhost:3000 in the browser.
## Developing with the browser example
Start watching of the hello world extension.
Start watching of Concourse extension.
cd concourse-extension
cd concourse
yarn watch
Start watching of the browser example.
@@ -57,9 +57,9 @@ Open http://localhost:3000 in the browser.
## Developing with the Electron example
Start watching of the hello world extension.
Start watching of the Concourse extension.
cd concourse-extension
cd concourse
yarn watch
Start watching of the electron example.
@@ -70,7 +70,7 @@ Start watching of the electron example.
Launch `Start Electron Backend` configuration from VS code.
## Publishing concourse-extension
## Publishing Concourse extension
Create a npm user and login to the npm registry, [more on npm publishing](https://docs.npmjs.com/getting-started/publishing-npm-packages).

View File

@@ -1,10 +1,3 @@
/*
* Copyright (C) 2017 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
import * as path from 'path';
import * as glob from 'glob';
import { injectable } from 'inversify';

View File

@@ -1,10 +1,3 @@
/*
* Copyright (C) 2018 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
import { interfaces } from 'inversify';
import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
@@ -18,27 +11,15 @@ export const BootConfigSchema: PreferenceSchema = {
type: 'boolean',
description: 'Enable/Disable Spring running Boot application live hints decorators in Java source code.',
default: true
},
'spring-boot.ls.java.home': {
type: 'string',
description: `Override JAVA_HOME used for launching the spring-boot-language-server JVM process.`,
default: null
},
'spring-boot.ls.java.heap': {
type: 'string',
description: `Max JVM heap value, passed via -Xmx argument when launching spring-boot-language-server JVM process.`,
default: null
}
}
};
export interface BootConfiguration {
'boot-java.boot-hints.on': boolean;
'spring-boot.ls.java.home': string | null;
'spring-boot.ls.java.heap': string | null;
}
export const BootPreferences = Symbol('BootJavaPreferences');
export const BootPreferences = Symbol('BootPreferences');
export type BootPreferences = PreferenceProxy<BootConfiguration>;
export function createBootPreferences(preferences: PreferenceService): BootPreferences {