The Atlassian Plugin SDK

Atlassian provides plugin developers with a Software Development Kit (SDK). By using this SDK, developers can create plugins that extend the functionality of all Atlassian products. The SDK allows you to quickly connect and use the plugin development platform.

The Atlassian Plugin SDK makes your life easier by helping to do the following:

  • Build plugins for any Atlassian application with a single tool.
  • Create a plugin skeleton, specific to the Atlassian application you are developing for.
  • Download the application binaries, install your plugin, and start the application.
  • Dynamically re-install your plugin after changes during development. No restart required.
  • Write quality unit tests and integration tests.
  • Speed up the all-important code-deploy-test cycle.

Installing the Atlassian Plugin SDK

Before we can start building our first plugin, we have to install the Atlassian Plugin SDK. We will go through the steps required to install the SDK on a Windows system.

Prerequisites

First we have to make sure our Windows system has the prerequisite software and is configured correctly. The Atlassian SDK relies on Version 1.6.x or higher of the Oracle JDK.

To install the Oracle JDK, perform the following steps:

  1. Download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

    Note

    At the time of writing the latest version is JDK 7 update 17.

  2. Double-click the downloaded installation file to start the installation wizard.
  3. Select where you would like to install Java, or simply accept the default values. The location where you install the JDK will be referred to as JAVA_HOME.
  4. Right-click the Computer icon.
  5. Select Advanced system settings from the left-hand side menu.
  6. Click on the Environment Variables button.
  7. Create a new environmental variable name JAVA_HOME with the value of where you just installed Java as shown:
    Prerequisites

Now that you have the JDK installed on your system, add the JAVA bin directory to your path to ensure that you can use Java from the command prompt. Again, we assume a Windows setup.

To add JAVA_HOME to your path, perform the following steps:

  1. Right-click the Computer icon.
  2. Select Advanced system settings from the left-hand side menu.
  3. Click on the Environment Variables button.
  4. Locate the Path variable under the System variables and click on Edit....
  5. Add ;_VA_HOME%in to the end of variable value.
  6. Save the changes and close all dialogs.

Before we continue, we have to make sure the JDK is installed correctly so that the Atlassian SDK is able to use it.

To verify your JDK installation, perform the following steps:

  1. Open a command prompt window in Windows.
  2. Type the following command to verify that the JAVA_HOME variable is set:
    echo %JAVA_HOME%
    
  3. This should return a path, that is C:Program Files (x86)Javajdk1.7.0_17.
  4. When the variable is set, verify that your Path includes the JDK bin directory. Type the following command:
    java –version
    

    This should display the version of Java installed, that is:

    java version "1.7.0_17"
    Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
    Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)
    
  5. If you have the JDK installed and your Path is configured correctly, you can move forward to the next step.

When building a plugin for Confluence, the application will be running on your desktop. For Confluence to be able to start, it assumes port 1990 is available. On most machines this would not be an issue.

Verify your port numbers by performing the following step:

  1. Open a command prompt window and type the following command:
    netstat –a | find /I "1990"
    

If the preceding command doesn't return anything, the port is available. If the preceding command does return something, port 1990 is already being used by another application. The Atlassian SDK will notice this during startup and assign a different port to Confluence. We will go into this in the Building, installing, and running your plugin section.

Note

If you are developing your plugin on a Linux or Mac, you can follow the online guide for installing the JDK at https://developer.atlassian.com/display/DOCS/Set+up+the+SDK+Prerequisites+for+Linux+or+Mac.

Setting up the Atlassian SDK

With all the prerequisites installed, we can download and set up the Atlassian SDK.

  1. Download the latest version of the SDK via: https://marketplace.atlassian.com/download/plugins/atlassian-plugin-sdk-windows (direct download link).
  2. Locate the downloaded installer and double-click on the EXE file.
    Setting up the Atlassian SDK
  3. Click on Next and select a location to install the SDK.
  4. Follow the next screens to install the SDK.

The Atlassian Plugin SDK is now installed and we are ready to create our first plugin.

To verify that the SDK is configured correctly, perform the following step:

  1. Open a command prompt window and run the following command:
    atlas-version
    

    The system should respond with similar information as follows:

    ATLAS Version:    4.1.7
    ATLAS Home:       C:atlassian-plugin-sdk
    ATLAS Scripts:    C:atlassian-plugin-sdkin
    ATLAS Maven Home: C:atlassian-plugin-sdkapache-maven
    --------
    Executing: "C:atlassian-plugin-sdkapache-maveninmvn.bat" --version -gs C:atlassian-plugin-sdkapache-maven/conf/settings.xml
    Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
    Java version: 1.7.0_17
    Java home: C:Program Files (x86)Javajdk1.7.0_17jre
    Default locale: en_US, platform encoding: Cp1252
    OS name: "windows server 2008 r2" version: "6.1" arch: "x86" Family: "windows"
    

Commands

The Atlassian Plugin SDK provides a set of shell scripts for creating, installing, and building plugins for Atlassian products. Let's take a look at some typical tasks and examples of commands in the SDK.

Creating a new plugin

When you want to build a new plugin, you need to create a plugin skeleton. Open a command prompt and run the following command in the location where you want to create the plugin.

atlas-create-confluence-plugin

Adding a new module to your plugin

If you want to add a new module to your plugin, you could do this via the command line too. Open your command prompt and browse to the location of your plugin. Within your plugin directory run:

atlas-create-confluence-plugin-module

Running a plugin in an application

If you want to run your plugin in its target application, go to the plugin directory using the command prompt and type:

atlas-run

The preceding command will start the application specified in your plugin (Confluence, JIRA, and so on) and automatically install your plugin.

Running a specific version of an application

If you are building a plugin that should work for a specific version, or you just want to test your plugin against a new version of the application, you can specify this while starting the application. Run the following commands in your plugin directory:

atlas-clean
atlas-run –-version 5.0.1

The atlas-clean command will clear any previously run version of the plugin. This is only needed if the previous run was a different version.

Using the Maven Command Line Interface (CLI) plugin

The SDK bundles the Maven CLI plugin, allowing you to run a command against a development Confluence installation. To use it with your plugin's host application, go to the plugin's project directory (where you created the plugin) and type:

atlas-cli

When the command-line interface is started you can use the command pi to package your plugin and install it into the running Confluence installation.

Running a standalone application

If you want to quickly test a new version of an application, you can use the standalone command to start that application. You can run this command from anywhere, as there is no plugin required:

atlas-run-standalone-–product confluence --version 5.0.1

The help command

There are more commands available, but these are the most used. If you are ever in doubt how a command is used and which are available, run the following command:

atlas-help

Maven

When you are building a plugin, you will be using Maven as an underlying library dependency management and build tool. Maven is already bundled with the Atlassian Plugin SDK, so there is no need to install it on your machine. Even if you already have a Maven version installed, you should use the bundled version, as the SDK requires a specific Maven version.

The Atlassian SDK Maven comes with configured settings so that building an Atlassian plugin will be as easy as possible. Using Maven and building your plugin does require an active Internet connection, as Maven will resolve and download all dependencies needed during the build process.

If you are behind a company proxy, make sure to configure Maven accordingly:

  1. Open _ERPROFILE%/.m2/settings.xml in a text editor. If the file doesn't exist, you can create it.
  2. Add the following section to your file and make sure to replace the settings with your proxy settings:
    <settings>
      <proxies>
        <proxy>
          <active>true</active>
          <protocol>http</protocol>
          <host>proxy.somewhere.com</host>
          <port>8080</port>
          <username>proxyuser</username>
          <password>somepassword</password>
          <nonProxyHosts>
    www.google.com|*.somewhere.com
    </nonProxyHosts>
        </proxy>
      </proxies>
    </settings>
  3. Save the file.

With a normal Maven installation, or if you have multiple installations, mvn would be available via your command prompt. To ensure you use the Atlassian provided version, Maven uses atlas-mvn instead.

The pom.xml file

In the root of your plugin, there is a pom.xml file; this file is the core of a project's configuration in Maven. In this file, you can define dependencies on other libraries and specify which Confluence version you want to run, but it also holds the name and description of your plugin.

The pom.xml file is what is being used when you start your plugin with atlas-run.

The plugin descriptor

Every plugin must have a plugin descriptor file. The file, atlassian-plugin.xml, describes your plugin to the target application. The Atlassian SDK generates the atlassian-plugin.xml file when you create your plugin for the first time. The descriptor is also updated when you use atlassian-create-confluence-plugin-module to add a new module.

At some point during the development of you plugin, you will have to update the file manually, so it's a good idea to have a bit of understanding as to what is in the plugin descriptor. The plugin descriptor is located in the directory <plugin_home>/src/main/resources/.

A very minimal plugin descriptor's built looks as follows:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" 
  name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" 
  url="${project.organization.url}" />
</plugin-info>
</atlassian-plugin>

This descriptor file mostly contains variables; these are Maven variables and will be replaced with the values from your pom.xml file when you build your plugin. The rest of the descriptor file is empty; this plugin does not contain any components, which is very unlikely for a plugin.

We will be adding more modules to this file across this chapter, if you want an overview of the available modules, skip ahead to the Plugin module types section.

Using a development environment

When developing your plugin, it is a good idea to use an IDE, short for integrated development environment. A development environment will help you to make fewer mistakes, and can come in very handy when trying to debug your plugin.

Installing Eclipse on Windows

We will be using Eclipse, but if you have a different preference, use your own IDE.

  1. Download Eclipse for JAVA EE developers from http://www.eclipse.org/downloads/.
  2. Extract the downloaded ZIP file onto the root of you hard drive. When you are done, if your hard drive root is C:, you will have the following folder on your hard drive:
    Installing Eclipse on Windows

In the next step, we are making sure Eclipse uses the JDK we just installed; this is done by editing the Eclipse initialization file.

  1. Make a copy of the original eclipse.ini and name it eclipse.ini.original.
  2. Open the eclipse.ini file in Notepad.
  3. Add a –vm entry before any -vmargs entry in the file. The entry should point to the value of your _VA_HOME%/bin. Eclipse requires that you reverse the slashes to forward slashes. Your file should look similar to this:
    -startup
    plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
    --launcher.library
    plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.200.v20120913-144807
    -product
    org.eclipse.epp.package.jee.product
    --launcher.defaultAction
    openFile
    --launcher.XXMaxPermSize
    256M
    -showsplash
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    --launcher.defaultAction
    openFile
    -vm
    C:/Program Files/Java/jdk1.7.0_17/bin
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Dhelp.lucene.tokenizer=standard
    -Xms40m
    -Xmx512m
  4. Close and save the file.
  5. Start Eclipse and choose a location where Eclipse will store you workspaces.

Installing the Maven Eclipse plugin

We will be using the Maven Eclipse plugin, which will help us with getting the dependencies needed for our Confluence plugins.

  1. Select Help | Install new Software. Click on the Add button to add a new repository.
  2. Enter Sonatype M2Eclipse in the Name field.
  3. Enter http://m2eclipse.sonatype.org/sites/m2e in the Location field.
  4. Click on OK to close the dialog. The system searches the site for the plugin. After a moment, the Name field fills with the Maven Integration for Eclipse software as the following:
    Installing the Maven Eclipse plugin
  5. Check the checkbox and click on Next.
  6. Accept the terms of the license agreements and click on Finish.
  7. Restart Eclipse when prompted.

Configuring the Maven plugin

After Eclipse has restarted, ensure that the Maven plugin is configured correctly.

  1. Choose Window | Preferences from the eclipse menu bar.
  2. Type Maven in the filter text field and select Installations.
  3. Click on the Add button to add a new Maven installation.
  4. Browse to your Atlassian SDK installation and select the apache-maven folder.
  5. Click on OK.
    Configuring the Maven plugin
  6. Click on Apply.
  7. Click on the Maven root.
  8. Uncheck Download repository index updates on startup. This prevents Maven from updating on Eclipse startup, which can be time consuming. The atlas- commands will update the repositories for you.
  9. Click on OK to close the dialog.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.37.126