This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Milkman Plugin Development

This section shows some information on how to develop your own plugins for milkman

1 - Internal Model

Description of domain model of milkman

Plugins in milkman can extend various functionality. For this, an explanation of how a request is structured is necessary first.

Getting Started

A sample plugin was created that shows how to add an Aspect Tab to a Request.

if you want to setup a new project, an exemplary pom can be found here.

Data Model

img

The core of milkman is very abstract and is only intended to organize workspaces, which contain environments and collections of requests. A request is of a specific type and might contain some basic data. In the case of an HttpRequest, this might be the URL and the Method.

A request can also contain several RequestAspects which describe the request object further. In our example, this might be headers or the body of a request, but can also contain totally unrelated and auxiliary attributes.

All Aspects and the container gets serialized using Jackson and stored in a local Database.

Extension Points

Milkman uses SPI for extension. You just have to provide an implementation to one of the Extension Points below and move your packaged jar into the /plugin folder to have milkman pick up your plugin.

RequestAspectsPlugin

A request aspect can add aspects to either a request- or response container as well as according editors (providing the Tab to edit this specific aspect).

ContentTypePlugin

A content type plugin is used to format and highlight content based on a mime-type.

RequestTypePlugin

A plugin providing a request type such as HttpRequest, or SQL request or whatever you can think of. This plugin has to provide a small editor for basic attributes of the request as well.

ImporterPlugin

a plugin that imports things into the current workspace, such as collections, requests, environments.

OptionPageProvider

a plugin to provide a UI for editing options of a “logical” plugin. The OptionPageBuilder can be used to create common ui. On startup, changed options will be loaded from database.

UI Theme Plugin

provides an application-theme css and a syntax-theme css for styling.

Workspace Synchronizer Plugin

provides a mechanism to synchronize the workspace with some external mechanism

Request Export Plugin

extension point for adding export methods to a request-type.

Collection Export Plugin

extension point for adding export methods to a collection.

Persistence

All requests and RequestAspects (not response-aspects) will be stored in database and serialized using jackson. So you have to make sure that your classes properly serialize/deserialize.

Common Components

Some common components are provided by milkman to make development of plugins easier:

  • TableEditor: a table that might or might not be editable. used for editing headers or environments or such.
  • ContentEditor: a content editor that supports highlighting and formatting
  • Dialogs: some common dialogs, such as credentialsInput or StringInput.

Testing

milkman uses TestFX for testing. A sample test can be seen in the notes plugin.

Gotchas

JavaFX uses a lot of weak references. That means, if you don’t keep references to e.g. bindings or controllers even (if they are not referred to by e.g. FXML-onActions), they get garbage-collected and the bindings simply don’t work. You can use setUserData in some cases to have a strong reference of the UI element to e.g. the controller, so they both get garbage-collected at the same time.

2 - Development Setup

Description of how to setup your environment

for creating a new plugin, you can use following pom:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	
	<groupId>...</groupId>
	<artifactId>...</artifactId>
	<version>...</version>
	
	
	<dependencies>
		<dependency>
			<groupId>com.github.warmuuh.milkman</groupId>
			<artifactId>milkman</artifactId>
			<version>...</version>
			<scope>provided</scope>
		</dependency>
		<!-- and for refering to plugins of milkman: -->
		<dependency> 
			<groupId>com.github.warmuuh.milkman</groupId> 
			<artifactId>milkman-rest</artifactId> 
			<version>...</version> 
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- for packaging all your dependencies into one jar, excluding provided ones -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<appendAssemblyId>false</appendAssemblyId>
				</configuration>
				<executions>
					<execution>
						<id>assemble-all</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	
	
	<repositories>
		<repository>
			<id>jitpack.io</id>
			<url>https://jitpack.io</url>
		</repository>
	</repositories>

</project>