public interface OsgiExecable extends Serializable, Runnable
Runs code that lives outside an OSGi container inside of it. Works just like JavaExecable
.
Make sure the code you execute only uses classes which are available to the OSGi runtime you’re using. If you’d like to call some code which is only available inside the OSGi container, use a OsgiExecable.ReflectionHost
and OsgiExecable.ReflectionClient
pair, as such:
class ProjectImporter extends OsgiExecable.ReflectionHost {
private static final long serialVersionUID = 6542985814638851088L;
ArrayList<File> projects;
public ProjectImporter(Collection<File> projects) {
super("com.diffplug.gradle.oomph.ProjectImporterInternal");
this.projects = new ArrayList<>(projects);
}
}
class ProjectImporterInternal extends OsgiExecable.ReflectionClient<ProjectImporter> {
ProjectImporterInternal(ProjectImporter host) {
super(host);
}
public void run() {
// add all projects to the workspace
IWorkspace workspace = ResourcesPlugin.getWorkspace();
for (File projectFile : host.projects) {
try {
Path path = new Path(projectFile.toString());
IProjectDescription description = workspace.loadProjectDescription(path);
etc.
Modifier and Type | Interface and Description |
---|---|
static class |
OsgiExecable.ReflectionClient<Host extends OsgiExecable.ReflectionHost>
Client code which gets called within the OSGi runtime.
|
static class |
OsgiExecable.ReflectionHost
Defines data which will be passed via reflection to code within the OSGi runtime - the reflection allows us to call code for which we don’t have the necessary dependencies to resolve its imports unless it is only instantiated within the OSGi container.
|
Modifier and Type | Method and Description |
---|---|
static <T extends OsgiExecable> |
exec(org.osgi.framework.BundleContext context,
T input)
Executes the given
OsgiExecable within an embedded OSGi runtime. |
static <T extends OsgiExecable> T exec(org.osgi.framework.BundleContext context, T input) throws Exception
Executes the given OsgiExecable
within an embedded OSGi runtime.
Exception