Search in sources :

Example 16 with ExtendedPluginFQN

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

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

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

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

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

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)

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