| /*=============================================================================# |
| # Copyright (c) 2015, 2019 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.redocs.r.ui.processing; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.debug.core.ILaunchConfiguration; |
| import org.eclipse.debug.ui.IDebugUIConstants; |
| import org.eclipse.osgi.util.NLS; |
| |
| import org.eclipse.statet.ecommons.debug.core.util.OverlayLaunchConfiguration; |
| import org.eclipse.statet.ecommons.variables.core.VariableText2; |
| import org.eclipse.statet.ecommons.variables.core.VariableUtils; |
| |
| import org.eclipse.statet.docmlet.base.ui.DocmlBaseUI; |
| import org.eclipse.statet.docmlet.base.ui.processing.DocProcessingConfig; |
| import org.eclipse.statet.docmlet.base.ui.processing.operations.AbstractLaunchConfigOperation; |
| import org.eclipse.statet.docmlet.base.ui.processing.operations.RunExternalProgramOperation.ExternalProgramLaunchConfig; |
| import org.eclipse.statet.internal.redocs.r.Messages; |
| import org.eclipse.statet.r.cmd.ui.launching.RCmdLaunching; |
| |
| |
| public class RunRCmdToolOperation extends AbstractLaunchConfigOperation { |
| |
| |
| public static final String ID= "org.eclipse.statet.redocs.docProcessing.RunRCmdToolOperation"; //$NON-NLS-1$ |
| |
| public static final String LAUNCH_CONFIG_NAME_ATTR_NAME= ID + '/' + LAUNCH_CONFIG_NAME_ATTR_KEY; |
| |
| |
| public RunRCmdToolOperation() { |
| super(RCmdLaunching.R_CMD_CONFIGURATION_TYPE_ID); |
| } |
| |
| |
| @Override |
| public String getId() { |
| return ID; |
| } |
| |
| @Override |
| public String getLabel() { |
| return Messages.ProcessingOperation_RunRCmdTool_label; |
| } |
| |
| |
| @Override |
| protected ILaunchConfiguration preprocessConfig(final ILaunchConfiguration config) throws CoreException { |
| final Map<String, Object> additionalAttributes= new HashMap<>(); |
| final VariableText2 variableResolver= createVariableResolver(); |
| |
| additionalAttributes.put(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false); |
| |
| try { |
| String value= config.getAttribute(RCmdLaunching.WORKING_DIRECTORY_ATTR_NAME, ""); //$NON-NLS-1$ |
| if (value.isEmpty()) { |
| value= VariableUtils.getValue(getStepConfig().getToolConfig().getVariables() |
| .get(DocProcessingConfig.WD_LOC_VAR_NAME) ); |
| additionalAttributes.put(ExternalProgramLaunchConfig.WORKING_DIRECTORY_ATTR_NAME, value); |
| } |
| else { |
| value= variableResolver.performStringSubstitution(value, null); |
| additionalAttributes.put(ExternalProgramLaunchConfig.ARGUMENTS_ATTR_NAME, value); |
| } |
| } |
| catch (final CoreException e) { |
| throw new CoreException(new Status(IStatus.ERROR, DocmlBaseUI.BUNDLE_ID, |
| NLS.bind(Messages.ProcessingOperation_RunRCmdTool_Wd_error_SpecInvalid_message, |
| e.getMessage() ))); |
| } |
| |
| try { |
| String value= config.getAttribute(RCmdLaunching.R_CMD_RESOURCE_ATTR_NAME, ""); //$NON-NLS-1$ |
| if (!value.isEmpty()) { |
| value= variableResolver.performStringSubstitution(value, null); |
| additionalAttributes.put(ExternalProgramLaunchConfig.ARGUMENTS_ATTR_NAME, value); |
| } |
| } |
| catch (final CoreException e) { |
| throw new CoreException(new Status(IStatus.ERROR, DocmlBaseUI.BUNDLE_ID, |
| NLS.bind(Messages.ProcessingOperation_RunRCmdTool_RCmdResource_error_SpecInvalid_message, |
| e.getMessage() ))); |
| } |
| |
| try { |
| String value= config.getAttribute(RCmdLaunching.R_CMD_OPTIONS_ATTR_NAME, ""); //$NON-NLS-1$ |
| if (!value.isEmpty()) { |
| value= variableResolver.performStringSubstitution(value, null); |
| additionalAttributes.put(ExternalProgramLaunchConfig.ARGUMENTS_ATTR_NAME, value); |
| } |
| } |
| catch (final CoreException e) { |
| throw new CoreException(new Status(IStatus.ERROR, DocmlBaseUI.BUNDLE_ID, |
| NLS.bind(Messages.ProcessingOperation_RunRCmdTool_RCmdOptions_error_SpecInvalid_message, |
| e.getMessage() ))); |
| } |
| |
| return new OverlayLaunchConfiguration(config, additionalAttributes); |
| } |
| |
| } |