Skip to content

Commit

Permalink
e4: use ILog instead of deprecated LogService constants
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jan 23, 2024
1 parent c21bef8 commit c1cf342
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.State;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.e4.core.commands.internal.HandlerServiceImpl;
Expand All @@ -38,7 +39,6 @@
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.bindings.EBindingService;
import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.IUpdateService;
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
Expand All @@ -57,7 +57,6 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolItem;
import org.osgi.service.log.LogService;

public class HandledContributionItem extends AbstractContributionItem {
/**
Expand Down Expand Up @@ -246,10 +245,11 @@ protected void updateMenuItem() {
String keyBindingText = null;
if (parmCmd != null) {
if (text == null || text.isEmpty()) {
String localizedCommandName = getModel().getCommand().getLocalizedCommandName();
try {
text = parmCmd.getName(getModel().getCommand().getLocalizedCommandName());
text = parmCmd.getName(localizedCommandName);
} catch (NotDefinedException e) {
Activator.log(LogService.LOG_DEBUG, e.getMessage(), e);
ILog.get().warn("not found: " + localizedCommandName, e); //$NON-NLS-1$
}
}
if (bindingService != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import jakarta.inject.Inject;
import java.lang.reflect.Method;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
Expand All @@ -32,7 +32,6 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Widget;
import org.osgi.service.log.LogService;

public class MenuManagerServiceFilter implements Listener {
public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
Expand All @@ -53,7 +52,7 @@ public static Method getAboutToShow() {
.getDeclaredMethod("handleAboutToShow"); //$NON-NLS-1$
aboutToShow.setAccessible(true);
} catch (SecurityException | NoSuchMethodException e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
ILog.get().error(e.getMessage(), e);
}
}
return aboutToShow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -62,7 +63,6 @@
import org.eclipse.e4.ui.css.swt.theme.IThemeManager;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.di.PersistState;
import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.MApplicationElement;
Expand Down Expand Up @@ -106,7 +106,6 @@
import org.eclipse.ui.testing.TestableObject;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.osgi.service.log.LogService;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSStyleDeclaration;

Expand Down Expand Up @@ -1372,7 +1371,7 @@ public void setClassnameAndId(Object widget, String classname, String id) {
cssEngine.parseStyleSheet(stream);
}
} catch (IOException e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
ILog.get().error(e.getMessage(), e);
}

Shell[] shells = display.getShells();
Expand All @@ -1382,7 +1381,7 @@ public void setClassnameAndId(Object widget, String classname, String id) {
s.reskin(SWT.ALL);
cssEngine.applyStyles(s, true);
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
ILog.get().error(e.getMessage(), e);
} finally {
s.setRedraw(true);
}
Expand Down Expand Up @@ -1470,7 +1469,7 @@ protected Set<IEclipsePreferences> getThemeRelatedPreferences() {
bundleIDs.add(nameSpace);
}
} catch (InvalidRegistryObjectException e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
ILog.get().error( e.getMessage(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import jakarta.inject.Inject;
import java.util.List;
import java.util.Locale;
import org.eclipse.core.runtime.ILog;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.internal.services.ResourceBundleHelper;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.core.services.nls.ILocaleChangeService;
Expand All @@ -34,7 +34,6 @@
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
import org.osgi.service.log.LogService;

/**
* Default implementation of {@link ILocaleChangeService} that changes the {@link Locale} in the
Expand All @@ -50,9 +49,6 @@ public class LocaleChangeServiceImpl implements ILocaleChangeService {
@Inject
IEventBroker broker;

@Inject
@Optional
LogService logService;

/**
* Create a new {@link LocaleChangeServiceImpl} for the given {@link IEclipseContext}.
Expand Down Expand Up @@ -97,9 +93,7 @@ public void changeApplicationLocale(String localeString) {
} catch (Exception e) {
// performing a locale update failed
// there is no locale change performed
if (logService != null)
logService.log(LogService.LOG_ERROR, e.getMessage()
+ " - No Locale change will be performed."); //$NON-NLS-1$
ILog.get().error("No Locale change performed.", e); //$NON-NLS-1$
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.ServiceTracker;

/**
* BundleActivator to access the required OSGi services.
Expand All @@ -58,8 +56,6 @@ public class Activator implements BundleActivator, DebugOptionsListener {

private BundleContext context;

private ServiceTracker<LogService, LogService> logTracker;

/** Tracks all bundles which are in the state: RESOLVED, STARTING, ACTIVE or STOPPING. */
private BundleTracker<List<Bundle>> resolvedBundles;

Expand Down Expand Up @@ -109,10 +105,6 @@ public void start(BundleContext context) throws Exception {

@Override
public void stop(BundleContext context) throws Exception {
if (logTracker != null) {
logTracker.close();
logTracker = null;
}
if (resolvedBundles != null) {
// the close of the BundleTracker will also remove all entries form the BundleFinder
resolvedBundles.close();
Expand Down Expand Up @@ -141,51 +133,4 @@ public DebugTrace getTrace() {
public static void trace(String option, String msg, Throwable error) {
activator.getTrace().trace(option, msg, error);
}

public LogService getLogService() {
LogService logService = null;
if (logTracker != null) {
logService = logTracker.getService();
} else if (context != null) {
logTracker = new ServiceTracker<>(context,
LogService.class.getName(), null);
logTracker.open();
logService = logTracker.getService();
}
if (logService == null) {
throw new IllegalStateException("No LogService is available."); //$NON-NLS-1$
}
return logService;
}

/**
* @param level
* one from {@code LogService} constants
* @see LogService#LOG_ERROR
* @see LogService#LOG_WARNING
* @see LogService#LOG_INFO
* @see LogService#LOG_DEBUG
*/
public static void log(int level, String message) {
LogService logService = activator.getLogService();
if (logService != null) {
logService.log(level, message);
}
}

/**
* @param level
* one from {@code LogService} constants
* @see LogService#LOG_ERROR
* @see LogService#LOG_WARNING
* @see LogService#LOG_INFO
* @see LogService#LOG_DEBUG
*/
public static void log(int level, String message, Throwable exception) {
LogService logService = activator.getLogService();
if (logService != null) {
logService.log(level, message, exception);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
package org.eclipse.e4.ui.internal.workbench;

import java.util.Map;
import org.eclipse.core.runtime.ILog;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.InjectionException;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
import org.eclipse.e4.core.services.contributions.IContributionFactorySpi;
import org.eclipse.emf.common.util.URI;
import org.osgi.framework.Bundle;
import org.osgi.service.log.LogService;

/**
* Create the contribution factory.
Expand All @@ -48,10 +48,9 @@ private Object doCreate(String uriString, IEclipseContext context, IEclipseConte
}
// translate old-style platform:/plugin/ class specifiers into new-style bundleclass:// URIs
if (uriString.startsWith("platform:/plugin/")) { //$NON-NLS-1$
Activator.log(LogService.LOG_ERROR,
"platform-style URIs deprecated for referencing types: " + uriString); //$NON-NLS-1$
ILog.get().error("platform-style URIs deprecated for referencing types: " + uriString); //$NON-NLS-1$
uriString = uriString.replace("platform:/plugin/", "bundleclass://"); //$NON-NLS-1$ //$NON-NLS-2$
Activator.log(LogService.LOG_ERROR, "URI rewritten as: " + uriString); //$NON-NLS-1$
ILog.get().error("URI rewritten as: " + uriString); //$NON-NLS-1$
}
URI uri = URI.createURI(uriString);
Bundle bundle = getBundle(uri);
Expand All @@ -60,7 +59,7 @@ private Object doCreate(String uriString, IEclipseContext context, IEclipseConte
contribution = createFromBundle(bundle, context, staticContext, uri);
} else {
contribution = null;
Activator.log(LogService.LOG_ERROR, "Unable to retrieve the bundle from the URI: " //$NON-NLS-1$
ILog.get().error( "Unable to retrieve the bundle from the URI: " //$NON-NLS-1$
+ uriString);
}
return contribution;
Expand All @@ -74,7 +73,7 @@ protected Object createFromBundle(Bundle bundle, IEclipseContext context,
IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix);
if (factory == null) {
String message = "Unsupported contribution factory type '" + prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$
Activator.log(LogService.LOG_ERROR, message);
ILog.get().error( message);
return null;
}
StringBuilder resource = new StringBuilder(uri.segment(1));
Expand All @@ -96,26 +95,26 @@ protected Object createFromBundle(Bundle bundle, IEclipseContext context,
if (contribution == null) {
String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
Activator.log(LogService.LOG_ERROR, message, new Exception());
ILog.get().error( message, new Exception());
}
} catch (ClassNotFoundException e) {
contribution = null;
String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
Activator.log(LogService.LOG_ERROR, message, e);
ILog.get().error( message, e);
} catch (InjectionException e) {
contribution = null;
String message = "Unable to create class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
Activator.log(LogService.LOG_ERROR, message, e);
ILog.get().error( message, e);
}
}
return contribution;
}

protected Bundle getBundle(URI platformURI) {
if (platformURI.authority() == null) {
Activator.log(LogService.LOG_ERROR, "Failed to get bundle for: " + platformURI); //$NON-NLS-1$
ILog.get().error( "Failed to get bundle for: " + platformURI); //$NON-NLS-1$
return null;
}
return Activator.getDefault().getBundleForName(platformURI.authority());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.spi.RegistryContributor;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.service.log.LogService;

/**
* Collection of URI-related utilities
Expand Down Expand Up @@ -86,7 +86,7 @@ static public Bundle getBundle(String contributorURI) {
try {
uri = new URI(contributorURI);
} catch (URISyntaxException e) {
Activator.log(LogService.LOG_ERROR, "Invalid contributor URI: " + contributorURI); //$NON-NLS-1$
ILog.get().error("Invalid contributor URI: " + contributorURI); //$NON-NLS-1$
return null;
}
if (!PLATFORM_SCHEMA.equals(uri.getScheme()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.core.commands.IParameter;
import org.eclipse.core.commands.ParameterType;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.internal.HandlerServiceImpl;
import org.eclipse.e4.core.services.events.IEventBroker;
Expand Down Expand Up @@ -163,8 +164,7 @@ public void commandManagerChanged(CommandManagerEvent commandManagerEvent) {
categoryModel);
application.getCommands().add(createdCommand);
} catch (NotDefinedException e) {
Activator.getDefault().getLogService()
.log(0, "Failed to create command " + commandId, e); //$NON-NLS-1$
ILog.get().error("Failed to create command " + commandId, e); //$NON-NLS-1$
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package org.eclipse.ui.internal.services;

import static org.osgi.service.log.LogLevel.ERROR;

import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.IEvaluationContext;
Expand Down Expand Up @@ -78,7 +76,7 @@ public boolean evaluate(IEvaluationContext context) {
cache = expression.evaluate(context) != EvaluationResult.FALSE;
} catch (CoreException e) {
String message = "Failed to evaluate: " + expression; //$NON-NLS-1$
boolean logged = logThrottle.log(ERROR.ordinal(), message, e);
boolean logged = logThrottle.error(message, e);
if (!logged && Policy.DEBUG_CMDS) {
Activator.trace(Policy.DEBUG_CMDS_FLAG, message, e);
}
Expand Down
Loading

0 comments on commit c1cf342

Please sign in to comment.