/******************************************************************************* * Copyright (c) 2016 QNX Software Systems and others. * 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 *******************************************************************************/ package org.eclipse.cdt.debug.internal.core.launch; import java.io.IOException; import java.nio.file.Paths; import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate; import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.core.target.launch.ITargetedLaunch; public class CoreBuildLocalRunLaunchDelegate extends CoreBuildLaunchConfigDelegate { @Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { IProject project = getProject(configuration); ILaunchTarget target = ((ITargetedLaunch) launch).getLaunchTarget(); ICBuildConfiguration buildConfig = getBuildConfiguration(project, mode, target, monitor); IBinary exeFile = getBinary(buildConfig); try { ProcessBuilder builder = new ProcessBuilder(Paths.get(exeFile.getLocationURI()).toString()); buildConfig.setBuildEnvironment(builder.environment()); Process process = builder.start(); DebugPlugin.newProcess(launch, process, exeFile.getPath().lastSegment()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, InternalDebugCoreMessages.CoreBuildLocalRunLaunchDelegate_ErrorLaunching, e)); } } }