package tool.launching;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
import tool.ToolPlugin;
import tool.builder.ToolBuilder;
import tool.repository.FScript;
import tool.repository.ToolRepositoryException;
/**
* delegate to run a Plan/Project in the tool repository
* @author Peter
*
*/
public class LocalLaunchConfigurationDelegate implements ILaunchConfigurationDelegate{
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launce,
IProgressMonitor monitor) throws CoreException {
if (mode.equalsIgnoreCase("debug")){
System.out.println("cannot launch in debug: " + configuration.getName());
return;
}
// get a connection to fscript
IProject project = getProject(configuration);
FScript repos = ToolBuilder.getRepository(project);
String planName = configuration.getAttribute(IToolLaunchConstants.PLAN_NAME, "");
try {
repos.runPlan(planName);
} catch (ToolRepositoryException e) {
ToolPlugin.showError("Error running plan: " + planName, e);
}
}
private static IProject getProject(ILaunchConfiguration configuration) throws CoreException {
String projectName = getProjectName(configuration);
if (projectName != null && projectName.trim().length() != 0)
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
return null;
}
private static String getProjectName(ILaunchConfiguration configuration) throws CoreException {
return configuration.getAttribute(IToolLaunchConstants.PROJECT_NAME, (String) null);
}
}