Book Image

JIRA 5.x Development Cookbook

Book Image

JIRA 5.x Development Cookbook

Overview of this book

JIRA provides issue tracking and project tracking for software development teams to improve code quality and the speed of development. "JIRA 5.x Development Cookbook" is a one stop resource to master extensions and customizations in JIRA. You will learn how to create your own JIRA plugins, customize the look and feel of your JIRA UI, work with workflows, issues, custom fields, and much more. "JIRA 5.x Development Cookbook" starts with recipes on simplifying the plugin development process followed by a complete chapter dedicated to the plugin framework to master plugins in JIRA. Then we will move on to writing custom field plugins to create new field types or custom searchers. We then learn how to program and customize workflows to transform JIRA into a user friendly system. Reporting support in an application like JIRA is inevitable! With so much data spanning across different projects, issues, and so on, and a lot of planning done for the project, we will cover how to work on reports and gadgets to get customized data according to our needs. We will then look at customizing the various searching aspects of JIRA such as JQL, searching in plugins, managing filters, and so on. "JIRA 5.x Development Cookbook" steers towards programming issues, such as creating, editing, and deleting issues, creating new issue operations, managing the various other operations available on issues via the JIRA APIs, and so on. In the latter half of "JIRA 5.x Development Cookbook", you will learn how to customize JIRA by adding new tabs, menus, and web items, communicate with JIRA via the REST, SOAP or XML/RPC interfaces, and work with the JIRA database. The book ends with a chapter on useful and general JIRA recipes.
Table of Contents (19 chapters)
JIRA 5.x Development Cookbook
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

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

Before beginning this recipe, make sure you have the Atlassian plugin SDK installed.

How to do it…

Following are the steps to create a skeleton plugin:

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

    Note

    Make sure you use a directory without any spaces in its name, because there are known issues with the SDK not working in directory names with spaces. See https://studio.atlassian.com/browse/AMPS-126 for more details.

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

  3. Press 1 if you want to create a JIRA 5 plugin or 2 if you want to create a plugin for JIRA 4 or earlier versions.

    Note

    This step can be avoided if you use the atlas-create-jira5-plugin command instead of atlas-create-jira-plugin. Note the use of jira5 instead of jira!

  4. Enter the group-id information when prompted. group-id 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. group-id will be used to identify your plugin along with artifact-id, for example, com.jtricks.demo.

  5. Enter the artifact-id information (the identifier for this artifact) when prompted. Do not use spaces here, for example, demoplugin.

  6. Enter the version information when prompted. The default version is 1.0-SNAPSHOT. Enter a new version if you want to change it or press Enter to keep the default version, for example, 1.0.

  7. Enter the package information when prompted. Press Enter if the package value is the same as the group-id value. If not, enter the new value here and press Enter, for example, com.jtricks.mypackage.

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

  9. Wait for the BUILD SUCCESSFUL message to appear.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com . If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

How it works…

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

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

As you can see, there is a pom.xml file 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 shown in the previous screenshot are populated from the pom.xml file. In our case, the plugin key will be populated as com.jtricks.demo:demoplugin when the plugin is built.

There are two more folders under the src/test tree. The src/test/resources folder, which will hold any resources required for unit tests or integration tests, and the src/test/xml folder, which can hold the XML data from any other JIRA instance. If the XML is supplied, the SDK will use it to configure the JIRA instance before running the integration tests.

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

Tip

Remember, the first Maven run is going to take some time, as it downloads all the dependencies into 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 the next 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 the parameters such as group-id, artifact-id, and so on, as arguments to the atlas-create-jira-plugin command:

atlas-create-jira5-plugin -g my_groupID -a my_artefactId -v my_version -p my_package ---non-interactive

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

atlas-create-jira5-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 too!

Creating an Eclipse project

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

atlas-mvneclipse: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 File | Import | Existing Maven Projects option, and select the relevant project.

See also

  • The Adding plugin modules recipe

  • The Deploying a JIRA plugin recipe

  • The Making changes to and redeploying a plugin recipe