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

This widget could not be displayed.

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;

This widget could not be displayed.

Anyone ?????

This widget could not be displayed.
Add annotaion:
...

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

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

...

This widget could not be displayed.

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

This widget could not be displayed.

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

This widget could not be displayed.

Anyone ?????

Please !!!!!!!!

This widget could not be displayed.

Help !!!!!!!

This widget could not be displayed.

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");

}

This widget could not be displayed.

@Victor Viana

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

This widget could not be displayed.

@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.

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

492 views 3 18
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