-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This extension point allows any projects wanting to extend any KLighD behavior for different run configurations to only need to register this extension once via Eclipse extension and via Java ServiceLoader in META-INF/services and programatically register everything needed in the implementation of this extension with the KLighD API for registering extensions programmatically.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
<extension-point id="extensions" name="Compound extension point for all kinds of extensions" schema="schema/extensions.exsd"/> | ||
<extension-point id="diagramSyntheses" name="Diagram syntheses registering point" schema="schema/diagramSyntheses.exsd"/> | ||
<extension-point id="de.cau.cs.kieler.klighd.preservedProperties" name="Preserved Properties" schema="schema/preservedProperties.exsd"/> | ||
<extension-point id="klighdStartupHook" name="Startup Hook for KLighD" schema="schema/klighdStartupHook.exsd"/> | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
NiklasRentzCAU
Author
Member
|
||
<extension | ||
point="org.eclipse.core.runtime.preferences"> | ||
<initializer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!-- Schema file written by PDE --> | ||
<schema targetNamespace="de.cau.cs.kieler.klighd" xmlns="http://www.w3.org/2001/XMLSchema"> | ||
<annotation> | ||
<appinfo> | ||
<meta.schema plugin="de.cau.cs.kieler.klighd" id="klighdStartupHook" name="Startup Hook extension point"/> | ||
</appinfo> | ||
<documentation> | ||
This extension point is to be used to programmatically register KLighD extensions during startup. | ||
</documentation> | ||
</annotation> | ||
|
||
<element name="extension"> | ||
<annotation> | ||
<appinfo> | ||
<meta.element /> | ||
</appinfo> | ||
</annotation> | ||
<complexType> | ||
<sequence minOccurs="1" maxOccurs="unbounded"> | ||
<element ref="startupHook"/> | ||
</sequence> | ||
<attribute name="point" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="id" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="name" type="string"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
<appinfo> | ||
<meta.attribute translatable="true"/> | ||
</appinfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<element name="startupHook"> | ||
<complexType> | ||
<attribute name="id" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
|
||
</documentation> | ||
</annotation> | ||
</attribute> | ||
<attribute name="class" type="string" use="required"> | ||
<annotation> | ||
<documentation> | ||
The implementation of this hook. May use public KLighD API to register other extensions in KLighD programmatically. | ||
</documentation> | ||
<appinfo> | ||
<meta.attribute kind="java" basedOn="de.cau.cs.kieler.klighd.IKlighdStartupHook"/> | ||
</appinfo> | ||
</annotation> | ||
</attribute> | ||
</complexType> | ||
</element> | ||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="since"/> | ||
</appinfo> | ||
<documentation> | ||
2.0.0 | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="examples"/> | ||
</appinfo> | ||
<documentation> | ||
[Enter extension point usage example here.] | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="apiinfo"/> | ||
</appinfo> | ||
<documentation> | ||
[Enter API information here.] | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="implementation"/> | ||
</appinfo> | ||
<documentation> | ||
[Enter information about supplied implementation of this extension point.] | ||
</documentation> | ||
</annotation> | ||
|
||
<annotation> | ||
<appinfo> | ||
<meta.section type="copyright"/> | ||
</appinfo> | ||
<documentation> | ||
KIELER - Kiel Integrated Environment for Layout Eclipse RichClient | ||
|
||
http://rtsys.informatik.uni-kiel.de/kieler | ||
|
||
Copyright 2020 by | ||
+ Kiel University | ||
+ Department of Computer Science | ||
+ Real-Time and Embedded Systems Group | ||
|
||
This code is provided under the terms of the Eclipse Public License (EPL). | ||
|
||
</documentation> | ||
</annotation> | ||
|
||
</schema> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient | ||
* | ||
* http://rtsys.informatik.uni-kiel.de/kieler | ||
* | ||
* Copyright 2020 by | ||
* + Kiel University | ||
* + Department of Computer Science | ||
* + Real-Time and Embedded Systems Group | ||
* | ||
* This code is provided under the terms of the Eclipse Public License (EPL). | ||
*/ | ||
package de.cau.cs.kieler.klighd; | ||
|
||
import de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis; | ||
|
||
/** | ||
* Interface for the KLighD extension to add functionality in terms of other extensions during the startup of KLighD | ||
* programmatically. This is meant to register e.g. {@link IAction}, {@link AbstractDiagramSynthesis}, and other | ||
* extensions programmatically using the programmatic extension registration in {@link KlighdDataManager} to avoid | ||
* having to use Eclipse extensions or Java Service loader in different launch scenarios. | ||
* | ||
* @author nre | ||
*/ | ||
public interface IKlighdStartupHook { | ||
|
||
/** | ||
* The hook that gets executed during the startup of KLighD. | ||
*/ | ||
void execute(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
@@ -52,7 +51,6 @@ | |
import com.google.common.collect.Multimap; | ||
|
||
import de.cau.cs.kieler.klighd.internal.ISynthesis; | ||
import de.cau.cs.kieler.klighd.internal.macrolayout.KlighdDiagramLayoutConnector; | ||
import de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis; | ||
import de.cau.cs.kieler.klighd.syntheses.GuiceBasedSynthesisFactory; | ||
import de.cau.cs.kieler.klighd.syntheses.ReinitializingDiagramSynthesisProxy; | ||
|
@@ -71,6 +69,9 @@ public final class KlighdDataManager { | |
/** identifier of the extension point for model transformations. */ | ||
private static final String EXTP_ID_DIAGRAM_SYNTHESES = "de.cau.cs.kieler.klighd.diagramSyntheses"; | ||
|
||
/** identifier of the extension point for startup hooks. */ | ||
private static final String EXTP_ID_STARTUP_HOOK = "de.cau.cs.kieler.klighd.klighdStartupHook"; | ||
|
||
/** name of the 'viewer' element. */ | ||
private static final String ELEMENT_VIEWER = "viewer"; | ||
|
||
|
@@ -95,6 +96,9 @@ public final class KlighdDataManager { | |
/** name of the 'offscreenRenderer' element. */ | ||
private static final String ELEMENT_OFFSCREEN_RENDERER = "offscreenRenderer"; | ||
|
||
/** name of the 'startupHook' element. */ | ||
private static final String ELEMENT_STARTUP_HOOK = "startupHook"; | ||
|
||
/** name of the 'id' attribute in the extension points. */ | ||
private static final String ATTRIBUTE_ID = "id"; | ||
|
||
|
@@ -142,6 +146,9 @@ public final class KlighdDataManager { | |
private static final String INSTANTIATION_FAILURE_MSG = | ||
"KLighD: An unexpected failure occured while instantiating " | ||
+ "class <<CLAZZ>>. See attached trace for details." + NEW_LINE; | ||
|
||
private static final String STARTUP_HOOK_ERROR_MSG = | ||
"KLighD: an unexpected failure occured while executing a startup hook. See attached trace for details."; | ||
|
||
/** the singleton instance. */ | ||
private static KlighdDataManager instance; | ||
|
@@ -151,6 +158,12 @@ public final class KlighdDataManager { | |
*/ | ||
static { | ||
instance = new KlighdDataManager(); | ||
// Load the startup hooks after creating the instance, as they should use this instance to hook into. | ||
if (Klighd.IS_PLATFORM_RUNNING) { | ||
loadStartupHooksViaExtensionPoint(); | ||
} else { | ||
loadStartupHooksViaServiceLoader(); | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
sailingKieler
Member
|
||
} | ||
|
||
/** | ||
|
@@ -717,6 +730,62 @@ private void loadDiagramSynthesesViaServiceLoader(Map<String, ISynthesis> idSynt | |
} | ||
} | ||
|
||
/** | ||
* Loads the registered {@link de.cau.cs.kieler.klighd.IKlighdStartupHook} from the extension point. | ||
*/ | ||
private static final void loadStartupHooksViaExtensionPoint() { | ||
final Iterable<IConfigurationElement> extensions = Iterables.filter( | ||
Arrays.asList( | ||
Platform.getExtensionRegistry().getConfigurationElementsFor(EXTP_ID_STARTUP_HOOK) | ||
), | ||
element -> ELEMENT_STARTUP_HOOK.equals(element.getName()) | ||
); | ||
|
||
for (final IConfigurationElement element : extensions) { | ||
final String id = element.getAttribute(ATTRIBUTE_ID); | ||
if (Strings.isNullOrEmpty(id)) | ||
reportError(EXTP_ID_STARTUP_HOOK, element, ATTRIBUTE_ID, null, null); | ||
|
||
else { | ||
|
||
// initialize model transformation from the extension point | ||
IKlighdStartupHook startupHook = null; | ||
try { | ||
startupHook = (IKlighdStartupHook) element.createExecutableExtension(ATTRIBUTE_CLASS); | ||
|
||
} catch (final CoreException exception) { | ||
Klighd.handle( | ||
new Status(IStatus.ERROR, Klighd.PLUGIN_ID, | ||
CORE_EXCEPTION_ERROR_MSG.replace("<<CLAZZ>>", | ||
element.getAttribute(ATTRIBUTE_CLASS)), exception)); | ||
} | ||
|
||
if (startupHook != null) { | ||
try { | ||
startupHook.execute(); | ||
} catch (Throwable t) { | ||
Klighd.log(new Status(IStatus.ERROR, Klighd.PLUGIN_ID, STARTUP_HOOK_ERROR_MSG, t)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Loads the registered {@link de.cau.cs.kieler.klighd.IKlighdStartupHook} via Java {@link ServiceLoader}. | ||
*/ | ||
private static void loadStartupHooksViaServiceLoader() { | ||
|
||
for (IKlighdStartupHook startupHook : ServiceLoader.load(IKlighdStartupHook.class, | ||
KlighdDataManager.class.getClassLoader())) { | ||
try { | ||
startupHook.execute(); | ||
} catch (Throwable t) { | ||
Klighd.log(new Status(IStatus.ERROR, Klighd.PLUGIN_ID, STARTUP_HOOK_ERROR_MSG, t)); | ||
} | ||
} | ||
} | ||
|
||
private void registerDiagramSynthesisClass(final String id, | ||
Class<? extends AbstractDiagramSynthesis<?>> clazz, boolean wrapWithReinitializer, | ||
Map<String, ISynthesis> idSynthesisMapping, | ||
|
Why these additional extension points?
klighdStartupHook
s could easily be registered via the existingextensions
point.