Skip to content

Commit c1cf342

Browse files
committed
e4: use ILog instead of deprecated LogService constants
1 parent c21bef8 commit c1cf342

File tree

11 files changed

+38
-105
lines changed

11 files changed

+38
-105
lines changed

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.core.commands.ParameterizedCommand;
3030
import org.eclipse.core.commands.State;
3131
import org.eclipse.core.commands.common.NotDefinedException;
32+
import org.eclipse.core.runtime.ILog;
3233
import org.eclipse.e4.core.commands.ECommandService;
3334
import org.eclipse.e4.core.commands.EHandlerService;
3435
import org.eclipse.e4.core.commands.internal.HandlerServiceImpl;
@@ -38,7 +39,6 @@
3839
import org.eclipse.e4.core.contexts.IEclipseContext;
3940
import org.eclipse.e4.core.di.annotations.Optional;
4041
import org.eclipse.e4.ui.bindings.EBindingService;
41-
import org.eclipse.e4.ui.internal.workbench.Activator;
4242
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
4343
import org.eclipse.e4.ui.internal.workbench.renderers.swt.IUpdateService;
4444
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
@@ -57,7 +57,6 @@
5757
import org.eclipse.swt.widgets.Event;
5858
import org.eclipse.swt.widgets.MenuItem;
5959
import org.eclipse.swt.widgets.ToolItem;
60-
import org.osgi.service.log.LogService;
6160

6261
public class HandledContributionItem extends AbstractContributionItem {
6362
/**
@@ -246,10 +245,11 @@ protected void updateMenuItem() {
246245
String keyBindingText = null;
247246
if (parmCmd != null) {
248247
if (text == null || text.isEmpty()) {
248+
String localizedCommandName = getModel().getCommand().getLocalizedCommandName();
249249
try {
250-
text = parmCmd.getName(getModel().getCommand().getLocalizedCommandName());
250+
text = parmCmd.getName(localizedCommandName);
251251
} catch (NotDefinedException e) {
252-
Activator.log(LogService.LOG_DEBUG, e.getMessage(), e);
252+
ILog.get().warn("not found: " + localizedCommandName, e); //$NON-NLS-1$
253253
}
254254
}
255255
if (bindingService != null) {

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerServiceFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
import jakarta.inject.Inject;
1717
import java.lang.reflect.Method;
18+
import org.eclipse.core.runtime.ILog;
1819
import org.eclipse.core.runtime.ISafeRunnable;
1920
import org.eclipse.core.runtime.SafeRunner;
2021
import org.eclipse.e4.core.contexts.IEclipseContext;
2122
import org.eclipse.e4.core.services.log.Logger;
22-
import org.eclipse.e4.ui.internal.workbench.Activator;
2323
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
2424
import org.eclipse.e4.ui.internal.workbench.swt.Policy;
2525
import org.eclipse.e4.ui.internal.workbench.swt.WorkbenchSWTActivator;
@@ -32,7 +32,6 @@
3232
import org.eclipse.swt.widgets.Listener;
3333
import org.eclipse.swt.widgets.Menu;
3434
import org.eclipse.swt.widgets.Widget;
35-
import org.osgi.service.log.LogService;
3635

3736
public class MenuManagerServiceFilter implements Listener {
3837
public static final String NUL_MENU_ITEM = "(None Applicable)"; //$NON-NLS-1$
@@ -53,7 +52,7 @@ public static Method getAboutToShow() {
5352
.getDeclaredMethod("handleAboutToShow"); //$NON-NLS-1$
5453
aboutToShow.setAccessible(true);
5554
} catch (SecurityException | NoSuchMethodException e) {
56-
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
55+
ILog.get().error(e.getMessage(), e);
5756
}
5857
}
5958
return aboutToShow;

bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.core.runtime.FileLocator;
3636
import org.eclipse.core.runtime.IConfigurationElement;
3737
import org.eclipse.core.runtime.IExtensionRegistry;
38+
import org.eclipse.core.runtime.ILog;
3839
import org.eclipse.core.runtime.ISafeRunnable;
3940
import org.eclipse.core.runtime.InvalidRegistryObjectException;
4041
import org.eclipse.core.runtime.Platform;
@@ -62,7 +63,6 @@
6263
import org.eclipse.e4.ui.css.swt.theme.IThemeManager;
6364
import org.eclipse.e4.ui.di.Focus;
6465
import org.eclipse.e4.ui.di.PersistState;
65-
import org.eclipse.e4.ui.internal.workbench.Activator;
6666
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
6767
import org.eclipse.e4.ui.model.application.MApplication;
6868
import org.eclipse.e4.ui.model.application.MApplicationElement;
@@ -106,7 +106,6 @@
106106
import org.eclipse.ui.testing.TestableObject;
107107
import org.osgi.service.event.Event;
108108
import org.osgi.service.event.EventHandler;
109-
import org.osgi.service.log.LogService;
110109
import org.w3c.dom.Element;
111110
import org.w3c.dom.css.CSSStyleDeclaration;
112111

@@ -1372,7 +1371,7 @@ public void setClassnameAndId(Object widget, String classname, String id) {
13721371
cssEngine.parseStyleSheet(stream);
13731372
}
13741373
} catch (IOException e) {
1375-
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
1374+
ILog.get().error(e.getMessage(), e);
13761375
}
13771376

13781377
Shell[] shells = display.getShells();
@@ -1382,7 +1381,7 @@ public void setClassnameAndId(Object widget, String classname, String id) {
13821381
s.reskin(SWT.ALL);
13831382
cssEngine.applyStyles(s, true);
13841383
} catch (Exception e) {
1385-
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
1384+
ILog.get().error(e.getMessage(), e);
13861385
} finally {
13871386
s.setRedraw(true);
13881387
}
@@ -1470,7 +1469,7 @@ protected Set<IEclipsePreferences> getThemeRelatedPreferences() {
14701469
bundleIDs.add(nameSpace);
14711470
}
14721471
} catch (InvalidRegistryObjectException e) {
1473-
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
1472+
ILog.get().error( e.getMessage(), e);
14741473
}
14751474
}
14761475
}

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import jakarta.inject.Inject;
1818
import java.util.List;
1919
import java.util.Locale;
20+
import org.eclipse.core.runtime.ILog;
2021
import org.eclipse.e4.core.contexts.IEclipseContext;
21-
import org.eclipse.e4.core.di.annotations.Optional;
2222
import org.eclipse.e4.core.internal.services.ResourceBundleHelper;
2323
import org.eclipse.e4.core.services.events.IEventBroker;
2424
import org.eclipse.e4.core.services.nls.ILocaleChangeService;
@@ -34,7 +34,6 @@
3434
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
3535
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
3636
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
37-
import org.osgi.service.log.LogService;
3837

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

53-
@Inject
54-
@Optional
55-
LogService logService;
5652

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

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Activator.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
import org.osgi.framework.Bundle;
4242
import org.osgi.framework.BundleActivator;
4343
import org.osgi.framework.BundleContext;
44-
import org.osgi.service.log.LogService;
4544
import org.osgi.util.tracker.BundleTracker;
46-
import org.osgi.util.tracker.ServiceTracker;
4745

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

5957
private BundleContext context;
6058

61-
private ServiceTracker<LogService, LogService> logTracker;
62-
6359
/** Tracks all bundles which are in the state: RESOLVED, STARTING, ACTIVE or STOPPING. */
6460
private BundleTracker<List<Bundle>> resolvedBundles;
6561

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

110106
@Override
111107
public void stop(BundleContext context) throws Exception {
112-
if (logTracker != null) {
113-
logTracker.close();
114-
logTracker = null;
115-
}
116108
if (resolvedBundles != null) {
117109
// the close of the BundleTracker will also remove all entries form the BundleFinder
118110
resolvedBundles.close();
@@ -141,51 +133,4 @@ public DebugTrace getTrace() {
141133
public static void trace(String option, String msg, Throwable error) {
142134
activator.getTrace().trace(option, msg, error);
143135
}
144-
145-
public LogService getLogService() {
146-
LogService logService = null;
147-
if (logTracker != null) {
148-
logService = logTracker.getService();
149-
} else if (context != null) {
150-
logTracker = new ServiceTracker<>(context,
151-
LogService.class.getName(), null);
152-
logTracker.open();
153-
logService = logTracker.getService();
154-
}
155-
if (logService == null) {
156-
throw new IllegalStateException("No LogService is available."); //$NON-NLS-1$
157-
}
158-
return logService;
159-
}
160-
161-
/**
162-
* @param level
163-
* one from {@code LogService} constants
164-
* @see LogService#LOG_ERROR
165-
* @see LogService#LOG_WARNING
166-
* @see LogService#LOG_INFO
167-
* @see LogService#LOG_DEBUG
168-
*/
169-
public static void log(int level, String message) {
170-
LogService logService = activator.getLogService();
171-
if (logService != null) {
172-
logService.log(level, message);
173-
}
174-
}
175-
176-
/**
177-
* @param level
178-
* one from {@code LogService} constants
179-
* @see LogService#LOG_ERROR
180-
* @see LogService#LOG_WARNING
181-
* @see LogService#LOG_INFO
182-
* @see LogService#LOG_DEBUG
183-
*/
184-
public static void log(int level, String message, Throwable exception) {
185-
LogService logService = activator.getLogService();
186-
if (logService != null) {
187-
logService.log(level, message, exception);
188-
}
189-
}
190-
191136
}

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ReflectionContributionFactory.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
package org.eclipse.e4.ui.internal.workbench;
1717

1818
import java.util.Map;
19+
import org.eclipse.core.runtime.ILog;
1920
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
2021
import org.eclipse.e4.core.contexts.IEclipseContext;
2122
import org.eclipse.e4.core.di.InjectionException;
2223
import org.eclipse.e4.core.services.contributions.IContributionFactory;
2324
import org.eclipse.e4.core.services.contributions.IContributionFactorySpi;
2425
import org.eclipse.emf.common.util.URI;
2526
import org.osgi.framework.Bundle;
26-
import org.osgi.service.log.LogService;
2727

2828
/**
2929
* Create the contribution factory.
@@ -48,10 +48,9 @@ private Object doCreate(String uriString, IEclipseContext context, IEclipseConte
4848
}
4949
// translate old-style platform:/plugin/ class specifiers into new-style bundleclass:// URIs
5050
if (uriString.startsWith("platform:/plugin/")) { //$NON-NLS-1$
51-
Activator.log(LogService.LOG_ERROR,
52-
"platform-style URIs deprecated for referencing types: " + uriString); //$NON-NLS-1$
51+
ILog.get().error("platform-style URIs deprecated for referencing types: " + uriString); //$NON-NLS-1$
5352
uriString = uriString.replace("platform:/plugin/", "bundleclass://"); //$NON-NLS-1$ //$NON-NLS-2$
54-
Activator.log(LogService.LOG_ERROR, "URI rewritten as: " + uriString); //$NON-NLS-1$
53+
ILog.get().error("URI rewritten as: " + uriString); //$NON-NLS-1$
5554
}
5655
URI uri = URI.createURI(uriString);
5756
Bundle bundle = getBundle(uri);
@@ -60,7 +59,7 @@ private Object doCreate(String uriString, IEclipseContext context, IEclipseConte
6059
contribution = createFromBundle(bundle, context, staticContext, uri);
6160
} else {
6261
contribution = null;
63-
Activator.log(LogService.LOG_ERROR, "Unable to retrieve the bundle from the URI: " //$NON-NLS-1$
62+
ILog.get().error( "Unable to retrieve the bundle from the URI: " //$NON-NLS-1$
6463
+ uriString);
6564
}
6665
return contribution;
@@ -74,7 +73,7 @@ protected Object createFromBundle(Bundle bundle, IEclipseContext context,
7473
IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix);
7574
if (factory == null) {
7675
String message = "Unsupported contribution factory type '" + prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$
77-
Activator.log(LogService.LOG_ERROR, message);
76+
ILog.get().error( message);
7877
return null;
7978
}
8079
StringBuilder resource = new StringBuilder(uri.segment(1));
@@ -96,26 +95,26 @@ protected Object createFromBundle(Bundle bundle, IEclipseContext context,
9695
if (contribution == null) {
9796
String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
9897
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
99-
Activator.log(LogService.LOG_ERROR, message, new Exception());
98+
ILog.get().error( message, new Exception());
10099
}
101100
} catch (ClassNotFoundException e) {
102101
contribution = null;
103102
String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
104103
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
105-
Activator.log(LogService.LOG_ERROR, message, e);
104+
ILog.get().error( message, e);
106105
} catch (InjectionException e) {
107106
contribution = null;
108107
String message = "Unable to create class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
109108
+ bundle.getBundleId() + "'"; //$NON-NLS-1$
110-
Activator.log(LogService.LOG_ERROR, message, e);
109+
ILog.get().error( message, e);
111110
}
112111
}
113112
return contribution;
114113
}
115114

116115
protected Bundle getBundle(URI platformURI) {
117116
if (platformURI.authority() == null) {
118-
Activator.log(LogService.LOG_ERROR, "Failed to get bundle for: " + platformURI); //$NON-NLS-1$
117+
ILog.get().error( "Failed to get bundle for: " + platformURI); //$NON-NLS-1$
119118
return null;
120119
}
121120
return Activator.getDefault().getBundleForName(platformURI.authority());

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/URIHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import java.net.URI;
2020
import java.net.URISyntaxException;
2121
import org.eclipse.core.runtime.IContributor;
22+
import org.eclipse.core.runtime.ILog;
2223
import org.eclipse.core.runtime.spi.RegistryContributor;
2324
import org.osgi.framework.Bundle;
2425
import org.osgi.framework.wiring.BundleRevision;
25-
import org.osgi.service.log.LogService;
2626

2727
/**
2828
* Collection of URI-related utilities
@@ -86,7 +86,7 @@ static public Bundle getBundle(String contributorURI) {
8686
try {
8787
uri = new URI(contributorURI);
8888
} catch (URISyntaxException e) {
89-
Activator.log(LogService.LOG_ERROR, "Invalid contributor URI: " + contributorURI); //$NON-NLS-1$
89+
ILog.get().error("Invalid contributor URI: " + contributorURI); //$NON-NLS-1$
9090
return null;
9191
}
9292
if (!PLATFORM_SCHEMA.equals(uri.getScheme()))

bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/addons/CommandProcessingAddon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.core.commands.IParameter;
2929
import org.eclipse.core.commands.ParameterType;
3030
import org.eclipse.core.commands.common.NotDefinedException;
31+
import org.eclipse.core.runtime.ILog;
3132
import org.eclipse.e4.core.commands.ECommandService;
3233
import org.eclipse.e4.core.commands.internal.HandlerServiceImpl;
3334
import org.eclipse.e4.core.services.events.IEventBroker;
@@ -163,8 +164,7 @@ public void commandManagerChanged(CommandManagerEvent commandManagerEvent) {
163164
categoryModel);
164165
application.getCommands().add(createdCommand);
165166
} catch (NotDefinedException e) {
166-
Activator.getDefault().getLogService()
167-
.log(0, "Failed to create command " + commandId, e); //$NON-NLS-1$
167+
ILog.get().error("Failed to create command " + commandId, e); //$NON-NLS-1$
168168
}
169169
}
170170
}

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationReference.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package org.eclipse.ui.internal.services;
1616

17-
import static org.osgi.service.log.LogLevel.ERROR;
18-
1917
import org.eclipse.core.expressions.EvaluationResult;
2018
import org.eclipse.core.expressions.Expression;
2119
import org.eclipse.core.expressions.IEvaluationContext;
@@ -78,7 +76,7 @@ public boolean evaluate(IEvaluationContext context) {
7876
cache = expression.evaluate(context) != EvaluationResult.FALSE;
7977
} catch (CoreException e) {
8078
String message = "Failed to evaluate: " + expression; //$NON-NLS-1$
81-
boolean logged = logThrottle.log(ERROR.ordinal(), message, e);
79+
boolean logged = logThrottle.error(message, e);
8280
if (!logged && Policy.DEBUG_CMDS) {
8381
Activator.trace(Policy.DEBUG_CMDS_FLAG, message, e);
8482
}

0 commit comments

Comments
 (0)