Jira plugin "afterPropertiesSet" and "destroy" not called!

I'm having the following problem:

I'm trying to make the "afterPropertiesSet" or "destroy" are called when the plugin is installed or uninstalled, only that neither is called, I do not know what to do.

Here is an excerpt from my code:

atlassian-plugin.xml

<atlassian-plugin key="com.suati.jira.listener" name="Suati - Plugin TFS"
	plugins-version="2">
	<plugin-info>
		<description>Plugin que efetua a integração do Jira com o TFS.
		</description>
		<version>1.2</version>
		<vendor name="Suati Suporte Avançado em Tecnologia da Informação."
			url="http://www.suati.com.br" />
	</plugin-info>

	<component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher">
		<description>eventPublisher.</description>
	</component-import>

	<component key="eventListener" class="com.suati.jira.listener.IssueListener">
		<description>Class that processes the incoming JIRA events.</description>
	</component>
</atlassian-plugin>

IssueListener.java (My listener class)

package com.suati.jira.listener;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import org.ofbiz.core.entity.GenericValue;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.context.GlobalIssueContext;
import com.atlassian.jira.issue.context.JiraContextNode;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.screen.FieldScreen;
import com.atlassian.jira.issue.fields.screen.FieldScreenManager;
import com.atlassian.jira.issue.fields.screen.FieldScreenTab;
import com.suati.tfs.model.basic.WorkItem;
import com.suati.tfs.service.WorkItemService;

public class IssueListener implements InitializingBean, DisposableBean {

	private final EventPublisher eventPublisher;

	private final WorkItemService wis;

	private static final String TEST_TEXT_CF = "Test Text CF";
	private final CustomFieldManager customFieldManager;
	private final FieldScreenManager fieldScreenManager;

	public IssueListener(EventPublisher eventPublisher, CustomFieldManager customFieldManager, FieldScreenManager fieldScreenManager) {
		System.out.println("################################ IssueListener: IssueEvent 4.0 ################################################");
		this.wis = new WorkItemService();
		this.eventPublisher = eventPublisher;
		this.eventPublisher.register(this);
		this.customFieldManager = customFieldManager;
		this.fieldScreenManager = fieldScreenManager;
	}

	@Override
	public void destroy() throws Exception {
		//Get the already installed custom field by name
        CustomField cField = this.customFieldManager.getCustomFieldObjectByName(TEST_TEXT_CF);
        //Remove if not null
        if (cField != null) {
            this.customFieldManager.removeCustomField(cField);
        }
		this.eventPublisher.unregister(this);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("################################ afterPropertiesSet: Plugin 4.0 ################################################");
		// Create a list of issue types for which the custom field needs to be
		// available
		List<GenericValue> issueTypes = new ArrayList<GenericValue>();
		issueTypes.add(null);

		// Create a list of project contexts for which the custom field needs to
		// be available
		List<JiraContextNode> contexts = new ArrayList<JiraContextNode>();
		contexts.add(GlobalIssueContext.getInstance());

		// Add custom field
		CustomField cField = this.customFieldManager.createCustomField(
						TEST_TEXT_CF,
						"A Sample Text Field",
						this.customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:textfield"),
						this.customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:textsearcher"),
						contexts, 
						issueTypes
		);

		// Add field to default Screen
		FieldScreen defaultScreen = fieldScreenManager.getFieldScreen(FieldScreen.DEFAULT_SCREEN_ID);
		if (!defaultScreen.containsField(cField.getId())) {
			FieldScreenTab firstTab = defaultScreen.getTab(0);
			firstTab.addFieldScreenLayoutItem(cField.getId());
		}
	}

	/**
	 * Receives any {@code IssueEvent}s sent by JIRA.
	 * 
	 * @param issueEvent
	 *            the IssueEvent passed to us
	 * @throws RemoteException
	 */
	@EventListener
	public void onIssueEvent(IssueEvent issueEvent) throws RemoteException {
		System.out.println("################################ onIssueEvent: Plugin 4.0 ################################################");
		Issue issue = issueEvent.getIssue();
		WorkItem wi;

		try {
			// TODO Validar se foi marcado o checkBox
			wi = new WorkItem(issue);
			wis.saveWorkItem(wi);
		} catch (Exception e) {
			// issue.

		}
	}

}

Does anyone know why the afterPropertiesSet and destroy are not called?????????

11 answers

0 vote

Your component xml should have an <interface> node under <component>... does it work aside from the afterPropertiesSet not being called?

Sorry but i dont understand what you mean quiz!

what would this interface?

I modified my file Atlassian-plugin.xml, but still not working:

&lt;atlassian-plugin key="com.suati.jira.listener" name="Suati - Plugin TFS"
	plugins-version="2"&gt;
	&lt;plugin-info&gt;
		&lt;description&gt;Plugin que efetua a integração do Jira com o TFS.
		&lt;/description&gt;
		&lt;version&gt;1.2&lt;/version&gt;
		&lt;vendor name="Suati Suporte Avançado em Tecnologia da Informação."
			url="http://www.suati.com.br" /&gt;
	&lt;/plugin-info&gt;

	&lt;component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher" /&gt;

	&lt;component key="eventListener" class="com.suati.jira.listener.IssueListener"&gt;
		&lt;interface&gt;com.atlassian.event.api.EventPublisher&lt;/interface&gt;
		&lt;interface&gt;com.atlassian.jira.issue.CustomFieldManager&lt;/interface&gt;
		&lt;interface&gt;com.atlassian.jira.issue.fields.screen.FieldScreenManager&lt;/interface&gt;
		&lt;description&gt;Class that processes the incoming JIRA events.&lt;/description&gt;
	&lt;/component&gt;
&lt;/atlassian-plugin&gt;

Anyone ?????

Add annotaion:
...

@PreDestroy
public void destroy() throws Exception ...{}

@PostConstruct
public void afterPropertiesSet() throws Exception {...}

...

0 vote

Why did you remove your answer where you said this was working through use of annotations?

Because I thought for sure would work, but when I test it did not work!

Anyone ?????

Please !!!!!!!!

Help !!!!!!!

I have same problem. do somebody have jiraListener example for jira 5.

I added some print outs (see below), but it does not work. I see nothing on the catalina.out. it looks like the plugin is not loaded the JIRA and @EventListener does not work.

@Override
public void afterPropertiesSet() throws Exception {

eventPublisher.register( this);

System.out.println("REGISTERED");

}

/**

* Called when the plugin is being disabled or removed.

*

@throws

Exception

*/

@Override publicvoid destroy() throws Exception {
eventPublisher.unregister( this);

System.out.println("DESTROYED");

}

@Victor Viana

You add <Export-Package> element in atlassian-plugin.xml as specified in the comments of link

@Victor Viana

You add <Export-Package> element in atlassian-plugin.xml as specified in the comments of link

Also you need not specify <component-import> element for EventPublisher.

Hi Victor,

I would say that those SPRING events are disabled on JIRA by default and they must be explicitly enabled in the beans xml configuration file located MANIFEST/spring/ according to these instructions:

http://static.springsource.org/spring/docs/3.0.0.RC3/reference/html/ch03s09.html

which is as prety simple as adding the following line:

&lt;context:annotation-config/&gt;

and of course, add the context namespace too:

 xmlns:context="http://www.springframework.org/schema/context"

After doing it, your annotated methods will be invoked:

@PreDestroy

public void doSomeCleanUpStuff(){
	
	System.out.println("I'm so happy ;)");

}

Pablo.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

352 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you