wiki:BuildASimplePlugin

Version 4 (modified by jri, 9 years ago) (diff)

--

Build a simple plugin

This page describes how to build a very simple DeepaMehta plugin. This demo plugin just creates a new topic type.

Once the plugin runs the topic type will appear in DeepaMehta's create menu, so you can create instances. And you will be able to fulltext search for the instances.

Developing such a simple plugin involves no Java coding at all. All is declarative, mainly in JSON format.

Of course the topic type could be created interactively as well, by using DeepaMehta's type editor. However, being packaged as a plugin you can publish it. When other DeepaMehta users install your plugin they can use your type definitions.

Preparation

All you need is Java 1.6 and Maven (version 3 is recommended) installed.

You don't need a DeepaMehta installation. The DeepaMehta build system will provision a DeepaMehta installation (including a test database) for your plugin on-the-fly.

Create the plugin

You create the plugin just by creating directories and text files. A DeepaMehta plugin project adheres to a certain directory structure and file name conventions.

Setup a directory structure as follows:

demo-plugin-1/
    pom.xml
    src/
        main/
            resources/
                migrations/
                    migration1.json
                plugin.properties

Create the file pom.xml with this content:

<project>
    <modelVersion>4.0.0</modelVersion>

    <name>DM4 Demo Plugin 1</name>
    <groupId>de.deepamehta.demo-plugins</groupId>
    <artifactId>dm4-demo-plugin-1</artifactId>
    <version>4.0.RC1</version>
    <packaging>bundle</packaging>

    <parent>
        <groupId>de.deepamehta</groupId>
        <artifactId>deepamehta-plugin-parent</artifactId>
        <version>4.0.RC1</version>
    </parent>

    <repositories>
        <repository>
            <id>deepamehta-public-repository</id>
            <url>http://www.deepamehta.de/maven2</url>
        </repository>
    </repositories>
</project>

Create the file migration1.json:

{
    topic_types: [
        {
            value: "My Topic Type",
            uri: "domain.dm4_demo_plugins.my_topic_type",
            data_type_uri: "dm4.core.text",
            index_mode_uris: ["dm4.core.fulltext"],
            view_config_topics: [
                {
                    type_uri: "dm4.webclient.view_config",
                    composite: {
                        dm4.webclient.add_to_create_menu: true
                    }
                }
            ]
        }
    ]
}

Create the file plugin.properties:

requiredPluginMigrationNr = 1
importModels = de.deepamehta.webclient

Install the plugin

cd demo-plugin-1
mvn install

This builds the plugin and installs it in your local Maven repository.

Run the plugin

mvn pax:run

This provisions a DeepaMehta installation with your plugin installed, and runs it. Eventually the usual DeepaMehta web client will show up in a new browser window. You'll find the new topic type in DeepaMehta's create menu.