From 758d0f2943094a1c5c4c149ede57cbeef99f174c Mon Sep 17 00:00:00 2001 From: Darin Swanson Date: Thu, 5 Dec 2002 04:10:38 +0000 Subject: Bug 26455 - -find option not yet implemented --- .../AntLaunchConfigurationMessages.properties | 2 +- .../launchConfigurations/AntLaunchShortcut.java | 72 +++++++++++++++------- org.eclipse.ui.externaltools/plugin.properties | 4 +- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchConfigurationMessages.properties b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchConfigurationMessages.properties index a61bcefaf..5eadca7ce 100644 --- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchConfigurationMessages.properties +++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchConfigurationMessages.properties @@ -12,7 +12,7 @@ AntLaunchDelegate.Launching_{0}_1=Launching {0} AntLaunchDelegate.Running_{0}_2=Running {0} -AntLaunchShortcut.Unable_to_determine_which_Ant_file_to_run._1=Unable to determine which Ant file to run. +AntLaunchShortcut.Unable_to_determine_which_Ant_file_to_run._1=Unable to find an Ant file to run. AntLaunchShortcut.An_exception_occurred_while_creating_a_default_Ant_launch_configuration_for_{0}_2=An exception occurred while creating a default Ant launch configuration for {0} AntLaunchShortcut.An_exception_occurred_while_retrieving_Ant_launch_configurations._3=An exception occurred while retrieving Ant launch configurations. AntLaunchShortcut.Ant_Configuration_Selection_4=Ant Configuration Selection diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchShortcut.java b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchShortcut.java index d09a1b01e..3a0677f5f 100644 --- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchShortcut.java +++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/launchConfigurations/AntLaunchShortcut.java @@ -13,8 +13,11 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -63,10 +66,12 @@ public class AntLaunchShortcut implements ILaunchShortcut { if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection)selection; Object object = structuredSelection.getFirstElement(); - if (object instanceof IFile) { - IFile file = (IFile)object; - launch(file, mode); - return; + if (object instanceof IAdaptable) { + IResource resource = (IResource)((IAdaptable)object).getAdapter(IResource.class); + if (resource != null) { + launch(resource, mode); + return; + } } } antFileNotFound(); @@ -85,13 +90,16 @@ public class AntLaunchShortcut implements ILaunchShortcut { * @param file * @param mode */ - protected void launch(IFile file, String mode) { - if ("xml".equalsIgnoreCase(file.getFileExtension())) { //$NON-NLS-1$ + protected void launch(IResource resource, String mode) { + ILaunchConfiguration configuration= null; + if (!("xml".equalsIgnoreCase(resource.getFileExtension()))) { //$NON-NLS-1$ + resource= findBuildFile(resource); + } + if (resource != null) { if (verifyMode(mode)) { - ILaunchConfiguration configuration= null; - List configurations = findExistingLaunchConfigurations(file); + List configurations = findExistingLaunchConfigurations((IFile)resource); if (configurations.isEmpty()) { - configuration = createDefaultLaunchConfiguration(file); + configuration = createDefaultLaunchConfiguration((IFile)resource); } else { if (configurations.size() == 1) { configuration= (ILaunchConfiguration)configurations.get(0); @@ -102,22 +110,44 @@ public class AntLaunchShortcut implements ILaunchShortcut { return; } } - - } - if (configuration != null) { - if (fShowDialog) { - DebugUITools.openLaunchConfigurationDialogOnGroup(ExternalToolsPlugin.getActiveWorkbenchWindow().getShell(), new StructuredSelection(configuration), IExternalToolConstants.ID_EXTERNAL_TOOLS_LAUNCH_GROUP); - - } else { - DebugUITools.launch(configuration, mode); - } - return; } } } + + if (configuration != null) { + if (fShowDialog) { + DebugUITools.openLaunchConfigurationDialogOnGroup(ExternalToolsPlugin.getActiveWorkbenchWindow().getShell(), new StructuredSelection(configuration), IExternalToolConstants.ID_EXTERNAL_TOOLS_LAUNCH_GROUP); + + } else { + DebugUITools.launch(configuration, mode); + } + return; + } antFileNotFound(); - + } + + /** + * Walks the file hierarchy looking for a build file. + * Returns the first build file found that matches the + * search criteria. + */ + private IFile findBuildFile(IResource parent) { + if (parent.getType() == IFile.FILE) { + parent= parent.getParent(); + } + if (parent == null) { + return null; + } + IResource file= ((IContainer)parent).findMember("build.xml"); + while (file == null || file.getType() != IFile.FILE) { + parent = parent.getParent(); + if (parent == null) { + return null; + } + file= ((IContainer)parent).findMember("build.xml"); + } + return (IFile)file; } /** @@ -255,7 +285,7 @@ public class AntLaunchShortcut implements ILaunchShortcut { } else { status = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, throwable); } - ErrorDialog.openError(ExternalToolsPlugin.getActiveWorkbenchWindow().getShell(), AntLaunchConfigurationMessages.getString("AntLaunchShortcut.Error_7"), message, status); //$NON-NLS-1$ + ErrorDialog.openError(ExternalToolsPlugin.getActiveWorkbenchWindow().getShell(), AntLaunchConfigurationMessages.getString("AntLaunchShortcut.Error_7"), "Build Failed", status); //$NON-NLS-1$ } /** diff --git a/org.eclipse.ui.externaltools/plugin.properties b/org.eclipse.ui.externaltools/plugin.properties index 1ad508ed5..365d7aae0 100644 --- a/org.eclipse.ui.externaltools/plugin.properties +++ b/org.eclipse.ui.externaltools/plugin.properties @@ -11,14 +11,14 @@ Plugin.name = External Tools Plugin.providerName = Eclipse.org -AntLaunchShortcut.label = Ant Script +AntLaunchShortcut.label = &Ant Build ExtPoint.configurationDuplicationMaps = Launch Configuration Duplication Maps ExtPoint.toolTypes = External Tool Types ExtPoint.argumentVariables = Argument Variables ExtPoint.directoryVariables = Directory Variables ExtPoint.fileVariables = File Variables ExtPoint.refreshVariables = Refresh Scope Variables -ExternalToolsLaunchGroup.label = External Tools +ExternalToolsLaunchGroup.label = &External Tools ToolType.programName = Program ToolType.programDescription = An external tool that runs an application, a batch file, etc. ToolType.antBuildName = Ant Build -- cgit v1.2.3