-
-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: gRPC core client init integration test
- Copied the env-variable server from Theia and made it possible to customize it for the tests. Each test has its own `data` folder. - Relaxed the primary package and library index error detection. This should make the init error detection locale independent. - Kill the daemon process subtree when stopping the daemon. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
- Loading branch information
Showing
13 changed files
with
596 additions
and
91 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
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
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
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
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
119 changes: 108 additions & 11 deletions
119
arduino-ide-extension/src/node/theia/env-variables/env-variables-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 |
---|---|---|
@@ -1,15 +1,112 @@ | ||
import { join } from 'path'; | ||
import { homedir } from 'os'; | ||
import { injectable } from '@theia/core/shared/inversify'; | ||
import { FileUri } from '@theia/core/lib/node/file-uri'; | ||
import { | ||
EnvVariable, | ||
EnvVariablesServer as TheiaEnvVariablesServer, | ||
} from '@theia/core/lib/common/env-variables/env-variables-protocol'; | ||
import { isWindows } from '@theia/core/lib/common/os'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { BackendApplicationConfigProvider } from '@theia/core/lib/node/backend-application-config-provider'; | ||
import { EnvVariablesServerImpl as TheiaEnvVariablesServerImpl } from '@theia/core/lib/node/env-variables/env-variables-server'; | ||
import { FileUri } from '@theia/core/lib/node/file-uri'; | ||
import { | ||
inject, | ||
injectable, | ||
postConstruct, | ||
} from '@theia/core/shared/inversify'; | ||
import { list as listDrives } from 'drivelist'; | ||
import { homedir } from 'os'; | ||
import { join } from 'path'; | ||
|
||
@injectable() | ||
export class ConfigDirUriProvider { | ||
private uri: URI | undefined; | ||
|
||
configDirUri(): URI { | ||
if (!this.uri) { | ||
this.uri = FileUri.create( | ||
join(homedir(), BackendApplicationConfigProvider.get().configDirName) | ||
); | ||
} | ||
return this.uri; | ||
} | ||
} | ||
|
||
// Copy-pasted from https://github.com/eclipse-theia/theia/blob/v1.31.1/packages/core/src/node/env-variables/env-variables-server.ts | ||
// to simplify the binding of the config directory location for tests. | ||
@injectable() | ||
export class EnvVariablesServer extends TheiaEnvVariablesServerImpl { | ||
protected override readonly configDirUri = Promise.resolve( | ||
FileUri.create( | ||
join(homedir(), BackendApplicationConfigProvider.get().configDirName) | ||
).toString() | ||
); | ||
export class EnvVariablesServer implements TheiaEnvVariablesServer { | ||
@inject(ConfigDirUriProvider) | ||
private readonly configDirUriProvider: ConfigDirUriProvider; | ||
|
||
private readonly envs: { [key: string]: EnvVariable } = {}; | ||
private readonly homeDirUri = FileUri.create(homedir()).toString(); | ||
|
||
constructor() { | ||
const prEnv = process.env; | ||
Object.keys(prEnv).forEach((key: string) => { | ||
let keyName = key; | ||
if (isWindows) { | ||
keyName = key.toLowerCase(); | ||
} | ||
this.envs[keyName] = { name: keyName, value: prEnv[key] }; | ||
}); | ||
} | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
console.log( | ||
`Configuration directory URI: '${this.configDirUriProvider | ||
.configDirUri() | ||
.toString()}'` | ||
); | ||
} | ||
|
||
async getExecPath(): Promise<string> { | ||
return process.execPath; | ||
} | ||
|
||
async getVariables(): Promise<EnvVariable[]> { | ||
return Object.keys(this.envs).map((key) => this.envs[key]); | ||
} | ||
|
||
async getValue(key: string): Promise<EnvVariable | undefined> { | ||
if (isWindows) { | ||
key = key.toLowerCase(); | ||
} | ||
return this.envs[key]; | ||
} | ||
|
||
async getConfigDirUri(): Promise<string> { | ||
return this.configDirUriProvider.configDirUri().toString(); | ||
} | ||
|
||
async getHomeDirUri(): Promise<string> { | ||
return this.homeDirUri; | ||
} | ||
|
||
async getDrives(): Promise<string[]> { | ||
const uris: string[] = []; | ||
const drives = await listDrives(); | ||
for (const drive of drives) { | ||
for (const mountpoint of drive.mountpoints) { | ||
if (this.filterHiddenPartitions(mountpoint.path)) { | ||
uris.push(FileUri.create(mountpoint.path).toString()); | ||
} | ||
} | ||
} | ||
return uris; | ||
} | ||
|
||
/** | ||
* Filters hidden and system partitions. | ||
*/ | ||
private filterHiddenPartitions(path: string): boolean { | ||
// OS X: This is your sleep-image. When your Mac goes to sleep it writes the contents of its memory to the hard disk. (https://bit.ly/2R6cztl) | ||
if (path === '/private/var/vm') { | ||
return false; | ||
} | ||
// Ubuntu: This system partition is simply the boot partition created when the computers mother board runs UEFI rather than BIOS. (https://bit.ly/2N5duHr) | ||
if (path === '/boot/efi') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.