diff --git a/.gitignore b/.gitignore index f20f9773..013d2cc6 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ mg # Packer sometimes produces an error text file. error_stack.txt +/OutlawEditor/OutlawPluginExample/target/ \ No newline at end of file diff --git a/OutlawEditor/OutlawPluginExample/pom.xml b/OutlawEditor/OutlawPluginExample/pom.xml new file mode 100644 index 00000000..38887010 --- /dev/null +++ b/OutlawEditor/OutlawPluginExample/pom.xml @@ -0,0 +1,166 @@ + + 4.0.0 + + org.badvision + OutlawPluginExample + 0.1 + bundle + + OutlawPluginExample OSGi Bundle + + + UTF-8 + + + + + + org.apache.felix + maven-bundle-plugin + 3.0.1 + true + + + org.badvision.outlaw.plugin.example.* + org.badvision.outlaw.plugin.example.Activator + + + + + + + + + build-for-felix + + + org.apache.felix + org.apache.felix.main + 5.4.0 + provided + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + compile + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.6 + + + create-executable-jar + package + + single + + + + ${basedir}/src/main/assembly/felix.xml + + ${project.build.finalName} + + + + + + + + + run-on-felix + + + org.apache.felix + org.apache.felix.main + 5.4.0 + provided + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.felix + org.apache.felix.framework + 5.4.0 + jar + + + diff --git a/OutlawEditor/OutlawPluginExample/src/main/java/org/badvision/outlaw/plugin/example/Activator.java b/OutlawEditor/OutlawPluginExample/src/main/java/org/badvision/outlaw/plugin/example/Activator.java new file mode 100644 index 00000000..0a41f8e2 --- /dev/null +++ b/OutlawEditor/OutlawPluginExample/src/main/java/org/badvision/outlaw/plugin/example/Activator.java @@ -0,0 +1,19 @@ +package org.badvision.outlaw.plugin.example; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +/** + * + * @author blurry + */ +public class Activator implements BundleActivator { + + public void start(BundleContext bc) throws Exception { + System.out.println("Hello, world!"); + } + + public void stop(BundleContext bc) throws Exception { + } + +} diff --git a/OutlawEditor/pom.xml b/OutlawEditor/pom.xml index b37f5e36..753530bc 100644 --- a/OutlawEditor/pom.xml +++ b/OutlawEditor/pom.xml @@ -31,6 +31,7 @@ unpack-dependencies + META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA system junit,org.mockito,org.hamcrest ${project.build.directory}/classes @@ -130,5 +131,20 @@ jaxb2-basics 0.11.0 + + org.apache.felix + org.apache.felix.framework + 5.4.0 + + + org.apache.felix + org.apache.felix.main + 5.4.0 + + + org.osgi + org.osgi.core + 4.3.0 + diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java index af07791b..2ce38482 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java @@ -7,19 +7,24 @@ * ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ - package org.badvision.outlaweditor; import java.io.IOException; -import javafx.event.EventHandler; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; import javafx.stage.WindowEvent; +import org.apache.felix.framework.Felix; +import org.apache.felix.main.AutoProcessor; import org.badvision.outlaweditor.data.xml.GameData; import org.badvision.outlaweditor.ui.ApplicationUIController; +import org.osgi.framework.BundleException; /** * @@ -35,7 +40,17 @@ public class Application extends javafx.application.Application { return instance; } + public static void shutdown() { + try { + instance.pluginContainer.stop(); + instance.pluginContainer.waitForStop(0L); + } catch (BundleException | InterruptedException ex) { + Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); + } + } + private ApplicationUIController controller; + private Felix pluginContainer; public ApplicationUIController getController() { return controller; @@ -53,6 +68,13 @@ public class Application extends javafx.application.Application { this.primaryStage = primaryStage; javafx.application.Platform.setImplicitExit(true); + try { + startPluginContainer(); + } catch (BundleException ex) { + Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); + throw new RuntimeException(ex); + } + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ApplicationUI.fxml")); fxmlLoader.setResources(null); try { @@ -82,4 +104,14 @@ public class Application extends javafx.application.Application { public static void main(String[] args) { launch(args); } + + private void startPluginContainer() throws BundleException { + Map pluginConfiguration = new HashMap<>(); + pluginConfiguration.put("felix.cache.locking", "false"); + pluginConfiguration.put("felix.auto.deploy.action", "install,start"); + pluginConfiguration.put("felix.auto.deploy.dir", "install"); + pluginContainer = new Felix(pluginConfiguration); + pluginContainer.start(); + AutoProcessor.process(pluginConfiguration, pluginContainer.getBundleContext()); + } } diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ui/UIAction.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ui/UIAction.java index dbebd976..3751e1fc 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ui/UIAction.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ui/UIAction.java @@ -188,6 +188,7 @@ public class UIAction { } public static void quitWithoutConfirming() { + Application.shutdown(); Platform.runLater(Platform::exit); }