Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
fix(plugins-view): Register custom plugin registries from devfile plu…
Browse files Browse the repository at this point in the history
…gins (#1131)

Scan devfile plugins and if it has custom plugin registry source, add it's plugin registry to che-theia's plugin registry cache.
  • Loading branch information
vinokurig authored Jun 11, 2021
1 parent 1217e60 commit 7e03e0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { inject, injectable, postConstruct } from 'inversify';
import { ChePluginFrontentService } from './che-plugin-frontend-service';
import { ChePluginPreferences } from './che-plugin-preferences';
import { ChePluginServiceClientImpl } from './che-plugin-service-client';
import { DevfileService } from '@eclipse-che/theia-remote-api/lib/common/devfile-service';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { PluginFilter } from '../../common/plugin/plugin-filter';
import { PluginServer } from '@theia/plugin-ext/lib/common/plugin-protocol';
Expand Down Expand Up @@ -79,6 +80,9 @@ export class ChePluginManager {
@inject(OpenerService)
protected readonly openerService: OpenerService;

@inject(DevfileService)
protected readonly devfileService: DevfileService;

@postConstruct()
async onStart() {
await this.initDefaults();
Expand Down Expand Up @@ -222,6 +226,20 @@ export class ChePluginManager {
registries[registry.name] = registry;
}

/**
* Scan devfile plugins for custom registry, add the registry to cache if detected.
*/
const devfile = await this.devfileService.get();
if (devfile.components) {
devfile.components
.filter(component => component.plugin && component.plugin.id && component.plugin.registryUrl)
.forEach(component => {
const registryUrl = component.plugin?.registryUrl!;
const name = component.plugin?.id!;
registries[name] = { name, uri: registryUrl, publicUri: registryUrl };
});
}

await this.chePluginService.updateCache(registries);
}

Expand Down Expand Up @@ -450,10 +468,9 @@ export class ChePluginManager {

try {
// remove the plugin from workspace configuration
await this.chePluginService.removePlugin(metadata.key);
this.messageService.info(
`Plugin '${metadata.publisher}/${metadata.name}/${metadata.version}' has been successfully removed`
);
const key = `${metadata.publisher}/${metadata.name}/${metadata.version}`;
await this.chePluginService.removePlugin(key);
this.messageService.info(`Plugin '${key}' has been successfully removed`);

// remove the plugin from the list of workspace plugins
this.installedPlugins = this.installedPlugins.filter(p => p !== metadata.key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class ChePluginServiceImpl implements ChePluginService {

for (let pIndex = 0; pIndex < registryPlugins.length; pIndex++) {
const metadataInternal: ChePluginMetadataInternal = registryPlugins[pIndex];
const pluginYamlURI = this.getPluginYampURI(registry, metadataInternal);
const pluginYamlURI = this.getPluginYamlURI(registry, metadataInternal);

try {
const pluginMetadata = await this.loadPluginMetadata(pluginYamlURI, longKeyFormat, registry.publicUri);
Expand Down Expand Up @@ -335,7 +335,7 @@ export class ChePluginServiceImpl implements ChePluginService {
* @param plugin plugin metadata
* @return uri to plugin yaml file
*/
private getPluginYampURI(registry: ChePluginRegistry, plugin: ChePluginMetadataInternal): string {
private getPluginYamlURI(registry: ChePluginRegistry, plugin: ChePluginMetadataInternal): string {
if (plugin.links && plugin.links.self) {
const self: string = plugin.links.self;
if (self.startsWith('/')) {
Expand Down

0 comments on commit 7e03e0b

Please sign in to comment.