Search in sources :

Example 1 with WorkspaceExportException

use of org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException in project che-server by eclipse-che.

the class CommandConverter method toDevfileCommand.

/**
 * Converts the specified workspace command to devfile command.
 *
 * @param command source workspace command
 * @return created devfile command based on the specified workspace command
 * @throws WorkspaceExportException if workspace command does not has specified component name
 *     attribute where it should be run
 */
public CommandImpl toDevfileCommand(org.eclipse.che.api.workspace.server.model.impl.CommandImpl command) throws WorkspaceExportException {
    String componentName = command.getAttributes().remove(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE);
    if (componentName == null) {
        throw new WorkspaceExportException(format("Command `%s` has no specified component where it should be run", command.getName()));
    }
    CommandImpl devCommand = new CommandImpl();
    devCommand.setName(command.getName());
    ActionImpl action = new ActionImpl();
    action.setCommand(command.getCommandLine());
    action.setType(command.getType());
    action.setWorkdir(command.getAttributes().remove(WORKING_DIRECTORY_ATTRIBUTE));
    action.setComponent(componentName);
    action.setType(Constants.EXEC_ACTION_TYPE);
    devCommand.getActions().add(action);
    devCommand.setAttributes(command.getAttributes());
    return devCommand;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) WorkspaceExportException(org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException)

Example 2 with WorkspaceExportException

use of org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException in project devspaces-images by redhat-developer.

the class CommandConverter method toDevfileCommand.

/**
 * Converts the specified workspace command to devfile command.
 *
 * @param command source workspace command
 * @return created devfile command based on the specified workspace command
 * @throws WorkspaceExportException if workspace command does not has specified component name
 *     attribute where it should be run
 */
public CommandImpl toDevfileCommand(org.eclipse.che.api.workspace.server.model.impl.CommandImpl command) throws WorkspaceExportException {
    String componentName = command.getAttributes().remove(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE);
    if (componentName == null) {
        throw new WorkspaceExportException(format("Command `%s` has no specified component where it should be run", command.getName()));
    }
    CommandImpl devCommand = new CommandImpl();
    devCommand.setName(command.getName());
    ActionImpl action = new ActionImpl();
    action.setCommand(command.getCommandLine());
    action.setType(command.getType());
    action.setWorkdir(command.getAttributes().remove(WORKING_DIRECTORY_ATTRIBUTE));
    action.setComponent(componentName);
    action.setType(Constants.EXEC_ACTION_TYPE);
    devCommand.getActions().add(action);
    devCommand.setAttributes(command.getAttributes());
    return devCommand;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) WorkspaceExportException(org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException)

Aggregations

WorkspaceExportException (org.eclipse.che.api.workspace.server.devfile.exception.WorkspaceExportException)2 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)2 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl)2