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());
}
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);
}
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);
}
Aggregations