Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d837cabffe1ca1d0acf633505e132f4d16ce37a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2017 Dennis Wagelaar.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Dennis Wagelaar - initial API and implementation
 *******************************************************************************/
package org.eclipse.m2m.atl.emftvm.launcher.compat;

import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.m2m.atl.common.ATLLaunchConstants;
import org.eclipse.m2m.atl.emftvm.launcher.debug.NetworkDebugger;
import org.eclipse.m2m.atl.emftvm.util.VMException;

/**
 * The EMFTVM UI extension of the {@link EMFTVMLauncher}, which supports debug.
 * 
 * @author <a href="mailto:dwagelaar@gmail.com">Dennis Wagelaar</a>
 */
public class EMFTVMUILauncher extends EMFTVMLauncher {

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.m2m.atl.emftvm.launcher.compat.EMFTVMLauncher#launch(java.lang.String,
	 *      org.eclipse.core.runtime.IProgressMonitor, java.util.Map,
	 *      java.lang.Object[])
	 */
	@Override
	public Object launch(final String mode, final IProgressMonitor monitor, final Map<String, Object> options,
			final Object... modules) {
		try {
			if (mode.equals(ILaunchManager.DEBUG_MODE)) {
				final ILaunch launch = (ILaunch) options.get("launch");
				return internalLaunch(new NetworkDebugger(launch, getPort(launch), true), monitor, options, modules); // $NON-NLS-1$
			} else {
				return internalLaunch(null, monitor, options, modules);
			}
		} catch (CoreException e) {
			throw new VMException(null, e.getLocalizedMessage(), e);
		}
	}

	private int getPort(ILaunch launch) throws CoreException {
		String portOption = ""; //$NON-NLS-1$
		if (launch != null) {
			portOption = launch.getLaunchConfiguration().getAttribute(ATLLaunchConstants.PORT,
					Integer.valueOf(ATLLaunchConstants.DEFAULT_PORT).toString());
		}
		if (portOption.equals("")) { //$NON-NLS-1$
			portOption = Integer.valueOf(ATLLaunchConstants.DEFAULT_PORT).toString();
		}
		return new Integer(portOption).intValue();
	}

	/**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.m2m.atl.core.launch.ILauncher#getModes()
	 */
	@Override
	public String[] getModes() {
		return new String[] { RUN_MODE, DEBUG_MODE };
	}

}

Back to the top