Download

Online

Gallery

Blog

  Index  | Recent Threads  | List Attachments  | Search
 Welcome Guest  |  Register  |  Login
Login Name  Password
 

Sweet Home 3D Forum



No member browsing this thread
Thread Status: Active
Total posts in this thread: 4
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 3180 times and has 3 replies Next Thread
Daniels118
Advanced Member
Member's Avatar

Italy
Joined: Nov 17, 2021
Post Count: 398
Status: Offline
Reply to this Post  Reply with Quote 
devilish PluginDevToolkit: the dynamic plugin loader for developers

Hello SH3D developers! While writing my plugins the code become a bit complex, and sometime it required a trial and error approach. The major drawback using this method is that every small change to the code requires exporting the project as jar into the plugins folder and restart SH3D, which could be a big waste of time because of the splash screen and eventually loading a large test home from the disk... not taking into account for temporary changes to the home that would be lost, camera positioning, and so on. Before starting to write my last plugin I decided to create a system to overcome these limitations. The system worked like a charm, and I've extensively tested it almost for a month while working to the Wirings plugin, so I decided to share it to help the plugins ecosystem growing faster smile.

Integrating the system into existing plugins is a matter of minutes.

First you have to setup your plugin project as described in the plug-in developer's guide, completing the Debugging the plug-in step in order to have a working run configuration. If you experience trouble with this step see the troubleshooting section at the end of this post.
Once you have a working run configuration follow these simple steps:
  • Download PluginDevToolkit.zip
  • Right click on the src folder of your project, select Import..., General > Archive file, select the file you downloaded at the previous step and click Finish.
  • Create a new class named YourPluginLoader which extends DynamicPluginLoader and override its constructor as
    public YourPluginLoader() {
    super("your.package.YourPlugin", new String[] {"your.package"});
    }
    where YourPlugin is the real plugin class, and your.package is the package name.
  • Edit the ApplicationPlugin.properties and change the value of the class parameter to the fully qualified name of the class you created in the previous step (eg. your.package.YourPluginLoader).
  • Build your .sh3p package just once and place it in the SH3D plugins folder.
  • Add to your run configuration a Java property named plugin.classpath pointing to the absolute path of the output folder of your class files. To do this, go to Arguments tab and put the following line in the VM arguments field:
    -Dplugin.classpath="${workspace_loc}\your_project\bin"
You can then run your configuration withour rebuilding the sh3p package, and even test your changes while SH3D is running.
When you're ready to release your plugin to the public there is no need to remove the customizations, you can safely leave them in place,
but don't forget to rebuild the sh3p package before distributing it!

Lifecycle management
To avoid unexpected results when reloading the plugin at runtime, you should correctly implement the plugin lifecycle management by overriding the init() and destroy() methods in your real plugin class. Everytime a change is detected in class files, the DynamicPluginLoader calls the destroy() method to let you release any allocated resource; your plugin is then replaced by a fresh new instance of the new class and the init() method is called to let you initialize your plugin.

Limitations
  • If you add or remove a PluginAction from the values returned by getActions() method, you have to rerun your configuration before the change takes effect. Existing actions will be updated in a seamless way.

Examples
You can download this example which is the VolumePlugin proposed in the developer guide already configured to work with the PluginDevToolkit, you just have to add the SweetHome3D-x.y.jar from your local filesystem. Try to change the output unit from m3 to liters while the SH3D is running!

Troubleshooting
If you didn't succeed to run SH3D from Eclipse getting the following exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "com.jogamp.nativewindow.awt.AWTGraphicsConfiguration.getAWTGraphicsConfiguration()" because "<local3>" is null
this may occurr because your java version is too old to support SH3D. To solve the problem edit your run configuration, under the tab JRE select Alternate JRE, click Installed JREs..., Add..., select Standard VM, click Next, Directory..., browse to C:\Program Files\Sweet Home 3D\runtime and click Select folder, type a meaningful name like SH3D JRE, then confirm all the rest and select the just created JRE. Now you should be able to run SH3D from Eclipse. If this doesn't solve your problem search the forum or ask for help.

Hope you have nice times developing SH3D plugins!
Cheers! smile
[Jan 11, 2022, 6:14:01 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Puybaret
Expert
Member's Avatar

France
Joined: Nov 7, 2005
Post Count: 9141
Status: Offline
Reply to this Post  Reply with Quote 
Re: PluginDevToolkit: the dynamic plugin loader for developers

Nice tool! smile
Please add a license to your source code if you want developers to use it (I would suggest LGPL 2.0 if you're ok).
----------------------------------------
Emmanuel Puybaret, Sweet Home 3D developer
[Jan 12, 2022, 5:25:51 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Daniels118
Advanced Member
Member's Avatar

Italy
Joined: Nov 17, 2021
Post Count: 398
Status: Offline
Reply to this Post  Reply with Quote 
Re: PluginDevToolkit: the dynamic plugin loader for developers

Salut Emmanuel,
I have added the LGPL v3 to both the toolkit and example archives :)

Thank you
Daniele
[Jan 13, 2022, 12:03:20 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Daniels118
Advanced Member
Member's Avatar

Italy
Joined: Nov 17, 2021
Post Count: 398
Status: Offline
Reply to this Post  Reply with Quote 
Re: PluginDevToolkit: the dynamic plugin loader for developers

The toolkit has been updated to version 1.1, the download links stay the same.

Changelog:
  • Added support for multiple paths to monitor
  • Bug fixes
If you need to reference multiple paths in plugin.classpath you can concatenate them using the system path separator (semicolon ";" on Windows, colon ":" on Linux). If you plan to use this feature be sure to update all of your plugins.
----------------------------------------
[Edit 1 times, last edit by Daniels118 at Mar 24, 2022, 10:24:58 AM]
[Mar 23, 2022, 12:21:26 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread

    Get Sweet Home 3D at SourceForge.net. Fast, secure and Free Open Source software downloads
   
© Copyright 2006-2024 eTeks - All rights reserved