Refined guards enabling Sphinx to be used when an OSGi runtime is
available but no Eclipse workspace is present
diff --git a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/MapModelIndex.java b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/MapModelIndex.java
index 507533a..2df4b3f 100644
--- a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/MapModelIndex.java
+++ b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/MapModelIndex.java
@@ -60,13 +60,21 @@
public void startListening() {
if (ExtendedPlatform.IS_PLATFORM_RUNNING && ExtendedPlatform.IS_WORKSPACE_AVAILABLE) {
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ try {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ } catch (Exception ex) {
+ // Ignore Exception
+ }
}
}
public void stopListening() {
if (ExtendedPlatform.IS_PLATFORM_RUNNING && ExtendedPlatform.IS_WORKSPACE_AVAILABLE) {
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ try {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ } catch (Exception ex) {
+ // Ignore Exception
+ }
}
}
diff --git a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ModelConverterRegistry.java b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ModelConverterRegistry.java
index 237e262..3a18c28 100644
--- a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ModelConverterRegistry.java
+++ b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ModelConverterRegistry.java
@@ -1,16 +1,16 @@
/**
* <copyright>
- *
+ *
* Copyright (c) 2008-2019 See4sys, BMW Car IT and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* See4sys - Initial API and implementation
* BMW Car IT - Added mechanism for converter description management
- *
+ *
* </copyright>
*/
package org.eclipse.sphinx.emf.resource;
@@ -61,18 +61,20 @@
fModelConverters = new ArrayList<IModelConverter>();
try {
if (ExtendedPlatform.IS_PLATFORM_RUNNING) {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- if (registry != null) {
+ if (Activator.getPlugin() != null) {
String symbolicName = Activator.getPlugin().getSymbolicName();
- IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(symbolicName, EXTP_MODEL_CONVERTERS);
- for (IConfigurationElement element : configurationElements) {
- try {
- IModelConverter converter = (IModelConverter) element.createExecutableExtension(ATTR_CLASS);
- IModelConverterDescription convDesc = new ModelConverterDescription(getDescription(element), getWarning(element));
- fConverterDescriptions.put(converter, convDesc);
- fModelConverters.add(converter);
- } catch (CoreException ex) {
- PlatformLogUtil.logAsError(Activator.getDefault(), ex);
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ if (registry != null) {
+ IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(symbolicName, EXTP_MODEL_CONVERTERS);
+ for (IConfigurationElement element : configurationElements) {
+ try {
+ IModelConverter converter = (IModelConverter) element.createExecutableExtension(ATTR_CLASS);
+ IModelConverterDescription convDesc = new ModelConverterDescription(getDescription(element), getWarning(element));
+ fConverterDescriptions.put(converter, convDesc);
+ fModelConverters.add(converter);
+ } catch (CoreException ex) {
+ PlatformLogUtil.logAsError(Activator.getDefault(), ex);
+ }
}
}
}
@@ -110,7 +112,7 @@
/**
* Gets the registered converters.
- *
+ *
* @return the converters
*/
public List<IModelConverter> getConverters() {
@@ -140,7 +142,7 @@
/**
* Returns the IModelConverterDescription for the specified <code>converter</code>
- *
+ *
* @param converter
* The IModelConverter for which the IModelConverterDescription is to be retrieved.
* @return The IModelConverterDescription of the <code>converter</code>.
@@ -152,7 +154,7 @@
/**
* Returns the descriptions of all the IModelConverters which target at <code>targetResourceVersion</code>.
- *
+ *
* @param targetResourceVersion
* The target resource version of the IModelConverters whom's descriptions are to be returned.
* @return The IModelConverterDescriptions of all IModelConverters which target at the specified
diff --git a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java
index 764a63b..cedd528 100644
--- a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java
+++ b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/resource/ResourceHandlerRegistry.java
@@ -1,16 +1,16 @@
/**
* <copyright>
- *
+ *
* Copyright (c) 2008-2019 See4sys, BMW Car IT and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* See4sys - Initial API and implementation
* BMW Car IT - Added/Updated javadoc
- *
+ *
* </copyright>
*/
package org.eclipse.sphinx.emf.resource;
@@ -58,15 +58,17 @@
private void readRegistry() {
try {
if (ExtendedPlatform.IS_PLATFORM_RUNNING) {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- if (registry != null) {
+ if (Activator.getPlugin() != null) {
String symbolicName = Activator.getPlugin().getSymbolicName();
- IConfigurationElement[] contributions = registry.getConfigurationElementsFor(symbolicName, EXTPOINT_RESOURCE_HANDLERS);
- for (IConfigurationElement contribution : contributions) {
- try {
- readContribution(contribution);
- } catch (Exception ex) {
- PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ if (registry != null) {
+ IConfigurationElement[] contributions = registry.getConfigurationElementsFor(symbolicName, EXTPOINT_RESOURCE_HANDLERS);
+ for (IConfigurationElement contribution : contributions) {
+ try {
+ readContribution(contribution);
+ } catch (Exception ex) {
+ PlatformLogUtil.logAsError(Activator.getPlugin(), ex);
+ }
}
}
}
@@ -91,7 +93,7 @@
/**
* Creates a ResourceHandler of the type registered for the given namespace URI.
- *
+ *
* @param nsURI
* The URI of the namespace for which a ResourceHandler is to be retrieved.
* @return The ResourceHandler associated with the given namespace URI.
@@ -110,7 +112,7 @@
* Registers a ResourceHandler type with namespaces. A ResourceHandle of the specified type will be created if
* {@link #getHandler(String)} is called with a namespace URI matching the namespace URI pattern passed to this
* method.
- *
+ *
* @param nsURIPattern
* A namespace URI pattern describing for which namespaces a ResourceHandler of the given type is to be
* returned.
diff --git a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/util/EcoreResourceUtil.java b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/util/EcoreResourceUtil.java
index bad5f73..d4eecea 100644
--- a/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/util/EcoreResourceUtil.java
+++ b/plugins/org.eclipse.sphinx.emf/src/org/eclipse/sphinx/emf/util/EcoreResourceUtil.java
@@ -130,16 +130,20 @@
uriConverter = new ExtensibleURIConverterImpl();
}
if (ExtendedPlatform.IS_PLATFORM_RUNNING && ExtendedPlatform.IS_WORKSPACE_AVAILABLE) {
- // Initialize URI mappings
- IPath workspaceRootPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath().addTrailingSeparator();
- URI workspaceRootURI = URI.createPlatformResourceURI(workspaceRootPath.toString(), true);
+ try {
+ // Initialize URI mappings
+ IPath workspaceRootPath = ResourcesPlugin.getWorkspace().getRoot().getFullPath().addTrailingSeparator();
+ URI workspaceRootURI = URI.createPlatformResourceURI(workspaceRootPath.toString(), true);
- IPath workspaceRootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().addTrailingSeparator();
- URI workspaceRootLocationURI = URI.createURI(workspaceRootLocation.toString(), true);
- URI workspaceRootLocationFileURI = URI.createFileURI(workspaceRootLocation.toString());
+ IPath workspaceRootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().addTrailingSeparator();
+ URI workspaceRootLocationURI = URI.createURI(workspaceRootLocation.toString(), true);
+ URI workspaceRootLocationFileURI = URI.createFileURI(workspaceRootLocation.toString());
- uriConverter.getURIMap().put(workspaceRootLocationURI, workspaceRootURI);
- uriConverter.getURIMap().put(workspaceRootLocationFileURI, workspaceRootURI);
+ uriConverter.getURIMap().put(workspaceRootLocationURI, workspaceRootURI);
+ uriConverter.getURIMap().put(workspaceRootLocationFileURI, workspaceRootURI);
+ } catch (Exception ex) {
+ // Ignore exception
+ }
}
return uriConverter;
}