import java.util.ArrayList;
import java.util.List;
+import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants;
+import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
+import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
+import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
+import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
-import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants;
-import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
-import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
-import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
public class PHPLaunchShortcut implements ILaunchShortcut {
public PHPLaunchShortcut() {
}
- public void launch(ISelection selection, String mode) {
+ public void launch(ISelection selection, String mode) {
if (selection instanceof IStructuredSelection) {
- Object firstSelection = ((IStructuredSelection)selection).getFirstElement();
+ Object firstSelection = ((IStructuredSelection) selection)
+ .getFirstElement();
if (firstSelection instanceof IFile) {
- if (
- ((IFile) firstSelection).getFileExtension().equals("php") ||
- ((IFile) firstSelection).getFileExtension().equals("php3") ||
- ((IFile) firstSelection).getFileExtension().equals("php4")
- ) {
- ILaunchConfiguration config = findLaunchConfiguration((IFile)firstSelection, mode);
+ if (PHPFileUtil.isPHPFile((IFile) firstSelection)) {
+ ILaunchConfiguration config = findLaunchConfiguration(
+ (IFile) firstSelection, mode);
try {
if (config != null)
config.launch(mode, null);
log("The resource selected is not a PHP file.");
}
- public void launch(IEditorPart editor, String mode) {
+ public void launch(IEditorPart editor, String mode) {
IEditorInput input = editor.getEditorInput();
- ISelection selection = new StructuredSelection(input.getAdapter(IFile.class));
+ ISelection selection = new StructuredSelection(input
+ .getAdapter(IFile.class));
launch(selection, mode);
}
- protected ILaunchConfiguration findLaunchConfiguration(IFile phpFile, String mode) {
+ protected ILaunchConfiguration findLaunchConfiguration(IFile phpFile,
+ String mode) {
ILaunchConfigurationType configType = getPHPLaunchConfigType();
List candidateConfigs = null;
try {
- ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType);
+ ILaunchConfiguration[] configs = getLaunchManager()
+ .getLaunchConfigurations(configType);
candidateConfigs = new ArrayList(configs.length);
for (int i = 0; i < configs.length; i++) {
ILaunchConfiguration config = configs[i];
- if (config.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "").equals(phpFile.getFullPath().toString())) {
- candidateConfigs.add(config);
+ if (config.getAttribute(
+ PHPLaunchConfigurationAttribute.FILE_NAME, "").equals(
+ phpFile.getFullPath().toString())) {
+ candidateConfigs.add(config);
}
}
} catch (CoreException e) {
log(e);
}
-
+
switch (candidateConfigs.size()) {
- case 0 :
- return createConfiguration(phpFile);
- case 1 :
- return (ILaunchConfiguration) candidateConfigs.get(0);
- default :
- log(new RuntimeException(PHPDebugUiMessages.getString("LaunchConfigurationShortcut.PHP.multipleConfigurationsError")));
- return null;
+ case 0:
+ return createConfiguration(phpFile);
+ case 1:
+ return (ILaunchConfiguration) candidateConfigs.get(0);
+ default:
+ log(new RuntimeException(
+ PHPDebugUiMessages
+ .getString("LaunchConfigurationShortcut.PHP.multipleConfigurationsError")));
+ return null;
}
}
ILaunchConfiguration config = null;
try {
ILaunchConfigurationType configType = getPHPLaunchConfigType();
- ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(phpFile.getName()));
- wc.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, phpFile.getProject().getName());
- wc.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, phpFile.getProjectRelativePath().toString());
- wc.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
- config = wc.doSave();
+ ILaunchConfigurationWorkingCopy wc = configType.newInstance(null,
+ getLaunchManager()
+ .generateUniqueLaunchConfigurationNameFrom(
+ phpFile.getName()));
+ wc.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,
+ phpFile.getProject().getName());
+ wc.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, phpFile
+ .getProjectRelativePath().toString());
+ wc.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
+ PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
+ config = wc.doSave();
} catch (CoreException ce) {
- log(ce);
+ log(ce);
}
return config;
}
protected ILaunchConfigurationType getPHPLaunchConfigType() {
- return getLaunchManager().getLaunchConfigurationType(PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE);
+ return getLaunchManager().getLaunchConfigurationType(
+ PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE);
}
-
+
protected ILaunchManager getLaunchManager() {
return DebugPlugin.getDefault().getLaunchManager();
}
-
+
protected void log(String message) {
- PHPDebugUiPlugin.getDefault().log(new Status(Status.INFO, PHPDebugUiPlugin.PLUGIN_ID, Status.INFO, message, null));
+ PHPDebugUiPlugin.log(new Status(Status.INFO,
+ PHPDebugUiPlugin.PLUGIN_ID, Status.INFO, message, null));
}
-
+
protected void log(Throwable t) {
- PHPDebugUiPlugin.getDefault().log(t);
+ PHPDebugUiPlugin.log(t);
}
}