Osmosis/Writing Plugins

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Osmosis/Writing Plugins
· Afrikaans · Alemannisch · aragonés · asturianu · azərbaycanca · Bahasa Indonesia · Bahasa Melayu · Bân-lâm-gú · Basa Jawa · Baso Minangkabau · bosanski · brezhoneg · català · čeština · dansk · Deutsch · eesti · English · español · Esperanto · estremeñu · euskara · français · Frysk · Gaeilge · Gàidhlig · galego · Hausa · hrvatski · Igbo · interlingua · Interlingue · isiXhosa · isiZulu · íslenska · italiano · Kiswahili · Kreyòl ayisyen · kréyòl gwadloupéyen · Kurdî · latviešu · Lëtzebuergesch · lietuvių · magyar · Malagasy · Malti · Nederlands · Nedersaksies · norsk bokmål · norsk nynorsk · occitan · Oromoo · oʻzbekcha/ўзбекча · Plattdüütsch · polski · português · português do Brasil · română · shqip · slovenčina · slovenščina · Soomaaliga · suomi · svenska · Tiếng Việt · Türkçe · Vahcuengh · vèneto · Wolof · Yorùbá · Zazaki · српски / srpski · беларуская · български · қазақша · македонски · монгол · русский · тоҷикӣ · українська · Ελληνικά · Հայերեն · ქართული · नेपाली · मराठी · हिन्दी · অসমীয়া · বাংলা · ਪੰਜਾਬੀ · ગુજરાતી · ଓଡ଼ିଆ · தமிழ் · తెలుగు · ಕನ್ನಡ · മലയാളം · සිංහල · ไทย · မြန်မာဘာသာ · ລາວ · ភាសាខ្មែរ · ⵜⴰⵎⴰⵣⵉⵖⵜ · አማርኛ · 한국어 · 日本語 · 中文(简体)‎ · 吴语 · 粵語 · 中文(繁體)‎ · ייִדיש · עברית · اردو · العربية · پښتو · سنڌي · فارسی · ދިވެހިބަސް

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).