mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
[181939] Deferred class loading for keystoreProviders
This commit is contained in:
parent
8f161352bd
commit
4bf1cf9199
2 changed files with 121 additions and 36 deletions
|
@ -14,6 +14,7 @@
|
||||||
* David Dykstal (IBM) - added utility method for finding qualifiedHostNames
|
* David Dykstal (IBM) - added utility method for finding qualifiedHostNames
|
||||||
* Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods
|
* Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods
|
||||||
* Martin Oberhuber (Wind River) - [186525] Move keystoreProviders to core
|
* Martin Oberhuber (Wind River) - [186525] Move keystoreProviders to core
|
||||||
|
* Martin Oberhuber (Wind River) - [181939] Deferred class loading for keystoreProviders
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
package org.eclipse.rse.core;
|
package org.eclipse.rse.core;
|
||||||
|
|
||||||
|
@ -24,7 +25,6 @@ import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionRegistry;
|
import org.eclipse.core.runtime.IExtensionRegistry;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.rse.core.comm.ISystemKeystoreProvider;
|
|
||||||
import org.eclipse.rse.core.comm.SystemKeystoreProviderManager;
|
import org.eclipse.rse.core.comm.SystemKeystoreProviderManager;
|
||||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||||
import org.eclipse.rse.internal.core.RSECoreRegistry;
|
import org.eclipse.rse.internal.core.RSECoreRegistry;
|
||||||
|
@ -119,7 +119,7 @@ public class RSECorePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a qualified hostname given a potentially unqualified hostname
|
* Returns a qualified host name given a potentially unqualified host name
|
||||||
*/
|
*/
|
||||||
public static String getQualifiedHostName(String hostName) {
|
public static String getQualifiedHostName(String hostName) {
|
||||||
try {
|
try {
|
||||||
|
@ -221,7 +221,10 @@ public class RSECorePlugin extends Plugin {
|
||||||
getLogger().logError("Unexpected Exception", t); //$NON-NLS-1$
|
getLogger().logError("Unexpected Exception", t); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerKeystoreProviders()
|
/**
|
||||||
|
* Register declared keystore providers.
|
||||||
|
*/
|
||||||
|
private void registerKeystoreProviders()
|
||||||
{
|
{
|
||||||
// Get reference to the plug-in registry
|
// Get reference to the plug-in registry
|
||||||
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
IExtensionRegistry registry = Platform.getExtensionRegistry();
|
||||||
|
@ -231,28 +234,16 @@ public class RSECorePlugin extends Plugin {
|
||||||
|
|
||||||
for (int i = 0; i < systemTypeExtensions.length; i++)
|
for (int i = 0; i < systemTypeExtensions.length; i++)
|
||||||
{
|
{
|
||||||
try
|
// get the name space of the declaring extension
|
||||||
{
|
String nameSpace = systemTypeExtensions[i].getDeclaringExtension().getNamespaceIdentifier();
|
||||||
// get the name space of the declaring extension
|
String keystoreProviderType = systemTypeExtensions[i].getAttribute("class"); //$NON-NLS-1$
|
||||||
String nameSpace = systemTypeExtensions[i].getDeclaringExtension().getNamespaceIdentifier();
|
|
||||||
|
|
||||||
String keystoreProviderType = systemTypeExtensions[i].getAttribute("class"); //$NON-NLS-1$
|
// use the name space to get the bundle
|
||||||
|
Bundle bundle = Platform.getBundle(nameSpace);
|
||||||
// use the name space to get the bundle
|
if (bundle.getState() != Bundle.UNINSTALLED)
|
||||||
Bundle bundle = Platform.getBundle(nameSpace);
|
{
|
||||||
|
SystemKeystoreProviderManager.getInstance().registerKeystoreProvider(bundle, keystoreProviderType);
|
||||||
if (bundle.getState() != Bundle.UNINSTALLED)
|
}
|
||||||
{
|
|
||||||
Class keystoreProvider = bundle.loadClass(keystoreProviderType);
|
|
||||||
|
|
||||||
ISystemKeystoreProvider extension = (ISystemKeystoreProvider)keystoreProvider.getConstructors()[0].newInstance(null);
|
|
||||||
SystemKeystoreProviderManager.getInstance().registerKeystoreProvider(extension);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Oberhuber (Wind River) - [186525] Move keystoreProviders to core
|
* Martin Oberhuber (Wind River) - [186525] Move keystoreProviders to core
|
||||||
|
* Martin Oberhuber (Wind River) - [181939] Deferred class loading for keystoreProviders
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.core.comm;
|
package org.eclipse.rse.core.comm;
|
||||||
|
@ -19,48 +20,141 @@ package org.eclipse.rse.core.comm;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.rse.core.RSECorePlugin;
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Registry of keystore providers, with the ability to instantiate
|
||||||
|
* providers lazily when needed.
|
||||||
|
*/
|
||||||
public class SystemKeystoreProviderManager
|
public class SystemKeystoreProviderManager
|
||||||
{
|
{
|
||||||
private static SystemKeystoreProviderManager _instance = new SystemKeystoreProviderManager();
|
private static SystemKeystoreProviderManager _instance = new SystemKeystoreProviderManager();
|
||||||
|
|
||||||
private List _extensions;
|
private List _extensions;
|
||||||
|
|
||||||
|
private static class ExtensionInfo {
|
||||||
|
public Bundle bundle;
|
||||||
|
public String className;
|
||||||
|
public ExtensionInfo(Bundle bundle, String className) {
|
||||||
|
this.bundle = bundle;
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SystemKeystoreProviderManager()
|
private SystemKeystoreProviderManager()
|
||||||
{
|
{
|
||||||
_extensions= new ArrayList();
|
_extensions= new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the SystemKeystoreProviderManager Instance.
|
||||||
|
* @return the singleton instance.
|
||||||
|
*/
|
||||||
public static SystemKeystoreProviderManager getInstance()
|
public static SystemKeystoreProviderManager getInstance()
|
||||||
{
|
{
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a keystore provider.
|
||||||
|
* @param ext keystore provider to register.
|
||||||
|
*/
|
||||||
public void registerKeystoreProvider(ISystemKeystoreProvider ext)
|
public void registerKeystoreProvider(ISystemKeystoreProvider ext)
|
||||||
{
|
{
|
||||||
_extensions.add(ext);
|
_extensions.add(ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a keystore provider for deferred (lazy) loading.
|
||||||
|
*
|
||||||
|
* @param bundle the bundle that declares the extension. The bundle
|
||||||
|
* must be installed and will be activated lazily when trying
|
||||||
|
* to load the given class name.
|
||||||
|
* @param className fully qualified classname of the keystore provider
|
||||||
|
* declared in the given bundle.
|
||||||
|
*/
|
||||||
|
public void registerKeystoreProvider(Bundle bundle, String className)
|
||||||
|
{
|
||||||
|
_extensions.add(new ExtensionInfo(bundle, className));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasProvider()
|
public boolean hasProvider()
|
||||||
{
|
{
|
||||||
return !_extensions.isEmpty();
|
return !_extensions.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISystemKeystoreProvider getDefaultProvider()
|
/**
|
||||||
|
* Return the keystore provider at the given index in the registry,
|
||||||
|
* or <code>null</code> if there is no provider at the given index
|
||||||
|
* or it cannot be loaded.
|
||||||
|
* @return An ISystemKeystoreProvider instance, or <code>null</code>
|
||||||
|
* if no provider is found at the given index.
|
||||||
|
*/
|
||||||
|
public ISystemKeystoreProvider getProviderAt(int idx)
|
||||||
{
|
{
|
||||||
if (_extensions.size() > 0)
|
if (idx >= 0 && idx < _extensions.size()) {
|
||||||
{
|
Object o = _extensions.get(idx);
|
||||||
return (ISystemKeystoreProvider)_extensions.get(_extensions.size() - 1);
|
if (o instanceof ISystemKeystoreProvider) {
|
||||||
|
return (ISystemKeystoreProvider)o;
|
||||||
|
} else if (o instanceof ExtensionInfo) {
|
||||||
|
ExtensionInfo info = (ExtensionInfo)o;
|
||||||
|
try {
|
||||||
|
Class keystoreProvider = info.bundle.loadClass(info.className);
|
||||||
|
ISystemKeystoreProvider extension = (ISystemKeystoreProvider)keystoreProvider.getConstructors()[0].newInstance(null);
|
||||||
|
_extensions.set(idx, extension);
|
||||||
|
return extension;
|
||||||
|
} catch(Exception e) {
|
||||||
|
RSECorePlugin.getDefault().getLog().log(
|
||||||
|
new Status(IStatus.ERROR, info.bundle.getSymbolicName(), -1, e.getMessage(), e));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the default keystore provider.
|
||||||
|
* The default provider is the one which was added last by the
|
||||||
|
* extension registry, and loads properly.
|
||||||
|
* @return An ISystemKeystoreProvider instance, or <code>null</code>
|
||||||
|
* if no provider is found at the given index.
|
||||||
|
*/
|
||||||
|
public ISystemKeystoreProvider getDefaultProvider()
|
||||||
|
{
|
||||||
|
int idx = _extensions.size()-1;
|
||||||
|
while (idx>=0) {
|
||||||
|
ISystemKeystoreProvider provider = getProviderAt(idx);
|
||||||
|
if (provider!=null) {
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
_extensions.remove(idx);
|
||||||
|
idx--;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of all registered keystore providers.
|
||||||
|
* The default provider is the one which was added last by the
|
||||||
|
* extension registry, and loads properly.
|
||||||
|
* @return An array of all registered keystore providers
|
||||||
|
* that load properly.
|
||||||
|
*/
|
||||||
public ISystemKeystoreProvider[] getProviders()
|
public ISystemKeystoreProvider[] getProviders()
|
||||||
{
|
{
|
||||||
ISystemKeystoreProvider[] providers = new ISystemKeystoreProvider[_extensions.size()];
|
List providers = new ArrayList();
|
||||||
for (int i = 0; i < _extensions.size(); i++)
|
for (int i = _extensions.size()-1; i>=0; i--) {
|
||||||
{
|
ISystemKeystoreProvider provider = getProviderAt(i);
|
||||||
providers[i] = (ISystemKeystoreProvider)_extensions.get(i);
|
if (provider!=null) {
|
||||||
|
providers.add(0, provider);
|
||||||
|
} else {
|
||||||
|
_extensions.remove(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return providers;
|
ISystemKeystoreProvider[] result = (ISystemKeystoreProvider[])providers.toArray(new ISystemKeystoreProvider[providers.size()]);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue