Osmosis/Writing Plugins

From OpenStreetMap Wiki
Jump to navigation Jump to search

Anatomy of a plugin

A plugin for osmosis consists of

  • one zip-file containing:
  • a file plugin.xml
  • the classes of the plugin

Content of plugin.xml

(example plugin.xml)

<?xml version="1.0" ?>
<!DOCTYPE plugin PUBLIC "-//JPF//Java Plug-in Manifest 1.0" "http://jpf.sourceforge.net/plugin_1_0.dtd">
<plugin id="LibOSM" version="2.5.2.0"
    class="org.openstreetmap.osm.Plugins.LibOSMOsmosisPlugin">

    <!--These are library-files we require including our own code. -->
    <requires>
           <import plugin-id="org.openstreetmap.osmosis.core.plugin.Core" plugin-version="0.32" reverse-lookup="false"/>
    </requires>
    
    <!--These are library-files we require including our own code. -->
    <runtime>
        <library id="mycode" path="/" type="code"/>
    </runtime>

<!--This is where our plugin plugs into.
    The extension-point 'task' with a subclass of PluginLoader named 'WriteOSMBinPlugin'
    that tells Osmosis what tasks are provided.-->
    <extension plugin-id="org.openstreetmap.osmosis.core.plugin.Core"
               point-id="Task" id="LibOSM/OsmBin-Tasks/writeOsmBin">
       <parameter id="name"
               value="writeOsmBin"/>
       <parameter id="class"
               value="org.openstreetmap.osm.data.osmbin.OSMBinPlugin"/>
    </extension>
    <!--extension plugin-id="org.openstreetmap.osmosis.core.plugin.Core"
               point-id="Task" id="LibOSM/OsmBin-Tasks/writeOsmBin-0.6">
       <parameter id="name"
               value="writeOsmBin-0.6"/>
       <parameter id="class"
               value="org.openstreetmap.osm.data.osmbin.OSMBinPlugin"/>
    </extension-->
</plugin>

Where to plug into

Currently there is only one extension-point task

Adding tasks

the plugin-loader

To plug into the extension-point task you need to write one factory-class that extends com.bretth.osmosis.core.plugin.PluginLoader (example).

This class is required for historic reasons.

the TaskManagerFactory

This class contains a method loadTaskFactories() that returns a map from command-line-name to instance of TaskManagerFactory.

Obvisiously you need to write one implementation of com.bretth.osmosis.core.pipeline.common.TaskManagerFactory (example) for every task you want to add. This class is tasked with parsing the command-line arguments, instanciating your task and wrapping it in a TaskManager. For example a com.bretth.osmosis.core.pipeline.v0_5.SinkManager for a task that consumes osm-data.

the Task

Last but not least you need to implement the actual task (example).