EditorComponentToWorkspaceApplier implements ComponentToWorkspaceApplier { @Override public void apply( WorkspaceConfigImpl workspaceConfig, ComponentImpl editorComponent, FileContentProvider contentProvider) throws DevfileException { checkArgument(workspaceConfig != null, "Workspace config must not be null"); checkArgument(editorComponent != null, "Component must not be null"); checkArgument( EDITOR_COMPONENT_TYPE.equals(editorComponent.getType()), format("Plugin must have `%s` type", EDITOR_COMPONENT_TYPE)); final String editorComponentAlias = editorComponent.getAlias(); final String editorId = editorComponent.getId(); final String registryUrl = editorComponent.getRegistryUrl(); final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(editorComponent, contentProvider); if (!isNullOrEmpty(fqn.getReference())) { workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, fqn.getReference()); } else { workspaceConfig .getAttributes() .put( WORKSPACE_TOOLING_EDITOR_ATTRIBUTE, componentFQNParser.getCompositeId(registryUrl, editorId)); } workspaceConfig .getCommands() .stream() .filter( c -> editorComponentAlias != null && editorComponentAlias.equals( c.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE))) .forEach(c -> c.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId())); editorComponent.setId(fqn.getId()); } @Inject  EditorComponentToWorkspaceApplier(ComponentFQNParser componentFQNParser); @Override void apply(
      WorkspaceConfigImpl workspaceConfig,
      ComponentImpl editorComponent,
      FileContentProvider contentProvider);  }
@Test public void shouldProvisionWorkspaceEditorAttributeDuringCheEditorComponentApplying() throws Exception { String editorId = "eclipse/super-editor/0.0.1"; WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); ComponentImpl editorComponent = new ComponentImpl(); editorComponent.setType(EDITOR_COMPONENT_TYPE); editorComponent.setAlias("editor"); editorComponent.setId(editorId); editorComponent.setMemoryLimit("12345M"); editorComponentApplier.apply(workspaceConfig, editorComponent, null); assertEquals(workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE), editorId); }
@Test public void shouldProvisionWorkspaceEditorAttributeWithCustomRegistryDuringCheEditorComponentApplying() throws Exception { String editorId = "eclipse/super-editor/0.0.1"; String registryUrl = "https: WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); ComponentImpl editorComponent = new ComponentImpl(); editorComponent.setType(EDITOR_COMPONENT_TYPE); editorComponent.setAlias("editor1"); editorComponent.setId(editorId); editorComponent.setRegistryUrl(registryUrl); editorComponent.setMemoryLimit("12345M"); editorComponentApplier.apply(workspaceConfig, editorComponent, null); assertEquals( workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE), registryUrl + "#" + editorId); }
@Test public void shouldProvisionWorkspaceEditorAttributeWithReferenceDuringCheEditorComponentApplying() throws Exception { String reference = "https: String meta = "apiVersion: v2\n" + "publisher: eclipse\n" + "name: super-editor\n" + "version: 0.0.1\n" + "type: Che Editor"; WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); ComponentImpl editorComponent = new ComponentImpl(); editorComponent.setType(EDITOR_COMPONENT_TYPE); editorComponent.setAlias("editor1"); editorComponent.setReference(reference); editorComponent.setMemoryLimit("12345M"); when(fileContentProvider.fetchContent(anyString())).thenReturn(meta); editorComponentApplier.apply(workspaceConfig, editorComponent, fileContentProvider); assertEquals( workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_EDITOR_ATTRIBUTE), reference); assertEquals(editorComponent.getId(), "eclipse/super-editor/0.0.1"); }
@Test public void shouldProvisionPluginCommandAttributesDuringCheEditorComponentApplying() throws Exception { ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("editor"); superPluginComponent.setId("eclipse/super-editor/0.0.1"); superPluginComponent.setType(EDITOR_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "editor"); workspaceConfig.getCommands().add(command); editorComponentApplier.apply(workspaceConfig, superPluginComponent, null); assertEquals( workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-editor/0.0.1"); }
@Test public void shouldProvisionPluginCommandAttributeWhenIdIsURLToCustomPluginRegistry() throws Exception { ComponentImpl superPluginComponent = new ComponentImpl(); superPluginComponent.setAlias("editor"); superPluginComponent.setId("https: superPluginComponent.setType(EDITOR_COMPONENT_TYPE); WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl(); CommandImpl command = new CommandImpl(); command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "editor"); workspaceConfig.getCommands().add(command); editorComponentApplier.apply(workspaceConfig, superPluginComponent, null); assertEquals( workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-editor/0.0.1"); }