diff --git a/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF b/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF index 64ab4e2541a..5f045c73188 100644 --- a/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF +++ b/update/org.eclipse.update.configurator/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.update.configurator; singleton:=true -Bundle-Version: 3.5.500.qualifier +Bundle-Version: 3.5.600.qualifier Bundle-Activator: org.eclipse.update.internal.configurator.ConfigurationActivator Bundle-Vendor: %providerName Bundle-Localization: plugin @@ -17,6 +17,7 @@ Import-Package: javax.xml.parsers, org.w3c.dom, org.xml.sax, org.xml.sax.helpers -Service-Component: OSGI-INF/org.eclipse.update.internal.configurator.BundleGroupComponent.xml Bundle-ActivationPolicy: lazy Automatic-Module-Name: org.eclipse.update.configurator +Service-Component: OSGI-INF/org.eclipse.update.internal.configurator.BundleGroupComponent.xml, + OSGI-INF/org.eclipse.update.internal.configurator.PlatformConfigurationFactory.xml diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java index c445319852c..068d1be7e01 100644 --- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java +++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java @@ -7,37 +7,58 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.update.internal.configurator; +import java.util.ArrayList; + import org.eclipse.core.runtime.IBundleGroup; import org.eclipse.core.runtime.IBundleGroupProvider; +import org.eclipse.update.configurator.IPlatformConfiguration; +import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry; +import org.eclipse.update.configurator.IPlatformConfigurationFactory; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; /** * Declarative services component that provides an implementation of * {@link IBundleGroupProvider}. This allows the bundle group provider to be * made available in the service registry before this bundle has started. */ -@Component +@Component(service = IBundleGroupProvider.class) +@SuppressWarnings("deprecation") public class BundleGroupComponent implements IBundleGroupProvider { + + private IPlatformConfigurationFactory factory; + + @Activate + public BundleGroupComponent(@Reference IPlatformConfigurationFactory factory) { + this.factory = factory; + } + @Override public IBundleGroup[] getBundleGroups() { - ConfigurationActivator activator = ConfigurationActivator.getConfigurator(); - if (activator.bundleGroupProviderSR != null) - // we manually registered the group in the activator; return no groups - // the manually registered service will handle the groups we know about + IPlatformConfiguration configuration = factory.getCurrentPlatformConfiguration(); + if (configuration == null) { return new IBundleGroup[0]; - return activator.getBundleGroups(); + } + IPlatformConfiguration.IFeatureEntry[] features = configuration.getConfiguredFeatureEntries(); + ArrayList bundleGroups = new ArrayList<>(features.length); + for (IFeatureEntry feature : features) { + if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding()) + bundleGroups.add((IBundleGroup) feature); + } + return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]); } @Override public String getName() { - return ConfigurationActivator.getConfigurator().getName(); + return Messages.BundleGroupProvider; } } diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java index 5bcc7e4cbbc..da08a5c183f 100644 --- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java +++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java @@ -13,27 +13,13 @@ *******************************************************************************/ package org.eclipse.update.internal.configurator; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; - -import org.eclipse.core.runtime.IBundleGroup; -import org.eclipse.core.runtime.IBundleGroupProvider; import org.eclipse.osgi.framework.log.FrameworkLog; -import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.debug.DebugOptions; -import org.eclipse.osgi.util.NLS; -import org.eclipse.update.configurator.IPlatformConfiguration; -import org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry; -import org.eclipse.update.configurator.IPlatformConfigurationFactory; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -public class ConfigurationActivator implements BundleActivator, IBundleGroupProvider, IConfigurationConstants { +public class ConfigurationActivator implements BundleActivator, IConfigurationConstants { public static String PI_CONFIGURATOR = "org.eclipse.update.configurator"; //$NON-NLS-1$ public static final String LAST_CONFIG_STAMP = "last.config.stamp"; //$NON-NLS-1$ @@ -46,91 +32,22 @@ public class ConfigurationActivator implements BundleActivator, IBundleGroupProv public static boolean DEBUG = false; private static BundleContext context; - private ServiceRegistration configurationFactorySR; - ServiceRegistration bundleGroupProviderSR; - private PlatformConfiguration configuration; - - // Location of the configuration data - private Location configLocation; - - // Singleton - private static ConfigurationActivator configurator; - - public ConfigurationActivator() { - configurator = this; - } @Override public void start(BundleContext ctx) throws Exception { context = ctx; loadOptions(); acquireFrameworkLogService(); - try { - initialize(); - } catch (Exception e) { - //we failed to start, so make sure Utils closes its service trackers - Utils.shutdown(); - throw e; - } - Utils.debug("Starting update configurator..."); //$NON-NLS-1$ } - - private void initialize() throws Exception { - - configLocation = Utils.getConfigurationLocation(); - // create the name space directory for update (configuration/org.eclipse.update) - if (!configLocation.isReadOnly()) { - try { - URL privateURL = new URL(configLocation.getURL(), NAME_SPACE); - File f = new File(privateURL.getFile()); - if (!f.exists()) - f.mkdirs(); - } catch (MalformedURLException e1) { - // ignore - } - } - configurationFactorySR = context.registerService(IPlatformConfigurationFactory.class, new PlatformConfigurationFactory(), null); - configuration = getPlatformConfiguration(Utils.getInstallURL(), configLocation); - if (configuration == null) - throw Utils.newCoreException(NLS.bind(Messages.ConfigurationActivator_createConfig, (new String[] {configLocation.getURL().toExternalForm()})), null); - - } @Override public void stop(BundleContext ctx) throws Exception { - // quick fix (hack) for bug 47861 - try { - PlatformConfiguration.shutdown(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - configurationFactorySR.unregister(); - if (bundleGroupProviderSR != null) - bundleGroupProviderSR.unregister(); Utils.shutdown(); } - /** - * Creates and starts the platform configuration. - * @return the just started platform configuration - */ - private PlatformConfiguration getPlatformConfiguration(URL installURL, Location configLocation) { - try { - PlatformConfiguration.startup(installURL, configLocation); - } catch (Exception e) { - String message = e.getMessage(); - if (message == null) - message = ""; //$NON-NLS-1$ - Utils.log(Utils.newStatus(message, e)); - } - return PlatformConfiguration.getCurrent(); - - } - private void loadOptions() { - // all this is only to get the application args + // all this is only to get the application args DebugOptions service = null; ServiceReference reference = context.getServiceReference(DebugOptions.class); if (reference != null) @@ -149,29 +66,6 @@ public static BundleContext getBundleContext() { return context; } - @Override - public String getName() { - return Messages.BundleGroupProvider; - } - - @Override - public IBundleGroup[] getBundleGroups() { - if (configuration == null) - return new IBundleGroup[0]; - - IPlatformConfiguration.IFeatureEntry[] features = configuration.getConfiguredFeatureEntries(); - ArrayList bundleGroups = new ArrayList<>(features.length); - for (IFeatureEntry feature : features) { - if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding()) - bundleGroups.add((IBundleGroup) feature); - } - return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]); - } - - public static ConfigurationActivator getConfigurator() { - return configurator; - } - private void acquireFrameworkLogService() { ServiceReference logServiceReference = context.getServiceReference(FrameworkLog.class); if (logServiceReference == null) diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java index a3393e54474..d3b2567c56e 100644 --- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java +++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java @@ -411,7 +411,7 @@ public URL[] getPluginPath() { public Set getPluginPaths() { HashSet paths = new HashSet<>(); - + for (ISiteEntry site : getConfiguredSites()) { for (String plugin : site.getPlugins()) { paths.add(plugin); @@ -429,12 +429,12 @@ public PluginEntry[] getPlugins() { Utils.debug("computed plug-ins:"); //$NON-NLS-1$ ISiteEntry[] sites = getConfiguredSites(); - for (int i = 0; i < sites.length; i++) { - if (!(sites[i] instanceof SiteEntry)) { - Utils.debug("Site " + sites[i].getURL() + " is not a SiteEntry"); //$NON-NLS-1$ //$NON-NLS-2$ + for (ISiteEntry site : sites) { + if (!(site instanceof SiteEntry)) { + Utils.debug("Site " + site.getURL() + " is not a SiteEntry"); //$NON-NLS-1$ //$NON-NLS-2$ continue; } - for (PluginEntry plugin : ((SiteEntry) sites[i]).getPluginEntries()) { + for (PluginEntry plugin : ((SiteEntry) site).getPluginEntries()) { allPlugins.add(plugin); Utils.debug(" " + plugin.getURL()); //$NON-NLS-1$ } @@ -494,7 +494,7 @@ public synchronized void save(URL url) throws IOException { // not a file protocol - attempt to save to the URL URLConnection uc = url.openConnection(); uc.setDoOutput(true); - + try(OutputStream os = uc.getOutputStream()) { saveAsXML(os); config.setDirty(false); @@ -595,9 +595,7 @@ public static PlatformConfiguration getCurrent() { /** * Starts a platform installed at specified installURL using configuration located at platformConfigLocation. */ - public static synchronized void startup(URL installURL, Location platformConfigLocation) throws Exception { - PlatformConfiguration.installURL = installURL; - + public static synchronized void startup(Location platformConfigLocation) throws Exception { // create current configuration if (currentPlatformConfiguration == null) { currentPlatformConfiguration = new PlatformConfiguration(platformConfigLocation); @@ -645,7 +643,7 @@ private synchronized void initializeCurrent(Location platformConfigLocation) thr // try loading the configuration try { - config = loadConfig(configFileURL, installURL); + config = loadConfig(configFileURL, getInstallURL()); Utils.debug("Using configuration " + configFileURL.toString()); //$NON-NLS-1$ } catch (Exception e) { // failed to load, see if we can find pre-initialized configuration. @@ -655,7 +653,7 @@ private synchronized void initializeCurrent(Location platformConfigLocation) thr throw new IOException(); // no platform.xml found, need to create default site URL sharedConfigFileURL = new URL(parentLocation.getURL(), CONFIG_NAME); - config = loadConfig(sharedConfigFileURL, installURL); + config = loadConfig(sharedConfigFileURL, getInstallURL()); // pre-initialized config loaded OK ... copy any remaining update metadata // Only copy if the default config location is not the install location @@ -667,7 +665,7 @@ private synchronized void initializeCurrent(Location platformConfigLocation) thr return; } catch (Exception ioe) { Utils.debug("Creating default configuration from " + configFileURL.toExternalForm()); //$NON-NLS-1$ - createDefaultConfiguration(configFileURL, installURL); + createDefaultConfiguration(configFileURL, getInstallURL()); } } finally { // if config == null an unhandled exception has been thrown and we allow it to propagate @@ -951,6 +949,9 @@ private URL getBasePathLocation(URL url, URL installLocation, URL configLocation } public static URL getInstallURL() { + if (installURL == null) { + installURL = Utils.getInstallURL(); + } return installURL; } diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfigurationFactory.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfigurationFactory.java index 7458f115351..4cf67664498 100644 --- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfigurationFactory.java +++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfigurationFactory.java @@ -13,18 +13,36 @@ *******************************************************************************/ package org.eclipse.update.internal.configurator; +import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.update.configurator.IPlatformConfiguration; import org.eclipse.update.configurator.IPlatformConfigurationFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +@SuppressWarnings("deprecation") +@Component(service = IPlatformConfigurationFactory.class) public class PlatformConfigurationFactory implements IPlatformConfigurationFactory { + private Location configLocation; + @Override public IPlatformConfiguration getCurrentPlatformConfiguration() { + try { + PlatformConfiguration.startup(configLocation); + } catch (Exception e) { + String message = e.getMessage(); + if (message == null) + message = ""; //$NON-NLS-1$ + Utils.log(Utils.newStatus(message, e)); + } return PlatformConfiguration.getCurrent(); } - + @Override public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOException { try { @@ -35,7 +53,7 @@ public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOExcepti throw new IOException(e.getMessage()); } } - + @Override public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws IOException { try { @@ -46,5 +64,29 @@ public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws throw new IOException(e.getMessage()); } } - + + @Activate + public void startup() { + configLocation = Utils.getConfigurationLocation(); + // create the name space directory for update (configuration/org.eclipse.update) + if (!configLocation.isReadOnly()) { + try { + URL privateURL = new URL(configLocation.getURL(), ConfigurationActivator.NAME_SPACE); + File f = new File(privateURL.getFile()); + if (!f.exists()) + f.mkdirs(); + } catch (MalformedURLException e1) { + // ignore + } + } + } + + @Deactivate + public void shutdown() { + try { + PlatformConfiguration.shutdown(); + } catch (IOException e) { + } + } + }