Skip to content

Commit 9cf50f4

Browse files
committed
Make the PlatformConfigurationFactory a component
Currently the activator created the factory (but only register it as a plain service) and on the other hand the BundleGroupComponent then access the activator in a static way. This now decouples the Factory and BundleGroupComponent from the activator by making them components.
1 parent 5d8ee71 commit 9cf50f4

File tree

4 files changed

+40
-58
lines changed

4 files changed

+40
-58
lines changed

update/org.eclipse.update.configurator/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Import-Package: javax.xml.parsers,
1717
org.w3c.dom,
1818
org.xml.sax,
1919
org.xml.sax.helpers
20-
Service-Component: OSGI-INF/org.eclipse.update.internal.configurator.BundleGroupComponent.xml
2120
Bundle-ActivationPolicy: lazy
2221
Automatic-Module-Name: org.eclipse.update.configurator
22+
Service-Component: OSGI-INF/org.eclipse.update.internal.configurator.BundleGroupComponent.xml,
23+
OSGI-INF/org.eclipse.update.internal.configurator.PlatformConfigurationFactory.xml

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,58 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
1414
package org.eclipse.update.internal.configurator;
1515

16+
import java.util.ArrayList;
17+
1618
import org.eclipse.core.runtime.IBundleGroup;
1719
import org.eclipse.core.runtime.IBundleGroupProvider;
20+
import org.eclipse.update.configurator.IPlatformConfiguration;
21+
import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry;
22+
import org.eclipse.update.configurator.IPlatformConfigurationFactory;
23+
import org.osgi.service.component.annotations.Activate;
1824
import org.osgi.service.component.annotations.Component;
25+
import org.osgi.service.component.annotations.Reference;
1926

2027
/**
2128
* Declarative services component that provides an implementation of
2229
* {@link IBundleGroupProvider}. This allows the bundle group provider to be
2330
* made available in the service registry before this bundle has started.
2431
*/
25-
@Component
32+
@Component(service = IBundleGroupProvider.class)
33+
@SuppressWarnings("deprecation")
2634
public class BundleGroupComponent implements IBundleGroupProvider {
2735

36+
37+
private IPlatformConfigurationFactory factory;
38+
39+
@Activate
40+
public BundleGroupComponent(@Reference IPlatformConfigurationFactory factory) {
41+
this.factory = factory;
42+
}
43+
2844
@Override
2945
public IBundleGroup[] getBundleGroups() {
30-
ConfigurationActivator activator = ConfigurationActivator.getConfigurator();
31-
if (activator.bundleGroupProviderSR != null)
32-
// we manually registered the group in the activator; return no groups
33-
// the manually registered service will handle the groups we know about
46+
IPlatformConfiguration configuration = factory.getCurrentPlatformConfiguration();
47+
if (configuration == null) {
3448
return new IBundleGroup[0];
35-
return activator.getBundleGroups();
49+
}
50+
IPlatformConfiguration.IFeatureEntry[] features = configuration.getConfiguredFeatureEntries();
51+
ArrayList<IBundleGroup> bundleGroups = new ArrayList<>(features.length);
52+
for (IFeatureEntry feature : features) {
53+
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding())
54+
bundleGroups.add((IBundleGroup) feature);
55+
}
56+
return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]);
3657
}
3758

3859
@Override
3960
public String getName() {
40-
return ConfigurationActivator.getConfigurator().getName();
61+
return Messages.BundleGroupProvider;
4162
}
4263

4364
}

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,16 @@
1717
import java.io.IOException;
1818
import java.net.MalformedURLException;
1919
import java.net.URL;
20-
import java.util.ArrayList;
2120

22-
import org.eclipse.core.runtime.IBundleGroup;
23-
import org.eclipse.core.runtime.IBundleGroupProvider;
2421
import org.eclipse.osgi.framework.log.FrameworkLog;
2522
import org.eclipse.osgi.service.datalocation.Location;
2623
import org.eclipse.osgi.service.debug.DebugOptions;
2724
import org.eclipse.osgi.util.NLS;
28-
import org.eclipse.update.configurator.IPlatformConfiguration;
29-
import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry;
30-
import org.eclipse.update.configurator.IPlatformConfigurationFactory;
3125
import org.osgi.framework.BundleActivator;
3226
import org.osgi.framework.BundleContext;
3327
import org.osgi.framework.ServiceReference;
34-
import org.osgi.framework.ServiceRegistration;
3528

36-
public class ConfigurationActivator implements BundleActivator, IBundleGroupProvider, IConfigurationConstants {
29+
public class ConfigurationActivator implements BundleActivator, IConfigurationConstants {
3730

3831
public static String PI_CONFIGURATOR = "org.eclipse.update.configurator"; //$NON-NLS-1$
3932
public static final String LAST_CONFIG_STAMP = "last.config.stamp"; //$NON-NLS-1$
@@ -46,20 +39,11 @@ public class ConfigurationActivator implements BundleActivator, IBundleGroupProv
4639
public static boolean DEBUG = false;
4740

4841
private static BundleContext context;
49-
private ServiceRegistration<IPlatformConfigurationFactory> configurationFactorySR;
50-
ServiceRegistration<?> bundleGroupProviderSR;
5142
private PlatformConfiguration configuration;
5243

5344
// Location of the configuration data
5445
private Location configLocation;
5546

56-
// Singleton
57-
private static ConfigurationActivator configurator;
58-
59-
public ConfigurationActivator() {
60-
configurator = this;
61-
}
62-
6347
@Override
6448
public void start(BundleContext ctx) throws Exception {
6549
context = ctx;
@@ -75,7 +59,7 @@ public void start(BundleContext ctx) throws Exception {
7559

7660
Utils.debug("Starting update configurator..."); //$NON-NLS-1$
7761
}
78-
62+
7963
private void initialize() throws Exception {
8064

8165
configLocation = Utils.getConfigurationLocation();
@@ -90,7 +74,6 @@ private void initialize() throws Exception {
9074
// ignore
9175
}
9276
}
93-
configurationFactorySR = context.registerService(IPlatformConfigurationFactory.class, new PlatformConfigurationFactory(), null);
9477
configuration = getPlatformConfiguration(Utils.getInstallURL(), configLocation);
9578
if (configuration == null)
9679
throw Utils.newCoreException(NLS.bind(Messages.ConfigurationActivator_createConfig, (new String[] {configLocation.getURL().toExternalForm()})), null);
@@ -106,9 +89,6 @@ public void stop(BundleContext ctx) throws Exception {
10689
// TODO Auto-generated catch block
10790
e.printStackTrace();
10891
}
109-
configurationFactorySR.unregister();
110-
if (bundleGroupProviderSR != null)
111-
bundleGroupProviderSR.unregister();
11292
Utils.shutdown();
11393
}
11494

@@ -130,7 +110,7 @@ private PlatformConfiguration getPlatformConfiguration(URL installURL, Location
130110
}
131111

132112
private void loadOptions() {
133-
// all this is only to get the application args
113+
// all this is only to get the application args
134114
DebugOptions service = null;
135115
ServiceReference<DebugOptions> reference = context.getServiceReference(DebugOptions.class);
136116
if (reference != null)
@@ -149,29 +129,6 @@ public static BundleContext getBundleContext() {
149129
return context;
150130
}
151131

152-
@Override
153-
public String getName() {
154-
return Messages.BundleGroupProvider;
155-
}
156-
157-
@Override
158-
public IBundleGroup[] getBundleGroups() {
159-
if (configuration == null)
160-
return new IBundleGroup[0];
161-
162-
IPlatformConfiguration.IFeatureEntry[] features = configuration.getConfiguredFeatureEntries();
163-
ArrayList<IBundleGroup> bundleGroups = new ArrayList<>(features.length);
164-
for (IFeatureEntry feature : features) {
165-
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding())
166-
bundleGroups.add((IBundleGroup) feature);
167-
}
168-
return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]);
169-
}
170-
171-
public static ConfigurationActivator getConfigurator() {
172-
return configurator;
173-
}
174-
175132
private void acquireFrameworkLogService() {
176133
ServiceReference<FrameworkLog> logServiceReference = context.getServiceReference(FrameworkLog.class);
177134
if (logServiceReference == null)

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfigurationFactory.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818

1919
import org.eclipse.update.configurator.IPlatformConfiguration;
2020
import org.eclipse.update.configurator.IPlatformConfigurationFactory;
21+
import org.osgi.service.component.annotations.Component;
2122

23+
@SuppressWarnings("deprecation")
24+
@Component(service = IPlatformConfigurationFactory.class)
2225
public class PlatformConfigurationFactory implements IPlatformConfigurationFactory {
2326
@Override
2427
public IPlatformConfiguration getCurrentPlatformConfiguration() {
2528
return PlatformConfiguration.getCurrent();
2629
}
27-
30+
2831
@Override
2932
public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOException {
3033
try {
@@ -35,7 +38,7 @@ public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOExcepti
3538
throw new IOException(e.getMessage());
3639
}
3740
}
38-
41+
3942
@Override
4043
public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws IOException {
4144
try {
@@ -46,5 +49,5 @@ public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws
4649
throw new IOException(e.getMessage());
4750
}
4851
}
49-
52+
5053
}

0 commit comments

Comments
 (0)