From bc65f42c5bdbc5cdc373d18c8d4b661ad6ae593b Mon Sep 17 00:00:00 2001 From: Philip Langer Date: Thu, 20 Jul 2023 10:57:51 +0200 Subject: [PATCH] Generalize example generator and isolate examples (#63) * Centralize definition of examples * Generalize example generator * Introduce contribution point for examples * Support merging of new launch and task configs with existing ones * Add reveal navigator after project generation * Enforce a target folder (no generation into root) Contributed on behalf of STMicroelectronics --- applications/browser/package.json | 2 +- applications/docker/package.json | 2 +- applications/electron/package.json | 2 +- .../blueprint-example-generator/package.json | 5 +- .../cmake-example/.theia/launch.json | 15 --- .../resources/cmake-example/.theia/tasks.json | 35 ------- .../example-generator-frontend-module.ts | 6 +- .../src/browser/index.ts | 5 +- .../src/common/protocol.ts | 42 ++++++-- .../node/example-generator-backend-module.ts | 5 +- .../src/node/example-generator-service.ts | 88 +++++++++++------ .../src/node/index.ts | 17 ++++ .../blueprint-examples/.eslintrc.js | 10 ++ .../blueprint-examples/package.json | 53 ++++++++++ .../clangd-contexts/.clangd-contexts | 0 .../resources/clangd-contexts/.gitignore | 0 .../clangd-contexts/CLANGD_CONTEXTS_README.md | 0 .../clangd-contexts/app/CMakeLists.txt | 0 .../resources/clangd-contexts/app/file_1.c | 0 .../resources/clangd-contexts/app/file_2.c | 0 .../resources/clangd-contexts/app/file_3.c | 0 .../resources/clangd-contexts/app/files.h | 0 .../resources/clangd-contexts/app/main.c | 0 .../resources/clangd-contexts/build.sh | 0 .../clangd-contexts/lib/CMakeLists.txt | 0 .../resources/clangd-contexts/lib/lib.c | 0 .../resources/clangd-contexts/lib/lib.h | 0 .../cmake-example/CMAKE_EXAMPLE_README.md | 0 .../resources/cmake-example/CMakeLists.txt | 0 .../cmake-example/include/Rectangle.h | 0 .../resources/cmake-example/src/Rectangle.cpp | 0 .../resources/cmake-example/src/main.cpp | 0 .../example-traces/EXAMPLE_TRACES_README.md | 0 .../traces/cat-kernel/index/k_0.idx | Bin .../traces/cat-kernel/index/k_1.idx | Bin .../traces/cat-kernel/index/k_2.idx | Bin .../traces/cat-kernel/index/k_3.idx | Bin .../traces/cat-kernel/index/k_4.idx | Bin .../traces/cat-kernel/index/k_5.idx | Bin .../traces/cat-kernel/index/k_6.idx | Bin .../traces/cat-kernel/index/k_7.idx | Bin .../example-traces/traces/cat-kernel/k_0 | Bin .../example-traces/traces/cat-kernel/k_1 | Bin .../example-traces/traces/cat-kernel/k_2 | Bin .../example-traces/traces/cat-kernel/k_3 | Bin .../example-traces/traces/cat-kernel/k_4 | Bin .../example-traces/traces/cat-kernel/k_5 | Bin .../example-traces/traces/cat-kernel/k_6 | Bin .../example-traces/traces/cat-kernel/k_7 | Bin .../example-traces/traces/cat-kernel/metadata | Bin .../traces/cat-ust/index/u_0.idx | Bin .../traces/cat-ust/index/u_1.idx | Bin .../traces/cat-ust/index/u_2.idx | Bin .../traces/cat-ust/index/u_3.idx | Bin .../traces/cat-ust/index/u_4.idx | Bin .../traces/cat-ust/index/u_5.idx | Bin .../traces/cat-ust/index/u_6.idx | Bin .../traces/cat-ust/index/u_7.idx | Bin .../example-traces/traces/cat-ust/metadata | Bin .../example-traces/traces/cat-ust/u_0 | Bin .../example-traces/traces/cat-ust/u_1 | Bin .../example-traces/traces/cat-ust/u_2 | Bin .../example-traces/traces/cat-ust/u_3 | Bin .../example-traces/traces/cat-ust/u_4 | Bin .../example-traces/traces/cat-ust/u_5 | Bin .../example-traces/traces/cat-ust/u_6 | Bin .../example-traces/traces/cat-ust/u_7 | Bin ...ueprint-examples-frontend-contribution.ts} | 93 ++++++++++++++---- .../blueprint-examples-frontend-module.ts | 24 +++++ .../blueprint-examples/src/browser/index.ts | 18 ++++ .../src/common/cdt-blueprint-examples.ts | 21 ++++ .../node/blueprint-examples-backend-module.ts | 24 +++++ .../node/blueprint-examples-contribution.ts | 84 ++++++++++++++++ .../blueprint-examples/tsconfig.json | 11 +++ .../theia-blueprint-product/package.json | 2 +- .../src/browser/branding-util.tsx | 6 +- ...theia-blueprint-getting-started-widget.tsx | 14 +-- 77 files changed, 451 insertions(+), 133 deletions(-) delete mode 100644 theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/launch.json delete mode 100644 theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/tasks.json create mode 100644 theia-extensions/blueprint-example-generator/src/node/index.ts create mode 100644 theia-extensions/blueprint-examples/.eslintrc.js create mode 100644 theia-extensions/blueprint-examples/package.json rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/.clangd-contexts (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/.gitignore (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/CLANGD_CONTEXTS_README.md (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/CMakeLists.txt (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/file_1.c (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/file_2.c (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/file_3.c (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/files.h (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/app/main.c (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/build.sh (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/lib/CMakeLists.txt (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/lib/lib.c (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/clangd-contexts/lib/lib.h (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/cmake-example/CMAKE_EXAMPLE_README.md (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/cmake-example/CMakeLists.txt (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/cmake-example/include/Rectangle.h (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/cmake-example/src/Rectangle.cpp (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/cmake-example/src/main.cpp (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/EXAMPLE_TRACES_README.md (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_0.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_1.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_2.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_3.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_4.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_5.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_6.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/index/k_7.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_0 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_1 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_2 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_3 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_4 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_5 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_6 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/k_7 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-kernel/metadata (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_0.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_1.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_2.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_3.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_4.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_5.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_6.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/index/u_7.idx (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/metadata (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_0 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_1 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_2 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_3 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_4 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_5 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_6 (100%) rename theia-extensions/{blueprint-example-generator => blueprint-examples}/resources/example-traces/traces/cat-ust/u_7 (100%) rename theia-extensions/{blueprint-example-generator/src/browser/example-generator-contribution.ts => blueprint-examples/src/browser/blueprint-examples-frontend-contribution.ts} (56%) create mode 100644 theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-module.ts create mode 100644 theia-extensions/blueprint-examples/src/browser/index.ts create mode 100644 theia-extensions/blueprint-examples/src/common/cdt-blueprint-examples.ts create mode 100644 theia-extensions/blueprint-examples/src/node/blueprint-examples-backend-module.ts create mode 100644 theia-extensions/blueprint-examples/src/node/blueprint-examples-contribution.ts create mode 100644 theia-extensions/blueprint-examples/tsconfig.json diff --git a/applications/browser/package.json b/applications/browser/package.json index e5dcb06..a0bb66a 100644 --- a/applications/browser/package.json +++ b/applications/browser/package.json @@ -85,7 +85,7 @@ "cdt-cloud-blueprint-updater": "1.38.0", "cdt-cloud-blueprint-product": "1.38.0", "theia-traceviewer": "0.2.0-next.20230619144800.297af68.0", - "@eclipse-cdt-cloud/blueprint-example-generator": "1.38.0" + "@eclipse-cdt-cloud/blueprint-examples": "1.38.0" }, "devDependencies": { "@theia/cli": "1.38.0" diff --git a/applications/docker/package.json b/applications/docker/package.json index af1f513..d42bbc1 100644 --- a/applications/docker/package.json +++ b/applications/docker/package.json @@ -80,7 +80,7 @@ "cdt-cloud-blueprint-product": "1.38.0", "cdt-cloud-blueprint-launcher": "1.38.0", "theia-traceviewer": "0.2.0-next.20230619144800.297af68.0", - "@eclipse-cdt-cloud/blueprint-example-generator": "1.38.0" + "@eclipse-cdt-cloud/blueprint-examples": "1.38.0" }, "devDependencies": { "@theia/cli": "1.38.0" diff --git a/applications/electron/package.json b/applications/electron/package.json index d81fef5..69bea5d 100644 --- a/applications/electron/package.json +++ b/applications/electron/package.json @@ -95,7 +95,7 @@ "cdt-cloud-blueprint-product": "1.38.0", "cdt-cloud-blueprint-launcher": "1.38.0", "theia-traceviewer": "0.2.0-next.20230619144800.297af68.0", - "@eclipse-cdt-cloud/blueprint-example-generator": "1.38.0" + "@eclipse-cdt-cloud/blueprint-examples": "1.38.0" }, "devDependencies": { "@theia/cli": "1.38.0", diff --git a/theia-extensions/blueprint-example-generator/package.json b/theia-extensions/blueprint-example-generator/package.json index 63d8574..532f3a0 100644 --- a/theia-extensions/blueprint-example-generator/package.json +++ b/theia-extensions/blueprint-example-generator/package.json @@ -4,9 +4,8 @@ "description": "Extension for generating examples in CDT Cloud Blueprint", "dependencies": { "@theia/core": "1.38.0", - "@theia/workspace": "1.38.0", - "@theia/filesystem": "1.38.0", - "@theia/editor": "1.38.0", + "@theia/debug": "1.38.0", + "@theia/task": "1.38.0", "fs-extra": "^8.1.0", "inversify": "^5.1.1" }, diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/launch.json b/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/launch.json deleted file mode 100644 index c5a18c5..0000000 --- a/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - "version": "0.2.0", - "configurations": [ - { - "type": "gdb", - "request": "launch", - "name": "Debug Example C++", - "program": "${workspaceFolder}/Example", - "initCommands": ["tbreak main"], - "preLaunchTask": "Binary build" - } - ] -} diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/tasks.json b/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/tasks.json deleted file mode 100644 index 618109d..0000000 --- a/theia-extensions/blueprint-example-generator/resources/cmake-example/.theia/tasks.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Binary build", - "type": "shell", - "command": "cmake . && make", - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": [], - "runOptions": { - "runOn": "folderOpen" - } - }, - { - "label": "Launch Example C++", - "type": "shell", - "command": "${workspaceFolder}/Example", - "dependsOn": [ "Binary build" ], - "presentation": { - "echo": true, - "reveal": "always", - "focus": true, - "panel": "shared", - "showReuseMessage": false, - "clear": true - }, - "problemMatcher": [] - } - ] -} diff --git a/theia-extensions/blueprint-example-generator/src/browser/example-generator-frontend-module.ts b/theia-extensions/blueprint-example-generator/src/browser/example-generator-frontend-module.ts index add49fa..bbca556 100644 --- a/theia-extensions/blueprint-example-generator/src/browser/example-generator-frontend-module.ts +++ b/theia-extensions/blueprint-example-generator/src/browser/example-generator-frontend-module.ts @@ -14,15 +14,11 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { CommandContribution } from '@theia/core'; import { WebSocketConnectionProvider } from '@theia/core/lib/browser'; import { ContainerModule } from '@theia/core/shared/inversify'; -import { ExampleGeneratorService, EXAMPLE_GENERATOR_PATH } from '../common/protocol'; -import { ExampleGeneratorCommandContribution, GenerateExampleCommandHandler } from './example-generator-contribution'; +import { EXAMPLE_GENERATOR_PATH, ExampleGeneratorService } from '../common/protocol'; export default new ContainerModule((bind, _unbind, isBound, rebind) => { - bind(GenerateExampleCommandHandler).toSelf().inSingletonScope(); - bind(CommandContribution).to(ExampleGeneratorCommandContribution).inSingletonScope(); bind(ExampleGeneratorService).toDynamicValue(ctx => { const connection = ctx.container.get(WebSocketConnectionProvider); return connection.createProxy(EXAMPLE_GENERATOR_PATH); diff --git a/theia-extensions/blueprint-example-generator/src/browser/index.ts b/theia-extensions/blueprint-example-generator/src/browser/index.ts index 24223ee..e672654 100644 --- a/theia-extensions/blueprint-example-generator/src/browser/index.ts +++ b/theia-extensions/blueprint-example-generator/src/browser/index.ts @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2022 STMicroelectronics and others. + * Copyright (C) 2023 STMicroelectronics and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -14,5 +14,4 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -export { GenerateExampleCommand } from './example-generator-contribution'; -export { Examples } from '../common/protocol'; +export { Example, ExampleGeneratorService } from '../common/protocol'; diff --git a/theia-extensions/blueprint-example-generator/src/common/protocol.ts b/theia-extensions/blueprint-example-generator/src/common/protocol.ts index e111223..631d7b8 100644 --- a/theia-extensions/blueprint-example-generator/src/common/protocol.ts +++ b/theia-extensions/blueprint-example-generator/src/common/protocol.ts @@ -14,24 +14,46 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ +import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration'; +import { TaskCustomization } from '@theia/task/lib/common/task-protocol'; + export const ExampleGeneratorService = Symbol('ExampleGeneratorService'); export const EXAMPLE_GENERATOR_PATH = '/services/example-generator'; -export enum Examples { - CMAKE_EXAMPLE = 'cmake-example', - EXAMPLE_TRACES = 'example-traces', - CLANGD_CONTEXTS = 'clangd-contexts' +export interface ExampleOptions { + /** The full path of the selected target folder. */ + targetFolder: string; + /** The name of the target folder. */ + targetFolderName: string; +} + +export interface Example { + id: string; + label: string; + resourcesPath: string; + welcomeFile?: string; + tasks?: (options: ExampleOptions) => TaskCustomization[]; + launches?: (options: ExampleOptions) => DebugConfiguration[]; } /** - * Service for generating CDT Cloud Blueprint examples. + * Service for generating examples. */ export interface ExampleGeneratorService { /** - * Generates the example with the name `exampleId` into the specified folder `targetFolderName`. - * @param exampleId identifyer of the example. - * @param targetFolderUri URI of the folder into which the example shall be generated. - * @returns (optional) URI of a file to be opened in an editor. + * Returns all examples available for generation. */ - generateExample(exampleId: string, targetFolderUri: string): Promise + getExamples(): Promise; + /** + * Generates the specified `example` into the specified folder `targetPath`. + * @param example the example to generate. + * @param targetPath URI of the folder into which the example shall be generated. + * @param targetFolderName The user-specified name of the target folder. + */ + generateExample(example: Example, targetPath: string, targetFolderName: string): Promise +} + +export const ExamplesContribution = Symbol('ExamplesContribution'); +export interface ExamplesContribution { + readonly examples: Example[]; } diff --git a/theia-extensions/blueprint-example-generator/src/node/example-generator-backend-module.ts b/theia-extensions/blueprint-example-generator/src/node/example-generator-backend-module.ts index 93f9205..08f8230 100644 --- a/theia-extensions/blueprint-example-generator/src/node/example-generator-backend-module.ts +++ b/theia-extensions/blueprint-example-generator/src/node/example-generator-backend-module.ts @@ -14,12 +14,13 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { ConnectionHandler, JsonRpcConnectionHandler } from '@theia/core'; +import { ConnectionHandler, JsonRpcConnectionHandler, bindContributionProvider } from '@theia/core'; import { ContainerModule } from '@theia/core/shared/inversify'; -import { ExampleGeneratorService, EXAMPLE_GENERATOR_PATH } from '../common/protocol'; +import { EXAMPLE_GENERATOR_PATH, ExampleGeneratorService, ExamplesContribution } from '../common/protocol'; import { ExampleGeneratorServiceImpl } from './example-generator-service'; export default new ContainerModule((bind, unbind, isBound, rebind) => { + bindContributionProvider(bind, ExamplesContribution); bind(ExampleGeneratorService).to(ExampleGeneratorServiceImpl).inSingletonScope(); bind(ConnectionHandler).toDynamicValue(ctx => new JsonRpcConnectionHandler(EXAMPLE_GENERATOR_PATH, diff --git a/theia-extensions/blueprint-example-generator/src/node/example-generator-service.ts b/theia-extensions/blueprint-example-generator/src/node/example-generator-service.ts index e5d795e..e913fd1 100644 --- a/theia-extensions/blueprint-example-generator/src/node/example-generator-service.ts +++ b/theia-extensions/blueprint-example-generator/src/node/example-generator-service.ts @@ -14,53 +14,85 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ +import { ContributionProvider } from '@theia/core'; import URI from '@theia/core/lib/common/uri'; import { FileUri } from '@theia/core/lib/node/file-uri'; -import { injectable } from '@theia/core/shared/inversify'; +import { inject, injectable, named } from '@theia/core/shared/inversify'; import * as fs from 'fs-extra'; -import { ExampleGeneratorService, Examples } from '../common/protocol'; - -const EXAMPLE_DIRECTORY = 'resources'; +import { Example, ExamplesContribution, ExampleGeneratorService } from '../common/protocol'; +import { TaskConfiguration } from '@theia/task/lib/common'; +import { DebugConfiguration } from '@theia/debug/lib/common/debug-configuration'; @injectable() export class ExampleGeneratorServiceImpl implements ExampleGeneratorService { - async generateExample(exampleId: string, targetFolderUri: string): Promise { - const examplesUri = new URI(module.path).resolve(`../../${EXAMPLE_DIRECTORY}`).normalizePath(); - const examplesPath = FileUri.fsPath(examplesUri); - if (!examplesPath || !fs.existsSync(examplesPath)) { - throw new Error('Could not find examples folder'); - } + @inject(ContributionProvider) @named(ExamplesContribution) + protected readonly examplesProvider: ContributionProvider; + + async getExamples(): Promise { + const contributions = this.examplesProvider.getContributions(); + return contributions.flatMap(contribution => contribution.examples); + } - const exampleUri = examplesUri.resolve(exampleId); + async generateExample(example: Example, target: string, folderName: string): Promise { + const resolvedExample = (await this.getExamples()).find(e => e.id === example.id) ?? example; + const exampleUri = new URI(resolvedExample.resourcesPath); const examplePath = FileUri.fsPath(exampleUri); if (!examplePath || !fs.existsSync(examplePath)) { - throw new Error(`Could not find files in ${examplePath}`); + throw new Error(`Could not find resources of example in ${examplePath}`); } - const targetUri = new URI(targetFolderUri); - const targetPath = FileUri.fsPath(targetUri); - fs.copySync(examplePath, targetPath, { recursive: true, errorOnExist: true }); + const targetUri = new URI(target); + this.copyFiles(targetUri, examplePath); - const fileToBeOpened = this.getFileToBeOpened(exampleId); - if (fileToBeOpened) { - return FileUri.fsPath(targetUri.resolve(fileToBeOpened)); + if (resolvedExample.tasks || resolvedExample.launches) { + const workspaceRoot = folderName ? targetUri.parent : targetUri; + const configFolder = FileUri.fsPath(workspaceRoot.resolve('.theia')); + fs.ensureDirSync(configFolder); + this.createOrAmendTasksJson(resolvedExample, workspaceRoot, folderName); + this.createOrAmendLaunchJson(resolvedExample, workspaceRoot, folderName); } + } - return undefined; + protected copyFiles(targetUri: URI, examplePath: string): void { + const targetPath = FileUri.fsPath(targetUri); + fs.copySync(examplePath, targetPath, { recursive: true, errorOnExist: true }); } - protected getFileToBeOpened(exampleId: string): string | undefined { - if (exampleId === Examples.CMAKE_EXAMPLE) { - return 'CMAKE_EXAMPLE_README.md'; + protected createOrAmendTasksJson(example: Example, workspaceRoot: URI, targetFolderName: string): void { + if (example.tasks) { + const tasksJsonPath = FileUri.fsPath(workspaceRoot.resolve('.theia/tasks.json')); + if (!fs.existsSync(tasksJsonPath)) { + fs.writeFileSync(tasksJsonPath, `{ + "version": "2.0.0", + "tasks": [] + }`); + } + const tasksJson = JSON.parse(fs.readFileSync(tasksJsonPath).toString()); + const existingTaskConfigurations = tasksJson['tasks'] as TaskConfiguration[]; + const targetFolder = FileUri.fsPath(workspaceRoot.resolve(targetFolderName)); + const newTasks = example.tasks({targetFolderName, targetFolder}); + tasksJson['tasks'] = [...existingTaskConfigurations, ...newTasks]; + fs.writeFileSync(tasksJsonPath, JSON.stringify(tasksJson, undefined, 2)); } - if (exampleId === Examples.CLANGD_CONTEXTS) { - return 'CLANGD_CONTEXTS_README.md'; - } - if (exampleId === Examples.EXAMPLE_TRACES) { - return 'EXAMPLE_TRACES_README.md'; + } + + protected createOrAmendLaunchJson(example: Example, workspaceRoot: URI, targetFolderName: string): void { + if (example.launches) { + const launchJsonPath = FileUri.fsPath(workspaceRoot.resolve('.theia/launch.json')); + if (!fs.existsSync(launchJsonPath)) { + fs.writeFileSync(launchJsonPath, `{ + "version": "2.0.0", + "configurations": [] + }`); + } + const launchJson = JSON.parse(fs.readFileSync(launchJsonPath).toString()); + const existingLaunchConfigurations = launchJson['configurations'] as DebugConfiguration[]; + const targetFolder = FileUri.fsPath(workspaceRoot.resolve(targetFolderName)); + const newLaunchConfigs = example.launches({targetFolderName, targetFolder}); + launchJson['configurations'] = [...existingLaunchConfigurations, ...newLaunchConfigs]; + fs.writeFileSync(launchJsonPath, JSON.stringify(launchJson, undefined, 2)); } - return undefined; } } diff --git a/theia-extensions/blueprint-example-generator/src/node/index.ts b/theia-extensions/blueprint-example-generator/src/node/index.ts new file mode 100644 index 0000000..260102c --- /dev/null +++ b/theia-extensions/blueprint-example-generator/src/node/index.ts @@ -0,0 +1,17 @@ +/******************************************************************************** + * Copyright (C) 2023 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +export { Example, ExampleGeneratorService, ExamplesContribution, ExampleOptions } from '../common/protocol'; diff --git a/theia-extensions/blueprint-examples/.eslintrc.js b/theia-extensions/blueprint-examples/.eslintrc.js new file mode 100644 index 0000000..1308994 --- /dev/null +++ b/theia-extensions/blueprint-examples/.eslintrc.js @@ -0,0 +1,10 @@ +/** @type {import('eslint').Linter.Config} */ +module.exports = { + extends: [ + '../../configs/build.eslintrc.json' + ], + parserOptions: { + tsconfigRootDir: __dirname, + project: 'tsconfig.json' + } +}; diff --git a/theia-extensions/blueprint-examples/package.json b/theia-extensions/blueprint-examples/package.json new file mode 100644 index 0000000..1bd4ec1 --- /dev/null +++ b/theia-extensions/blueprint-examples/package.json @@ -0,0 +1,53 @@ +{ + "name": "@eclipse-cdt-cloud/blueprint-examples", + "version": "1.38.0", + "description": "Extension for generating examples in CDT Cloud Blueprint", + "dependencies": { + "@theia/core": "1.38.0", + "@theia/workspace": "1.38.0", + "@theia/navigator": "1.38.0", + "@theia/task": "1.38.0", + "@theia/debug": "1.38.0", + "@theia/filesystem": "1.38.0", + "@theia/editor": "1.38.0", + "@eclipse-cdt-cloud/blueprint-example-generator": "1.38.0", + "inversify": "^5.1.1" + }, + "devDependencies": { + "rimraf": "^2.7.1", + "tslint": "^5.12.0", + "typescript": "^4.5.5" + }, + "theiaExtensions": [ + { + "frontendElectron": "lib/browser/blueprint-examples-frontend-module", + "frontend": "lib/browser/blueprint-examples-frontend-module", + "backend": "lib/node/blueprint-examples-backend-module" + } + ], + "keywords": [ + "theia-extension" + ], + "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", + "repository": { + "type": "git", + "url": "https://github.com/eclipse-cdt-cloud/cdt-cloud-blueprint.git" + }, + "bugs": { + "url": "https://github.com/eclipse-cdt-cloud/cdt-cloud-blueprint/issues" + }, + "homepage": "https://www.eclipse.org/cdt-cloud/", + "files": [ + "resources", + "lib", + "src" + ], + "scripts": { + "prepare": "yarn clean && yarn build", + "clean": "rimraf lib *.tsbuildinfo", + "build": "tsc -b", + "lint": "eslint --ext js,jsx,ts,tsx src", + "lint:fix": "eslint --ext js,jsx,ts,tsx src --fix", + "update:next": "ts-node ../../scripts/update-theia-to-next.ts" + } +} diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/.clangd-contexts b/theia-extensions/blueprint-examples/resources/clangd-contexts/.clangd-contexts similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/.clangd-contexts rename to theia-extensions/blueprint-examples/resources/clangd-contexts/.clangd-contexts diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/.gitignore b/theia-extensions/blueprint-examples/resources/clangd-contexts/.gitignore similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/.gitignore rename to theia-extensions/blueprint-examples/resources/clangd-contexts/.gitignore diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/CLANGD_CONTEXTS_README.md b/theia-extensions/blueprint-examples/resources/clangd-contexts/CLANGD_CONTEXTS_README.md similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/CLANGD_CONTEXTS_README.md rename to theia-extensions/blueprint-examples/resources/clangd-contexts/CLANGD_CONTEXTS_README.md diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/CMakeLists.txt b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/CMakeLists.txt similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/CMakeLists.txt rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/CMakeLists.txt diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_1.c b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_1.c similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_1.c rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_1.c diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_2.c b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_2.c similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_2.c rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_2.c diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_3.c b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_3.c similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/file_3.c rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/file_3.c diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/files.h b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/files.h similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/files.h rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/files.h diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/main.c b/theia-extensions/blueprint-examples/resources/clangd-contexts/app/main.c similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/app/main.c rename to theia-extensions/blueprint-examples/resources/clangd-contexts/app/main.c diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/build.sh b/theia-extensions/blueprint-examples/resources/clangd-contexts/build.sh similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/build.sh rename to theia-extensions/blueprint-examples/resources/clangd-contexts/build.sh diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/CMakeLists.txt b/theia-extensions/blueprint-examples/resources/clangd-contexts/lib/CMakeLists.txt similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/CMakeLists.txt rename to theia-extensions/blueprint-examples/resources/clangd-contexts/lib/CMakeLists.txt diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/lib.c b/theia-extensions/blueprint-examples/resources/clangd-contexts/lib/lib.c similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/lib.c rename to theia-extensions/blueprint-examples/resources/clangd-contexts/lib/lib.c diff --git a/theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/lib.h b/theia-extensions/blueprint-examples/resources/clangd-contexts/lib/lib.h similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/clangd-contexts/lib/lib.h rename to theia-extensions/blueprint-examples/resources/clangd-contexts/lib/lib.h diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/CMAKE_EXAMPLE_README.md b/theia-extensions/blueprint-examples/resources/cmake-example/CMAKE_EXAMPLE_README.md similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/cmake-example/CMAKE_EXAMPLE_README.md rename to theia-extensions/blueprint-examples/resources/cmake-example/CMAKE_EXAMPLE_README.md diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/CMakeLists.txt b/theia-extensions/blueprint-examples/resources/cmake-example/CMakeLists.txt similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/cmake-example/CMakeLists.txt rename to theia-extensions/blueprint-examples/resources/cmake-example/CMakeLists.txt diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/include/Rectangle.h b/theia-extensions/blueprint-examples/resources/cmake-example/include/Rectangle.h similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/cmake-example/include/Rectangle.h rename to theia-extensions/blueprint-examples/resources/cmake-example/include/Rectangle.h diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/src/Rectangle.cpp b/theia-extensions/blueprint-examples/resources/cmake-example/src/Rectangle.cpp similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/cmake-example/src/Rectangle.cpp rename to theia-extensions/blueprint-examples/resources/cmake-example/src/Rectangle.cpp diff --git a/theia-extensions/blueprint-example-generator/resources/cmake-example/src/main.cpp b/theia-extensions/blueprint-examples/resources/cmake-example/src/main.cpp similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/cmake-example/src/main.cpp rename to theia-extensions/blueprint-examples/resources/cmake-example/src/main.cpp diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/EXAMPLE_TRACES_README.md b/theia-extensions/blueprint-examples/resources/example-traces/EXAMPLE_TRACES_README.md similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/EXAMPLE_TRACES_README.md rename to theia-extensions/blueprint-examples/resources/example-traces/EXAMPLE_TRACES_README.md diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_0.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_0.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_0.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_0.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_1.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_1.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_1.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_1.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_2.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_2.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_2.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_2.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_3.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_3.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_3.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_3.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_4.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_4.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_4.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_4.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_5.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_5.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_5.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_5.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_6.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_6.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_6.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_6.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_7.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_7.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/index/k_7.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/index/k_7.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_0 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_0 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_0 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_0 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_1 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_1 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_1 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_1 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_2 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_2 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_2 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_2 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_3 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_3 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_3 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_3 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_4 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_4 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_4 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_4 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_5 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_5 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_5 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_5 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_6 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_6 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_6 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_6 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_7 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_7 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/k_7 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/k_7 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/metadata b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/metadata similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-kernel/metadata rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-kernel/metadata diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_0.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_0.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_0.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_0.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_1.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_1.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_1.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_1.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_2.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_2.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_2.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_2.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_3.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_3.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_3.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_3.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_4.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_4.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_4.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_4.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_5.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_5.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_5.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_5.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_6.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_6.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_6.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_6.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_7.idx b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_7.idx similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/index/u_7.idx rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/index/u_7.idx diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/metadata b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/metadata similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/metadata rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/metadata diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_0 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_0 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_0 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_0 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_1 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_1 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_1 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_1 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_2 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_2 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_2 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_2 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_3 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_3 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_3 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_3 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_4 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_4 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_4 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_4 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_5 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_5 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_5 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_5 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_6 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_6 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_6 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_6 diff --git a/theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_7 b/theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_7 similarity index 100% rename from theia-extensions/blueprint-example-generator/resources/example-traces/traces/cat-ust/u_7 rename to theia-extensions/blueprint-examples/resources/example-traces/traces/cat-ust/u_7 diff --git a/theia-extensions/blueprint-example-generator/src/browser/example-generator-contribution.ts b/theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-contribution.ts similarity index 56% rename from theia-extensions/blueprint-example-generator/src/browser/example-generator-contribution.ts rename to theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-contribution.ts index 3a4b66f..7a3ca17 100644 --- a/theia-extensions/blueprint-example-generator/src/browser/example-generator-contribution.ts +++ b/theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-contribution.ts @@ -14,14 +14,16 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { Command, CommandContribution, CommandHandler, CommandRegistry, MessageService, nls } from '@theia/core'; +import { Example, ExampleGeneratorService } from '@eclipse-cdt-cloud/blueprint-example-generator/lib/browser'; +import { Command, CommandContribution, CommandHandler, CommandRegistry, CommandService, MessageService, nls } from '@theia/core'; import { LabelProvider, QuickInputService, QuickPickService, QuickPickValue } from '@theia/core/lib/browser'; import URI from '@theia/core/lib/common/uri'; import { EditorManager } from '@theia/editor/lib/browser'; import { FileService } from '@theia/filesystem/lib/browser/file-service'; +import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; + import { inject, injectable } from 'inversify'; -import { ExampleGeneratorService, Examples } from '../common/protocol'; export const GenerateExampleCommand: Command = { id: 'eclipse-cdt-cloud.example-generator.generate-example', @@ -55,23 +57,40 @@ export class GenerateExampleCommandHandler implements CommandHandler { @inject(EditorManager) protected readonly editorManager: EditorManager; + @inject(CommandService) + protected readonly commandService: CommandService; + async execute(...args: string[]): Promise { - const exampleId = await this.getExampleId(args); - if (!exampleId) { + const example = await this.selectExample(args); + if (!example) { return; } - const targetFolder = await this.getWorkspaceRoot(); - if (!targetFolder) { + const workspaceFolder = await this.getWorkspaceRoot(); + if (!workspaceFolder) { this.messageService.error('Cannot resolve workspace root, please open a workspace'); return; } - const progress = await this.messageService.showProgress({ text: 'Starting to report progress' }); + const targetFolder = await this.specifyTargetFolder(example, workspaceFolder); + if (!targetFolder) { + return; + } + + const targetFolderName = targetFolder.path.name; + if (await this.validateFolderName(targetFolderName, workspaceFolder)) { + throw new Error('Target folder is invalid, probably it already exists.'); + } + + const progress = await this.messageService.showProgress({ + text: `Generating example ${example.label} to ${targetFolderName}` + }); try { - const fileToBeOpened = await this.exampleGeneratorService.generateExample(exampleId, targetFolder.toString()); - if (fileToBeOpened) { - this.editorManager.open(new URI(fileToBeOpened)); + await this.exampleGeneratorService.generateExample(example, targetFolder.toString(), targetFolderName); + await this.refreshAndReveal(targetFolder); + if (example.welcomeFile) { + const fileUri = targetFolder.resolve(example.welcomeFile); + await this.editorManager.open(fileUri); } } catch (error) { console.error('Uncaught Exception: ', error.toString()); @@ -80,19 +99,23 @@ export class GenerateExampleCommandHandler implements CommandHandler { } } - protected async getExampleId(args: string[]): Promise { + protected async selectExample(args: string[]): Promise { if (args.length < 1 || typeof args[0] !== 'string') { return this.askUserToChooseExample(); } - return args[0]; + + const examples = await this.exampleGeneratorService.getExamples(); + const matchedExample = examples.filter((e: Example) => args[0] === e.id); + if (matchedExample.length > 0) { + return matchedExample[0]; + } + + return undefined; } - protected async askUserToChooseExample(): Promise { - const items: QuickPickValue[] = [ - { label: 'CMake example', value: Examples.CMAKE_EXAMPLE }, - { label: 'Example traces', value: Examples.EXAMPLE_TRACES }, - { label: 'Clangd contexts', value: Examples.CLANGD_CONTEXTS } - ]; + protected async askUserToChooseExample(): Promise { + const examples = await this.exampleGeneratorService.getExamples(); + const items: QuickPickValue[] = examples.map((e: Example) => >{ label: e.label, value: e }); const selection = await this.quickPickService.show(items, { placeholder: 'Select type of example to generate' }); @@ -128,6 +151,39 @@ export class GenerateExampleCommandHandler implements CommandHandler { }); return root?.value; } + + protected async refreshAndReveal(fileUri: URI): Promise { + await this.commandService.executeCommand(FileNavigatorCommands.REFRESH_NAVIGATOR.id); + await this.commandService.executeCommand(FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id, fileUri); + } + + protected async specifyTargetFolder(example: Example, workspaceFolder: URI): Promise { + const targetFolder = await this.quickInputService.input({ + placeHolder: example.id, + value: example.id, + prompt: 'Specify the name of the target folder', + validateInput: input => this.validateFolderName(input, workspaceFolder) + }) ?? ''; + return workspaceFolder.resolve(targetFolder.length > 0 ? targetFolder : example.id); + } + + protected async validateFolderName(input: string, workspaceFolder: URI): Promise { + const inputIsNotEmpty = input.length !== 0; + const validFolderNameRegExp = /^[^\s^\x00-\x1f\\?*:"";<>|\/.][^\x00-\x1f\\?*:"";<>|\/]*[^\s^\x00-\x1f\\?*:"";<>|\/.]+$/; + if (inputIsNotEmpty && !validFolderNameRegExp.test(input)) { + return { + content: 'Invalid folder name', + severity: 3 // Error + }; + } + if (inputIsNotEmpty && await this.fileService.exists(workspaceFolder.resolve(input))) { + return { + content: 'Folder already exists', + severity: 3 // Error + }; + } + return undefined; + } } @injectable() @@ -139,4 +195,5 @@ export class ExampleGeneratorCommandContribution implements CommandContribution registerCommands(commands: CommandRegistry): void { commands.registerCommand(GenerateExampleCommand, this.generateExampleCommandHandler); } + } diff --git a/theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-module.ts b/theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-module.ts new file mode 100644 index 0000000..009d4e9 --- /dev/null +++ b/theia-extensions/blueprint-examples/src/browser/blueprint-examples-frontend-module.ts @@ -0,0 +1,24 @@ +/******************************************************************************** + * Copyright (C) 2023 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { CommandContribution } from '@theia/core'; +import { ContainerModule } from '@theia/core/shared/inversify'; +import { ExampleGeneratorCommandContribution, GenerateExampleCommandHandler } from './blueprint-examples-frontend-contribution'; + +export default new ContainerModule((bind, _unbind, isBound, rebind) => { + bind(GenerateExampleCommandHandler).toSelf().inSingletonScope(); + bind(CommandContribution).to(ExampleGeneratorCommandContribution).inSingletonScope(); +}); diff --git a/theia-extensions/blueprint-examples/src/browser/index.ts b/theia-extensions/blueprint-examples/src/browser/index.ts new file mode 100644 index 0000000..b24086a --- /dev/null +++ b/theia-extensions/blueprint-examples/src/browser/index.ts @@ -0,0 +1,18 @@ +/******************************************************************************** + * Copyright (C) 2023 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +export { GenerateExampleCommand } from './blueprint-examples-frontend-contribution'; +export { CdtCloudBlueprintExamples } from '../common/cdt-blueprint-examples'; diff --git a/theia-extensions/blueprint-examples/src/common/cdt-blueprint-examples.ts b/theia-extensions/blueprint-examples/src/common/cdt-blueprint-examples.ts new file mode 100644 index 0000000..c3f9a71 --- /dev/null +++ b/theia-extensions/blueprint-examples/src/common/cdt-blueprint-examples.ts @@ -0,0 +1,21 @@ +/******************************************************************************** + * Copyright (C) 2023 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +export enum CdtCloudBlueprintExamples { + CMAKE_EXAMPLE = 'cmake-example', + EXAMPLE_TRACES = 'example-traces', + CLANGD_CONTEXTS = 'clangd-contexts' +} diff --git a/theia-extensions/blueprint-examples/src/node/blueprint-examples-backend-module.ts b/theia-extensions/blueprint-examples/src/node/blueprint-examples-backend-module.ts new file mode 100644 index 0000000..30a052d --- /dev/null +++ b/theia-extensions/blueprint-examples/src/node/blueprint-examples-backend-module.ts @@ -0,0 +1,24 @@ +/******************************************************************************** + * Copyright (C) 2022 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { ContainerModule } from '@theia/core/shared/inversify'; +import { CdtCloudBlueprintExamplesContribution } from './blueprint-examples-contribution'; +import { ExamplesContribution } from '@eclipse-cdt-cloud/blueprint-example-generator/lib/node'; + +export default new ContainerModule((bind, unbind, isBound, rebind) => { + bind(CdtCloudBlueprintExamplesContribution).toSelf().inSingletonScope(); + bind(ExamplesContribution).toService(CdtCloudBlueprintExamplesContribution); +}); diff --git a/theia-extensions/blueprint-examples/src/node/blueprint-examples-contribution.ts b/theia-extensions/blueprint-examples/src/node/blueprint-examples-contribution.ts new file mode 100644 index 0000000..b09f36f --- /dev/null +++ b/theia-extensions/blueprint-examples/src/node/blueprint-examples-contribution.ts @@ -0,0 +1,84 @@ +/******************************************************************************** + * Copyright (C) 2023 STMicroelectronics and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { Example, ExampleOptions, ExamplesContribution } from '@eclipse-cdt-cloud/blueprint-example-generator/lib/node'; +import { URI } from '@theia/core'; +import { injectable } from '@theia/core/shared/inversify'; +import { PanelKind, RevealKind } from '@theia/task/lib/common'; +import { CdtCloudBlueprintExamples } from '../common/cdt-blueprint-examples'; + +@injectable() +export class CdtCloudBlueprintExamplesContribution implements ExamplesContribution { + get examples(): Example[] { + return [{ + id: CdtCloudBlueprintExamples.CMAKE_EXAMPLE, + label: 'CMake example', + welcomeFile: 'CMAKE_EXAMPLE_README.md', + resourcesPath: new URI(module.path).resolve('../../resources/cmake-example').normalizePath().toString(), + launches: (options: ExampleOptions) => [{ + 'type': 'gdb', + 'request': 'launch', + 'name': `Debug Example C++ (${options.targetFolderName})`, + 'program': `\${workspaceFolder}/${options.targetFolderName}/Example`, + 'initCommands': ['tbreak main'], + 'preLaunchTask': `Binary build (${options.targetFolderName})` + }], + tasks: (options: ExampleOptions) => [{ + 'label': `Binary build (${options.targetFolderName})`, + 'type': 'shell', + 'command': 'cmake . && make', + 'group': { + 'kind': 'build', + 'isDefault': true + }, + 'options': { + 'cwd': `\${workspaceFolder}/${options.targetFolderName}` + }, + 'problemMatcher': [] + }, + { + 'label': `Launch Example C++ (${options.targetFolderName})`, + 'type': 'shell', + 'command': './Example', + 'dependsOn': [ `Binary build (${options.targetFolderName})` ], + 'presentation': { + 'echo': true, + 'reveal': RevealKind.Always, + 'focus': true, + 'panel': PanelKind.Shared, + 'showReuseMessage': false, + 'clear': true + }, + 'options': { + 'cwd': `\${workspaceFolder}/${options.targetFolderName}` + }, + 'problemMatcher': [] + }] + }, + { + id: CdtCloudBlueprintExamples.EXAMPLE_TRACES, + label: 'Example traces', + welcomeFile: 'EXAMPLE_TRACES_README.md', + resourcesPath: new URI(module.path).resolve('../../resources/example-traces').normalizePath().toString() + }, + { + id: CdtCloudBlueprintExamples.CLANGD_CONTEXTS, + label: 'Clangd contexts', + welcomeFile: 'CLANGD_CONTEXTS_README.md', + resourcesPath: new URI(module.path).resolve('../../resources/clangd-contexts').normalizePath().toString() + }]; + } +} diff --git a/theia-extensions/blueprint-examples/tsconfig.json b/theia-extensions/blueprint-examples/tsconfig.json new file mode 100644 index 0000000..b7ed750 --- /dev/null +++ b/theia-extensions/blueprint-examples/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../configs/base.tsconfig", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib", + "baseUrl": "." + }, + "include": [ + "src" + ] +} diff --git a/theia-extensions/theia-blueprint-product/package.json b/theia-extensions/theia-blueprint-product/package.json index f04d318..b8897ac 100644 --- a/theia-extensions/theia-blueprint-product/package.json +++ b/theia-extensions/theia-blueprint-product/package.json @@ -8,7 +8,7 @@ "@theia/getting-started": "1.38.0", "@theia/vsx-registry": "1.38.0", "@theia/workspace": "1.38.0", - "@eclipse-cdt-cloud/blueprint-example-generator": "1.38.0", + "@eclipse-cdt-cloud/blueprint-examples": "1.38.0", "inversify": "^5.1.1" }, "devDependencies": { diff --git a/theia-extensions/theia-blueprint-product/src/browser/branding-util.tsx b/theia-extensions/theia-blueprint-product/src/browser/branding-util.tsx index 995b663..e9c472a 100644 --- a/theia-extensions/theia-blueprint-product/src/browser/branding-util.tsx +++ b/theia-extensions/theia-blueprint-product/src/browser/branding-util.tsx @@ -18,7 +18,7 @@ import { Key, KeyCode } from '@theia/core/lib/browser'; import { nls } from '@theia/core'; import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { CommandService } from '@theia/core/lib/common/command'; -import { GenerateExampleCommand, Examples } from '@eclipse-cdt-cloud/blueprint-example-generator/lib/browser'; +import { GenerateExampleCommand, CdtCloudBlueprintExamples } from '@eclipse-cdt-cloud/blueprint-examples/lib/browser'; import * as React from 'react'; export interface ExternalBrowserLinkProps { @@ -71,13 +71,13 @@ export function renderWhatIs(windowService: WindowService, commandService: Comma generateExample(commandService, Examples.EXAMPLE_TRACES)}> + onClick={() => generateExample(commandService, CdtCloudBlueprintExamples.EXAMPLE_TRACES)}> {nls.localizeByDefault('Generate example traces')} {' '} and open them with Trace Compass Cloud. ; } -function generateExample(commandService: CommandService, exampleId?: Examples): void { +function generateExample(commandService: CommandService, exampleId?: string): void { commandService.executeCommand(GenerateExampleCommand.id, exampleId); } diff --git a/theia-extensions/theia-blueprint-product/src/browser/theia-blueprint-getting-started-widget.tsx b/theia-extensions/theia-blueprint-product/src/browser/theia-blueprint-getting-started-widget.tsx index 7981ba2..68fedae 100644 --- a/theia-extensions/theia-blueprint-product/src/browser/theia-blueprint-getting-started-widget.tsx +++ b/theia-extensions/theia-blueprint-product/src/browser/theia-blueprint-getting-started-widget.tsx @@ -23,7 +23,7 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service'; import { codicon, Message, PreferenceService } from '@theia/core/lib/browser'; import { BlueprintPreferences } from './theia-blueprint-preferences'; import { CommandService, nls } from '@theia/core'; -import { GenerateExampleCommand, Examples } from '@eclipse-cdt-cloud/blueprint-example-generator/lib/browser'; +import { GenerateExampleCommand, CdtCloudBlueprintExamples } from '@eclipse-cdt-cloud/blueprint-examples/lib/browser'; @injectable() export class TheiaBlueprintGettingStartedWidget extends GettingStartedWidget { @@ -173,8 +173,8 @@ export class TheiaBlueprintGettingStartedWidget extends GettingStartedWidget { this.doGenerateExample(Examples.CMAKE_EXAMPLE)} - onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, Examples.CMAKE_EXAMPLE)}> + onClick={() => this.doGenerateExample(CdtCloudBlueprintExamples.CMAKE_EXAMPLE)} + onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, CdtCloudBlueprintExamples.CMAKE_EXAMPLE)}> {nls.localizeByDefault('CMake Example')} @@ -182,8 +182,8 @@ export class TheiaBlueprintGettingStartedWidget extends GettingStartedWidget { this.doGenerateExample(Examples.EXAMPLE_TRACES)} - onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, Examples.EXAMPLE_TRACES)}> + onClick={() => this.doGenerateExample(CdtCloudBlueprintExamples.EXAMPLE_TRACES)} + onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, CdtCloudBlueprintExamples.EXAMPLE_TRACES)}> {nls.localizeByDefault('Example traces')} @@ -191,8 +191,8 @@ export class TheiaBlueprintGettingStartedWidget extends GettingStartedWidget { this.doGenerateExample(Examples.CLANGD_CONTEXTS)} - onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, Examples.CLANGD_CONTEXTS)}> + onClick={() => this.doGenerateExample(CdtCloudBlueprintExamples.CLANGD_CONTEXTS)} + onKeyDown={(e: React.KeyboardEvent) => this.doGenerateExampleEnter(e, CdtCloudBlueprintExamples.CLANGD_CONTEXTS)}> {nls.localizeByDefault('Clangd contexts')}