diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java index bfb3d37df5e..96b49f6c906 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractAutotoolsHandler.java @@ -10,29 +10,66 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.StringTokenizer; +import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.ConsoleOutputStream; +import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.model.ICContainer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.resources.IConsole; +import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.remote.core.RemoteCommandLauncher; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; public abstract class AbstractAutotoolsHandler extends AbstractHandler { - protected Object execute(ExecutionEvent event, InvokeAction a) { + private IContainer fContainer; + + protected abstract void run(Shell activeShell); + + protected Object execute1(ExecutionEvent event) { ISelection k = HandlerUtil.getCurrentSelection(event); if (!k.isEmpty() && k instanceof IStructuredSelection) { Object obj = ((IStructuredSelection)k).getFirstElement(); IContainer container = getContainer(obj); if (container != null) { - a.setSelectedContainer(container); - a.run(null); + setSelectedContainer(container); + run(HandlerUtil.getActiveShell(event)); } } return null; @@ -68,5 +105,310 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler { } return fContainer; } + + public final String SHELL_COMMAND = "sh"; //$NON-NLS-1$ + + protected void showError(String title, String content) { + MessageDialog.openError(new Shell(), title, content); + } + + /** + * Separate targets to array from a string. + * + * @param rawArgList + * @return targets in string[] array. if targets are not formatted properly, + * returns null + */ + protected List separateTargets(String rawArgList) { + + StringTokenizer st = new StringTokenizer(rawArgList, " "); //$NON-NLS-1$ + List targetList = new ArrayList<>(); + + while (st.hasMoreTokens()) { + String currentWord = st.nextToken().trim(); + + if (currentWord.startsWith("'")) { //$NON-NLS-1$ + StringBuffer tmpTarget = new StringBuffer(); + while (!currentWord.endsWith("'")) { //$NON-NLS-1$ + tmpTarget.append(currentWord + " "); //$NON-NLS-1$ + if (!st.hasMoreTokens()) { + // quote not closed properly, so return null + return null; + } + currentWord = st.nextToken().trim(); + } + + tmpTarget.append(currentWord); + targetList.add(tmpTarget.toString()); + continue; + } + + if (currentWord.startsWith("\"")) { //$NON-NLS-1$ + StringBuffer tmpTarget = new StringBuffer(); + while (!currentWord.endsWith("\"")) { //$NON-NLS-1$ + tmpTarget.append(currentWord + " "); //$NON-NLS-1$ + if (!st.hasMoreTokens()) { + // double quote not closed properly, so return null + return null; + } + currentWord = st.nextToken().trim(); + } + + tmpTarget.append(currentWord); + targetList.add(tmpTarget.toString()); + continue; + } + + // for targets without quote/double quotes. + targetList.add(currentWord); + + } + + return targetList; + } + + protected List separateOptions(String rawArgList) { + List argList = new ArrayList<>(); + // May be multiple user-specified options in which case we + // need to split them up into individual options + rawArgList = rawArgList.trim(); + boolean finished = false; + int lastIndex = rawArgList.indexOf("--"); //$NON-NLS-1$ + if (lastIndex != -1) { + while (!finished) { + int index = rawArgList.indexOf("--", lastIndex + 2); //$NON-NLS-1$ + if (index != -1) { + String previous = rawArgList.substring(lastIndex, index).trim(); + argList.add(previous); + rawArgList = rawArgList.substring(index); + } else { + argList.add(rawArgList); + finished = true; + } + } + } + + return argList; + + } + + protected List simpleParseOptions(String rawArgList) { + List argList = new ArrayList<>(); + int lastArgIndex = -1; + int i = 0; + while (i < rawArgList.length()) { + char ch = rawArgList.charAt(i); + // Skip white-space + while (Character.isWhitespace(ch)) { + ++i; + if (i < rawArgList.length()) + ch = rawArgList.charAt(i); + else // Otherwise we are done + return argList; + } + + // Simplistic parser. We break up into strings delimited + // by blanks. If quotes are used, we ignore blanks within. + // If a backslash is used, we ignore the next character and + // pass it through. + lastArgIndex = i; + boolean inString = false; + while (i < rawArgList.length()) { + ch = rawArgList.charAt(i); + if (ch == '\\') // escape character + ++i; // skip over the next character + else if (ch == '\"') { // double quotes + inString = !inString; + } else if (Character.isWhitespace(ch)) { + if (!inString) { + argList.add(rawArgList.substring(lastArgIndex, i)); + break; + } + } + ++i; + } + // Look for the case where we ran out of chars for the last + // token. + if (i >= rawArgList.length()) + argList.add(rawArgList.substring(lastArgIndex)); + ++i; + } + return argList; + } + + protected IPath getExecDir(IContainer container) { + int type = container.getType(); + IPath execDir = null; + if (type == IResource.FILE) { + execDir = container.getLocation().removeLastSegments(1); + } else { + execDir = container.getLocation(); + } + return execDir; + } + + protected IPath getCWD(IContainer container) { + int type = container.getType(); + IPath cwd = null; + if (type == IResource.FILE) { + cwd = container.getFullPath().removeLastSegments(1); + } else { + cwd = container.getFullPath(); + } + return cwd; + } + + protected void executeConsoleCommand(final String actionName, final String command, final List argumentList, + final IPath execDir) { + // We need to use a workspace root scheduling rule because adding + // MakeTargets + // may end up saving the project description which runs under a + // workspace root rule. + final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); + + Job backgroundJob = new Job(actionName) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> { + try { + String errMsg = null; + IProject project = getSelectedContainer().getProject(); + // Get a build console for the project + IConsole console = CCorePlugin.getDefault() + .getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$ + console.start(project); + CUIPlugin.getDefault().startGlobalConsole(); + ConsoleOutputStream consoleOutStream = console.getOutputStream(); + // FIXME: we want to remove need for + // ManagedBuilderManager, but how do we + // get environment variables. + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IConfiguration cfg = info.getDefaultConfiguration(); + + StringBuffer buf = new StringBuffer(); + String[] consoleHeader = new String[3]; + + consoleHeader[0] = actionName; + consoleHeader[1] = cfg.getName(); + consoleHeader[2] = project.getName(); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$ + new String[] { actionName, execDir.toString() }); // $NON-NLS-1$ + buf.append(invokeMsg); + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ + consoleOutStream.write(buf.toString().getBytes()); + consoleOutStream.flush(); + + ArrayList additionalEnvs = new ArrayList<>(); + String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs); + // Get a launcher for the config command + RemoteCommandLauncher launcher = new RemoteCommandLauncher(); + launcher.setProject(project); + // Set the environment + IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider() + .getVariables(cfg, true); + String[] env = null; + ArrayList envList = new ArrayList<>(); + if (variables != null) { + for (int i = 0; i < variables.length; i++) { + envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$ + } + if (additionalEnvs.size() > 0) + envList.addAll(additionalEnvs); // add any + // additional + // environment + // variables + // specified + // ahead of + // script + env = envList.toArray(new String[envList.size()]); + } + + String[] newArgumentList; + + // Fix for bug #343905 and bug #371277 + // For Windows and Mac, we cannot run a script + // directly (in this case, + // autotools are scripts). We need to run "sh -c + // command args where command + // plus args is represented in a single string. The + // same applies for + // some Linux shells such as dash. Using sh -c will + // work on all Linux + // POSIX-compliant shells. + StringBuffer command1 = new StringBuffer(strippedCommand); + for (String arg : argumentList) { + command1.append(" " + arg); + } + newArgumentList = new String[] { "-c", command1.toString() }; + + OutputStream stdout = consoleOutStream; + OutputStream stderr = consoleOutStream; + + launcher.showCommand(true); + // Run the shell script via shell command. + Process proc = launcher.execute(new Path(SHELL_COMMAND), newArgumentList, env, execDir, + new NullProgressMonitor()); + if (proc != null) { + try { + // Close the input of the process since we + // will never write to + // it + proc.getOutputStream().close(); + } catch (IOException e1) { + } + + if (launcher.waitAndRead(stdout, stderr, + SubMonitor.convert(monitor1)) != ICommandLauncher.OK) { + errMsg = launcher.getErrorMessage(); + } + + // Force a resync of the projects without + // allowing the user to + // cancel. + // This is probably unkind, but short of this + // there is no way to + // ensure + // the UI is up-to-date with the build results + // monitor.subTask(ManagedMakeMessages + // .getResourceString(REFRESH)); + monitor1.subTask(AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$ + try { + project.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e2) { + monitor1.subTask( + AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$ + } + } else { + errMsg = launcher.getErrorMessage(); + } + + if (errMsg != null) + AutotoolsUIPlugin.logErrorMessage(errMsg); + + } catch (IOException e3) { + AutotoolsUIPlugin.log(e3); + } + }, rule, IWorkspace.AVOID_UPDATE, monitor); + } catch (CoreException e) { + return e.getStatus(); + } + return Status.OK_STATUS; + } + }; + + backgroundJob.setRule(rule); + backgroundJob.schedule(); + } + + protected IContainer getSelectedContainer() { + return fContainer; + } + + public void setSelectedContainer(IContainer container) { + fContainer = container; + } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractTargetAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractTargetAction.java deleted file mode 100644 index 24525d9a9fd..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AbstractTargetAction.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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 - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.autotools.core.AutotoolsPlugin; -import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin; -import org.eclipse.cdt.core.model.ICContainer; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; -import org.eclipse.ui.actions.ActionDelegate; - - -public abstract class AbstractTargetAction - extends ActionDelegate - implements IObjectActionDelegate, IWorkbenchWindowActionDelegate { - private IWorkbenchPart fPart; - private IWorkbenchWindow fWindow; - private IContainer fContainer; - - protected Shell getShell() { - if (fPart != null) { - return fPart.getSite().getShell(); - } else if (fWindow != null) { - return fWindow.getShell(); - } - return AutotoolsUIPlugin.getActiveWorkbenchShell(); - } - - protected IContainer getSelectedContainer() { - return fContainer; - } - - public void setSelectedContainer(IContainer container) { - fContainer = container; - } - - @Override - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - fPart = targetPart; - } - - @Override - public void init(IWorkbenchWindow window) { - fWindow = window; - } - - @Override - public void selectionChanged(IAction action, ISelection selection) { - boolean enabled = false; - if (selection instanceof IStructuredSelection) { - IStructuredSelection sel = (IStructuredSelection) selection; - Object obj = sel.getFirstElement(); - if (obj instanceof ICElement) { - if ( obj instanceof ICContainer || obj instanceof ICProject) { - fContainer = (IContainer) ((ICElement) obj).getUnderlyingResource(); - } else { - obj = ((ICElement)obj).getResource(); - if ( obj != null) { - fContainer = ((IResource)obj).getParent(); - } - } - } else if (obj instanceof IResource) { - if (obj instanceof IContainer) { - fContainer = (IContainer) obj; - } else { - fContainer = ((IResource)obj).getParent(); - } - } else { - fContainer = null; - } - if (fContainer != null && AutotoolsPlugin.hasTargetBuilder(fContainer.getProject())) { - enabled = true; - } - } - action.setEnabled(enabled); - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AclocalHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AclocalHandler.java index d10880ba560..3e052619155 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AclocalHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AclocalHandler.java @@ -10,7 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.widgets.Shell; /** * @author Jeff Johnston @@ -20,7 +29,74 @@ public class AclocalHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeAclocalAction()); + return execute1(event); + } + + private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ + private static final String DEFAULT_COMMAND = "aclocal"; //$NON-NLS-1$ + + @Override + protected void run(Shell activeShell) { + + IContainer container = getSelectedContainer(); + if (container == null) { + return; + } + + IPath execDir = getExecDir(container); + String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ + + TwoInputDialog optionDialog = new TwoInputDialog(activeShell, cwd, + InvokeMessages.getString("InvokeAclocalAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAclocalAction.message.options.otherOptions"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAclocalAction.message.options.includeDir"), DEFAULT_OPTION, null); //$NON-NLS-1$ + + optionDialog.open(); + + // chop args into string array + String rawArgList = optionDialog.getValue(); + + List optionsList = separateOptions(rawArgList); + + // chop args into string array + rawArgList = optionDialog.getSecondValue(); + + List targetList = separateTargets(rawArgList); + + if (targetList == null) { + + showError(InvokeMessages.getString("InvokeAction.execute.windowTitle.error"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAction.windowTitle.quoteError")); //$NON-NLS-1$ + return; + } + + int iOption = 0; + if (targetList.size() > 0) { + iOption = 1; + } + + List argumentList = new ArrayList<>(); + + argumentList.addAll(optionsList); + + if (iOption == 1) + argumentList.add("-I"); //$NON-NLS-1$ + + argumentList.addAll(targetList); + String aclocalCommand = null; + IProject project = getSelectedContainer().getProject(); + try { + aclocalCommand = project.getPersistentProperty(AutotoolsPropertyConstants.ACLOCAL_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If unset, use default system path + if (aclocalCommand == null) { + aclocalCommand = DEFAULT_COMMAND; + } + + executeConsoleCommand(DEFAULT_COMMAND, aclocalCommand, argumentList, execDir); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoconfHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoconfHandler.java index 331161140f1..cfa7a02b1f3 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoconfHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoconfHandler.java @@ -10,13 +10,46 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.ArrayList; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.widgets.Shell; public class AutoconfHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeAutoconfAction()); + return execute1(event); + } + + private final static String DEFAULT_COMMAND = "autoconf"; //$NON-NLS-1$ + + @Override + public void run(Shell activeShell) { + IContainer container = getSelectedContainer(); + if (container == null) + return; + + IPath execDir = getExecDir(container); + + IProject project = container.getProject(); + String autoconfCommand = null; + try { + autoconfCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOCONF_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If unset for the project, default to system path + if (autoconfCommand == null) { + autoconfCommand = DEFAULT_COMMAND; + } + executeConsoleCommand(DEFAULT_COMMAND, autoconfCommand, new ArrayList<>(), execDir); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoheaderHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoheaderHandler.java index fe97a1cf1c5..77fc0688b81 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoheaderHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoheaderHandler.java @@ -10,7 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.List; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.widgets.Shell; /** * @author Jeff Johnston @@ -20,7 +29,48 @@ public class AutoheaderHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeAutoheaderAction()); + return execute1(event); + } + + private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ + private static final String DEFAULT_COMMAND = "autoheader"; //$NON-NLS-1$ + + @Override + public void run(Shell activeShell) { + + IContainer container = getSelectedContainer(); + if (container == null) { + return; + } + IPath execDir = getExecDir(container); + String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ + + InputDialog optionDialog = new SingleInputDialog(activeShell, cwd, + InvokeMessages.getString("InvokeAutoheaderAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAutoheaderAction.message.options.otherOptions"), //$NON-NLS-1$ + DEFAULT_OPTION, null); + optionDialog.open(); + + // chop args into string array + String rawArgList = optionDialog.getValue(); + + List optionsList = simpleParseOptions(rawArgList); + + String autoheaderCommand = null; + IProject project = getSelectedContainer().getProject(); + try { + autoheaderCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOHEADER_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If unset, use default system path + if (autoheaderCommand == null) { + autoheaderCommand = DEFAULT_COMMAND; + } + + executeConsoleCommand(DEFAULT_COMMAND, autoheaderCommand, optionsList, execDir); + } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutomakeHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutomakeHandler.java index 2676f554f1b..76d4f7f00c6 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutomakeHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutomakeHandler.java @@ -10,13 +10,81 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.widgets.Shell; public class AutomakeHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeAutomakeAction()); + return execute1(event); + } + + private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ + private static final String DEFAULT_COMMAND = "automake"; //$NON-NLS-1$ + + @Override + public void run(Shell activeShell) { + + IContainer container = getSelectedContainer(); + if (container == null) { + return; + } + + IPath execDir = getExecDir(container); + String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ + TwoInputDialog optionDialog = new TwoInputDialog(activeShell, cwd, + InvokeMessages.getString("InvokeAutomakeAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAutomakeAction.message.options.otherOptions"), //$NON-NLS-1$ + InvokeMessages + .getString("InvokeAutomakeAction.message.options.makeTargets"), //$NON-NLS-1$ + DEFAULT_OPTION, null); + + optionDialog.open(); + + // chop args into string array + String rawArgList = optionDialog.getValue(); + + List optionsList = separateOptions(rawArgList); + + // chop args into string array + rawArgList = optionDialog.getSecondValue(); + + List targetList = separateTargets(rawArgList); + + if (targetList == null) { + + showError(InvokeMessages.getString("InvokeAction.execute.windowTitle.error"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAction.windowTitle.quoteError")); //$NON-NLS-1$ + return; + } + + List argumentList = new ArrayList<>(); + argumentList.addAll(optionsList); + argumentList.addAll(targetList); + + IProject project = container.getProject(); + String automakeCommand = null; + try { + automakeCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOMAKE_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If automake path not set for the project, default to system path + if (automakeCommand == null) { + automakeCommand = DEFAULT_COMMAND; + } + + executeConsoleCommand(DEFAULT_COMMAND, automakeCommand, argumentList, execDir); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoreconfHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoreconfHandler.java index add8b89222d..bfc02d10f7a 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoreconfHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/AutoreconfHandler.java @@ -10,7 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.List; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.widgets.Shell; /** * @author Jeff Johnston @@ -20,7 +29,48 @@ public class AutoreconfHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeAutoreconfAction()); + return execute1(event); + } + + private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ + private static final String DEFAULT_COMMAND = "autoreconf"; //$NON-NLS-1$ + + @Override + public void run(Shell activeShell) { + + IContainer container = getSelectedContainer(); + if (container == null) { + return; + } + + IPath execDir = getExecDir(container); + String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ + + InputDialog optionDialog = new SingleInputDialog(activeShell, cwd, + InvokeMessages.getString("InvokeAutoreconfAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeAutoreconfAction.message.options.otherOptions"), //$NON-NLS-1$ + DEFAULT_OPTION, null); + optionDialog.open(); + + // chop args into string array + String rawArgList = optionDialog.getValue(); + + List optionsList = simpleParseOptions(rawArgList); + + String autoreconfCommand = null; + IProject project = getSelectedContainer().getProject(); + try { + autoreconfCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTORECONF_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If unset, use default system path + if (autoreconfCommand == null) { + autoreconfCommand = DEFAULT_COMMAND; + } + + executeConsoleCommand(DEFAULT_COMMAND, autoreconfCommand, optionsList, execDir); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java deleted file mode 100644 index 6a6bf4ba01f..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAclocalAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; - - -public class InvokeAclocalAction extends InvokeAction { - - private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ - private static final String DEFAULT_COMMAND = "aclocal"; //$NON-NLS-1$ - - @Override - public void run(IAction action) { - - IContainer container = getSelectedContainer(); - if (container == null) { - return; - } - - IPath execDir = getExecDir(container); - String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - - TwoInputDialog optionDialog = new TwoInputDialog(getShell(), cwd, - InvokeMessages.getString("InvokeAclocalAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAclocalAction.message.options.otherOptions"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAclocalAction.message.options.includeDir"), DEFAULT_OPTION, null); //$NON-NLS-1$ - - optionDialog.open(); - - // chop args into string array - String rawArgList = optionDialog.getValue(); - - String[] optionsList = separateOptions(rawArgList); - - // chop args into string array - rawArgList = optionDialog.getSecondValue(); - - String[] targetList = separateTargets(rawArgList); - - if (targetList == null) { - - showError(InvokeMessages - .getString("InvokeAction.execute.windowTitle.error"), //$NON-NLS-1$ - InvokeMessages - .getString("InvokeAction.windowTitle.quoteError")); //$NON-NLS-1$ - return; - } - - int iOption = 0; - if (targetList.length > 0) { - iOption = 1; - } - - String[] argumentList = new String[targetList.length + optionsList.length + iOption]; - - System.arraycopy(optionsList, 0, argumentList, 0, optionsList.length); - - if (iOption == 1) - argumentList[optionsList.length] = "-I"; //$NON-NLS-1$ - - System.arraycopy(targetList, 0, argumentList, optionsList.length + iOption, targetList.length); - - String aclocalCommand = null; - IProject project = getSelectedContainer().getProject(); - try { - aclocalCommand = project.getPersistentProperty(AutotoolsPropertyConstants.ACLOCAL_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If unset, use default system path - if (aclocalCommand == null) { - aclocalCommand = DEFAULT_COMMAND; - } - - executeConsoleCommand(DEFAULT_COMMAND, aclocalCommand, argumentList, execDir); - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java deleted file mode 100644 index be5e325f239..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007, 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.ConsoleOutputStream; -import org.eclipse.cdt.core.ICommandLauncher; -import org.eclipse.cdt.core.envvar.IEnvironmentVariable; -import org.eclipse.cdt.core.resources.IConsole; -import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; -import org.eclipse.cdt.managedbuilder.core.IConfiguration; -import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; -import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.cdt.remote.core.RemoteCommandLauncher; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; - -public abstract class InvokeAction extends AbstractTargetAction { - - public final String SHELL_COMMAND = "sh"; //$NON-NLS-1$ - - protected void showError(String title, String content) { - MessageDialog.openError(new Shell(), title, content); - } - - /** - * Separate targets to array from a string. - * - * @param rawArgList - * @return targets in string[] array. if targets are not formatted properly, - * returns null - */ - protected String[] separateTargets(String rawArgList) { - - StringTokenizer st = new StringTokenizer(rawArgList, " "); //$NON-NLS-1$ - List targetList = new ArrayList<>(); - - while (st.hasMoreTokens()) { - String currentWord = st.nextToken().trim(); - - if (currentWord.startsWith("'")) { //$NON-NLS-1$ - StringBuffer tmpTarget = new StringBuffer(); - while (!currentWord.endsWith("'")) { //$NON-NLS-1$ - tmpTarget.append(currentWord + " "); //$NON-NLS-1$ - if (!st.hasMoreTokens()) { - // quote not closed properly, so return null - return null; - } - currentWord = st.nextToken().trim(); - } - - tmpTarget.append(currentWord); - targetList.add(tmpTarget.toString()); - continue; - } - - if (currentWord.startsWith("\"")) { //$NON-NLS-1$ - StringBuffer tmpTarget = new StringBuffer(); - while (!currentWord.endsWith("\"")) { //$NON-NLS-1$ - tmpTarget.append(currentWord + " "); //$NON-NLS-1$ - if (!st.hasMoreTokens()) { - // double quote not closed properly, so return null - return null; - } - currentWord = st.nextToken().trim(); - } - - tmpTarget.append(currentWord); - targetList.add(tmpTarget.toString()); - continue; - } - - // for targets without quote/double quotes. - targetList.add(currentWord); - - } - - return targetList.toArray(new String[targetList.size()]); - } - - protected String[] separateOptions(String rawArgList) { - List argList = new ArrayList<>(); - // May be multiple user-specified options in which case we - // need to split them up into individual options - rawArgList = rawArgList.trim(); - boolean finished = false; - int lastIndex = rawArgList.indexOf("--"); //$NON-NLS-1$ - if (lastIndex != -1) { - while (!finished) { - int index = rawArgList.indexOf("--", lastIndex + 2); //$NON-NLS-1$ - if (index != -1) { - String previous = rawArgList.substring(lastIndex, index) - .trim(); - argList.add(previous); - rawArgList = rawArgList.substring(index); - } else { - argList.add(rawArgList); - finished = true; - } - } - } - - return argList.toArray(new String[argList.size()]); - - } - - protected String[] simpleParseOptions(String rawArgList) { - List argList = new ArrayList<>(); - int lastArgIndex = -1; - int i = 0; - while (i < rawArgList.length()) { - char ch = rawArgList.charAt(i); - // Skip white-space - while (Character.isWhitespace(ch)) { - ++i; - if (i < rawArgList.length()) - ch = rawArgList.charAt(i); - else // Otherwise we are done - return argList.toArray(new String[argList.size()]); - } - - // Simplistic parser. We break up into strings delimited - // by blanks. If quotes are used, we ignore blanks within. - // If a backslash is used, we ignore the next character and - // pass it through. - lastArgIndex = i; - boolean inString = false; - while (i < rawArgList.length()) { - ch = rawArgList.charAt(i); - if (ch == '\\') // escape character - ++i; // skip over the next character - else if (ch == '\"') { // double quotes - inString = !inString; - } else if (Character.isWhitespace(ch)) { - if (!inString) { - argList.add(rawArgList.substring(lastArgIndex, i)); - break; - } - } - ++i; - } - // Look for the case where we ran out of chars for the last - // token. - if (i >= rawArgList.length()) - argList.add(rawArgList.substring(lastArgIndex)); - ++i; - } - return argList.toArray(new String[argList.size()]); - } - - protected IPath getExecDir(IContainer container) { - int type = container.getType(); - IPath execDir = null; - if (type == IResource.FILE) { - execDir = container.getLocation().removeLastSegments(1); - } else { - execDir = container.getLocation(); - } - return execDir; - } - - protected IPath getCWD(IContainer container) { - int type = container.getType(); - IPath cwd = null; - if (type == IResource.FILE) { - cwd = container.getFullPath().removeLastSegments(1); - } else { - cwd = container.getFullPath(); - } - return cwd; - } - - protected void executeConsoleCommand(final String actionName, final String command, - final String[] argumentList, final IPath execDir) { - // We need to use a workspace root scheduling rule because adding MakeTargets - // may end up saving the project description which runs under a workspace root rule. - final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); - - Job backgroundJob = new Job(actionName) { - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> { - try { - String errMsg = null; - IProject project = getSelectedContainer().getProject(); - // Get a build console for the project - IConsole console = CCorePlugin.getDefault() - .getConsole("org.eclipse.cdt.autotools.ui.autotoolsConsole"); //$NON-NLS-1$ - console.start(project); - CUIPlugin.getDefault().startGlobalConsole(); - ConsoleOutputStream consoleOutStream = console.getOutputStream(); - // FIXME: we want to remove need for - // ManagedBuilderManager, but how do we - // get environment variables. - IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); - IConfiguration cfg = info.getDefaultConfiguration(); - - StringBuffer buf = new StringBuffer(); - String[] consoleHeader = new String[3]; - - consoleHeader[0] = actionName; - consoleHeader[1] = cfg.getName(); - consoleHeader[2] = project.getName(); - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - String invokeMsg = InvokeMessages.getFormattedString("InvokeAction.console.message", //$NON-NLS-1$ - new String[] { actionName, execDir.toString() }); // $NON-NLS-1$ - buf.append(invokeMsg); - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - buf.append(System.getProperty("line.separator", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ - consoleOutStream.write(buf.toString().getBytes()); - consoleOutStream.flush(); - - ArrayList additionalEnvs = new ArrayList<>(); - String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs); - // Get a launcher for the config command - RemoteCommandLauncher launcher = new RemoteCommandLauncher(); - launcher.setProject(project); - // Set the environment - IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider() - .getVariables(cfg, true); - String[] env = null; - ArrayList envList = new ArrayList<>(); - if (variables != null) { - for (int i = 0; i < variables.length; i++) { - envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$ - } - if (additionalEnvs.size() > 0) - envList.addAll(additionalEnvs); // add any - // additional - // environment - // variables - // specified - // ahead of - // script - env = envList.toArray(new String[envList.size()]); - } - - String[] newArgumentList; - - // Fix for bug #343905 and bug #371277 - // For Windows and Mac, we cannot run a script - // directly (in this case, - // autotools are scripts). We need to run "sh -c - // command args where command - // plus args is represented in a single string. The - // same applies for - // some Linux shells such as dash. Using sh -c will - // work on all Linux - // POSIX-compliant shells. - StringBuffer command1 = new StringBuffer(strippedCommand); - for (String arg : argumentList) { - command1.append(" " + arg); - } - newArgumentList = new String[] { "-c", command1.toString() }; - - OutputStream stdout = consoleOutStream; - OutputStream stderr = consoleOutStream; - - launcher.showCommand(true); - // Run the shell script via shell command. - Process proc = launcher.execute(new Path(SHELL_COMMAND), newArgumentList, env, execDir, - new NullProgressMonitor()); - if (proc != null) { - try { - // Close the input of the process since we - // will never write to - // it - proc.getOutputStream().close(); - } catch (IOException e1) { - } - - if (launcher.waitAndRead(stdout, stderr, - SubMonitor.convert(monitor1)) != ICommandLauncher.OK) { - errMsg = launcher.getErrorMessage(); - } - - // Force a resync of the projects without - // allowing the user to - // cancel. - // This is probably unkind, but short of this - // there is no way to - // ensure - // the UI is up-to-date with the build results - // monitor.subTask(ManagedMakeMessages - // .getResourceString(REFRESH)); - monitor1.subTask(AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh")); //$NON-NLS-1$ - try { - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } catch (CoreException e2) { - monitor1.subTask( - AutotoolsUIPlugin.getResourceString("MakeGenerator.refresh.error")); //$NON-NLS-1$ - } - } else { - errMsg = launcher.getErrorMessage(); - } - - if (errMsg != null) - AutotoolsUIPlugin.logErrorMessage(errMsg); - - } catch (IOException e3) { - AutotoolsUIPlugin.log(e3); - } - }, rule, IWorkspace.AVOID_UPDATE, monitor); - } catch (CoreException e) { - return e.getStatus(); - } - return Status.OK_STATUS; - } - }; - - backgroundJob.setRule(rule); - backgroundJob.schedule(); - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoconfAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoconfAction.java deleted file mode 100644 index 59ac2b63696..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoconfAction.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; - - -/** - * Class responsible for invoking autoconf. - */ -public class InvokeAutoconfAction extends InvokeAction { - - private final static String DEFAULT_COMMAND = "autoconf"; //$NON-NLS-1$ - @Override - public void run(IAction action) { - IContainer container = getSelectedContainer(); - if (container == null) - return; - - IPath execDir = getExecDir(container); - - IProject project = container.getProject(); - String autoconfCommand = null; - try { - autoconfCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOCONF_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If unset for the project, default to system path - if (autoconfCommand == null) { - autoconfCommand = DEFAULT_COMMAND; - } - executeConsoleCommand(DEFAULT_COMMAND, autoconfCommand, new String[] {}, execDir); - } - - - @Override - public void dispose() { - } -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java deleted file mode 100644 index 65fd653475f..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoheaderAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.InputDialog; - - -public class InvokeAutoheaderAction extends InvokeAction { - - private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ - private static final String DEFAULT_COMMAND = "autoheader"; //$NON-NLS-1$ - - @Override - public void run(IAction action) { - - IContainer container = getSelectedContainer(); - if (container == null) { - return; - } - IPath execDir = getExecDir(container); - String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - - InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, - InvokeMessages.getString("InvokeAutoheaderAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAutoheaderAction.message.options.otherOptions"), //$NON-NLS-1$ - DEFAULT_OPTION, null); - optionDialog.open(); - - // chop args into string array - String rawArgList = optionDialog.getValue(); - - String[] optionsList = simpleParseOptions(rawArgList); - - String[] argumentList = new String[optionsList.length]; - - System.arraycopy(optionsList, 0, argumentList, 0, optionsList.length); - - String autoheaderCommand = null; - IProject project = getSelectedContainer().getProject(); - try { - autoheaderCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOHEADER_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If unset, use default system path - if (autoheaderCommand == null) { - autoheaderCommand = DEFAULT_COMMAND; - } - - executeConsoleCommand(DEFAULT_COMMAND, autoheaderCommand, argumentList, execDir); - - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java deleted file mode 100644 index 5421e3321b8..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutomakeAction.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; - - -/** - * Class responsible for invoking automake. - * - * @author klee - * - */ -public class InvokeAutomakeAction extends InvokeAction { - - private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ - private static final String DEFAULT_COMMAND = "automake"; //$NON-NLS-1$ - - @Override - public void run(IAction action) { - - IContainer container = getSelectedContainer(); - if (container == null) { - return; - } - - IPath execDir = getExecDir(container); - String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - TwoInputDialog optionDialog = new TwoInputDialog(getShell(), cwd, - InvokeMessages.getString("InvokeAutomakeAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAutomakeAction.message.options.otherOptions"), InvokeMessages //$NON-NLS-1$ - .getString("InvokeAutomakeAction.message.options.makeTargets"), //$NON-NLS-1$ - DEFAULT_OPTION, null); - - optionDialog.open(); - - // chop args into string array - String rawArgList = optionDialog.getValue(); - - String[] optionsList = separateOptions(rawArgList); - - - // chop args into string array - rawArgList = optionDialog.getSecondValue(); - - String[] targetList = separateTargets(rawArgList); - - if (targetList == null) { - - showError(InvokeMessages.getString("InvokeAction.execute.windowTitle.error"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAction.windowTitle.quoteError")); //$NON-NLS-1$ - return; - } - - String[] argumentList = new String[targetList.length - + optionsList.length]; - - System.arraycopy(optionsList, 0, argumentList, 0, optionsList.length); - System.arraycopy(targetList, 0, argumentList, optionsList.length, - targetList.length); - - IProject project = container.getProject(); - String automakeCommand = null; - try { - automakeCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTOMAKE_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If automake path not set for the project, default to system path - if (automakeCommand == null) { - automakeCommand = DEFAULT_COMMAND; - } - - executeConsoleCommand(DEFAULT_COMMAND, automakeCommand, argumentList, execDir); - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java deleted file mode 100644 index 5749e7b366c..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAutoreconfAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.InputDialog; - - -public class InvokeAutoreconfAction extends InvokeAction { - - private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ - private static final String DEFAULT_COMMAND = "autoreconf"; //$NON-NLS-1$ - - @Override - public void run(IAction action) { - - IContainer container = getSelectedContainer(); - if (container == null) { - return; - } - - IPath execDir = getExecDir(container); - String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - - InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, - InvokeMessages.getString("InvokeAutoreconfAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeAutoreconfAction.message.options.otherOptions"), //$NON-NLS-1$ - DEFAULT_OPTION, null); - optionDialog.open(); - - // chop args into string array - String rawArgList = optionDialog.getValue(); - - String[] optionsList = simpleParseOptions(rawArgList); - - String[] argumentList = new String[optionsList.length]; - - System.arraycopy(optionsList, 0, argumentList, 0, optionsList.length); - - String autoreconfCommand = null; - IProject project = getSelectedContainer().getProject(); - try { - autoreconfCommand = project.getPersistentProperty(AutotoolsPropertyConstants.AUTORECONF_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If unset, use default system path - if (autoreconfCommand == null) { - autoreconfCommand = DEFAULT_COMMAND; - } - - executeConsoleCommand(DEFAULT_COMMAND, autoreconfCommand, argumentList, execDir); - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java deleted file mode 100644 index e4f349df8a5..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeLibtoolizeAction.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.InputDialog; - - -public class InvokeLibtoolizeAction extends InvokeAction { - - private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ - private static final String DEFAULT_COMMAND = "libtoolize"; //$NON-NLS-1$ - - @Override - public void run(IAction action) { - - IContainer container = getSelectedContainer(); - if (container == null) { - return; - } - - IPath execDir = getExecDir(container); - String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ - - InputDialog optionDialog = new SingleInputDialog(getShell(), cwd, - InvokeMessages.getString("InvokeLibtoolizeAction.windowTitle.options"), //$NON-NLS-1$ - InvokeMessages.getString("InvokeLibtoolizeAction.message.options.otherOptions"), //$NON-NLS-1$ - DEFAULT_OPTION, null); - optionDialog.open(); - - // chop args into string array - String rawArgList = optionDialog.getValue(); - - String[] optionsList = simpleParseOptions(rawArgList); - - String[] argumentList = new String[optionsList.length]; - - System.arraycopy(optionsList, 0, argumentList, 0, optionsList.length); - - String libtoolizeCommand = null; - IProject project = getSelectedContainer().getProject(); - try { - libtoolizeCommand = project.getPersistentProperty(AutotoolsPropertyConstants.LIBTOOLIZE_TOOL); - } catch (CoreException e) { - // do nothing - } - - // If unset, use default system path - if (libtoolizeCommand == null) { - libtoolizeCommand = DEFAULT_COMMAND; - } - - executeConsoleCommand(DEFAULT_COMMAND, libtoolizeCommand, argumentList, execDir); - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/LibtoolizeHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/LibtoolizeHandler.java index 20e800281fb..8ce59c58176 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/LibtoolizeHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/LibtoolizeHandler.java @@ -10,7 +10,16 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import java.util.List; + +import org.eclipse.cdt.internal.autotools.core.AutotoolsPropertyConstants; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.widgets.Shell; /** * @author Jeff Johnston @@ -20,7 +29,48 @@ public class LibtoolizeHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new InvokeLibtoolizeAction()); + return execute1(event); + } + + private static final String DEFAULT_OPTION = ""; //$NON-NLS-1$ + private static final String DEFAULT_COMMAND = "libtoolize"; //$NON-NLS-1$ + + @Override + public void run(Shell activeShell) { + + IContainer container = getSelectedContainer(); + if (container == null) { + return; + } + + IPath execDir = getExecDir(container); + String cwd = InvokeMessages.getString("CWD") + getCWD(container); //$NON-NLS-1$ + + InputDialog optionDialog = new SingleInputDialog(activeShell, cwd, + InvokeMessages.getString("InvokeLibtoolizeAction.windowTitle.options"), //$NON-NLS-1$ + InvokeMessages.getString("InvokeLibtoolizeAction.message.options.otherOptions"), //$NON-NLS-1$ + DEFAULT_OPTION, null); + optionDialog.open(); + + // chop args into string array + String rawArgList = optionDialog.getValue(); + + List optionsList = simpleParseOptions(rawArgList); + + String libtoolizeCommand = null; + IProject project = getSelectedContainer().getProject(); + try { + libtoolizeCommand = project.getPersistentProperty(AutotoolsPropertyConstants.LIBTOOLIZE_TOOL); + } catch (CoreException e) { + // do nothing + } + + // If unset, use default system path + if (libtoolizeCommand == null) { + libtoolizeCommand = DEFAULT_COMMAND; + } + + executeConsoleCommand(DEFAULT_COMMAND, libtoolizeCommand, optionsList, execDir); } } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureAction.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureAction.java deleted file mode 100644 index b70f914dc82..00000000000 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Red Hat Inc.. - * 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 - * - * Contributors: - * Red Hat Incorporated - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.internal.autotools.ui.actions; - -import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; -import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; -import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -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.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.action.IAction; - - -public class ReconfigureAction extends InvokeAction { - - @Override - public void run(IAction action) { - IContainer container = getSelectedContainer(); - if (container == null) - return; - - // We need to use a workspace root scheduling rule because adding MakeTargets - // may end up saving the project description which runs under a workspace root rule. - final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); - - Job backgroundJob = new Job("Reconfigure Action"){ //$NON-NLS-1$ - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> { - IProject project = getSelectedContainer().getProject(); - AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator(); - IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); - CUIPlugin.getDefault().startGlobalConsole(); - m.initialize(project, info, monitor1); - try { - m.reconfigure(); - } catch (CoreException e) { - // do nothing for now - } - }, rule, IWorkspace.AVOID_UPDATE, monitor); - } catch (CoreException e) { - return e.getStatus(); - } - IStatus returnStatus = Status.OK_STATUS; - return returnStatus; - } - }; - - backgroundJob.setRule(rule); - backgroundJob.schedule(); - } - - @Override - public void dispose() { - - } - -} diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java index d452352dd13..4874c395a3c 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/actions/ReconfigureHandler.java @@ -10,7 +10,23 @@ *******************************************************************************/ package org.eclipse.cdt.internal.autotools.ui.actions; +import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +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.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Shell; /** * @author Jeff Johnston @@ -20,7 +36,47 @@ public class ReconfigureHandler extends AbstractAutotoolsHandler { @Override public Object execute(ExecutionEvent event) { - return execute(event, new ReconfigureAction()); + return execute1(event); + } + + @Override + public void run(Shell activeShell) { + IContainer container = getSelectedContainer(); + if (container == null) + return; + + // We need to use a workspace root scheduling rule because adding + // MakeTargets + // may end up saving the project description which runs under a + // workspace root rule. + final ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRoot(); + + Job backgroundJob = new Job("Reconfigure Action") { //$NON-NLS-1$ + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + ResourcesPlugin.getWorkspace().run((IWorkspaceRunnable) monitor1 -> { + IProject project = getSelectedContainer().getProject(); + AutotoolsNewMakeGenerator m = new AutotoolsNewMakeGenerator(); + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + CUIPlugin.getDefault().startGlobalConsole(); + m.initialize(project, info, monitor1); + try { + m.reconfigure(); + } catch (CoreException e) { + // do nothing for now + } + }, rule, IWorkspace.AVOID_UPDATE, monitor); + } catch (CoreException e) { + return e.getStatus(); + } + IStatus returnStatus = Status.OK_STATUS; + return returnStatus; + } + }; + + backgroundJob.setRule(rule); + backgroundJob.schedule(); } }