Book Image

JIRA Development Cookbook - Third Edition

By : Jobin Kuruvilla
Book Image

JIRA Development Cookbook - Third Edition

By: Jobin Kuruvilla

Overview of this book

JIRA provides issue and project tracking for software development teams to improve code quality and the speed of development. With the new version of JIRA, you can create your own JIRA plugins and customize the look and feel of your JIRA UI easier than ever. JIRA Development Cookbook , Third Edition, is a one-stop resource to master extensions and customizations in JIRA. This book starts with recipes about simplifying the plugin development process followed by recipes dedicated to the plugin framework. Then, you will move on to writing custom field plugins to create new field types or custom searchers. You will also learn how to program and customize workflows to transform JIRA into a user-friendly system. With so much data spanning different projects, issues, and so on, we will cover how to work on reports and gadgets to get customized data according to our needs. At the end of the book, you will learn how to customize JIRA by adding new tabs, menus, and web items; communicate with JIRA via the REST APIs; and work with the JIRA database.
Table of Contents (18 chapters)
JIRA Development Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Creating a skeleton plugin


In this recipe we will look at creating a skeleton plugin. We will use the Atlassian Plugin SDK to create the skeleton.

Getting ready

Make sure you have the Atlassian Plugin SDK installed.

How to do it...

  1. Open a command window and go to the folder where you want to create the plugin.

  2. Type atlas-create-jira-plugin and press Enter.

  3. Enter the groupID when prompted. groupID would normally be coming from your organization name and mostly resembles the Java package. Of course, you can enter a different package name as we move forward if you want to keep it separate. groupID will be used to identify your plugin along with artifactID.

    For example: com.jtricks.demo

  4. Enter the artifactId. The identifier for this artifact. Do not use spaces here.

    For example: demoplugin

  5. The default version is 1.0-SNAPSHOT. Enter a new version if you want to change it or press Enter to keep the default.

    For example: 1.0

  6. Press Enter if the package value is same as the groupID. If not, enter the new value here and press Enter.

    For example: com.jtricks.mypackage

  7. Confirm the selection when prompted. If you want to change any of the entered values, type N and press Enter.

  8. Wait for the BUILD SUCCESSFUL message.

How it works...

A skeleton plugin is nothing but a set of directories and subdirectories along with a pom.xml (Maven project object model) file and some sample Java and XML files in the appropriate folders.

Here is a snapshot of how the project will look in Eclipse. It also shows the design view of the default atlassian-plugin.xml:

As you can see, there is a pom.xml at the root level and a src folder. A sample LICENSE file and a README file are also created for you at the root level.

Under the src folder, you will find two folders, main and test, with an identical folder structure. All your main Java code goes under the main folder. Any JUnit tests you write will go into the same location under the test folder. There is an additional folder, it, under the test folder where all the integration tests will go.

You will find the plugin descriptor, that is, atlassian-plugin.xml, under src/main/resources with sample values already populated in it. The values in the preceding screenshot are populated from the pom.xml. In our case, the plugin key will be populated as com.jtricks.demo:demoplugin when the plugin is built.

You will also notice that the skeleton plugin has some sample resources, which includes a CSS file, a JavaScript file, a plugin icon image, and a plugin logo image. The CSS and JS files are registered as resources under a web-resource plugin module. The images folder is also registered as a resource under the same module. The skeleton plugin also has a demoplugin.properties file, which is registered as an i18n resource. These files are placeholders and we can use them to add the respective functionality to the plugin.

So, that is our plugin skeleton. All that is pending is some useful Java code and proper module types in the atlassian-plugin.xml!

Tip

Remember, the first Maven run is going to take some time as it downloads all the dependencies in to your local repository. A coffee break might not be enough! If you have a choice, plan your meals.

There's more...

Sometimes, for the geeks, it is much easier to run a single command to create a project without bothering about the step-by-step creation. In this section, we will quickly see how to do it. We will also have a look at how to create an Eclipse project if you opt out of installing m2eclipse.

One step to your skeleton plugin

You can ignore the interactive mode by passing parameters such as groupID, artifactId, and so on, as arguments to the atlas-create-jira-plugin command:

atlas-create-jira-plugin -g my_groupID -a my_artifactId -v my_version -p my_package   --non-interactive

For the example values we saw previously, the single line command will be as follows:

atlas-create-jira-plugin -g com.jtricks.demo  -a demoplugin -v 1.0 -p com.jtricks.mypackage --non-interactive

You can pick and choose the parameters and provide the rest in an interactive mode as well!

Creating an Eclipse project

If you are not using m2eclipse, just run the following command from the folder where you have the pom.xml file:

atlas-mvn eclipse:eclipse

This will generate the plugin project for Eclipse, and you can then import this project into the IDE.

Execute atlas-mvn eclipse:clean eclipse:eclipse if you want to clean the old project and create again.

With IDEA or m2eclipse, just opening a file will do. That is, you can just import the project using the option File | Import | Existing Maven Projects, and select the relevant project.