Search in sources :

Example 1 with ExtendedPluginFQN

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

the class PluginFQNParser method evaluateFqn.

/**
 * Evaluates plugin FQN from provided reference by trying to fetch and parse its meta information.
 *
 * @param reference plugin reference to evaluate FQN from
 * @param fileContentProvider content provider instance to perform plugin meta requests
 * @return plugin FQN evaluated from given reference
 * @throws InfrastructureException if plugin reference is invalid or inaccessible
 */
public ExtendedPluginFQN evaluateFqn(String reference, FileContentProvider fileContentProvider) throws InfrastructureException {
    JsonNode contentNode;
    try {
        String pluginMetaContent = fileContentProvider.fetchContent(reference);
        contentNode = yamlReader.readTree(pluginMetaContent);
    } catch (DevfileException | IOException e) {
        throw new InfrastructureException(format("Plugin reference URL '%s' is invalid.", reference), e);
    }
    JsonNode publisher = contentNode.path("publisher");
    if (publisher.isMissingNode()) {
        throw new InfrastructureException(formatMessage(reference, "publisher"));
    }
    JsonNode name = contentNode.get("name");
    if (name.isMissingNode()) {
        throw new InfrastructureException(formatMessage(reference, "name"));
    }
    JsonNode version = contentNode.get("version");
    if (version.isMissingNode()) {
        throw new InfrastructureException(formatMessage(reference, "version"));
    }
    if (!version.isValueNode()) {
        throw new InfrastructureException(format("Plugin specified by reference URL '%s' has version field that cannot be parsed to string", reference));
    }
    return new ExtendedPluginFQN(reference, publisher.textValue(), name.textValue(), version.asText());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 2 with ExtendedPluginFQN

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

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

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

the class PluginFQNParserTest method shouldParsePluginOrEditorFromReference.

@Test(dataProvider = "validPluginReferencesProvider")
public void shouldParsePluginOrEditorFromReference(String reference, String pluginYaml, ExtendedPluginFQN expected) throws Exception {
    when(fileContentProvider.fetchContent(eq(reference))).thenReturn(pluginYaml);
    ExtendedPluginFQN actual = parser.evaluateFqn(reference, fileContentProvider);
    assertEquals(actual, expected);
}
Also used : ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) Test(org.testng.annotations.Test)

Example 4 with ExtendedPluginFQN

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

the class PluginFQNParserTest method shouldParsePluginOrEditorToExtendedFQN.

@Test(dataProvider = "validPluginStringProvider")
public void shouldParsePluginOrEditorToExtendedFQN(String plugin, ExtendedPluginFQN expected) throws Exception {
    ExtendedPluginFQN actual = parser.parsePluginFQN(plugin);
    assertEquals(actual, expected);
}
Also used : ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN) Test(org.testng.annotations.Test)

Example 5 with ExtendedPluginFQN

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

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)

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