diff options
author | Jared Burns | 2002-09-25 14:06:32 +0000 |
---|---|---|
committer | Jared Burns | 2002-09-25 14:06:32 +0000 |
commit | 49878c4663a509f24deddac7432e4c2a2cfb78e3 (patch) | |
tree | d200395f669c089677afa7358b047f06273f576b | |
parent | 4d0d5305ec3fedcb3da06b1d5f9a375325e0330d (diff) | |
download | eclipse.platform.debug-49878c4663a509f24deddac7432e4c2a2cfb78e3.tar.gz eclipse.platform.debug-49878c4663a509f24deddac7432e4c2a2cfb78e3.tar.xz eclipse.platform.debug-49878c4663a509f24deddac7432e4c2a2cfb78e3.zip |
Improved "Run Ant..." action (almost works)
5 files changed, 171 insertions, 68 deletions
diff --git a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/dialog/AntExternalToolNewWizard.java b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/dialog/AntExternalToolNewWizard.java index 2760efbe1..0a58ace07 100644 --- a/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/dialog/AntExternalToolNewWizard.java +++ b/org.eclipse.ui.externaltools/Ant Tools Support/org/eclipse/ui/externaltools/internal/ant/dialog/AntExternalToolNewWizard.java @@ -9,7 +9,11 @@ http://www.eclipse.org/legal/cpl-v10.html Contributors: **********************************************************************/ +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.externaltools.dialog.ExternalToolGroupWizardPage; import org.eclipse.ui.externaltools.dialog.ExternalToolNewWizard; import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; @@ -23,6 +27,7 @@ import org.eclipse.ui.externaltools.model.IExternalToolConstants; */ public class AntExternalToolNewWizard extends ExternalToolNewWizard { private AntTargetsGroup antTargetsGroup; + private IFile xmlFile; /** * Creates the wizard for a new external tool @@ -30,6 +35,11 @@ public class AntExternalToolNewWizard extends ExternalToolNewWizard { public AntExternalToolNewWizard() { super(IExternalToolConstants.TOOL_TYPE_ANT_BUILD); } + + public AntExternalToolNewWizard(IFile file) { + super(IExternalToolConstants.TOOL_TYPE_ANT_BUILD); + xmlFile= validateXMLFile(file); + } /* (non-Javadoc) * Method declared on IWizard. @@ -42,6 +52,17 @@ public class AntExternalToolNewWizard extends ExternalToolNewWizard { optionGroup.setPromptForArgumentLabel(ToolMessages.getString("AntExternalToolNewWizard.promptForArgumentLabel")); //$NON-NLS-1$ } + + /** + * Returns whether the given resource is an XML file + * based on the resource's file extension + *
* @param resource the resource to examine
* @return whether the given resource is an XML file
*/ + private IFile validateXMLFile(IFile file) { + if ("xml".equals(file.getFileExtension().toLowerCase())) { + return file; + } + return null; + } /* (non-Javadoc) * Method declared on ExternalToolNewWizard. @@ -85,4 +106,21 @@ public class AntExternalToolNewWizard extends ExternalToolNewWizard { return; antTargetsGroup = new AntTargetsGroup(); } + public IWizardPage getStartingPage() { + return super.getStartingPage(); + } + + public void createPageControls(Composite pageContainer) { + String fileLocation= null; + if (xmlFile != null) { + fileLocation= xmlFile.getLocation().toFile().getAbsolutePath(); + mainGroup.setInitialName("Temp garbage"); + mainGroup.setInitialLocation(fileLocation); + } + super.createPageControls(pageContainer); + if (fileLocation != null) { + antTargetsGroup.setFileLocation(fileLocation); + } + } + } diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IHelpContextIds.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IHelpContextIds.java index a10717274..a8bd119e3 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IHelpContextIds.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/model/IHelpContextIds.java @@ -47,10 +47,12 @@ public interface IHelpContextIds { public static final String EXTERNAL_TOOLS_VIEW = PREFIX + "external_tools_view_context"; //$NON-NLS-1$ // Wizards + public static final String ANT_LAUNCH_WIZARD = PREFIX + "ant_launch_wizard_context"; //$NON-NLS-1$ // Wizard Pages public static final String TOOL_MAIN_WIZARD_PAGE = PREFIX + "tool_main_wizard_page_context"; //$NON-NLS-1$ public static final String TOOL_OPTION_WIZARD_PAGE = PREFIX + "tool_option_wizard_page_context"; //$NON-NLS-1$ public static final String TOOL_REFRESH_WIZARD_PAGE = PREFIX + "tool_refresh_wizard_page_context"; //$NON-NLS-1$ public static final String ANT_TARGETS_WIZARD_PAGE = PREFIX + "ant_targets_wizard_page_context"; //$NON-NLS-1$ + public static final String ANT_LAUNCH_WIZARD_PAGE = PREFIX + "ant_launch_wizard_page_context"; //$NON-NLS-1$ } diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntAction.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntAction.java index 8f6bc80b8..00ec33878 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntAction.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntAction.java @@ -9,16 +9,27 @@ http://www.eclipse.org/legal/cpl-v05.html Contributors: **********************************************************************/ +import org.eclipse.ant.core.TargetInfo; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.MultiStatus; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.externaltools.internal.ant.model.*; -import org.eclipse.ui.externaltools.internal.model.*; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.NewWizardAction; +import org.eclipse.ui.externaltools.internal.ant.dialog.AntExternalToolNewWizard; +import org.eclipse.ui.externaltools.internal.ant.model.AntUtil; +import org.eclipse.ui.externaltools.internal.model.DefaultRunnerContext; +import org.eclipse.ui.externaltools.internal.model.IHelpContextIds; +import org.eclipse.ui.externaltools.internal.model.ToolMessages; +import org.eclipse.ui.externaltools.model.ExternalTool; +import org.eclipse.ui.externaltools.model.ExternalToolStorage; +import org.eclipse.ui.externaltools.model.IExternalToolConstants; +import org.eclipse.ui.externaltools.model.IStorageListener; import org.eclipse.ui.help.WorkbenchHelp; /** @@ -47,34 +58,60 @@ public class AntAction extends Action { * Method declared on IAction. */ public void run() { - if (file == null) - return; - - AntTargetList targetList = null; - try { - targetList = AntUtil.getTargetList(file.getLocation()); - } catch (CoreException e) { - ErrorDialog.openError( - window.getShell(), - ToolMessages.getString("AntAction.runErrorTitle"), //$NON-NLS-1$ - ToolMessages.format("AntAction.errorReadAntFile", new Object[] {file.getFullPath().toString()}), //$NON-NLS-1$; - e.getStatus()); + if (file == null) { return; } - if (targetList == null) { - MessageDialog.openError( - window.getShell(), - ToolMessages.getString("AntAction.runErrorTitle"), //$NON-NLS-1$; - ToolMessages.format("AntAction.noAntTargets", new Object[] {file.getFullPath().toString()})); //$NON-NLS-1$; - return; - } + new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new AntExternalToolNewWizard(file)).open(); + ExternalToolStorage.addStorageListener(new IStorageListener() { + public void toolDeleted(ExternalTool tool) { + } - AntLaunchWizard wizard = new AntLaunchWizard(targetList, file, window); - wizard.setNeedsProgressMonitor(true); - WizardDialog dialog = new WizardDialog(window.getShell(), wizard); - dialog.create(); - WorkbenchHelp.setHelp(dialog.getShell(), IHelpContextIds.ANT_LAUNCH_WIZARD); - dialog.open(); + public void toolCreated(ExternalTool tool) { + if (tool.getLocation().equals(file.getLocation().toString())) { + MultiStatus status = new MultiStatus(IExternalToolConstants.PLUGIN_ID, 0, "", null); + new DefaultRunnerContext(tool, file).run(null, status); + Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + if (!status.isOK()) { + MessageDialog.openError(shell, "Ant Error", "An exception occurred while running ant"); + } + ExternalToolStorage.deleteTool(tool, shell); + } + ExternalToolStorage.removeStorageListener(this); + } + + public void toolModified(ExternalTool tool) { + } + + public void toolsRefreshed() { + } + }); + +// TargetInfo[] targetList = null; +// try { +// targetList = AntUtil.getTargets(file.getFullPath().makeAbsolute().toString()); // getTargetList(file.getLocation()); +// } catch (CoreException e) { +// ErrorDialog.openError( +// window.getShell(), +// ToolMessages.getString("AntAction.runErrorTitle"), //$NON-NLS-1$ +// ToolMessages.format("AntAction.errorReadAntFile", new Object[] {file.getFullPath().toString()}), //$NON-NLS-1$; +// e.getStatus()); +// return; +// } +// +// if (targetList == null) { +// MessageDialog.openError( +// window.getShell(), +// ToolMessages.getString("AntAction.runErrorTitle"), //$NON-NLS-1$; +// ToolMessages.format("AntAction.noAntTargets", new Object[] {file.getFullPath().toString()})); //$NON-NLS-1$; +// return; +// } +// +// AntLaunchWizard wizard = new AntLaunchWizard(targetList, file, window); +// wizard.setNeedsProgressMonitor(true); +// WizardDialog dialog = new WizardDialog(window.getShell(), wizard); +// dialog.create(); +// WorkbenchHelp.setHelp(dialog.getShell(), IHelpContextIds.ANT_LAUNCH_WIZARD); +// dialog.open(); } }
\ No newline at end of file diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizard.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizard.java index 33169f7da..466fa15dc 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizard.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizard.java @@ -12,12 +12,15 @@ Contributors: import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import org.eclipse.ant.core.TargetInfo; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.externaltools.internal.ant.model.AntUtil; import org.eclipse.ui.externaltools.internal.model.*; import org.eclipse.ui.externaltools.model.*; @@ -37,7 +40,7 @@ public class AntLaunchWizard extends Wizard { /** * The Ant project described in the xml file. */ - private AntTargetList targetList = null; + private TargetInfo[] targetList = null; /** * The external tool representing the Ant file @@ -67,18 +70,21 @@ public class AntLaunchWizard extends Wizard { * @param antProject * @param antFile */ - public AntLaunchWizard(AntTargetList targetList, IFile antFile, IWorkbenchWindow window) { + public AntLaunchWizard(TargetInfo[] targetList, IFile antFile, IWorkbenchWindow window) { super(); this.targetList = targetList; this.antFile = antFile; this.window = window; String antPath = antFile.getFullPath().toString(); - this.antTool = ExternalToolsPlugin.getDefault().getRegistry().getExternalTool(antPath); + this.antTool = ExternalToolsPlugin.getDefault().getToolRegistry(getShell()).getToolNamed(antPath); if (this.antTool == null) { - this.antTool = new ExternalTool(); - this.antTool.setName(antPath); - this.antTool.setType(ExternalTool.TOOL_TYPE_ANT); - this.antTool.setLocation(ToolUtil.buildVariableTag(ExternalTool.VAR_WORKSPACE_LOC, antPath)); + try { + this.antTool = new ExternalTool(IExternalToolConstants.TOOL_TYPE_ANT_BUILD, antPath); + } catch (CoreException exception) { + MessageDialog.openError(getShell(), "Ant Error", "An exception occurred launching ant file"); + return; + } + this.antTool.setLocation(ToolUtil.buildVariableTag(IExternalToolConstants.VAR_WORKSPACE_LOC, antPath)); this.isNewTool = true; } setWindowTitle(ToolMessages.getString("AntLaunchWizard.shellTitle")); //$NON-NLS-1$; @@ -93,11 +99,11 @@ public class AntLaunchWizard extends Wizard { String args = antTool.getArguments(); StringBuffer buf = new StringBuffer(); - String[] targets = ToolUtil.extractVariableArguments(args, ExternalTool.VAR_ANT_TARGET, buf); + String[] targets = AntUtil.parseRunTargets(antTool.getExtraAttribute(AntUtil.RUN_TARGETS_ATTRIBUTE)); page1.setInitialTargets(targets); page1.setInitialArguments(buf.toString()); - page1.setInitialDisplayLog(antTool.getShowLog()); + page1.setInitialDisplayLog(antTool.getShowConsole()); } /* (non-Javadoc) @@ -105,16 +111,20 @@ public class AntLaunchWizard extends Wizard { */ public boolean performFinish() { updateTool(); - ToolUtil.saveDirtyEditors(window); - if (antTool.getShowLog()) { - ToolUtil.showLogConsole(window); - ToolUtil.clearLogDocument(); - } +// ToolUtil.saveDirtyEditors(window); +// if (antTool.getShowConsole()) { +// ToolUtil.showLogConsole(window); +// ToolUtil.clearLogDocument(); +// } IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - DefaultRunnerContext context = new DefaultRunnerContext(antTool, antFile.getProject(), window.getWorkbench().getWorkingSetManager()); - context.run(monitor, window.getShell()); + DefaultRunnerContext context = new DefaultRunnerContext(antTool, antFile); //new DefaultRunnerContext(antTool, antFile.getProject(), window.getWorkbench().getWorkingSetManager()); + MultiStatus status = new MultiStatus(IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$ + context.run(monitor, status); + if (!status.isOK()) { + MessageDialog.openError(getShell(), "Ant Error", "An exception occurred while running ant"); + } }; }; @@ -127,7 +137,7 @@ public class AntLaunchWizard extends Wizard { if (e.getTargetException() instanceof CoreException) status = ((CoreException)e.getTargetException()).getStatus(); else - status = new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0, ToolMessages.getString("AntLaunchWizard.internalAntError"), e.getTargetException()); //$NON-NLS-1$; + status = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, ToolMessages.getString("AntLaunchWizard.internalAntError"), e.getTargetException()); //$NON-NLS-1$; ErrorDialog.openError( getShell(), ToolMessages.getString("AntLaunchWizard.runErrorTitle"), //$NON-NLS-1$; @@ -145,16 +155,15 @@ public class AntLaunchWizard extends Wizard { private void updateTool() { StringBuffer buf = new StringBuffer(page1.getArguments()); String[] targets = page1.getSelectedTargets(); - ToolUtil.buildVariableTags(ExternalTool.VAR_ANT_TARGET, targets, buf); + ToolUtil.buildVariableTag(AntUtil.RUN_TARGETS_ATTRIBUTE, AntUtil.combineRunTargets(targets), buf); antTool.setArguments(buf.toString()); - antTool.setShowLog(page1.getShowLog()); + antTool.setShowConsole(page1.getShowLog()); - ArrayList tools = ExternalToolsPlugin.getDefault().getRegistry().getExternalTools(); if (isNewTool) { - tools.add(antTool); + ExternalToolsPlugin.getDefault().getToolRegistry(getShell()).saveTool(antTool); isNewTool = false; } - ExternalToolsPlugin.getDefault().getRegistry().setExternalTools(tools); + } }
\ No newline at end of file diff --git a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizardPage.java b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizardPage.java index 4b44c1894..9e32241f8 100644 --- a/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizardPage.java +++ b/org.eclipse.ui.externaltools/External Tools Base/org/eclipse/ui/externaltools/internal/ui/AntLaunchWizardPage.java @@ -9,17 +9,30 @@ http://www.eclipse.org/legal/cpl-v05.html Contributors: **********************************************************************/ -import java.net.*; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; +import org.eclipse.ant.core.TargetInfo; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.*; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.*; -import org.eclipse.swt.layout.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.externaltools.internal.model.*; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin; +import org.eclipse.ui.externaltools.internal.model.IHelpContextIds; +import org.eclipse.ui.externaltools.internal.model.ToolMessages; import org.eclipse.ui.help.WorkbenchHelp; /** @@ -31,7 +44,7 @@ public class AntLaunchWizardPage extends WizardPage { private static final int SIZING_SELECTION_WIDGET_HEIGHT = 200; private static final int SIZING_SELECTION_WIDGET_WIDTH = 200; - private AntTargetList targetList; + private TargetInfo[] targetList; private String initialTargets[]; private String initialArguments; private boolean initialDisplayLog = true; @@ -42,7 +55,7 @@ public class AntLaunchWizardPage extends WizardPage { private Button showLog; private Text argumentsField; - public AntLaunchWizardPage(AntTargetList targetList) { + public AntLaunchWizardPage(TargetInfo[] targetList) { super("AntScriptPage"); //$NON-NLS-1$; this.targetList = targetList; setTitle(ToolMessages.getString("AntLaunchWizard.dialogTitle")); //$NON-NLS-1$; @@ -85,8 +98,12 @@ public class AntLaunchWizardPage extends WizardPage { return ((String)o1).compareTo((String) o2); } }); - if (targetList.getDefaultTarget() != null) - labelProvider.setDefaultTargetName(targetList.getDefaultTarget()); + for (int i= 0, numTargets= targetList.length; i < numTargets; i++) { + if (targetList[i].isDefault()) { + labelProvider.setDefaultTargetName(targetList[i].getName()); + break; + } + } listViewer.setLabelProvider(labelProvider); listViewer.setContentProvider(new AntTargetContentProvider()); listViewer.setInput(targetList); @@ -156,11 +173,10 @@ public class AntLaunchWizardPage extends WizardPage { */ private void selectInitialTargets() { if (initialTargets != null && initialTargets.length > 0) { - String[] targets = targetList.getTargets(); for (int i = 0; i < initialTargets.length; i++) { - for (int j = 0; j < targets.length; j++) { - if (targets[j].equals(initialTargets[i])) { - String target = targets[j]; + for (int j = 0; j < targetList.length; j++) { + if (targetList[j].equals(initialTargets[i])) { + String target = targetList[j].getName(); listViewer.setChecked(target, true); selectedTargets.add(target); break; @@ -168,10 +184,11 @@ public class AntLaunchWizardPage extends WizardPage { } } } else { - String target = targetList.getDefaultTarget(); - if (target != null) { - listViewer.setChecked(target, true); - selectedTargets.add(target); + for (int i= 0, numTargets= targetList.length; i < numTargets; i++) { + if (targetList[i].isDefault()) { + listViewer.setChecked(targetList[i], true); + selectedTargets.add(targetList[i]); + } } } |