Step 1: Creating The Add-On Skeleton
Contents
Prerequisites
Ensure that you are good on the following prerequisites:
A decent grasp of the Java language
Basic knowledge about the toolchain (maven specifically)
Certain Spring framework notions (injection)
Know Atlassian app basics (see https://developer.atlassian.com/ for details). You will also need Atlassian SDK (see this documentation for reference)
An IDE (e.g. Eclipse). We use JetBrains IntelliJ Idea here.
Setup
Install the Atlassian developer kit from the terminal/command line
brew tap atlassian/tap brew install atlassian/tap/atlassian-plugin-sdk
Download your desired version of the SIL Engine from the marketplace.
Add the SIL Engine to the local maven repository
Template
atlas-mvn install:install-file -Dfile=<Location of Jar from step 2> -DgroupId=com.keplerrominfo.jira.plugins -DartifactId=katl-commons -Dversion=<Version of Jar> -Dpackaging=jar
Example
atlas-mvn install:install-file -Dfile=/var/atlassian/katl-commons-4.1.6-r20180917150405.jar -DgroupId=com.keplerrominfo.jira.plugins -DartifactId=katl-commons -Dversion=4.1.6 -Dpackaging=jar
Configuration
Adding functionality into SIL™ means that you need to create an Atlassian add-on. Add-ons are basically JAR files containing a descriptor (atlassian-plugin.xml). So let's create one, skipping the tools that Atlassian provides, because there's too much to be customized.
Create a skeleton maven project, name it, and choose a directory where the project will reside. Choose com.mycompany.silexample as a base package, where your sources will reside.
Upon finishing your IDE wizard, you will notice that there's a pom.xml in the root of the project. Open it and replace its content with the following:
pom.xml
SIL Version
The property <sil.version> will need to be updated to the version installed in the Setup section
You will notice that everything revolves around two maven plugins:
maven-jira-plugin – the building plugin
atlassian-spring-scanner-maven-plugin – a helper plugin, responsible to scan your sources and create spring beans from annotations.
You can find more information about these plugins in the Atlassian documentation.
Now that you have a build file, add the missing parts and let's start with all the support files needed.
In the resources directory, create a META-INF/spring directory and add a spring.xml file.
spring.xml
This adds support for bean scanning enabling you to annotate your components with stereotypes.
Starting with version 4.0.0, almost everything is a Spring Bean. No more static dependencies, now you rely on the injection mechanism.
We will create two more files in the META-INF directory: KINFO and KVERSION . These files are required by the Appfire framework support and while KINFO is free text (you can put there anything you want), KVERSION has a fixed structure, it must contain the released date of the plugin:
META-INF/KVERSION
META-INF/KINFO
Another thing to work on is the atlassian-plugin.xml file or the add-on descriptor. Create an empty add-on descriptor, like this:
atlassian-plugin.xml
Well, we have images for our add-on, but of course you can use any images you want there as long as you respect the scaling of the icons. Alternatively, you can skip the image part.
In the end, the structure will look like this:
Now you are ready to code.
The basic skeleton: a launcher and the plugin info
Our framework requires you to declare certain basic information about what you bring to SIL™. As you saw, certain information can be placed in descriptor files, but some other is declarative, in Java, since that info will get injected into different places.
Open the editor, and create a new java class named ExamplePluginInfoService in the com.mycompany.silexample package.
ExamplePluginInfoService.java
The bean implementation is straightforward. This is a local component, not exported to the outside world, this is what the @Component annotation is used for.
Now, register certain functions and CF descriptors, and you can do that at launch time of the plugin. The start-stop sequence of plugins in complicated enough therefore we use our own Launcher class, abstracting all those events in such a way that you will know that whatever you do, it is safe to be done. So, extend / implement com.keplerrominfo.refapp.launcher.AbstractPluginLauncher: create an ExampleLauncher class within the same package (com.mycompany.silexample). Override doAtLaunch() and doAtStop() members.
ExampleLauncher.java
We have commented where you should put your own code. You should also note the beans annotated as @ComponentImport, as well as the local bean pluginConfigurationService which offers a separate space to hold configuration values (key-values pairs), local to this plugin.
You will notice some (now unused) imported beans, we will use them to declare the new function and the new CF descriptor.