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