Skip to content

Commit

Permalink
Bug 568414 - Remove Activator from MPC Core
Browse files Browse the repository at this point in the history
The MPC.core plugin uses a Bundle-Activator which sets up some internal
state, but most of this can be refactored away. This allows applications
that depend on MPC to start faster.

Refactor dependencies that are present in the
MarketplaceClientCorePlugin so that the start/stop methods are no longer
required.

In addition, bump the require execution environment to Java 11, along
with a minor service bump, since it depends on bundles that depend on
Java 11.

Change-Id: Idbb5d0205e3f2864db31fef61345779508cab68d
Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com>
  • Loading branch information
alblue authored and l3-g5 committed Nov 5, 2020
1 parent 446fce5 commit 11719b7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 53 deletions.
5 changes: 2 additions & 3 deletions org.eclipse.epp.mpc.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.epp.mpc.core;singleton:=true
Bundle-Version: 1.8.5.qualifier
Bundle-Version: 1.9.0.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.osgi;bundle-version="3.6.0",
org.eclipse.core.runtime;bundle-version="3.6.0",
org.apache.commons.logging;bundle-version="1.0.4",
Expand Down Expand Up @@ -80,6 +80,5 @@ Import-Package: org.apache.http;version="4.4.0",
org.apache.http.util;version="4.4.0",
org.eclipse.equinox.p2.core;version="2.0.0"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin
Service-Component: OSGI-INF/services/*.xml
Automatic-Module-Name: org.eclipse.epp.mpc.core
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.FrameworkUtil;

/**
* @author David Green
Expand All @@ -45,7 +46,7 @@ public class MarketplaceClientCore {
private static final String PIPE_BROKEN_MESSAGE = "Pipe broken"; //$NON-NLS-1$

public static ILog getLog() {
return Platform.getLog(MarketplaceClientCorePlugin.getBundle());
return Platform.getLog(FrameworkUtil.getBundle(MarketplaceClientCore.class));
}

public static void error(String message, Throwable exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugOptionsListener;
import org.eclipse.osgi.service.debug.DebugTrace;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Component;

public class MarketplaceClientCorePlugin implements BundleActivator {
public class MarketplaceClientCorePlugin {

public static final String DEBUG_OPTION = "/debug"; //$NON-NLS-1$

Expand All @@ -38,38 +35,6 @@ public class MarketplaceClientCorePlugin implements BundleActivator {

private static DebugTrace debugTrace;

private static MarketplaceClientCorePlugin instance;

private Bundle bundle;

@Override
public void start(BundleContext context) throws Exception {
bundle = context.getBundle();
instance = this;
}

@Override
public void stop(BundleContext context) throws Exception {
debugTrace = null;
instance = null;
}

/**
* @deprecated Inject ServiceHelper as a service instead
*/
@Deprecated
public ServiceHelperImpl getServiceHelper() {
return ServiceHelperImpl.getImplInstance();
}

public static MarketplaceClientCorePlugin getDefault() {
return instance;
}

public static Bundle getBundle() {
return instance == null ? null : instance.bundle;
}

public static void trace(String option, String message) {
final DebugTrace trace = debugTrace;
if (DEBUG && trace != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCore;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin;
import org.eclipse.epp.internal.mpc.core.ServiceHelperImpl;
import org.eclipse.epp.mpc.core.service.ITransportFactory;
import org.eclipse.epp.mpc.core.service.ServiceHelper;
import org.eclipse.epp.mpc.core.service.ServiceUnavailableException;
Expand Down Expand Up @@ -227,8 +228,7 @@ public void removedService(ServiceReference<ITransportFactory> reference, Transp
*/
@Deprecated
public static synchronized TransportFactory instance() {
TransportFactory legacyTransportFactory = MarketplaceClientCorePlugin.getDefault()
.getServiceHelper()
TransportFactory legacyTransportFactory = ServiceHelperImpl.getImplInstance()
.getLegacyTransportFactory();
if (legacyTransportFactory == null) {
throw new IllegalStateException();
Expand All @@ -238,7 +238,7 @@ public static synchronized TransportFactory instance() {

public static org.eclipse.epp.mpc.core.service.ITransport createTransport() {
//search for registered factory service
BundleContext context = MarketplaceClientCorePlugin.getBundle().getBundleContext();
BundleContext context = FrameworkUtil.getBundle(TransportFactory.class).getBundleContext();
Collection<ServiceReference<ITransportFactory>> serviceReferences = getTransportServiceReferences(context);

MultiStatus serviceError = null;
Expand Down Expand Up @@ -464,4 +464,4 @@ protected static void handleServiceUnavailable(CoreException e) throws ServiceUn
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin;
import org.eclipse.epp.internal.mpc.core.ServiceLocator;
import org.eclipse.epp.internal.mpc.core.model.Catalog;
import org.eclipse.epp.internal.mpc.core.service.CatalogService;
Expand All @@ -37,6 +36,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

Expand Down Expand Up @@ -64,7 +64,7 @@ public List<Catalog> listCatalogs(IProgressMonitor monitor) throws CoreException

@Before
public void setUp() throws Exception {
bundleContext = MarketplaceClientCorePlugin.getBundle().getBundleContext();
bundleContext = FrameworkUtil.getBundle(CatalogServiceTest.class).getBundleContext();
serviceLocatorReference = bundleContext.getServiceReference(IMarketplaceServiceLocator.class);
serviceLocator = bundleContext.getService(serviceLocatorReference);
catalogService = serviceLocator.getCatalogService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin;
import org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransport;
import org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransportFactory;
import org.eclipse.epp.internal.mpc.core.util.FallbackTransportFactory;
Expand All @@ -34,6 +33,7 @@
import org.eclipse.epp.mpc.core.service.ServiceHelper;
import org.eclipse.epp.mpc.core.service.ServiceUnavailableException;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceRegistration;

public class MappedTransportFactory implements ITransportFactory {
Expand Down Expand Up @@ -134,7 +134,7 @@ public void register() throws IllegalStateException {
this.delegate = delegate;
Dictionary<String, Object> maxServiceRanking = new Hashtable<>(Collections.singletonMap(
Constants.SERVICE_RANKING, Integer.MAX_VALUE));
registration = MarketplaceClientCorePlugin.getBundle().getBundleContext().registerService(
registration = FrameworkUtil.getBundle(MappedTransportFactory.class).getBundleContext().registerService(
ITransportFactory.class, this,
maxServiceRanking);
transportFactory = ServiceHelper.getTransportFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
*******************************************************************************/
package org.eclipse.epp.mpc.tests.service;

import static org.hamcrest.Matchers.*;
import static org.junit.Assume.*;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -40,6 +45,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCore;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin;
import org.eclipse.epp.internal.mpc.core.ServiceHelperImpl;
import org.eclipse.epp.internal.mpc.core.ServiceLocator;
import org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService;
import org.eclipse.epp.mpc.core.model.IIu;
Expand Down Expand Up @@ -577,7 +583,7 @@ protected void after() {
protected void starting(final Description description) {
final IMarketplaceUnmarshaller marketplaceUnmarshaller = org.eclipse.epp.mpc.core.service.ServiceHelper
.getMarketplaceUnmarshaller();
unmarshallerRegistration = MarketplaceClientCorePlugin.getDefault().getServiceHelper()
unmarshallerRegistration = ServiceHelperImpl.getImplInstance()
.registerMarketplaceUnmarshaller(new IMarketplaceUnmarshaller() {

public <T> T unmarshal(InputStream in, Class<T> type, IProgressMonitor monitor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.apache.http.protocol.HttpContext;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCorePlugin;
import org.eclipse.epp.internal.mpc.core.ServiceHelperImpl;
import org.eclipse.epp.internal.mpc.core.transport.httpclient.ChainedCredentialsProvider;
import org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientCustomizer;
Expand Down Expand Up @@ -125,7 +124,7 @@ public void initServiceHelper() {

@Test
public void testRegisteredFactories() throws Exception {
BundleContext context = MarketplaceClientCorePlugin.getBundle().getBundleContext();
BundleContext context = FrameworkUtil.getBundle(TransportFactoryTest.class).getBundleContext();
Collection<ServiceReference<ITransportFactory>> serviceReferences = context.getServiceReferences(
ITransportFactory.class, null);
assertFalse(serviceReferences.isEmpty());
Expand Down

0 comments on commit 11719b7

Please sign in to comment.