use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project devspaces-images by redhat-developer.
the class PluginFQNParser method parsePluginFQN.
public ExtendedPluginFQN parsePluginFQN(String plugin) throws InfrastructureException {
String url;
String id;
String publisher;
String name;
String version;
URI registryURI = null;
Matcher matcher = PLUGIN_PATTERN.matcher(plugin);
if (matcher.matches()) {
url = matcher.group("url");
id = matcher.group("id");
publisher = matcher.group("publisher");
name = matcher.group("name");
version = matcher.group("version");
} else {
throw new InfrastructureException(format(INCORRECT_PLUGIN_FORMAT_TEMPLATE, plugin));
}
if (!isNullOrEmpty(url)) {
if (isNullOrEmpty(id)) {
// reference only
return new ExtendedPluginFQN(url);
} else {
// registry + id
try {
registryURI = new URI(url);
} catch (URISyntaxException e) {
throw new InfrastructureException(format("Plugin registry URL '%s' is invalid. Problematic plugin entry: '%s'", url, plugin));
}
}
}
return new ExtendedPluginFQN(registryURI, id, publisher, name, version);
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project devspaces-images by redhat-developer.
the class DefaultEditorProvisioner method createReferencePluginComponent.
/**
* Evaluates a plugin FQN by retrieving it's meta.yaml, and sets it's name and reference to the
* appropriate values.
*
* @param pluginRef - The formatted plugin reference (e.g.
* eclipse/che-machine-exec-plugin/nightly)
* @param contentProvider - The content provider used to read YAML data
* @return - A {@link ComponentImpl} with it's ID and reference URL set.
* @throws InfrastructureException when the parser cannot evalute the plugin's FQN.
*/
private ComponentImpl createReferencePluginComponent(String pluginRef, FileContentProvider contentProvider) throws InfrastructureException {
ExtendedPluginFQN fqn = pluginFQNParser.evaluateFqn(pluginRef, contentProvider);
ComponentImpl component = new ComponentImpl();
component.setType(PLUGIN_COMPONENT_TYPE);
if (!isNullOrEmpty(fqn.getId())) {
component.setId(fqn.getId());
}
if (!isNullOrEmpty(fqn.getReference())) {
component.setReference(fqn.getReference());
}
return component;
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project che-server by eclipse-che.
the class PluginFQNParserTest method shouldComposeIdWhenAllPartsGivenToTheConstructor.
@Test
public void shouldComposeIdWhenAllPartsGivenToTheConstructor() {
ExtendedPluginFQN pluginFQN = new ExtendedPluginFQN("reference", "publisher", "name", "version");
assertEquals(pluginFQN.getId(), "publisher/name/version");
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project che-server by eclipse-che.
the class EditorComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified editor component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param editorComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from cheEditor
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(editorComponent != null, "Component must not be null");
checkArgument(EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE));
final String editorComponentAlias = editorComponent.getAlias();
final String editorId = editorComponent.getId();
final String registryUrl = editorComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference());
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId));
}
workspaceConfig.getCommands().stream().filter(c -> editorComponentAlias != null && editorComponentAlias.equals(c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()));
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
editorComponent.setId(fqn.getId());
}
use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project che-server by eclipse-che.
the class PluginComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified plugin component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param pluginComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from chePlugin
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl pluginComponent, @Nullable FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(pluginComponent != null, "Component must not be null");
checkArgument(PLUGIN_COMPONENT_TYPE.equals(pluginComponent.getType()), format("Plugin must have `%s` type", PLUGIN_COMPONENT_TYPE));
String workspacePluginsAttribute = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE);
final String pluginId = pluginComponent.getId();
final String registryUrl = pluginComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(pluginComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, fqn.getReference()));
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, componentFQNParser.getCompositeId(registryUrl, pluginId)));
}
for (CommandImpl command : workspaceConfig.getCommands()) {
String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE);
if (commandComponent == null) {
// command does not have component information
continue;
}
if (!commandComponent.equals(pluginComponent.getAlias())) {
continue;
}
command.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId());
}
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
pluginComponent.setId(fqn.getId());
}
Aggregations