From 6818878737a9de0075976f79157e07283e7713d7 Mon Sep 17 00:00:00 2001 From: Christian Femers Date: Tue, 3 Sep 2019 07:12:26 +0200 Subject: [PATCH] Experimental approach to register machines via extension point Note: this does not work currently. Most likely, because the @Execute tagged method is not executed. How ironic. Need to look into that and how this works (it should work like that somehow) --- net.mograsim.machine/META-INF/MANIFEST.MF | 7 +- .../net/mograsim/machine/MachineRegistry.java | 69 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java diff --git a/net.mograsim.machine/META-INF/MANIFEST.MF b/net.mograsim.machine/META-INF/MANIFEST.MF index dfdcb05d..f7842aef 100644 --- a/net.mograsim.machine/META-INF/MANIFEST.MF +++ b/net.mograsim.machine/META-INF/MANIFEST.MF @@ -6,9 +6,10 @@ Bundle-Version: 0.1.0.qualifier Bundle-Vendor: Mograsim Team Automatic-Module-Name: net.mograsim.machine Bundle-RequiredExecutionEnvironment: JavaSE-11 -Require-Bundle: net.mograsim.logic.core;bundle-version="0.1.0", - net.mograsim.logic.model;bundle-version="0.1.0", - net.mograsim.preferences +Require-Bundle: net.mograsim.logic.model;bundle-version="0.1.0";visibility:=reexport, + net.mograsim.preferences, + org.eclipse.e4.core.di.annotations, + org.eclipse.core.runtime Export-Package: net.mograsim.machine, net.mograsim.machine.isa, net.mograsim.machine.isa.types, diff --git a/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java b/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java new file mode 100644 index 00000000..865a8993 --- /dev/null +++ b/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java @@ -0,0 +1,69 @@ +package net.mograsim.machine; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.e4.core.di.annotations.Execute; + +public class MachineRegistry +{ + private static final String MACHINE_EXT_ID = "net.mograsim.machine.machinedefinition"; + + private static Set installedMachines = new HashSet<>(); + + @Execute + public void execute(IExtensionRegistry registry) + { + System.out.println(Arrays.toString(registry.getExtensionPoints("net.mograsim.machine"))); + IConfigurationElement[] config = registry.getConfigurationElementsFor(MACHINE_EXT_ID); + try + { + for (IConfigurationElement e : config) + { + final Object o = e.createExecutableExtension("class"); + if (o instanceof MachineDefinition) + { + executeExtension(o); + } else + { + System.err.println("Invalid machine definition: " + o); + } + } + } + catch (CoreException ex) + { + System.out.println(ex.getMessage()); + } + } + + private void executeExtension(final Object o) + { + ISafeRunnable runnable = new ISafeRunnable() + { + @Override + public void handleException(Throwable e) + { + System.out.println("Exception in client"); + } + + @Override + public void run() throws Exception + { + System.out.println(((MachineDefinition) o).getAddressBits()); + } + }; + SafeRunner.run(runnable); + } + + public static Set getinstalledMachines() + { + return Collections.unmodifiableSet(installedMachines); + } +} -- 2.17.1