Plugin Installer

Developers forum for Univeral Media Server-related development (only for programmers)
Post Reply
User avatar
SharkHunter
Developer
Posts: 648
Joined: Fri Jun 01, 2012 9:36 pm

Plugin Installer

Post by SharkHunter »

In the 1.4.0 a new plugin installer framework is added. This will make plugin installation/distribution simpler for both users and developers. In the future plugins can be released and rated via the website but for now the the info is fetch from a small text file on github. The plugin install system of UMS will display available plugns to the users download and start them. For this it needs som information from the plugin developer. UMS reads a file containing a list of available plugins. Each plugin has the following structure

Code: Select all

name=xxx
url=some url
desc=This is the coolest plugin ever
type=list|jar
author=yyy
rating=5.0
The fields are intuitive except the type. All fields except name and url can be omitted.
If the plugin ONLY is a single jar file it is recommended that the url points directly to that jar file and the typ is set to jar (or omitted since jar is the default type). If the plugin needs more than a single jar (perhaps some config file etc.) a list should be used instead. If type is list the url should point to a text file where each line is of the format

Code: Select all

url,dest dir,name
where url is the url of the file to download, dest dir is the dir where the file should end up and name is the name of the file. Both dest dir and name can be omitted in and in that case the dest dir will be the plugin directory and name will be the last portion of the url.
It is strongly encouraged that the jar files containing the plugins all have some version indication in the filename (that is my_plug_100.jar) since when upgrading old jar files will be purged by the framework.

Once the files are downloaded they will be started just as if they would have been if placed in the plugins dir from the start. Just before the plugin is started a postInstall method will be called. The method should be defined in the main class of the plugin and should be defined as public static void postInstall(). This function can the perform whatever advanced task need before the plugin starts (like unzipping files, writing config etc.) NOTE! The postInstall method is ONLY called after the plugin has been installed via the plugin installer and NEVER otherwise.

Before releasing your new shiny plugin you should test your installer. This is done by placing a file called plugin_inst.tst (exactly that) in the plugins dir. This file should have the same syntax as the real text file. That is:

Code: Select all

name=xxx
url=some url
desc=This is the coolest plugin ever
type=list|jar
author=yyy
rating=5.0
If this file is found you will when you press the "Download and Install" button in the UMS gui see the plugin from that file to, all with a rating of TEST.
Once you've test to install your plugin some times you send that information to the dev team and the plugin will be added to the main installer.

Some samples
Installer for MoviInfo http://cloud.github.com/downloads/Shark ... i_inst.txt
Installer for Channels https://github.com/SharkHunter/Channel/ ... h_inst.txt
The main installer https://github.com/SharkHunter/Channel/ ... er/ext.txt

A final note. Java has a real nice feature when loading code. In order to be able to reload the same code each code bunch must be loaded in it's own classloader. This is no big issue UNLESS you want two plugins to talk to each other. To solve this you must load the plugins in the same classloader which is impossible since they must be in separate classloaders to upgradeable sigh....
To solve this add this code to the plugin that you wishes to use another plugin

Code: Select all

String plugin=PMS.getConfiguration().getPluginDirectory();
				File mi=new File(plugin+File.separator+<some jar here>);
				if(!mi.exists()) {
					inst.movieInfo=null;
					return;
				}
				URLClassLoader cl=(URLClassLoader) inst.getClass().getClassLoader();
				URL u=mi.toURI().toURL();
				Class clClass = URLClassLoader.class;
				Class[] parameters = new Class[]{URL.class};
				Method method = clClass.getDeclaredMethod("addURL", parameters);
				method.setAccessible(true);
				method.invoke(cl, new Object[]{u});
That's it for now questions and suggestions are more than welcome...
We reject: kings, presidents and voting.
We believe in: rough consensus and running code.
Post Reply