This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(multiple-workspace-root): Multi-root workspaces based on /projec…
…ts (or what has been configured as ROOT folder) Checks if there is a che.theia-workspace file. if there is one, returns that file as being a workspace root if none, generate the file by getting all clonedPath/path of the devfile projects enhancements: 1. make it optional for now (like if there is a special attribute in devfile, use that mode) 2. track new folders in /projects and add them to the che.theia-workspace file automatically (and if we delete folders) 3. allow to customize/provide different projects to be added in workspace root. Could be useful for a maven project to see only sub-folders/modules Change-Id: Idfb9370dc503bcfb5504ba37446f7f1ab171b515 Signed-off-by: Florent Benoit <fbenoit@redhat.com>
- Loading branch information
1 parent
8d39edf
commit 23712a2
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
extensions/eclipse-che-theia-workspace/src/node/che-workspace-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { injectable, inject } from 'inversify'; | ||
import { DefaultWorkspaceServer } from '@theia/workspace/lib/node/default-workspace-server'; | ||
import { CheApiService } from '@eclipse-che/theia-plugin-ext/lib/common/che-protocol'; | ||
import { FileUri } from '@theia/core/lib/node'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
|
||
interface TheiaWorkspace { | ||
folders: TheiaWorkspacePath[] | ||
}; | ||
|
||
interface TheiaWorkspacePath { | ||
path: string | ||
}; | ||
|
||
@injectable() | ||
export class CheWorkspaceServer extends DefaultWorkspaceServer { | ||
|
||
@inject(CheApiService) | ||
private cheApiService: CheApiService; | ||
|
||
// override any workspace that could have been defined through CLI and use entries from the devfile | ||
// if not possible, use default method | ||
protected async getRoot(): Promise<string | undefined> { | ||
|
||
let projectsRoot: string; | ||
if (process.env.CHE_PROJECTS_ROOT) { | ||
projectsRoot = process.env.CHE_PROJECTS_ROOT; | ||
} else { | ||
projectsRoot = '/projects'; | ||
} | ||
|
||
// first, check if we have a che.theia-workspace file | ||
const cheTheiaWorkspaceFile = path.resolve(projectsRoot, 'che.theia-workspace'); | ||
const exists = await fs.pathExists(cheTheiaWorkspaceFile); | ||
if (exists) { | ||
return FileUri.create(cheTheiaWorkspaceFile).toString(); | ||
} | ||
|
||
// no, then create the file | ||
|
||
const workspace = await this.cheApiService.currentWorkspace(); | ||
const devfile = workspace.devfile; | ||
if (devfile) { | ||
const projects = devfile.projects; | ||
if (projects) { | ||
// create a struc for each project | ||
const theiaWorkspace: TheiaWorkspace = { folders: [] }; | ||
for (const project of projects) { | ||
const projectPath = project.clonePath ? path.join(projectsRoot, project.clonePath) : path.join(projectsRoot, project.name!); | ||
// check parent folder exists | ||
const parentDir = path.resolve(projectPath, '..'); | ||
await fs.ensureDir(parentDir); | ||
theiaWorkspace.folders.push({ path: FileUri.create(projectPath).toString() }); | ||
} | ||
|
||
// now, need to write the content of this file | ||
await fs.writeFile(cheTheiaWorkspaceFile, JSON.stringify(theiaWorkspace), { encoding: 'utf8' }); | ||
|
||
// return this content | ||
return FileUri.create(cheTheiaWorkspaceFile).toString(); | ||
} | ||
} | ||
|
||
return super.getRoot(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
export * from './workspace-backend-module'; |
18 changes: 18 additions & 0 deletions
18
extensions/eclipse-che-theia-workspace/src/node/workspace-backend-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { CheWorkspaceServer } from './che-workspace-server'; | ||
import { WorkspaceServer } from '@theia/workspace/lib/common'; | ||
|
||
export default new ContainerModule((bind, unbind, isBound, rebind) => { | ||
bind(CheWorkspaceServer).toSelf().inSingletonScope(); | ||
rebind(WorkspaceServer).toService(CheWorkspaceServer); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters