diff options
author | Hannes Wellmann | 2021-07-22 19:39:44 +0000 |
---|---|---|
committer | Lars Vogel | 2021-07-26 09:25:47 +0000 |
commit | 753a02d1552e5dc2fbbdba626f8e229979fd969e (patch) | |
tree | bbb08562023bfe13f5429226a3ab7828ce656161 | |
parent | a539ccb597d0fb66d57786679a75fa3bbc588dd4 (diff) | |
download | rt.equinox.framework-753a02d1552e5dc2fbbdba626f8e229979fd969e.tar.gz rt.equinox.framework-753a02d1552e5dc2fbbdba626f8e229979fd969e.tar.xz rt.equinox.framework-753a02d1552e5dc2fbbdba626f8e229979fd969e.zip |
Bug 574872 - [Clean-up] Use lambda where possible in tests (2)
Clean up using the JDT clean-up:
- Convert functional interface instances: Use lambda where possible
Change-Id: I3f97cc918bb332bfe33c6e6c4002f73b6214fc30
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/183301
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
28 files changed, 690 insertions, 1086 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java index 1c1057fe0..fb9650e23 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,7 +14,6 @@ package org.eclipse.osgi.tests.hooks.framework.activator.a; import java.util.List; -import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; import org.eclipse.osgi.internal.hookregistry.HookConfigurator; import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.osgi.framework.BundleActivator; @@ -25,25 +24,19 @@ public class TestHookConfigurator1 implements HookConfigurator { public static volatile List<String> events; public void addHooks(HookRegistry hookRegistry) { - hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { - + hookRegistry.addActivatorHookFactory(() -> new BundleActivator() { @Override - public BundleActivator createActivator() { - return new BundleActivator() { - @Override - public void start(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK1 STARTED"); - } - } + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK1 STARTED"); + } + } - @Override - public void stop(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK1 STOPPED"); - } - } - }; + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK1 STOPPED"); + } } }); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java index b9724a59c..a02f58375 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,7 +14,6 @@ package org.eclipse.osgi.tests.hooks.framework.activator.a; import java.util.List; -import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; import org.eclipse.osgi.internal.hookregistry.HookConfigurator; import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.osgi.framework.BundleActivator; @@ -25,25 +24,19 @@ public class TestHookConfigurator2 implements HookConfigurator { @Override public void addHooks(HookRegistry hookRegistry) { - hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { - + hookRegistry.addActivatorHookFactory(() -> new BundleActivator() { @Override - public BundleActivator createActivator() { - return new BundleActivator() { - @Override - public void start(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK2 STARTED"); - } - } + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK2 STARTED"); + } + } - @Override - public void stop(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK2 STOPPED"); - } - } - }; + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK2 STOPPED"); + } } }); diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java index 85e2bfec3..69bd8999d 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,7 +14,6 @@ package org.eclipse.osgi.tests.hooks.framework.activator.a; import java.util.List; -import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; import org.eclipse.osgi.internal.hookregistry.HookConfigurator; import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.osgi.framework.BundleActivator; @@ -25,25 +24,19 @@ public class TestHookConfigurator3 implements HookConfigurator { @Override public void addHooks(HookRegistry hookRegistry) { - hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { - + hookRegistry.addActivatorHookFactory(() -> new BundleActivator() { @Override - public BundleActivator createActivator() { - return new BundleActivator() { - @Override - public void start(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK3 STARTED"); - } - } + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK3 STARTED"); + } + } - @Override - public void stop(BundleContext context) throws Exception { - if (events != null) { - events.add("HOOK3 STOPPED"); - } - } - }; + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK3 STOPPED"); + } } }); diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java index faff555b8..544238524 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/geturl/geturl/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2016 IBM Corporation and others. + * Copyright (c) 2010, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -28,30 +28,26 @@ public class Activator implements BundleActivator { final String urlSpec = (String) System.getProperties().get("test.url.spec"); Dictionary props = new Hashtable(); props.put("test.url", url); - context.registerService(PrivilegedAction.class, new PrivilegedAction() { - - @Override - public Object run() { - try { - throw new RuntimeException("Expected to fail to create: " + new URL(urlSpec)); - } catch (MalformedURLException e) { - // expected; the parseURL will cause this to fail - } - try { - new URL(url.getProtocol(), url.getHost(), url.getFile()); - } catch (MalformedURLException e) { - // unexpected; the handler does not get involved and we have a multiplexor cached - throw new RuntimeException("Could not create URL from parts: " + url); - } - url.toExternalForm(); + context.registerService(PrivilegedAction.class, () -> { + try { + throw new RuntimeException("Expected to fail to create: " + new URL(urlSpec)); + } catch (MalformedURLException e1) { + // expected; the parseURL will cause this to fail + } + try { + new URL(url.getProtocol(), url.getHost(), url.getFile()); + } catch (MalformedURLException e2) { + // unexpected; the handler does not get involved and we have a multiplexor cached + throw new RuntimeException("Could not create URL from parts: " + url); + } + url.toExternalForm(); - try { - url.openConnection(Proxy.NO_PROXY); - } catch (IOException e) { - // expected since our impl throws this - } - return Boolean.TRUE; + try { + url.openConnection(Proxy.NO_PROXY); + } catch (IOException e3) { + // expected since our impl throws this } + return Boolean.TRUE; }, props); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java index 684b93e1a..3a53f1726 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java @@ -32,7 +32,6 @@ import org.eclipse.osgi.container.Module; import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent; import org.eclipse.osgi.container.ModuleRevisionBuilder; import org.eclipse.osgi.container.ModuleRevisionBuilder.GenericInfo; -import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; import org.eclipse.osgi.internal.hookregistry.HookConfigurator; import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.eclipse.osgi.internal.hookregistry.StorageHookFactory; @@ -177,21 +176,15 @@ public class TestHookConfigurator implements HookConfigurator { public void addHooks(HookRegistry hookRegistry) { hookRegistry.addStorageHookFactory(new TestStorageHookFactory()); - hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { - + hookRegistry.addActivatorHookFactory(() -> new BundleActivator() { @Override - public BundleActivator createActivator() { - return new BundleActivator() { - @Override - public void start(BundleContext context) throws Exception { - TestHelper.setBundle(context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)); - } + public void start(BundleContext context) throws Exception { + TestHelper.setBundle(context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)); + } - @Override - public void stop(BundleContext context) throws Exception { - TestHelper.setBundle(null); - } - }; + @Override + public void stop(BundleContext context) throws Exception { + TestHelper.setBundle(null); } }); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/test.filter.a/test/filter/a/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/test.filter.a/test/filter/a/Activator.java index e661b9cbb..c32bb26d3 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/test.filter.a/test/filter/a/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/test.filter.a/test/filter/a/Activator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -22,11 +22,7 @@ public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { final boolean[] serviceChanged = {false}; - ServiceListener listener = new ServiceListener() { - public void serviceChanged(ServiceEvent event) { - serviceChanged[0] = true; - } - }; + ServiceListener listener = event -> serviceChanged[0] = true; context.addServiceListener(listener, "(&(objectClass=java.lang.String)(test=*))"); final boolean[] modifiedService = {false}; ServiceTracker tracker = new ServiceTracker(context, FrameworkUtil.createFilter("(&(objectClass=java.lang.String)(test=*))"), new ServiceTrackerCustomizer() { diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/org/eclipse/osgi/tests/wrapper/hooks/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/org/eclipse/osgi/tests/wrapper/hooks/a/TestHookConfigurator.java index ad8a83f7c..731832b7a 100755 --- a/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/org/eclipse/osgi/tests/wrapper/hooks/a/TestHookConfigurator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/wrapper.hooks.a/org/eclipse/osgi/tests/wrapper/hooks/a/TestHookConfigurator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 IBM Corporation and others. + * Copyright (c) 2015, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -17,72 +17,60 @@ import java.io.*; import java.net.*; import org.eclipse.osgi.container.Module; import org.eclipse.osgi.internal.hookregistry.*; -import org.eclipse.osgi.storage.BundleInfo.Generation; import org.eclipse.osgi.storage.bundlefile.*; public class TestHookConfigurator implements HookConfigurator { public void addHooks(HookRegistry hookRegistry) { - BundleFileWrapperFactoryHook modifyContent = new BundleFileWrapperFactoryHook() { + BundleFileWrapperFactoryHook modifyContent = (bundleFile, generation, base) -> new BundleFileWrapper(bundleFile) { @Override - public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) { - return new BundleFileWrapper(bundleFile) { - - @Override - public BundleEntry getEntry(String path) { - final BundleEntry original = super.getEntry(path); - final byte[] content = "CUSTOM_CONTENT".getBytes(); - if ("data/resource1".equals(path)) { - return new BundleEntry() { - - @Override - public long getTime() { - return original.getTime(); - } - - @Override - public long getSize() { - return content.length; - } - - @Override - public String getName() { - return original.getName(); - } - - @Override - public URL getLocalURL() { - return original.getLocalURL(); - } - - /** - * @throws IOException - */ - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(content); - } - - @Override - public URL getFileURL() { - return original.getFileURL(); - } - }; + public BundleEntry getEntry(String path) { + final BundleEntry original = super.getEntry(path); + final byte[] content = "CUSTOM_CONTENT".getBytes(); + if ("data/resource1".equals(path)) { + return new BundleEntry() { + + @Override + public long getTime() { + return original.getTime(); } - return original; - } - }; + @Override + public long getSize() { + return content.length; + } + + @Override + public String getName() { + return original.getName(); + } + + @Override + public URL getLocalURL() { + return original.getLocalURL(); + } + + /** + * @throws IOException + */ + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(content); + } + + @Override + public URL getFileURL() { + return original.getFileURL(); + } + }; + } + return original; } + }; - BundleFileWrapperFactoryHook noop = new BundleFileWrapperFactoryHook() { - @Override - public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) { - return new BundleFileWrapper(bundleFile) { - // Do nothing to test multiple wrappers - }; - } + BundleFileWrapperFactoryHook noop = (bundleFile, generation, base) -> new BundleFileWrapper(bundleFile) { + // Do nothing to test multiple wrappers }; // add no-op before the getResourceURL override hookRegistry.addBundleFileWrapperFactoryHook(noop); @@ -90,39 +78,33 @@ public class TestHookConfigurator implements HookConfigurator { // add a hook that modifies content hookRegistry.addBundleFileWrapperFactoryHook(modifyContent); - hookRegistry.addBundleFileWrapperFactoryHook(new BundleFileWrapperFactoryHook() { + hookRegistry.addBundleFileWrapperFactoryHook((bundleFile, generation, base) -> new BundleFileWrapper(bundleFile) { + @Override + public URL getResourceURL(String path, Module hostModule, int index) { + // just making sure the wrapper getResourceURL is never called + throw new RuntimeException("Should not be called"); + } @Override - public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) { - return new BundleFileWrapper(bundleFile) { - @Override - public URL getResourceURL(String path, Module hostModule, int index) { - // just making sure the wrapper getResourceURL is never called - throw new RuntimeException("Should not be called"); - } - - @Override - protected URL createResourceURL(BundleEntry bundleEntry, Module hostModule, int index, String path) { - final URL url = super.createResourceURL(bundleEntry, hostModule, index, path); - if (url == null) { - return null; - } - try { - return new URL("custom", "custom", 0, path, new URLStreamHandler() { - - @Override - protected URLConnection openConnection(URL u) throws IOException { - // TODO Auto-generated method stub - return url.openConnection(); - } - }); - } catch (MalformedURLException e) { - throw new RuntimeException(e); + protected URL createResourceURL(BundleEntry bundleEntry, Module hostModule, int index, String path) { + final URL url = super.createResourceURL(bundleEntry, hostModule, index, path); + if (url == null) { + return null; + } + try { + return new URL("custom", "custom", 0, path, new URLStreamHandler() { + + @Override + protected URLConnection openConnection(URL u) throws IOException { + // TODO Auto-generated method stub + return url.openConnection(); } - } - - }; + }); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } } + }); // And add no-op after diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java index 179e0317f..ce61ce47b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogReaderServiceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2015 Cognos Incorporated, IBM Corporation and others + * Copyright (c) 2012, 2021 Cognos Incorporated, IBM Corporation and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 which @@ -19,17 +19,13 @@ import java.util.Map; import org.eclipse.equinox.log.ExtendedLogEntry; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; -import org.eclipse.equinox.log.LogFilter; import org.eclipse.equinox.log.SynchronousLogListener; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogEntry; import org.osgi.service.log.LogLevel; -import org.osgi.service.log.LogListener; import org.osgi.service.log.LogService; import org.osgi.service.log.Logger; import org.osgi.service.log.admin.LoggerAdmin; @@ -76,11 +72,7 @@ public class ExtendedLogReaderServiceTest { @Test public void testaddFilteredListener() throws Exception { TestListener listener = new TestListener(); - reader.addLogListener(listener, new LogFilter() { - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - return true; - } - }); + reader.addLogListener(listener, (b, loggerName, logLevel) -> true); log.log(LogService.LOG_INFO, "info"); assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO); } @@ -100,20 +92,12 @@ public class ExtendedLogReaderServiceTest { @Test public void testaddFilteredListenerTwice() throws Exception { TestListener listener = new TestListener(); - reader.addLogListener(listener, new LogFilter() { - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - return false; - } - }); + reader.addLogListener(listener, (b, loggerName, logLevel) -> false); if (log.isLoggable(LogService.LOG_INFO)) fail(); - reader.addLogListener(listener, new LogFilter() { - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - return true; - } - }); + reader.addLogListener(listener, (b, loggerName, logLevel) -> true); log.log(LogService.LOG_INFO, "info"); assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO); } @@ -131,10 +115,8 @@ public class ExtendedLogReaderServiceTest { @Test public void testBadFilter() throws Exception { TestListener listener = new TestListener(); - reader.addLogListener(listener, new LogFilter() { - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - throw new RuntimeException("Expected error for testBadFilter."); - } + reader.addLogListener(listener, (b, loggerName, logLevel) -> { + throw new RuntimeException("Expected error for testBadFilter."); }); if (log.isLoggable(LogService.LOG_INFO)) @@ -145,11 +127,9 @@ public class ExtendedLogReaderServiceTest { public void testSynchronousLogListener() throws Exception { final Thread loggerThread = Thread.currentThread(); called = false; - LogListener listener = new SynchronousLogListener() { - public void logged(LogEntry entry) { - assertTrue(Thread.currentThread() == loggerThread); - called = true; - } + SynchronousLogListener listener = entry -> { + assertTrue(Thread.currentThread() == loggerThread); + called = true; }; reader.addLogListener(listener); log.log(LogService.LOG_INFO, "info"); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java index 116b8c43f..9d0e88177 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/ExtendedLogServiceTest.java @@ -1,9 +1,9 @@ /******************************************************************************* -s -s This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License 2.0 which accompanies this distribution, and is - * available at + * Copyright (c) 2007, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 @@ -21,7 +21,6 @@ import java.util.Map; import org.eclipse.equinox.log.ExtendedLogEntry; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; -import org.eclipse.equinox.log.LogFilter; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.After; import org.junit.Before; @@ -112,12 +111,7 @@ public class ExtendedLogServiceTest { @Test public void testNotIsLoggableWithListener() throws Exception { - reader.addLogListener(listener, new LogFilter() { - - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - return false; - } - }); + reader.addLogListener(listener, (b, loggerName, logLevel) -> false); if (log.isLoggable(LogService.LOG_INFO)) fail(); } @@ -188,13 +182,10 @@ public class ExtendedLogServiceTest { @Test public void testLoggerIsLoggableTrue() throws Exception { - reader.addLogListener(listener, new LogFilter() { - - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - if (loggerName.equals("test")) - return true; - return false; - } + reader.addLogListener(listener, (b, loggerName, logLevel) -> { + if (loggerName.equals("test")) + return true; + return false; }); if (!log.getLogger("test").isLoggable(LogService.LOG_INFO)) fail(); @@ -202,13 +193,10 @@ public class ExtendedLogServiceTest { @Test public void testLoggerNotIsLoggableWithListener() throws Exception { - reader.addLogListener(listener, new LogFilter() { - - public boolean isLoggable(Bundle b, String loggerName, int logLevel) { - if (loggerName.equals("test")) - return false; - return true; - } + reader.addLogListener(listener, (b, loggerName, logLevel) -> { + if (loggerName.equals("test")) + return false; + return true; }); if (log.getLogger("test").isLoggable(LogService.LOG_INFO)) fail(); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java index 301d7aa33..c123406ff 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java @@ -1,9 +1,9 @@ /******************************************************************************* -s -s This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License 2.0 which accompanies this distribution, and is - * available at + * Copyright (c) 2007, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 @@ -161,12 +161,9 @@ public class LogReaderServiceTest extends AbstractBundleTests { // this is just a bundle that is harmless to start/stop final Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$ final AtomicReference<Thread> logThread = new AtomicReference<>(); - LogListener listener = new SynchronousLogListener() { - @Override - public void logged(LogEntry entry) { - if (entry.getBundle() == testBundle) { - logThread.compareAndSet(null, Thread.currentThread()); - } + SynchronousLogListener listener = entry -> { + if (entry.getBundle() == testBundle) { + logThread.compareAndSet(null, Thread.currentThread()); } }; reader.addLogListener(listener); @@ -202,13 +199,10 @@ public class LogReaderServiceTest extends AbstractBundleTests { Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$ final AtomicReference<LogEntry> logEntry = new AtomicReference<>(); final CountDownLatch countDown = new CountDownLatch(1); - LogListener listener = new LogListener() { - @Override - public void logged(LogEntry entry) { - if ((entry.getLoggerName()).startsWith("Events.Framework.")) { - logEntry.set(entry); - countDown.countDown(); - } + LogListener listener = entry -> { + if ((entry.getLoggerName()).startsWith("Events.Framework.")) { + logEntry.set(entry); + countDown.countDown(); } }; reader.addLogListener(listener); @@ -229,13 +223,10 @@ public class LogReaderServiceTest extends AbstractBundleTests { final List<LogEntry> events = new CopyOnWriteArrayList<>(); final CountDownLatch countDown = new CountDownLatch(3); final Bundle b = getContext().getBundle(); - LogListener listener = new LogListener() { - @Override - public void logged(LogEntry entry) { - if (b.equals(entry.getBundle())) { - events.add(entry); - countDown.countDown(); - } + LogListener listener = entry -> { + if (b.equals(entry.getBundle())) { + events.add(entry); + countDown.countDown(); } }; reader.addLogListener(listener); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java index b84b956df..0eee66054 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 IBM Corporation and others. + * Copyright (c) 2007, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -330,17 +330,14 @@ public class ApplicationAdminTest extends OSGiTest { } assertNotNull("app handle is null", handle); //$NON-NLS-1$ final ApplicationHandle destroyHandle = handle; - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(1000); - destroyHandle.destroy(); - } catch (InterruptedException e) { - // nothing - } - + new Thread(() -> { + try { + Thread.sleep(1000); + destroyHandle.destroy(); + } catch (InterruptedException e) { + // nothing } + }).start(); String value = null; try { @@ -588,17 +585,14 @@ public class ApplicationAdminTest extends OSGiTest { } assertNotNull("app handle is null", handle); //$NON-NLS-1$ final ApplicationHandle destroyHandle = handle; - new Thread(new Runnable() { - @Override - public void run() { - try { - Thread.sleep(1000); - destroyHandle.destroy(); - } catch (InterruptedException e) { - // nothing - } - + new Thread(() -> { + try { + Thread.sleep(1000); + destroyHandle.destroy(); + } catch (InterruptedException e) { + // nothing } + }).start(); String value = null; try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java index 0d3facb28..7d2d6c2c5 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2020 IBM Corporation and others. + * Copyright (c) 2006, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -312,12 +312,7 @@ public class AbstractBundleTests extends CoreTest { final Exception[] failureException = new BundleException[1]; final FrameworkEvent[] success = new FrameworkEvent[] { null }; final String uuid = getUUID(equinox); - Thread waitForUpdate = new Thread(new Runnable() { - @Override - public void run() { - success[0] = waitForStop(equinox, uuid, false, 10000); - } - }, "test waitForStop thread"); //$NON-NLS-1$ + Thread waitForUpdate = new Thread((Runnable) () -> success[0] = waitForStop(equinox, uuid, false, 10000), "test waitForStop thread"); //$NON-NLS-1$ waitForUpdate.start(); try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java index 4c4a5a467..b6e0c6a95 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 IBM Corporation and others. + * Copyright (c) 2009, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -23,7 +23,6 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -267,11 +266,7 @@ public class BundleInstallUpdateTests extends AbstractBundleTests { junk = null; } - CollisionHook hook = new CollisionHook() { - public void filterCollisions(int operationType, Bundle target, Collection collisionCandidates) { - collisionCandidates.clear(); - } - }; + CollisionHook hook = (operationType, target, collisionCandidates) -> collisionCandidates.clear(); ServiceRegistration reg = OSGiTestsActivator.getContext().registerService(CollisionHook.class, hook, null); try { try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java index fd4da8e9c..9d05d27fc 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2016 IBM Corporation and others. + * Copyright (c) 2006, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -64,12 +64,7 @@ public class BundleInstaller { if (System.getSecurityManager() == null) return getBundleLocation0(name); try { - return (String) AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Object run() throws Exception { - return getBundleLocation0(name); - } - }); + return (String) AccessController.doPrivileged((PrivilegedExceptionAction) () -> getBundleLocation0(name)); } catch (PrivilegedActionException e) { throw (BundleException) e.getException(); } @@ -169,22 +164,16 @@ public class BundleInstaller { return null; PackageAdmin pa = (PackageAdmin) packageAdmin.getService(); final boolean[] flag = new boolean[] {false}; - FrameworkListener listener = new FrameworkListener() { - public void frameworkEvent(FrameworkEvent event) { - if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) - synchronized (flag) { - flag[0] = true; - flag.notifyAll(); - } - } + FrameworkListener listener = event -> { + if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) + synchronized (flag) { + flag[0] = true; + flag.notifyAll(); + } }; context.addFrameworkListener(listener); final HashSet refreshed = new HashSet(); - BundleListener refreshBundleListener = new SynchronousBundleListener() { - public void bundleChanged(BundleEvent event) { - refreshed.add(event.getBundle()); - } - }; + SynchronousBundleListener refreshBundleListener = event -> refreshed.add(event.getBundle()); context.addBundleListener(refreshBundleListener); try { pa.refreshPackages(refresh); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java index 0e7f0d367..e12ce5674 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2020 IBM Corporation and others. + * Copyright (c) 2006, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -51,11 +51,9 @@ import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.Bundle; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; -import org.osgi.framework.BundleListener; import org.osgi.framework.BundleReference; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkEvent; -import org.osgi.framework.FrameworkListener; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceReference; @@ -602,15 +600,12 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { final Bundle osgiE = installer.installBundle("osgi.lazystart.e"); //$NON-NLS-1$ assertTrue("osgi lazy start resolve", installer.resolveBundles(new Bundle[] {osgiD, osgiE})); //$NON-NLS-1$ - Thread t = new Thread(new Runnable() { - @Override - public void run() { - try { - osgiD.loadClass("osgi.lazystart.d.DTest"); - } catch (ClassNotFoundException e) { - // should fail here - throw new RuntimeException(e); - } + Thread t = new Thread((Runnable) () -> { + try { + osgiD.loadClass("osgi.lazystart.d.DTest"); + } catch (ClassNotFoundException e) { + // should fail here + throw new RuntimeException(e); } }, "Starting: " + osgiD); t.start(); @@ -878,16 +873,13 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { public void testBug258659_01() throws Exception { // install a bundle Bundle osgiA = installer.installBundle("osgi.lazystart.a"); //$NON-NLS-1$ - SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() { - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.LAZY_ACTIVATION) - try { - event.getBundle().loadClass("osgi.lazystart.a.ATest"); //$NON-NLS-1$ - } catch (ClassNotFoundException e) { - simpleResults.addEvent(e); - } - } - + SynchronousBundleListener testLoadClassListener = event -> { + if (event.getType() == BundleEvent.LAZY_ACTIVATION) + try { + event.getBundle().loadClass("osgi.lazystart.a.ATest"); //$NON-NLS-1$ + } catch (ClassNotFoundException e) { + simpleResults.addEvent(e); + } }; OSGiTestsActivator.getContext().addBundleListener(testLoadClassListener); try { @@ -905,16 +897,13 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { // install a bundle Bundle osgiA = installer.installBundle("osgi.lazystart.a"); //$NON-NLS-1$ osgiA.start(Bundle.START_ACTIVATION_POLICY); - SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() { - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.LAZY_ACTIVATION) - try { - event.getBundle().loadClass("osgi.lazystart.a.ATest"); //$NON-NLS-1$ - } catch (ClassNotFoundException e) { - simpleResults.addEvent(e); - } - } - + SynchronousBundleListener testLoadClassListener = event -> { + if (event.getType() == BundleEvent.LAZY_ACTIVATION) + try { + event.getBundle().loadClass("osgi.lazystart.a.ATest"); //$NON-NLS-1$ + } catch (ClassNotFoundException e) { + simpleResults.addEvent(e); + } }; OSGiTestsActivator.getContext().addBundleListener(testLoadClassListener); try { @@ -931,16 +920,13 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { public void testBug258659_03() throws Exception { // install a bundle Bundle test = installer.installBundle("test"); //$NON-NLS-1$ - SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() { - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STARTED) - try { - event.getBundle().stop(); - } catch (BundleException e) { - simpleResults.addEvent(e); - } - } - + SynchronousBundleListener testLoadClassListener = event -> { + if (event.getType() == BundleEvent.STARTED) + try { + event.getBundle().stop(); + } catch (BundleException e) { + simpleResults.addEvent(e); + } }; OSGiTestsActivator.getContext().addBundleListener(testLoadClassListener); try { @@ -959,16 +945,13 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { // install a bundle Bundle test = installer.installBundle("test"); //$NON-NLS-1$ test.start(); - SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() { - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STARTED) - try { - event.getBundle().stop(); - } catch (BundleException e) { - simpleResults.addEvent(e); - } - } - + SynchronousBundleListener testLoadClassListener = event -> { + if (event.getType() == BundleEvent.STARTED) + try { + event.getBundle().stop(); + } catch (BundleException e) { + simpleResults.addEvent(e); + } }; // clear the results from the initial start simpleResults.getResults(0); @@ -1935,25 +1918,21 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { public void testBug348805() { final boolean[] endCalled = {false}; - ResolverHookFactory error = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // Nothing - } + ResolverHookFactory error = triggers -> new ResolverHook() { + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // Nothing + } - public void filterResolvable(Collection candidates) { - throw new RuntimeException("Error"); - } + public void filterResolvable(Collection candidates) { + throw new RuntimeException("Error"); + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // Nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // Nothing + } - public void end() { - endCalled[0] = true; - } - }; + public void end() { + endCalled[0] = true; } }; ServiceRegistration reg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null); @@ -1975,25 +1954,21 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { } public void testBug348806() { - ResolverHookFactory error = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // Nothing - } + ResolverHookFactory error = triggers -> new ResolverHook() { + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // Nothing + } - public void filterResolvable(Collection candidates) { - // Nothing - } + public void filterResolvable(Collection candidates) { + // Nothing + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // Nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // Nothing + } - public void end() { - throw new RuntimeException("Error"); - } - }; + public void end() { + throw new RuntimeException("Error"); } }; ServiceRegistration reg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null); @@ -2015,31 +1990,25 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { public void testBug370258_beginException() { final boolean[] endCalled = {false}; - ResolverHookFactory endHook = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // Nothing - } + ResolverHookFactory endHook = triggers -> new ResolverHook() { + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // Nothing + } - public void filterResolvable(Collection candidates) { - throw new RuntimeException("Error"); - } + public void filterResolvable(Collection candidates) { + throw new RuntimeException("Error"); + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // Nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // Nothing + } - public void end() { - endCalled[0] = true; - } - }; + public void end() { + endCalled[0] = true; } }; - ResolverHookFactory error = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - throw new RuntimeException("Error"); - } + ResolverHookFactory error = triggers -> { + throw new RuntimeException("Error"); }; ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null); @@ -2064,46 +2033,38 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { public void testBug370258_endException() { final boolean[] endCalled = {false}; - ResolverHookFactory endHook = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // Nothing - } + ResolverHookFactory endHook = triggers -> new ResolverHook() { + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // Nothing + } - public void filterResolvable(Collection candidates) { - throw new RuntimeException("Error"); - } + public void filterResolvable(Collection candidates) { + throw new RuntimeException("Error"); + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // Nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // Nothing + } - public void end() { - endCalled[0] = true; - } - }; + public void end() { + endCalled[0] = true; } }; - ResolverHookFactory error = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // Nothing - } + ResolverHookFactory error = triggers -> new ResolverHook() { + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // Nothing + } - public void filterResolvable(Collection candidates) { - // Nothing - } + public void filterResolvable(Collection candidates) { + // Nothing + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // Nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // Nothing + } - public void end() { - throw new RuntimeException("Error"); - } - }; + public void end() { + throw new RuntimeException("Error"); } }; @@ -2183,49 +2144,38 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { final CountDownLatch startingB = new CountDownLatch(1); final CountDownLatch endedSecondThread = new CountDownLatch(1); - BundleListener delayB1 = new SynchronousBundleListener() { - @Override - public void bundleChanged(BundleEvent event) { - if (event.getBundle() == b1 && BundleEvent.STARTING == event.getType()) { - try { - startingB.countDown(); - System.out.println(getName() + ": Delaying now ..."); - Thread.sleep(15000); - System.out.println(getName() + ": Done delaying."); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } + SynchronousBundleListener delayB1 = event -> { + if (event.getBundle() == b1 && BundleEvent.STARTING == event.getType()) { + try { + startingB.countDown(); + System.out.println(getName() + ": Delaying now ..."); + Thread.sleep(15000); + System.out.println(getName() + ": Done delaying."); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } } }; getContext().addBundleListener(delayB1); try { - new Thread(new Runnable() { - - @Override - public void run() { - try { - System.out.println(getName() + ": Initial load test."); - a1.loadClass("test.bug490902.a.TestLoadA1").newInstance(); - } catch (Throwable e) { - e.printStackTrace(); - } + new Thread((Runnable) () -> { + try { + System.out.println(getName() + ": Initial load test."); + a1.loadClass("test.bug490902.a.TestLoadA1").newInstance(); + } catch (Throwable e) { + e.printStackTrace(); } }, "Initial load test thread.").start(); startingB.await(); - Thread secondThread = new Thread(new Runnable() { - - @Override - public void run() { - try { - System.out.println(getName() + ": Second load test."); - a1.loadClass("test.bug490902.a.TestLoadA1").newInstance(); - } catch (Throwable e) { - e.printStackTrace(); - } finally { - endedSecondThread.countDown(); - } + Thread secondThread = new Thread((Runnable) () -> { + try { + System.out.println(getName() + ": Second load test."); + a1.loadClass("test.bug490902.a.TestLoadA1").newInstance(); + } catch (Throwable e) { + e.printStackTrace(); + } finally { + endedSecondThread.countDown(); } }, "Second load test thread."); secondThread.start(); @@ -2260,23 +2210,19 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { if (!testThread.get()) { return null; } - WeavingHook hook = new WeavingHook() { - - @Override - public void weave(WovenClass wovenClass) { - if (loadNewClassInWeave.get()) { - // Force a load of inner class - Runnable run = new Runnable() { - @Override - public void run() { - // nothing - } - }; - run.run(); - weavingHookClasses.add(run.getClass().getName()); - } - called.add(wovenClass); + WeavingHook hook = wovenClass -> { + if (loadNewClassInWeave.get()) { + // Force a load of inner class (must not be a lambda) + Runnable run = new Runnable() { + @Override + public void run() { + // nothing + } + }; + run.run(); + weavingHookClasses.add(run.getClass().getName()); } + called.add(wovenClass); }; weavingHookClasses.add(hook.getClass().getName()); return hook; @@ -2297,7 +2243,7 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { // set flag to load inner class while weaving loadNewClassInWeave.set(true); - // Force a load of inner class + // Force a load of inner class (must not be a lambda) run = new Runnable() { @Override public void run() { @@ -2434,12 +2380,9 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { // add a framework event listener to find error message about invalud class loaders final BlockingQueue<FrameworkEvent> events = new LinkedBlockingQueue<>(); - getContext().addFrameworkListener(new FrameworkListener() { - @Override - public void frameworkEvent(FrameworkEvent event) { - if (event.getBundle() == requirer) { - events.add(event); - } + getContext().addFrameworkListener(event -> { + if (event.getBundle() == requirer) { + events.add(event); } }); @@ -2556,13 +2499,9 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { void refreshBundles(Collection<Bundle> bundles) throws InterruptedException { final CountDownLatch refreshSignal = new CountDownLatch(1); - getContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class).refreshBundles(bundles, new FrameworkListener() { - - @Override - public void frameworkEvent(FrameworkEvent event) { - if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { - refreshSignal.countDown(); - } + getContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class).refreshBundles(bundles, event -> { + if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { + refreshSignal.countDown(); } }); refreshSignal.await(30, TimeUnit.SECONDS); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/LoggingTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/LoggingTests.java index 4ee71f245..042f8a73d 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/LoggingTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/LoggingTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2011 IBM Corporation and others. + * Copyright (c) 2010, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -375,13 +375,10 @@ public class LoggingTests extends AbstractBundleTests { LogServiceReference logRef = getLogService(getContext()); final List events = new ArrayList(); - EventHandler testHandler = new EventHandler() { - - public void handleEvent(Event event) { - synchronized (events) { - events.add(event); - events.notifyAll(); - } + EventHandler testHandler = event -> { + synchronized (events) { + events.add(event); + events.notifyAll(); } }; @@ -415,15 +412,12 @@ public class LoggingTests extends AbstractBundleTests { LogServiceReference logRef = getLogService(getContext()); final List events = new ArrayList(); - EventHandler testHandler = new EventHandler() { - - public void handleEvent(Event event) { - synchronized (events) { - events.add(event); - events.notifyAll(); - } - throw new NullPointerException(); + EventHandler testHandler = event -> { + synchronized (events) { + events.add(event); + events.notifyAll(); } + throw new NullPointerException(); }; Dictionary props = new Hashtable(); @@ -453,12 +447,7 @@ public class LoggingTests extends AbstractBundleTests { final Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$ testBundle.start(); LogServiceReference logRef = getLogService(getContext()); - ILogListener recurseLog = new ILogListener() { - - public void logging(IStatus status, String plugin) { - Platform.getLog(testBundle).log(status); - } - }; + ILogListener recurseLog = (status, plugin) -> Platform.getLog(testBundle).log(status); Platform.addLogListener(recurseLog); try { logRef.fwkLog.log(new FrameworkLogEntry(getContext().getBundle().getSymbolicName(), FrameworkLogEntry.ERROR, 0, "Test message", 0, null, null)); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java index c0e582016..404cd9c77 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 IBM Corporation and others. + * Copyright (c) 2007, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -264,33 +264,27 @@ public class PackageAdminBundleTests extends AbstractBundleTests { } public void testUninstallWhileResolving() throws BundleException { - ServiceRegistration<ResolverHookFactory> resolverHookReg = getContext().registerService(ResolverHookFactory.class, new ResolverHookFactory() { + ServiceRegistration<ResolverHookFactory> resolverHookReg = getContext().registerService(ResolverHookFactory.class, triggers -> new ResolverHook() { @Override - public ResolverHook begin(Collection<BundleRevision> triggers) { - return new ResolverHook() { - - @Override - public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { - // Nothing - } + public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { + // Nothing + } - @Override - public void filterResolvable(Collection<BundleRevision> candidates) { - // prevent all resolves - candidates.clear(); - } + @Override + public void filterResolvable(Collection<BundleRevision> candidates) { + // prevent all resolves + candidates.clear(); + } - @Override - public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { - // nothing - } + @Override + public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { + // nothing + } - @Override - public void end() { - // nothing - } - }; + @Override + public void end() { + // nothing } }, null); try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java index 7c8b01682..ec82216fa 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PlatformAdminBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 IBM Corporation and others. + * Copyright (c) 2007, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -151,14 +151,10 @@ public class PlatformAdminBundleTests extends AbstractBundleTests { public void testNativeCodeFilterWithSpecialChars() throws BundleException, InterruptedException { final AtomicReference<FrameworkEvent> error = new AtomicReference<>(); final CountDownLatch errorCnt = new CountDownLatch(1); - FrameworkListener errorListener = new FrameworkListener() { - - @Override - public void frameworkEvent(FrameworkEvent event) { - if (event.getType() == FrameworkEvent.ERROR) { - error.set(event); - errorCnt.countDown(); - } + FrameworkListener errorListener = event -> { + if (event.getType() == FrameworkEvent.ERROR) { + error.set(event); + errorCnt.countDown(); } }; getContext().addFrameworkListener(errorListener); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index e0f6be2d4..23564d1bc 100755 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 IBM Corporation and others. + * Copyright (c) 2008, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -104,7 +104,6 @@ import org.osgi.framework.Version; import org.osgi.framework.hooks.resolver.ResolverHook; import org.osgi.framework.hooks.resolver.ResolverHookFactory; import org.osgi.framework.hooks.weaving.WeavingHook; -import org.osgi.framework.hooks.weaving.WovenClass; import org.osgi.framework.launch.Framework; import org.osgi.framework.launch.FrameworkFactory; import org.osgi.framework.namespace.NativeNamespace; @@ -1342,15 +1341,13 @@ public class SystemBundleTests extends AbstractBundleTests { long testID1 = test1.getBundleId(); final Bundle testFinal1 = test1; - ServiceRegistration reg = systemContext.registerService(WeavingHook.class, new WeavingHook() { - public void weave(WovenClass wovenClass) { - if (!testFinal1.equals(wovenClass.getBundleWiring().getBundle())) - return; - if (!"substitutes.x.Ax".equals(wovenClass.getClassName())) - return; - List dynamicImports = wovenClass.getDynamicImports(); - dynamicImports.add("*"); - } + ServiceRegistration reg = systemContext.registerService(WeavingHook.class, wovenClass -> { + if (!testFinal1.equals(wovenClass.getBundleWiring().getBundle())) + return; + if (!"substitutes.x.Ax".equals(wovenClass.getClassName())) + return; + List dynamicImports = wovenClass.getDynamicImports(); + dynamicImports.add("*"); }, null); try { @@ -1382,15 +1379,13 @@ public class SystemBundleTests extends AbstractBundleTests { long testID2 = test2.getBundleId(); final Bundle testFinal2 = test2; - reg = systemContext.registerService(WeavingHook.class, new WeavingHook() { - public void weave(WovenClass wovenClass) { - if (!testFinal2.equals(wovenClass.getBundleWiring().getBundle())) - return; - if (!"exporter.importer.test.Test1".equals(wovenClass.getClassName())) - return; - List dynamicImports = wovenClass.getDynamicImports(); - dynamicImports.add("*"); - } + reg = systemContext.registerService(WeavingHook.class, wovenClass -> { + if (!testFinal2.equals(wovenClass.getBundleWiring().getBundle())) + return; + if (!"exporter.importer.test.Test1".equals(wovenClass.getClassName())) + return; + List dynamicImports = wovenClass.getDynamicImports(); + dynamicImports.add("*"); }, null); try { @@ -1453,26 +1448,22 @@ public class SystemBundleTests extends AbstractBundleTests { } BundleContext systemContext = equinox.getBundleContext(); - systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { - public void filterResolvable(Collection candidates) { - // nothing - } + systemContext.registerService(ResolverHookFactory.class, triggers -> new ResolverHook() { + public void filterResolvable(Collection candidates) { + // nothing + } - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - // resolve all singletons - collisionCandidates.clear(); - } + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + // resolve all singletons + collisionCandidates.clear(); + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // nothing + } - public void end() { - // nothing - } - }; + public void end() { + // nothing } }, null); @@ -1628,42 +1619,34 @@ public class SystemBundleTests extends AbstractBundleTests { } final Bundle testFinal1 = test1; - ServiceRegistration reg = systemContext.registerService(WeavingHook.class, new WeavingHook() { - public void weave(WovenClass wovenClass) { - if (!testFinal1.equals(wovenClass.getBundleWiring().getBundle())) - return; - if (!"substitutes.x.Ax".equals(wovenClass.getClassName())) - return; - List dynamicImports = wovenClass.getDynamicImports(); - dynamicImports.add("*"); - } + ServiceRegistration reg = systemContext.registerService(WeavingHook.class, wovenClass -> { + if (!testFinal1.equals(wovenClass.getBundleWiring().getBundle())) + return; + if (!"substitutes.x.Ax".equals(wovenClass.getClassName())) + return; + List dynamicImports = wovenClass.getDynamicImports(); + dynamicImports.add("*"); }, null); - ServiceRegistration<ResolverHookFactory> resolverHookReg = systemContext.registerService(ResolverHookFactory.class, new ResolverHookFactory() { - @Override - public ResolverHook begin(Collection<BundleRevision> triggers) { - // just trying to delay the resolve so that we get two threads trying to apply off the same snapshot - try { - Thread.sleep(500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException(e); - } - return null; + ServiceRegistration<ResolverHookFactory> resolverHookReg = systemContext.registerService(ResolverHookFactory.class, triggers -> { + // just trying to delay the resolve so that we get two threads trying to apply off the same snapshot + try { + Thread.sleep(500); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); } + return null; }, null); final Set<Throwable> errors = Collections.newSetFromMap(new ConcurrentHashMap<Throwable, Boolean>()); try { - Runnable dynamicLoadClass = new Runnable() { - @Override - public void run() { - try { - testFinal1.loadClass("substitutes.x.Ax"); - testFinal1.loadClass("org.osgi.framework.hooks.bundle.FindHook"); - } catch (Throwable t) { - errors.add(t); - } + Runnable dynamicLoadClass = () -> { + try { + testFinal1.loadClass("substitutes.x.Ax"); + testFinal1.loadClass("org.osgi.framework.hooks.bundle.FindHook"); + } catch (Throwable t) { + errors.add(t); } }; Thread t1 = new Thread(dynamicLoadClass, getName() + "-1"); @@ -1702,15 +1685,13 @@ public class SystemBundleTests extends AbstractBundleTests { Bundle chainTestA = systemContext.installBundle(installer.getBundleLocation("chain.test.a")); //$NON-NLS-1$ Bundle chainTestB = systemContext.installBundle(installer.getBundleLocation("chain.test.b")); //$NON-NLS-1$ Bundle chainTestC = systemContext.installBundle(installer.getBundleLocation("chain.test.c")); //$NON-NLS-1$ - systemContext.registerService(WeavingHook.class, new WeavingHook() { - public void weave(WovenClass wovenClass) { - if (!chainTestD.equals(wovenClass.getBundleWiring().getBundle())) - return; - if (!"chain.test.d.DMultipleChain1".equals(wovenClass.getClassName())) - return; - List dynamicImports = wovenClass.getDynamicImports(); - dynamicImports.add("*"); - } + systemContext.registerService(WeavingHook.class, wovenClass -> { + if (!chainTestD.equals(wovenClass.getBundleWiring().getBundle())) + return; + if (!"chain.test.d.DMultipleChain1".equals(wovenClass.getClassName())) + return; + List dynamicImports = wovenClass.getDynamicImports(); + dynamicImports.add("*"); }, null); equinox.start(); @@ -1726,12 +1707,9 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("D is not active.", Bundle.ACTIVE, chainTestD.getState()); // record STOPPING order final List<Bundle> stoppingOrder = new ArrayList<>(); - systemContext.addBundleListener(new SynchronousBundleListener() { - @Override - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STOPPING) { - stoppingOrder.add(event.getBundle()); - } + systemContext.addBundleListener((SynchronousBundleListener) event -> { + if (event.getType() == BundleEvent.STOPPING) { + stoppingOrder.add(event.getBundle()); } }); stop(equinox); @@ -2175,20 +2153,16 @@ public class SystemBundleTests extends AbstractBundleTests { final AtomicInteger stoppingEvent = new AtomicInteger(); final AtomicInteger stoppedEvent = new AtomicInteger(); - BundleListener systemBundleListener = new SynchronousBundleListener() { - - @Override - public void bundleChanged(BundleEvent event) { - if (event.getBundle().getBundleId() == 0) { - switch (event.getType()) { - case BundleEvent.STOPPING : - stoppingEvent.incrementAndGet(); - break; - case BundleEvent.STOPPED : - stoppedEvent.incrementAndGet(); - default : - break; - } + SynchronousBundleListener systemBundleListener = event -> { + if (event.getBundle().getBundleId() == 0) { + switch (event.getType()) { + case BundleEvent.STOPPING : + stoppingEvent.incrementAndGet(); + break; + case BundleEvent.STOPPED : + stoppedEvent.incrementAndGet(); + default : + break; } } }; @@ -2954,13 +2928,7 @@ public class SystemBundleTests extends AbstractBundleTests { equinox.getBundleContext().addBundleListener(initialListener); long startTime = System.currentTimeMillis(); final CountDownLatch waitForStartLevel = new CountDownLatch(1); - equinox.adapt(FrameworkStartLevel.class).setStartLevel(numBundles * 3, new FrameworkListener() { - - @Override - public void frameworkEvent(FrameworkEvent event) { - waitForStartLevel.countDown(); - } - }); + equinox.adapt(FrameworkStartLevel.class).setStartLevel(numBundles * 3, event -> waitForStartLevel.countDown()); waitForStartLevel.await(20, TimeUnit.SECONDS); System.out.println("Start time: " + (System.currentTimeMillis() - startTime)); @@ -3060,27 +3028,19 @@ public class SystemBundleTests extends AbstractBundleTests { } final Set<Thread> startingThreads = Collections.synchronizedSet(new HashSet<Thread>()); - equinox.getBundleContext().addBundleListener(new SynchronousBundleListener() { - @Override - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STARTING) { - try { - Thread.sleep(50); - } catch (InterruptedException e) { - // nothing - } - startingThreads.add(Thread.currentThread()); + equinox.getBundleContext().addBundleListener((SynchronousBundleListener) event -> { + if (event.getType() == BundleEvent.STARTING) { + try { + Thread.sleep(50); + } catch (InterruptedException e) { + // nothing } + startingThreads.add(Thread.currentThread()); } }); final CountDownLatch waitForStartLevel = new CountDownLatch(1); - equinox.adapt(FrameworkStartLevel.class).setStartLevel(5, new FrameworkListener() { - @Override - public void frameworkEvent(FrameworkEvent event) { - waitForStartLevel.countDown(); - } - }); + equinox.adapt(FrameworkStartLevel.class).setStartLevel(5, event -> waitForStartLevel.countDown()); waitForStartLevel.await(10, TimeUnit.SECONDS); assertEquals("Did not finish start level setting.", 0, waitForStartLevel.getCount()); @@ -3146,28 +3106,20 @@ public class SystemBundleTests extends AbstractBundleTests { final Set<Thread> startingThreads = Collections.synchronizedSet(new HashSet<Thread>()); final List<Bundle> startingBundles = Collections.synchronizedList(new ArrayList<Bundle>()); - equinox.getBundleContext().addBundleListener(new SynchronousBundleListener() { - @Override - public void bundleChanged(BundleEvent event) { - if (event.getType() == BundleEvent.STARTING) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // nothing - } - startingBundles.add(event.getBundle()); - startingThreads.add(Thread.currentThread()); + equinox.getBundleContext().addBundleListener((SynchronousBundleListener) event -> { + if (event.getType() == BundleEvent.STARTING) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // nothing } + startingBundles.add(event.getBundle()); + startingThreads.add(Thread.currentThread()); } }); final CountDownLatch waitForStartLevel = new CountDownLatch(1); - equinox.adapt(FrameworkStartLevel.class).setStartLevel(10, new FrameworkListener() { - @Override - public void frameworkEvent(FrameworkEvent event) { - waitForStartLevel.countDown(); - } - }); + equinox.adapt(FrameworkStartLevel.class).setStartLevel(10, event -> waitForStartLevel.countDown()); waitForStartLevel.await(20, TimeUnit.SECONDS); assertEquals("Did not finish start level setting.", 0, waitForStartLevel.getCount()); @@ -3288,16 +3240,12 @@ public class SystemBundleTests extends AbstractBundleTests { final List<Throwable> errors = new CopyOnWriteArrayList<>(); try { for (final File testBundleFile : testBundles) { - executor.execute(new Runnable() { - - @Override - public void run() { - try { - systemContext.installBundle("file:///" + testBundleFile.getAbsolutePath()); - } catch (BundleException e) { - e.printStackTrace(); - errors.add(e); - } + executor.execute(() -> { + try { + systemContext.installBundle("file:///" + testBundleFile.getAbsolutePath()); + } catch (BundleException e) { + e.printStackTrace(); + errors.add(e); } }); } @@ -3361,14 +3309,11 @@ public class SystemBundleTests extends AbstractBundleTests { ExecutorService executor = Executors.newFixedThreadPool(10); try { for (int i = 0; i < 10; i++) { - executor.execute(new Runnable() { - @Override - public void run() { - List<Bundle> shuffled = new ArrayList<>(bundles); - Collections.shuffle(shuffled); - for (Bundle bundle : shuffled) { - bundle.getEntry("does/not/exist"); - } + executor.execute(() -> { + List<Bundle> shuffled = new ArrayList<>(bundles); + Collections.shuffle(shuffled); + for (Bundle bundle : shuffled) { + bundle.getEntry("does/not/exist"); } }); } @@ -3424,34 +3369,28 @@ public class SystemBundleTests extends AbstractBundleTests { testBundle.start(); final List<FrameworkEvent> errorsAndWarnings = new CopyOnWriteArrayList<>(); - FrameworkListener fwkListener = new FrameworkListener() { - @Override - public void frameworkEvent(FrameworkEvent event) { - int type = event.getType(); - if (type == FrameworkEvent.ERROR || type == FrameworkEvent.WARNING) { - errorsAndWarnings.add(event); - } + FrameworkListener fwkListener = event -> { + int type = event.getType(); + if (type == FrameworkEvent.ERROR || type == FrameworkEvent.WARNING) { + errorsAndWarnings.add(event); } }; systemContext.addFrameworkListener(fwkListener); - Runnable asyncTest = new Runnable() { - @Override - public void run() { - try { - assertNotNull("Entry not found.", testBundle.getEntry("dirA/fileA")); - assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirB/fileB")); - assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirC/fileC")); - assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirC/")); - URL dirBURL = converter.toFileURL(testBundle.getEntry("dirA/dirB/")); - assertNotNull("Failed to convert to file URL", dirBURL); - URL dirAURL = converter.toFileURL(testBundle.getEntry("dirA/")); - assertNotNull("Failed to convert to file URL", dirAURL); - List<URL> allEntries = testBundle.adapt(BundleWiring.class).findEntries("/", "*", BundleWiring.FINDENTRIES_RECURSE); - assertEquals("Wrong number of entries: " + allEntries, 8, allEntries.size()); - } catch (IOException e) { - throw new AssertionFailedError(e.getMessage()); - } + Runnable asyncTest = () -> { + try { + assertNotNull("Entry not found.", testBundle.getEntry("dirA/fileA")); + assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirB/fileB")); + assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirC/fileC")); + assertNotNull("Entry not found.", testBundle.getEntry("dirA/dirC/")); + URL dirBURL = converter.toFileURL(testBundle.getEntry("dirA/dirB/")); + assertNotNull("Failed to convert to file URL", dirBURL); + URL dirAURL = converter.toFileURL(testBundle.getEntry("dirA/")); + assertNotNull("Failed to convert to file URL", dirAURL); + List<URL> allEntries = testBundle.adapt(BundleWiring.class).findEntries("/", "*", BundleWiring.FINDENTRIES_RECURSE); + assertEquals("Wrong number of entries: " + allEntries, 8, allEntries.size()); + } catch (IOException e) { + throw new AssertionFailedError(e.getMessage()); } }; @@ -3689,19 +3628,16 @@ public class SystemBundleTests extends AbstractBundleTests { final List<Exception> errors = new CopyOnWriteArrayList<>(); try { for (final File f : testBundles) { - executor.execute(new Runnable() { - @Override - public void run() { - try { - String location = f.toURI().toURL().toExternalForm(); - System.out.println("Installing: " + f.getName()); - Bundle b = systemContext.installBundle(location); - b.start(); - BundleWiring wiring = b.adapt(BundleWiring.class); - wiring.getClassLoader().loadClass(BundleContext.class.getName()); - } catch (Exception e) { - errors.add(e); - } + executor.execute(() -> { + try { + String location = f.toURI().toURL().toExternalForm(); + System.out.println("Installing: " + f.getName()); + Bundle b = systemContext.installBundle(location); + b.start(); + BundleWiring wiring = b.adapt(BundleWiring.class); + wiring.getClassLoader().loadClass(BundleContext.class.getName()); + } catch (Exception e) { + errors.add(e); } }); } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java index 39920192e..a541ace04 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java @@ -144,17 +144,14 @@ public class TestModuleContainer extends AbstractTest { for (final Bundle bundle : bundles) { if (bundle.getBundleId() == 0) continue; - executor.execute(new Runnable() { - @Override - public void run() { - try { - ModuleRevisionBuilder builder = OSGiManifestBuilderFactory.createBuilder(asMap(bundle.getHeaders(""))); - container.install(null, bundle.getLocation(), builder, null); - } catch (Throwable t) { - t.printStackTrace(); - synchronized (installErrors) { - installErrors.add(t); - } + executor.execute(() -> { + try { + ModuleRevisionBuilder builder = OSGiManifestBuilderFactory.createBuilder(asMap(bundle.getHeaders(""))); + container.install(null, bundle.getLocation(), builder, null); + } catch (Throwable t) { + t.printStackTrace(); + synchronized (installErrors) { + installErrors.add(t); } } }); @@ -522,32 +519,26 @@ public class TestModuleContainer extends AbstractTest { @Test public void testSingleton02() throws BundleException, IOException { - ResolverHookFactory resolverHookFactory = new ResolverHookFactory() { + ResolverHookFactory resolverHookFactory = triggers -> new ResolverHook() { @Override - public ResolverHook begin(Collection<BundleRevision> triggers) { - return new ResolverHook() { - - @Override - public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { - collisionCandidates.clear(); - } + public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { + collisionCandidates.clear(); + } - @Override - public void filterResolvable(Collection<BundleRevision> candidates) { - // nothing - } + @Override + public void filterResolvable(Collection<BundleRevision> candidates) { + // nothing + } - @Override - public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { - // nothing - } + @Override + public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { + // nothing + } - @Override - public void end() { - // nothing - } - }; + @Override + public void end() { + // nothing } }; DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.emptyMap(), resolverHookFactory); @@ -587,32 +578,26 @@ public class TestModuleContainer extends AbstractTest { @Test public void testSingleton04() throws BundleException, IOException { final Collection<BundleRevision> disabled = new ArrayList<>(); - ResolverHookFactory resolverHookFactory = new ResolverHookFactory() { + ResolverHookFactory resolverHookFactory = triggers -> new ResolverHook() { @Override - public ResolverHook begin(Collection<BundleRevision> triggers) { - return new ResolverHook() { - - @Override - public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { - // nothing - } + public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { + // nothing + } - @Override - public void filterResolvable(Collection<BundleRevision> candidates) { - candidates.removeAll(disabled); - } + @Override + public void filterResolvable(Collection<BundleRevision> candidates) { + candidates.removeAll(disabled); + } - @Override - public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { - // nothing - } + @Override + public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { + // nothing + } - @Override - public void end() { - // nothing - } - }; + @Override + public void end() { + // nothing } }; DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.emptyMap(), resolverHookFactory); @@ -1845,21 +1830,13 @@ public class TestModuleContainer extends AbstractTest { // use sync queue to force thread creation BlockingQueue<Runnable> queue = new SynchronousQueue<>(); // try to name the threads with useful name - ThreadFactory threadFactory = new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r, "Resolver thread - UNIT TEST"); //$NON-NLS-1$ - t.setDaemon(true); - return t; - } + ThreadFactory threadFactory = r -> { + Thread t = new Thread(r, "Resolver thread - UNIT TEST"); //$NON-NLS-1$ + t.setDaemon(true); + return t; }; // use a rejection policy that simply runs the task in the current thread once the max threads is reached - RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() { - @Override - public void rejectedExecution(Runnable r, ThreadPoolExecutor exe) { - r.run(); - } - }; + RejectedExecutionHandler rejectHandler = (r, exe) -> r.run(); ExecutorService executor = new ThreadPoolExecutor(coreThreads, maxThreads, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler); ScheduledExecutorService timeoutExecutor = new ScheduledThreadPoolExecutor(1); @@ -2937,16 +2914,12 @@ public class TestModuleContainer extends AbstractTest { try { for (final Module module : modules) { - executor.execute(new Runnable() { - - @Override - public void run() { - try { - module.start(); - } catch (BundleException e) { - startErrors.offer(e); - e.printStackTrace(); - } + executor.execute(() -> { + try { + module.start(); + } catch (BundleException e) { + startErrors.offer(e); + e.printStackTrace(); } }); } @@ -3046,12 +3019,7 @@ public class TestModuleContainer extends AbstractTest { resolverHook.container = container; final AtomicReference<ModuleWire> dynamicWire = new AtomicReference<>(); - Runnable runForEvents = new Runnable() { - @Override - public void run() { - dynamicWire.set(container.resolveDynamic("org.osgi.framework", dynamicImport.getCurrentRevision())); - } - }; + Runnable runForEvents = () -> dynamicWire.set(container.resolveDynamic("org.osgi.framework", dynamicImport.getCurrentRevision())); adaptor.setRunForEvents(runForEvents); // install a bundle to resolve manifest.clear(); @@ -3639,14 +3607,11 @@ public class TestModuleContainer extends AbstractTest { final Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container); final ArrayBlockingQueue<BundleException> startExceptions = new ArrayBlockingQueue<>(2); - Runnable start = new Runnable() { - @Override - public void run() { - try { - module.start(); - } catch (BundleException e) { - startExceptions.offer(e); - } + Runnable start = () -> { + try { + module.start(); + } catch (BundleException e) { + startExceptions.offer(e); } }; Thread t1 = new Thread(start); @@ -3662,14 +3627,11 @@ public class TestModuleContainer extends AbstractTest { startError.printStackTrace(); final ArrayBlockingQueue<BundleException> stopExceptions = new ArrayBlockingQueue<>(2); - Runnable stop = new Runnable() { - @Override - public void run() { - try { - module.stop(); - } catch (BundleException e) { - stopExceptions.offer(e); - } + Runnable stop = () -> { + try { + module.stop(); + } catch (BundleException e) { + stopExceptions.offer(e); } }; Thread tStop1 = new Thread(stop); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java index 89b6f4fc2..1f5ec20f2 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2020 IBM Corporation and others. + * Copyright (c) 2013, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -28,9 +28,7 @@ import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkEvent; -import org.osgi.framework.FrameworkListener; import org.osgi.framework.hooks.weaving.WeavingHook; -import org.osgi.framework.hooks.weaving.WovenClass; import org.osgi.framework.launch.Framework; import org.osgi.framework.namespace.PackageNamespace; import org.osgi.framework.wiring.BundleRevision; @@ -120,13 +118,9 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests { public void testRejectTransformationFromWeavingHook() throws Exception { setRejectTransformation(true); initAndStartFramework(); - framework.getBundleContext().registerService(WeavingHook.class, new WeavingHook() { - - @Override - public void weave(WovenClass wovenClass) { - wovenClass.setBytes(new byte[] {'b', 'a', 'd', 'b', 'y', 't', 'e', 's'}); - wovenClass.getDynamicImports().add("badimport"); - } + framework.getBundleContext().registerService(WeavingHook.class, wovenClass -> { + wovenClass.setBytes(new byte[] {'b', 'a', 'd', 'b', 'y', 't', 'e', 's'}); + wovenClass.getDynamicImports().add("badimport"); }, null); Bundle b = installBundle(); b.loadClass(TEST_CLASSNAME); @@ -183,13 +177,9 @@ public class ClassLoaderHookTests extends AbstractFrameworkHookTests { private void refreshBundles(Collection<Bundle> bundles) throws InterruptedException { final CountDownLatch refreshSignal = new CountDownLatch(1); - framework.adapt(FrameworkWiring.class).refreshBundles(bundles, new FrameworkListener() { - - @Override - public void frameworkEvent(FrameworkEvent event) { - if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { - refreshSignal.countDown(); - } + framework.adapt(FrameworkWiring.class).refreshBundles(bundles, event -> { + if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) { + refreshSignal.countDown(); } }); refreshSignal.await(30, TimeUnit.SECONDS); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java index 74cff3232..8115ba0ae 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/listeners/ExceptionHandlerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2015 IBM Corporation and others. + * Copyright (c) 2004, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,7 +19,6 @@ import org.eclipse.core.tests.harness.BundleTestingHelper; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.Assert; import org.junit.Test; -import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; import org.osgi.framework.FrameworkEvent; @@ -62,10 +61,8 @@ public class ExceptionHandlerTests { FrameworkEventListenerWithResult fwkListener = new FrameworkEventListenerWithResult(); OSGiTestsActivator.getContext().addFrameworkListener(fwkListener); - BundleListener npeGenerator = new BundleListener() { - public void bundleChanged(BundleEvent event) { - throw new NullPointerException("Generated exception"); - } + BundleListener npeGenerator = event -> { + throw new NullPointerException("Generated exception"); }; OSGiTestsActivator.getContext().addBundleListener(npeGenerator); @@ -91,10 +88,8 @@ public class ExceptionHandlerTests { FrameworkEventListenerWithResult fwkListener = new FrameworkEventListenerWithResult(); OSGiTestsActivator.getContext().addFrameworkListener(fwkListener); - BundleListener fatalException = new BundleListener() { - public void bundleChanged(BundleEvent event) { - throw new OutOfMemoryError("Generated exception"); - } + BundleListener fatalException = event -> { + throw new OutOfMemoryError("Generated exception"); }; OSGiTestsActivator.getContext().addBundleListener(fatalException); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java index 2857c0e19..1670db32b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/BasicTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2015 IBM Corporation and others. + * Copyright (c) 2012, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -211,26 +211,11 @@ public class BasicTest extends AbstractResourceTest { */ private void assertTb2() { final BundleRevision revision = tb2.adapt(BundleRevision.class); - assertNotIdentityCapability(new CapabilityProvider() { - @Override - public List getCapabilities(String namespace) { - return revision.getDeclaredCapabilities(namespace); - } - }); + assertNotIdentityCapability(namespace -> revision.getDeclaredCapabilities(namespace)); final Resource resource = revision; - assertNotIdentityCapability(new CapabilityProvider() { - @Override - public List getCapabilities(String namespace) { - return resource.getCapabilities(namespace); - } - }); + assertNotIdentityCapability(namespace -> resource.getCapabilities(namespace)); final BundleWiring wiring = tb2.adapt(BundleWiring.class); - assertNotIdentityCapability(new CapabilityProvider() { - @Override - public List getCapabilities(String namespace) { - return wiring.getCapabilities(namespace); - } - }); + assertNotIdentityCapability(namespace -> wiring.getCapabilities(namespace)); } /* diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java index 128fa0fbe..b4ee9eb68 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/resource/ResolverHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2015 IBM Corporation and others. + * Copyright (c) 2011, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -36,41 +36,37 @@ public class ResolverHookTests extends AbstractResourceTest { public void testSingletonIdentity() throws Exception { final RuntimeException error[] = {null}; final boolean called[] = {false}; - ResolverHookFactory resolverHookFactory = new ResolverHookFactory() { - public ResolverHook begin(Collection triggers) { - return new ResolverHook() { + ResolverHookFactory resolverHookFactory = triggers -> new ResolverHook() { - public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { - if (error[0] != null) - return; - called[0] = true; - try { - assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, singleton.getNamespace()); - assertEquals("Wrong singleton directive", "true", singleton.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); - String symbolicName = (String) singleton.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE); - for (Iterator iCandidates = collisionCandidates.iterator(); iCandidates.hasNext();) { - BundleCapability candidate = (BundleCapability) iCandidates.next(); - assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, candidate.getNamespace()); - assertEquals("Wrong singleton directive", "true", candidate.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); - assertEquals("Wrong symbolic name", symbolicName, (String) candidate.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); - } - } catch (RuntimeException e) { - error[0] = e; - } + public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) { + if (error[0] != null) + return; + called[0] = true; + try { + assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, singleton.getNamespace()); + assertEquals("Wrong singleton directive", "true", singleton.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); + String symbolicName = (String) singleton.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE); + for (Iterator iCandidates = collisionCandidates.iterator(); iCandidates.hasNext();) { + BundleCapability candidate = (BundleCapability) iCandidates.next(); + assertEquals("Wrong namespace", IdentityNamespace.IDENTITY_NAMESPACE, candidate.getNamespace()); + assertEquals("Wrong singleton directive", "true", candidate.getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE)); + assertEquals("Wrong symbolic name", symbolicName, (String) candidate.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); } + } catch (RuntimeException e) { + error[0] = e; + } + } - public void filterResolvable(Collection candidates) { - // nothing - } + public void filterResolvable(Collection candidates) { + // nothing + } - public void filterMatches(BundleRequirement requirement, Collection candidates) { - // nothing - } + public void filterMatches(BundleRequirement requirement, Collection candidates) { + // nothing + } - public void end() { - // nothing - } - }; + public void end() { + // nothing } }; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java index 97da25725..2602ce762 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2020 IBM Corporation and others. + * Copyright (c) 2008, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -635,37 +635,31 @@ public class SecurityManagerTests extends AbstractBundleTests { BundleContext systemContext = equinox.getBundleContext(); // register a no-op resolver hook to test security - ResolverHookFactory dummyHook = new ResolverHookFactory() { + ResolverHookFactory dummyHook = triggers -> new ResolverHook() { @Override - public ResolverHook begin(Collection<BundleRevision> triggers) { - return new ResolverHook() { - - @Override - public void filterResolvable(Collection<BundleRevision> candidates) { - // nothing - } - - @Override - public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { - // nothing - } + public void filterResolvable(Collection<BundleRevision> candidates) { + // nothing + } - @Override - public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { - // always remove candidates for dynamic import - if (PackageNamespace.RESOLUTION_DYNAMIC.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE))) { - candidates.clear(); - } - } + @Override + public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) { + // nothing + } - @Override - public void end() { - // nothing - } + @Override + public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { + // always remove candidates for dynamic import + if (PackageNamespace.RESOLUTION_DYNAMIC.equals(requirement.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE))) { + candidates.clear(); + } + } - }; + @Override + public void end() { + // nothing } + }; systemContext.registerService(ResolverHookFactory.class, dummyHook, null); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java index 0e4e0c5ef..49afd98e5 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -37,29 +37,24 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testServiceListener01() { final String testMethodName = getName(); // simple ServiceListener test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; final boolean[] results = new boolean[] {false, false, false, false}; - ServiceListener testListener = new ServiceListener() { - public void serviceChanged(ServiceEvent event) { - switch (event.getType()) { - case ServiceEvent.REGISTERED : - results[0] = true; - break; - case ServiceEvent.MODIFIED : - results[1] = true; - break; - case ServiceEvent.MODIFIED_ENDMATCH : - results[2] = true; - break; - case ServiceEvent.UNREGISTERING : - results[3] = true; - break; - } + ServiceListener testListener = event -> { + switch (event.getType()) { + case ServiceEvent.REGISTERED : + results[0] = true; + break; + case ServiceEvent.MODIFIED : + results[1] = true; + break; + case ServiceEvent.MODIFIED_ENDMATCH : + results[2] = true; + break; + case ServiceEvent.UNREGISTERING : + results[3] = true; + break; } }; try { @@ -133,29 +128,24 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testServiceListener02() { final String testMethodName = getName(); // simple ServiceListener test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; final boolean[] results = new boolean[] {false, false, false, false}; - ServiceListener testListener = new ServiceListener() { - public void serviceChanged(ServiceEvent event) { - switch (event.getType()) { - case ServiceEvent.REGISTERED : - results[0] = true; - break; - case ServiceEvent.MODIFIED : - results[1] = true; - break; - case ServiceEvent.MODIFIED_ENDMATCH : - results[2] = true; - break; - case ServiceEvent.UNREGISTERING : - results[3] = true; - break; - } + ServiceListener testListener = event -> { + switch (event.getType()) { + case ServiceEvent.REGISTERED : + results[0] = true; + break; + case ServiceEvent.MODIFIED : + results[1] = true; + break; + case ServiceEvent.MODIFIED_ENDMATCH : + results[2] = true; + break; + case ServiceEvent.UNREGISTERING : + results[3] = true; + break; } }; try { @@ -229,29 +219,24 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testServiceListener03() { final String testMethodName = getName(); // simple ServiceListener test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; final int[] results = new int[] {0, 0, 0, 0}; - ServiceListener testListener = new ServiceListener() { - public void serviceChanged(ServiceEvent event) { - switch (event.getType()) { - case ServiceEvent.REGISTERED : - results[0]++; - break; - case ServiceEvent.MODIFIED : - results[1]++; - break; - case ServiceEvent.MODIFIED_ENDMATCH : - results[2]++; - break; - case ServiceEvent.UNREGISTERING : - results[3]++; - break; - } + ServiceListener testListener = event -> { + switch (event.getType()) { + case ServiceEvent.REGISTERED : + results[0]++; + break; + case ServiceEvent.MODIFIED : + results[1]++; + break; + case ServiceEvent.MODIFIED_ENDMATCH : + results[2]++; + break; + case ServiceEvent.UNREGISTERING : + results[3]++; + break; } }; try { @@ -360,11 +345,8 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testServiceOrdering01() { final String testMethodName = getName(); // test that getServiceReference returns the proper service - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put("name", testMethodName); //$NON-NLS-1$ @@ -398,11 +380,8 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testDuplicateObjectClass() { ServiceRegistration reg = null; try { - reg = OSGiTestsActivator.getContext().registerService(new String[] {Runnable.class.getName(), Object.class.getName(), Object.class.getName()}, new Runnable() { - @Override - public void run() { - // nothing - } + reg = OSGiTestsActivator.getContext().registerService(new String[] {Runnable.class.getName(), Object.class.getName(), Object.class.getName()}, (Runnable) () -> { + // nothing }, null); } catch (Throwable t) { fail("Failed to register service with duplicate objectClass names", t); //$NON-NLS-1$ @@ -415,11 +394,8 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testServiceReferenceCompare01() { final String testMethodName = getName(); // test that getServiceReference returns the proper service - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put("name", testMethodName); //$NON-NLS-1$ @@ -469,11 +445,8 @@ public class ServiceRegistryTests extends AbstractBundleTests { } public void testModifiedRanking() { - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put(getName(), Boolean.TRUE); @@ -497,21 +470,13 @@ public class ServiceRegistryTests extends AbstractBundleTests { public void testInvalidRanking() { final CountDownLatch warning = new CountDownLatch(1); - FrameworkListener warningListener = new FrameworkListener() { - - @Override - public void frameworkEvent(FrameworkEvent event) { - if (FrameworkEvent.WARNING == event.getType() && OSGiTestsActivator.getContext().getBundle().equals(event.getBundle())) { - warning.countDown(); - } + FrameworkListener warningListener = event -> { + if (FrameworkEvent.WARNING == event.getType() && OSGiTestsActivator.getContext().getBundle().equals(event.getBundle())) { + warning.countDown(); } }; - Runnable runIt = new Runnable() { - - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put(getName(), Boolean.TRUE); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceTrackerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceTrackerTests.java index 0d7c3f2c8..9010c184c 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceTrackerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceTrackerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -30,11 +30,8 @@ public class ServiceTrackerTests extends AbstractBundleTests { public void testServiceTracker01() { final String testMethodName = getName(); // simple ServiceTracker test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put(testMethodName, Boolean.TRUE); @@ -110,11 +107,8 @@ public class ServiceTrackerTests extends AbstractBundleTests { public void testServiceTracker02() { final String testMethodName = getName(); // simple ServiceTracker test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put(testMethodName, Boolean.FALSE); @@ -190,11 +184,8 @@ public class ServiceTrackerTests extends AbstractBundleTests { public void testServiceTracker03() { final String testMethodName = getName(); // simple ServiceTracker test - Runnable runIt = new Runnable() { - @Override - public void run() { - // nothing - } + Runnable runIt = () -> { + // nothing }; Hashtable props = new Hashtable(); props.put(testMethodName, Boolean.TRUE); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java index 21de7feae..45b5fea23 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2014 IBM Corporation and others. + * Copyright (c) 2004, 2021 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -38,7 +38,6 @@ import org.osgi.framework.BundleException; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogEntry; -import org.osgi.service.log.LogListener; import org.osgi.service.log.LogReaderService; import org.osgi.util.tracker.ServiceTracker; @@ -485,12 +484,7 @@ public class BasicLocationTests extends CoreTest { try { final List<LogEntry> logEntries = new ArrayList<>(); LogReaderService logReaderService = getLogReaderService(equinox); - LogListener logListener = new SynchronousLogListener() { - @Override - public void logged(LogEntry entry) { - logEntries.add(entry); - } - }; + SynchronousLogListener logListener = entry -> logEntries.add(entry); logReaderService.addLogListener(logListener); Map<String, Location> locations = getLocations(equinox); Location userLocation = locations.get(Location.USER_FILTER); |