-
-
Notifications
You must be signed in to change notification settings - Fork 491
test: gRPC core client init integration test #2023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
arduino-ide-extension/src/node/theia/env-variables/env-variables-server.ts
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.