Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose plugin id #14063

Merged
merged 7 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.annotations.Beta;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
Expand Down Expand Up @@ -104,11 +105,24 @@ private void handle(BrokerStatusChangedEvent event) {
private List<ChePlugin> parseTooling(String toolingString) {
if (!isNullOrEmpty(toolingString)) {
try {
return objectMapper.readValue(toolingString, new TypeReference<List<ChePlugin>>() {});
List<ChePlugin> plugins =
objectMapper.readValue(toolingString, new TypeReference<List<ChePlugin>>() {});
// when id of plugin is not set, we can compose it from publisher, name and version
return plugins.stream().map(this::composePluginIdWhenNull).collect(Collectors.toList());
} catch (IOException e) {
LOG.error("Parsing Che plugin broker event failed. Error: " + e.getMessage(), e);
}
}
return null;
}

private ChePlugin composePluginIdWhenNull(ChePlugin plugin) {
if (isNullOrEmpty(plugin.getId())
&& !isNullOrEmpty(plugin.getPublisher())
&& !isNullOrEmpty(plugin.getName())
&& !isNullOrEmpty(plugin.getVersion())) {
plugin.setId(plugin.getPublisher() + "/" + plugin.getName() + "/" + plugin.getVersion());
}
return plugin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public ExtendedPluginFQN(URI registry, String id, String publisher, String name,
this.version = version;
}

/** In this constructor, id is composed from given params */
public ExtendedPluginFQN(String reference, String publisher, String name, String version) {
super(reference);
super(reference, publisher + "/" + name + "/" + version);
this.publisher = publisher;
this.name = name;
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

/**
* Represents full information about plugin, including registry address and id, or direct reference
* to plugin descriptor. Should NOT contain both reference and id simultaneously.
* to plugin descriptor. When {@link PluginFQN#reference} and {@link PluginFQN#id} are set
* simultaneously, {@link PluginFQN#reference} should take precedence.
*
* @author Max Shaposhnyk
*/
Expand All @@ -34,6 +35,11 @@ public PluginFQN(URI registry, String id) {
this.id = id;
}

protected PluginFQN(String reference, String id) {
this.reference = reference;
this.id = id;
}

public PluginFQN(String reference) {
this.reference = reference;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public void shouldReturnEmptyListWhenNoPluginsOrEditors() throws Exception {
"PluginFQNParser should return empty list when attributes does not contain plugins or editors");
}

@Test
public void shouldComposeIdWhenAllPartsGivenToTheConstructor() {
ExtendedPluginFQN pluginFQN =
new ExtendedPluginFQN("reference", "publisher", "name", "version");
assertEquals(pluginFQN.getId(), "publisher/name/version");
}

@Test(dataProvider = "validAttributesProvider")
public void shouldParseAllPluginsAndEditor(AttributeParsingTestCase testCase) throws Exception {
Collection<PluginFQN> actual = parser.parsePlugins(testCase.attributes);
Expand Down