Search in sources :

Example 11 with ExtendedPluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project che-server by eclipse-che.

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 12 with ExtendedPluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project che-server by eclipse-che.

the class DefaultEditorProvisioner method addMissingPlugins.

/**
 * Tries to add default plugins to the Devfile components. Each plugin is initially parsed by
 * plugin ref. If the plugin does not have a reference, it is added to the component list, and its
 * plugin ID will be used to resolve it. If it has a reference, the Plugin is evaluated, so that
 * its meta.yaml can be retrieved. From the meta.yaml, the new Component's ID and reference are
 * properly set, and the Component is added to the list.
 *
 * @param devfileComponents - The list of Devfile components
 * @param contentProvider - The content provider to retrieve YAML
 * @param missingPluginsIdToRef - The list of default plugins that are not currently in the list
 *     of devfile components
 * @throws InfrastructureException if the parser is unable to evaluate the FQN of the plugin.
 */
private void addMissingPlugins(List<ComponentImpl> devfileComponents, FileContentProvider contentProvider, Map<String, String> missingPluginsIdToRef) throws InfrastructureException {
    for (String pluginRef : missingPluginsIdToRef.values()) {
        ComponentImpl component;
        ExtendedPluginFQN fqn = pluginFQNParser.parsePluginFQN(pluginRef);
        if (!isNullOrEmpty(fqn.getId())) {
            component = new ComponentImpl(PLUGIN_COMPONENT_TYPE, pluginRef);
        } else {
            component = createReferencePluginComponent(pluginRef, contentProvider);
        }
        devfileComponents.add(component);
    }
}
Also used : ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Example 13 with ExtendedPluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project devspaces-images by redhat-developer.

the class DefaultEditorProvisioner method addMissingPlugins.

/**
 * Tries to add default plugins to the Devfile components. Each plugin is initially parsed by
 * plugin ref. If the plugin does not have a reference, it is added to the component list, and its
 * plugin ID will be used to resolve it. If it has a reference, the Plugin is evaluated, so that
 * its meta.yaml can be retrieved. From the meta.yaml, the new Component's ID and reference are
 * properly set, and the Component is added to the list.
 *
 * @param devfileComponents - The list of Devfile components
 * @param contentProvider - The content provider to retrieve YAML
 * @param missingPluginsIdToRef - The list of default plugins that are not currently in the list
 *     of devfile components
 * @throws InfrastructureException if the parser is unable to evaluate the FQN of the plugin.
 */
private void addMissingPlugins(List<ComponentImpl> devfileComponents, FileContentProvider contentProvider, Map<String, String> missingPluginsIdToRef) throws InfrastructureException {
    for (String pluginRef : missingPluginsIdToRef.values()) {
        ComponentImpl component;
        ExtendedPluginFQN fqn = pluginFQNParser.parsePluginFQN(pluginRef);
        if (!isNullOrEmpty(fqn.getId())) {
            component = new ComponentImpl(PLUGIN_COMPONENT_TYPE, pluginRef);
        } else {
            component = createReferencePluginComponent(pluginRef, contentProvider);
        }
        devfileComponents.add(component);
    }
}
Also used : ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Example 14 with ExtendedPluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project devspaces-images by redhat-developer.

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 15 with ExtendedPluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN in project devspaces-images by redhat-developer.

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