Search in sources :

Example 6 with ExtendedPluginFQN

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);
}
Also used : Matcher(java.util.regex.Matcher) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 7 with ExtendedPluginFQN

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;
}
Also used : ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)

Example 8 with ExtendedPluginFQN

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");
}
Also used : ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) Test(org.testng.annotations.Test)

Example 9 with ExtendedPluginFQN

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());
}
Also used : PLUGIN_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WORKSPACE_TOOLING_EDITOR_ATTRIBUTE(org.eclipse.che.api.workspace.shared.Constants.WORKSPACE_TOOLING_EDITOR_ATTRIBUTE) String.format(java.lang.String.format) FileContentProvider(org.eclipse.che.api.workspace.server.devfile.FileContentProvider) ComponentToWorkspaceApplier(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) COMPONENT_ALIAS_COMMAND_ATTRIBUTE(org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE) EDITOR_COMPONENT_TYPE(org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE) ComponentFQNParser(org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Example 10 with ExtendedPluginFQN

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());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Aggregations

ExtendedPluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)18 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)6 Test (org.testng.annotations.Test)6 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)4 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)2 IOException (java.io.IOException)2 String.format (java.lang.String.format)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Matcher (java.util.regex.Matcher)2 Inject (javax.inject.Inject)2 PLUGIN_ATTRIBUTE (org.eclipse.che.api.core.model.workspace.config.Command.PLUGIN_ATTRIBUTE)2 COMPONENT_ALIAS_COMMAND_ATTRIBUTE (org.eclipse.che.api.workspace.server.devfile.Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE)2 EDITOR_COMPONENT_TYPE (org.eclipse.che.api.workspace.server.devfile.Constants.EDITOR_COMPONENT_TYPE)2 FileContentProvider (org.eclipse.che.api.workspace.server.devfile.FileContentProvider)2 ComponentFQNParser (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentFQNParser)2 ComponentToWorkspaceApplier (org.eclipse.che.api.workspace.server.devfile.convert.component.ComponentToWorkspaceApplier)2