PluginComponentToWorkspaceApplier implements ComponentToWorkspaceApplier { @Override public void apply( WorkspaceConfigImpl workspaceConfig, ComponentImpl pluginComponent, @Nullable FileContentProvider contentProvider) throws DevfileException { checkArgument(workspaceConfig != null, "Workspace config must not be null"); checkArgument(pluginComponent != null, "Component must not be null"); checkArgument( PLUGIN_COMPONENT_TYPE.equals(pluginComponent.getType()), format("Plugin must have `%s` type", PLUGIN_COMPONENT_TYPE)); String workspacePluginsAttribute = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE); final String pluginId = pluginComponent.getId(); final String registryUrl = pluginComponent.getRegistryUrl(); final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(pluginComponent, contentProvider); if (!isNullOrEmpty(fqn.getReference())) { workspaceConfig .getAttributes() .put( WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, fqn.getReference())); } else { workspaceConfig .getAttributes() .put( WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append( workspacePluginsAttribute, componentFQNParser.getCompositeId(registryUrl, pluginId))); } for (CommandImpl command : workspaceConfig.getCommands()) { String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE); if (commandComponent == null) { continue; } if (!commandComponent.equals(pluginComponent.getAlias())) { continue; } command.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId()); } pluginComponent.setId(fqn.getId()); } @Inject  PluginComponentToWorkspaceApplier(ComponentFQNParser componentFQNParser); @Override void apply(
      WorkspaceConfigImpl workspaceConfig,
      ComponentImpl pluginComponent,
      @Nullable FileContentProvider contentProvider);  }
@Test public void shouldProvisionPluginWorkspaceAttributeDuringChePluginComponentApplying() throws Exception { String superPluginId = "eclipse/super-plugin/0.0.1"; ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId(superPluginId); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); superPluginComponent.setMemoryLimit("1234M"); superPluginComponent.getPreferences().put("java-home", "/home/user/jdk11"); ComponentImpl customPluginComponent = new ComponentImpl(); customPluginComponent.setAlias("custom"); customPluginComponent.setId("publisher1/custom-plugin/v1"); customPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null); pluginComponentApplier.apply(workspaceConfig, customPluginComponent, null); String workspaceTooling = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE); assertTrue(workspaceTooling.matches("(.+/.+/.+),(.+/.+/.+)")); assertTrue(workspaceTooling.contains(superPluginId)); assertTrue(workspaceTooling.contains("publisher1/custom-plugin/v1")); }
@Test public void shouldProvisionPluginWorkspaceAttributeWithCustomRegistryDuringChePluginComponentApplying() throws Exception { String superPluginId = "eclipse/super-plugin/0.0.1"; String registryUrl = "https: ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId(superPluginId); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); superPluginComponent.setMemoryLimit("1234M"); ComponentImpl customPluginComponent = new ComponentImpl(); customPluginComponent.setAlias("custom"); customPluginComponent.setId("publisher1/custom-plugin/v1"); customPluginComponent.setRegistryUrl(registryUrl); customPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null); pluginComponentApplier.apply(workspaceConfig, customPluginComponent, null); String workspaceTooling = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE); assertTrue(workspaceTooling.matches("(.+/.+/.+),(.+/.+/.+)")); assertTrue(workspaceTooling.contains(superPluginId)); assertTrue(workspaceTooling.contains(registryUrl + "#" + "publisher1/custom-plugin/v1")); }
@Test public void shouldProvisionPluginWorkspaceAttributeWithReferenceDuringChePluginComponentApplying() throws Exception { String superPluginId = "eclipse/super-plugin/0.0.1"; String reference = "https: String meta = "apiVersion: v2\n" + "publisher: eclipse\n" + "name: super-plugin\n" + "version: 0.0.1\n" + "type: Che Plugin"; ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId(superPluginId); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); superPluginComponent.setMemoryLimit("1234M"); when(fileContentProvider.fetchContent(anyString())).thenReturn(meta); ComponentImpl customPluginComponent = new ComponentImpl(); customPluginComponent.setAlias("custom"); customPluginComponent.setType(PLUGIN_COMPONENT_TYPE); customPluginComponent.setReference(reference); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); pluginComponentApplier.apply(workspaceConfig, superPluginComponent, fileContentProvider); pluginComponentApplier.apply(workspaceConfig, customPluginComponent, fileContentProvider); String workspaceTooling = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE); assertTrue(workspaceTooling.matches("(.+/.+/.+),(https: assertTrue(workspaceTooling.contains(superPluginId)); assertTrue(workspaceTooling.contains(reference)); assertEquals(customPluginComponent.getId(), "eclipse/super-plugin/0.0.1"); }
@Test public void shouldProvisionPluginCommandAttributesDuringChePluginComponentApplying() throws Exception { ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId("eclipse/super-plugin/0.0.1"); superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin"); workspaceConfig.getCommands().add(command); pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null); assertEquals( workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-plugin/0.0.1"); }
@Test public void shouldProvisionPluginCommandAttributeWhenIdIsURLToCustomPluginRegistry() throws Exception { ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("super-plugin"); superPluginComponent.setId( "https: superPluginComponent.setType(PLUGIN_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin"); workspaceConfig.getCommands().add(command); pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null); assertEquals( workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-plugin/0.0.1"); }