use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGenerator method genLinksMapAndUpdateCommands.
/**
* Takes commands from given {@code workspace}. For all commands that have defined previewUrl,
* creates variable name in defined format and final preview url link. It updates the command so
* it's `previewUrl` attribute will contain variable in proper format. Method then returns map of
* all preview url links with these variables as keys:
*
* <pre>
* links:
* "previewURl/run_123": http://your.domain
* command:
* attributes:
* previewUrl: '${previewUrl/run_123}/some/path'
* </pre>
*
* @return map of all <commandPreviewUrlVariable, previewUrlFullLink>
*/
Map<String, String> genLinksMapAndUpdateCommands(WorkspaceImpl workspace, UriBuilder uriBuilder) {
if (workspace == null || workspace.getRuntime() == null || workspace.getRuntime().getCommands() == null || uriBuilder == null) {
return Collections.emptyMap();
}
Map<String, String> links = new HashMap<>();
for (Command command : workspace.getRuntime().getCommands()) {
Map<String, String> commandAttributes = command.getAttributes();
if (command.getPreviewUrl() != null && commandAttributes != null && commandAttributes.containsKey(PREVIEW_URL_ATTRIBUTE)) {
String previewUrlLinkValue = createPreviewUrlLinkValue(uriBuilder, command);
String previewUrlLinkKey = createPreviewUrlLinkKey(command);
links.put(previewUrlLinkKey, previewUrlLinkValue);
commandAttributes.replace(PREVIEW_URL_ATTRIBUTE, formatAttributeValue(previewUrlLinkKey, command.getPreviewUrl().getPath()));
}
}
return links;
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method shouldReturnCommandsAfterRuntimeStart.
@Test
public void shouldReturnCommandsAfterRuntimeStart() throws Exception {
// given
CommandImpl commandToProvision = new CommandImpl("provisioned-command", "build", "env");
doAnswer((Answer<Void>) invocationOnMock -> {
k8sEnv.getCommands().add(commandToProvision);
return null;
}).when(internalEnvironmentProvisioner).provision(any(), any());
internalRuntime.start(emptyMap());
// when
List<? extends Command> commands = internalRuntime.getCommands();
// then
assertEquals(commands.size(), 2);
Optional<? extends Command> envCommandOpt = commands.stream().filter(c -> "envCommand".equals(c.getName())).findAny();
assertTrue(envCommandOpt.isPresent());
Command envCommand = envCommandOpt.get();
assertEquals(envCommand.getCommandLine(), envCommand.getCommandLine());
assertEquals(envCommand.getType(), envCommand.getType());
Optional<? extends Command> provisionedCommandOpt = commands.stream().filter(c -> "provisioned-command".equals(c.getName())).findAny();
assertTrue(provisionedCommandOpt.isPresent());
Command provisionedCommand = provisionedCommandOpt.get();
assertEquals(provisionedCommand.getCommandLine(), provisionedCommand.getCommandLine());
assertEquals(provisionedCommand.getType(), provisionedCommand.getType());
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class CommandConverterTest method shouldAcceptActionWithCommand.
@Test
public void shouldAcceptActionWithCommand() throws Exception {
// given
CommandImpl devfileCommand = new CommandImpl();
devfileCommand.setName("build");
ActionImpl action = new ActionImpl();
action.setType("exec");
action.setCommand("blah");
devfileCommand.getActions().add(action);
// when
Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
// then
assertEquals(command.getCommandLine(), "blah");
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class CommandConverterTest method shouldAcceptActionWithReferenceContent.
@Test
public void shouldAcceptActionWithReferenceContent() throws Exception {
// given
CommandImpl devfileCommand = new CommandImpl();
devfileCommand.setName("build");
ActionImpl action = new ActionImpl();
action.setType("exec");
action.setReference("blah");
action.setReferenceContent("content");
devfileCommand.getActions().add(action);
// when
Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
// then
assertNull(command.getCommandLine());
assertEquals("blah", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_ATTRIBUTE));
assertEquals("content", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_CONTENT_ATTRIBUTE));
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
the class PreviewUrlLinksVariableGenerator method genLinksMapAndUpdateCommands.
/**
* Takes commands from given {@code workspace}. For all commands that have defined previewUrl,
* creates variable name in defined format and final preview url link. It updates the command so
* it's `previewUrl` attribute will contain variable in proper format. Method then returns map of
* all preview url links with these variables as keys:
*
* <pre>
* links:
* "previewURl/run_123": http://your.domain
* command:
* attributes:
* previewUrl: '${previewUrl/run_123}/some/path'
* </pre>
*
* @return map of all <commandPreviewUrlVariable, previewUrlFullLink>
*/
Map<String, String> genLinksMapAndUpdateCommands(WorkspaceImpl workspace, UriBuilder uriBuilder) {
if (workspace == null || workspace.getRuntime() == null || workspace.getRuntime().getCommands() == null || uriBuilder == null) {
return Collections.emptyMap();
}
Map<String, String> links = new HashMap<>();
for (Command command : workspace.getRuntime().getCommands()) {
Map<String, String> commandAttributes = command.getAttributes();
if (command.getPreviewUrl() != null && commandAttributes != null && commandAttributes.containsKey(PREVIEW_URL_ATTRIBUTE)) {
String previewUrlLinkValue = createPreviewUrlLinkValue(uriBuilder, command);
String previewUrlLinkKey = createPreviewUrlLinkKey(command);
links.put(previewUrlLinkKey, previewUrlLinkValue);
commandAttributes.replace(PREVIEW_URL_ATTRIBUTE, formatAttributeValue(previewUrlLinkKey, command.getPreviewUrl().getPath()));
}
}
return links;
}
Aggregations