From e061d9788178d2d7648165cf8d10d4570f32f606 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 2 Dec 2015 11:57:07 +0200 Subject: [PATCH] autotools: Sanitize activators. Reduce coupling by changing UI bundle to use UI activator and drop UI getters (e.g. workbench, window, shell) from the core bundle. Also remove other unused methods. Change-Id: Ida510d5a0e991c08332a998aefaba5843743172a Signed-off-by: Alexander Kurtakov --- .../cdt/autotools/core/AutotoolsPlugin.java | 113 ------------------ .../AutotoolsConfigurationManager.java | 2 +- .../cdt/autotools/ui/AutotoolsUIPlugin.java | 108 ++--------------- .../ui/actions/AbstractTargetAction.java | 3 +- .../ui/editors/automake/MakefileEditor.java | 5 +- 5 files changed, 17 insertions(+), 214 deletions(-) diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java index f4883820582..29ef7644907 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/autotools/core/AutotoolsPlugin.java @@ -22,19 +22,12 @@ import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -109,17 +102,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin { return ref != null ? context.getService(ref) : null; } - /** - * Returns active shell. - */ - public static Shell getActiveWorkbenchShell() { - IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - return window.getShell(); - } - return null; - } - /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. @@ -181,17 +163,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin { return false; } - /** - * Returns an image descriptor for the image file at the given - * plug-in relative path. - * - * @param path the path - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String path) { - return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); - } - public static void log(IStatus status) { ResourcesPlugin.getPlugin().getLog().log(status); } @@ -200,33 +171,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin { log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null)); } - public static void logException(Throwable e, final String title, String message) { - if (e instanceof InvocationTargetException) { - e = ((InvocationTargetException) e).getTargetException(); - } - IStatus status = null; - if (e instanceof CoreException) - status = ((CoreException) e).getStatus(); - else { - if (message == null) - message = e.getMessage(); - if (message == null) - message = e.toString(); - status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, message, e); - } - ResourcesPlugin.getPlugin().getLog().log(status); - Display display; - display = Display.getCurrent(); - if (display == null) - display = Display.getDefault(); - final IStatus fstatus = status; - display.asyncExec(() -> ErrorDialog.openError(null, title, null, fstatus)); - } - - public static void logException(Throwable e) { - logException(e, null, null); - } - public static void log(Throwable e) { if (e instanceof InvocationTargetException) e = ((InvocationTargetException) e).getTargetException(); @@ -238,63 +182,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin { log(status); } - /** - * Utility method with conventions - */ - public static void errorDialog(Shell shell, String title, String message, IStatus s) { - log(s); - // if the 'message' resource string and the IStatus' message are the same, - // don't show both in the dialog - if (s != null && message.equals(s.getMessage())) { - message = null; - } - ErrorDialog.openError(shell, title, message, s); - } - - /** - * Utility method with conventions - */ - public static void errorDialog(Shell shell, String title, String message, Throwable t) { - log(t); - IStatus status; - if (t instanceof CoreException) { - status = ((CoreException) t).getStatus(); - // if the 'message' resource string and the IStatus' message are the same, - // don't show both in the dialog - if (status != null && message.equals(status.getMessage())) { - message = null; - } - } else { - status = new Status(IStatus.ERROR, AutotoolsPlugin.getUniqueIdentifier(), -1, "Internal Error: ", t); //$NON-NLS-1$ - } - ErrorDialog.openError(shell, title, message, status); - } - - /** - * Returns the workspace instance. - */ - public static IWorkspace getWorkspace() { - return ResourcesPlugin.getWorkspace(); - } - - /** - * Returns the active workbench window or null if none - */ - public static IWorkbenchWindow getActiveWorkbenchWindow() { - return getDefault().getWorkbench().getActiveWorkbenchWindow(); - } - - /** - * Returns the active workbench page or null if none. - */ - public static IWorkbenchPage getActivePage() { - IWorkbenchWindow window= getActiveWorkbenchWindow(); - if (window != null) { - return window.getActivePage(); - } - return null; - } - /** * Return set of Autotool configuration options for a given build configuration id. * diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java index e82d0ebfea6..d52afd04684 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/configure/AutotoolsConfigurationManager.java @@ -86,7 +86,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener { private AutotoolsConfigurationManager() { configs = new HashMap<>(); tmpConfigs = new HashMap<>(); - AutotoolsPlugin.getWorkspace().addResourceChangeListener(this); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); } public static AutotoolsConfigurationManager getInstance() { diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/AutotoolsUIPlugin.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/AutotoolsUIPlugin.java index 9295ef5aeaf..880404060db 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/AutotoolsUIPlugin.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/autotools/ui/AutotoolsUIPlugin.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.autotools.ui; import java.lang.reflect.InvocationTargetException; -import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -21,9 +20,6 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; @@ -87,17 +83,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { return plugin; } - /** - * Returns active shell. - */ - public static Shell getActiveWorkbenchShell() { - IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - return window.getShell(); - } - return null; - } - /** * Returns the string from the plugin's resource bundle, * or 'key' if not found. @@ -114,18 +99,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { } } - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - * - * @param key the message key - * @param args an array of substituition strings - * @return the resource bundle message - */ - public static String getFormattedString(String key, String[] args) { - return MessageFormat.format(getResourceString(key), (Object[])args); - } - /** * Returns the plugin's resource bundle, */ @@ -133,17 +106,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { return resourceBundle; } - /** - * Returns an image descriptor for the image file at the given - * plug-in relative path. - * - * @param path the path - * @return the image descriptor - */ - public static ImageDescriptor getImageDescriptor(String path) { - return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); - } - public static void log(IStatus status) { ResourcesPlugin.getPlugin().getLog().log(status); } @@ -152,33 +114,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null)); } - public static void logException(Throwable e, final String title, String message) { - if (e instanceof InvocationTargetException) { - e = ((InvocationTargetException) e).getTargetException(); - } - IStatus status = null; - if (e instanceof CoreException) - status = ((CoreException) e).getStatus(); - else { - if (message == null) - message = e.getMessage(); - if (message == null) - message = e.toString(); - status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, message, e); - } - ResourcesPlugin.getPlugin().getLog().log(status); - Display display; - display = Display.getCurrent(); - if (display == null) - display = Display.getDefault(); - final IStatus fstatus = status; - display.asyncExec(() -> ErrorDialog.openError(null, title, null, fstatus)); - } - - public static void logException(Throwable e) { - logException(e, null, null); - } - public static void log(Throwable e) { if (e instanceof InvocationTargetException) e = ((InvocationTargetException) e).getTargetException(); @@ -190,38 +125,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { log(status); } - /** - * Utility method with conventions - */ - public static void errorDialog(Shell shell, String title, String message, IStatus s) { - log(s); - // if the 'message' resource string and the IStatus' message are the same, - // don't show both in the dialog - if (s != null && message.equals(s.getMessage())) { - message = null; - } - ErrorDialog.openError(shell, title, message, s); - } - - /** - * Utility method with conventions - */ - public static void errorDialog(Shell shell, String title, String message, Throwable t) { - log(t); - IStatus status; - if (t instanceof CoreException) { - status = ((CoreException) t).getStatus(); - // if the 'message' resource string and the IStatus' message are the same, - // don't show both in the dialog - if (status != null && message.equals(status.getMessage())) { - message = null; - } - } else { - status = new Status(IStatus.ERROR, AutotoolsUIPlugin.getUniqueIdentifier(), -1, "Internal Error: ", t); //$NON-NLS-1$ - } - ErrorDialog.openError(shell, title, message, status); - } - /** * Returns the workspace instance. */ @@ -246,4 +149,15 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin { } return null; } + + /** + * Returns active shell. + */ + public static Shell getActiveWorkbenchShell() { + IWorkbenchWindow window = getActiveWorkbenchWindow(); + if (window != null) { + return window.getShell(); + } + return null; + } } 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 index 52fc842a997..24525d9a9fd 100644 --- 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 @@ -11,6 +11,7 @@ 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; @@ -40,7 +41,7 @@ public abstract class AbstractTargetAction } else if (fWindow != null) { return fWindow.getShell(); } - return AutotoolsPlugin.getActiveWorkbenchShell(); + return AutotoolsUIPlugin.getActiveWorkbenchShell(); } protected IContainer getSelectedContainer() { diff --git a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileEditor.java b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileEditor.java index af7d8bd544a..59966a185ca 100644 --- a/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileEditor.java +++ b/build/org.eclipse.cdt.autotools.ui/src/org/eclipse/cdt/internal/autotools/ui/editors/automake/MakefileEditor.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.autotools.ui.editors.automake; import java.util.ResourceBundle; import org.eclipse.cdt.autotools.core.AutotoolsPlugin; +import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin; import org.eclipse.cdt.internal.autotools.ui.MakeUIMessages; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.ListenerList; @@ -216,8 +217,8 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe if (selection.isEmpty()) { resetHighlightRange(); } else if (selection instanceof IStructuredSelection){ - if (!isActivePart() && AutotoolsPlugin.getActivePage() != null) { - AutotoolsPlugin.getActivePage().bringToTop(this); + if (!isActivePart() && AutotoolsUIPlugin.getActivePage() != null) { + AutotoolsUIPlugin.getActivePage().bringToTop(this); } Object element = ((IStructuredSelection) selection).getFirstElement(); if (element instanceof IDirective) {