From 22ea1c7683acacf6bc378a64c3cbf0652395221b Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Fri, 30 Mar 2012 18:19:17 -0400 Subject: [PATCH] Add missing Autotools UI fixes done after initial move. - fix some findBugs warnings - use sh -c to invoke Autotool scripts - switch AutomakeErrorHandler to use IEditorInput --- build/org.eclipse.cdt.autotools.ui/ChangeLog | 28 +++++++++++++ .../autotools/ui/editors/AutoconfMacro.java | 7 ++++ .../autotools/ui/actions/InvokeAction.java | 39 +++++++------------ .../automake/AutomakeDocumentProvider.java | 4 +- .../ui/editors/automake/AutomakeEditor.java | 5 ++- .../automake/AutomakeErrorHandler.java | 5 +-- .../AutomakefileReconcilingStrategy.java | 2 +- 7 files changed, 57 insertions(+), 33 deletions(-) diff --git a/build/org.eclipse.cdt.autotools.ui/ChangeLog b/build/org.eclipse.cdt.autotools.ui/ChangeLog index b54ca73364c..5e62a8d5688 100644 --- a/build/org.eclipse.cdt.autotools.ui/ChangeLog +++ b/build/org.eclipse.cdt.autotools.ui/ChangeLog @@ -1,3 +1,31 @@ +2012-03-30 Jeff Johnston + + * src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java + (AutomakeEditor): Make constructor public so openEditor will work. + * src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeErrorHandler.java + (AutomakeErrorHandler): Change constructor to accept an IEditorInput rather than + an IDocument. + * src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileReconcilingStrategy.java + (AutomakefileReconcilingStrategy): Pass an IEditorInput to create the + AutomakeErrorHandler. + * src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeDocumentProvider.java + (connect): Ditto. + +2012-03-30 Jeff Johnston + + * src/org/eclipse/cdt/autotools/ui/editors/AutoconfMacro.java + (equals): Fix FindBugs error with missing null case. + (hashCode): New method to fix FindBugs error. + * src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java + (AutomakeEditor): Fix constructor to remove static variable. + (static initializer): Fix FindBugs error with static variable usage. + +2012-03-30 Jeff Johnston + + Bug #371277 + * src/org/eclipse/cdt/internal/autotools/ui/actions/InvokeAction.java + (..run): Use sh -c to execute the autotool scripts. + 2012-03-29 Jeff Johnston Resolves: bug#374026 diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfMacro.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfMacro.java index 6775b5a8379..e4875abef52 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfMacro.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/editors/AutoconfMacro.java @@ -42,7 +42,14 @@ public class AutoconfMacro implements Comparable { } public boolean equals(Object x) { + if (x == null) + return false; AutoconfMacro y = (AutoconfMacro)x; return getName().equals(y.getName()); } + + public int hashCode() { + return getName().hashCode(); + } + } 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 index 2e2cd1ac802..5e94c24c82f 100644 --- 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 @@ -41,7 +41,6 @@ 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.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.ISchedulingRule; @@ -259,7 +258,7 @@ public abstract class InvokeAction extends AbstractTargetAction { Process process = cmdL.execute(command, argumentList, envList, execDir, new NullProgressMonitor()); - if (cmdL.waitAndRead(stdout, stderr) == CommandLauncher.OK) { + if (cmdL.waitAndRead(stdout, stderr, new NullProgressMonitor()) == CommandLauncher.OK) { try { status = 0; monitor.done(); @@ -389,30 +388,18 @@ public abstract class InvokeAction extends AbstractTargetAction { String[] newArgumentList; - // Fix for bug #343905 - // For Windows and Mac, we cannot run a script directly (in this case, the - // autotools are scripts). We need to run "sh -c command args where command - // plus args is represented in a single string. - if (Platform.getOS().equals(Platform.OS_WIN32) - || Platform.getOS().equals(Platform.OS_MACOSX)) { - // Neither Mac or Windows support calling scripts directly. - StringBuffer command = new StringBuffer(strippedCommand); - for (String arg : argumentList) { - command.append(" " + arg); - } - newArgumentList = new String[] { "-c", command.toString() }; - } else { - // Otherwise, we don't need the -c argument and can present the command - // name and arguments as individual arguments - if (argumentList == null) - newArgumentList = new String[1]; - else - newArgumentList = new String[argumentList.length + 1]; - newArgumentList[0] = strippedCommand; - if (argumentList != null) - System.arraycopy(argumentList, 0, newArgumentList, 1, argumentList.length); - } - + // 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 command = new StringBuffer(strippedCommand); + for (String arg : argumentList) { + command.append(" " + arg); + } + newArgumentList = new String[] { "-c", command.toString() }; + OutputStream stdout = consoleOutStream; OutputStream stderr = consoleOutStream; diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeDocumentProvider.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeDocumentProvider.java index 7b9b6da9e57..a44ce420212 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeDocumentProvider.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeDocumentProvider.java @@ -17,6 +17,7 @@ import java.util.Iterator; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IURIEditorInput; import org.eclipse.ui.editors.text.TextFileDocumentProvider; @@ -105,8 +106,7 @@ public class AutomakeDocumentProvider extends TextFileDocumentProvider implement public void connect(Object element) throws CoreException { super.connect(element); IMakefile makefile = getWorkingCopy(element); - IDocument document = getDocument(element); - AutomakeErrorHandler errorHandler = new AutomakeErrorHandler(document); + AutomakeErrorHandler errorHandler = new AutomakeErrorHandler((IEditorInput)element); errorHandler.update(makefile); } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java index f033e31b65b..79c19f23ce9 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeEditor.java @@ -34,9 +34,12 @@ public class AutomakeEditor extends MakefileEditor { private static AutomakeEditor fgInstance; private IEditorInput input; + static { + fgInstance = new AutomakeEditor(); + } + public AutomakeEditor() { super(); - fgInstance = this; } /** diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeErrorHandler.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeErrorHandler.java index d6ea5f8ca28..e602a957190 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeErrorHandler.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakeErrorHandler.java @@ -52,9 +52,8 @@ public class AutomakeErrorHandler { } - public AutomakeErrorHandler(IDocument document) { - this.document = document; - IEditorInput input = AutomakeEditor.getDefault().getEditorInput(); + public AutomakeErrorHandler(IEditorInput input) { + this.document = AutomakeEditorFactory.getDefault().getAutomakefileDocumentProvider().getDocument(input); this.fAnnotationModel = (AnnotationModel)AutomakeEditorFactory.getDefault().getAutomakefileDocumentProvider().getAnnotationModel(input); } diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileReconcilingStrategy.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileReconcilingStrategy.java index 5b867dde764..58e9a657d18 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileReconcilingStrategy.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/AutomakefileReconcilingStrategy.java @@ -42,7 +42,7 @@ public class AutomakefileReconcilingStrategy implements IReconcilingStrategy { input = (IEditorInput) fEditor.getEditorInput(); fManager= AutomakeEditorFactory.getDefault().getWorkingCopyManager(); fDocumentProvider= AutomakeEditorFactory.getDefault().getAutomakefileDocumentProvider(); - fErrorHandler= new AutomakeErrorHandler(fDocumentProvider.getDocument(input)); + fErrorHandler= new AutomakeErrorHandler(input); fMakefileReconcilingParticipant= (IReconcilingParticipant)fEditor; }