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

Victor Viana January 14, 2013

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 votes
Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 15, 2013

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:

<context:annotation-config/>

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.

0 votes
Bharadwaj Jannu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2013

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

0 votes
Bharadwaj Jannu
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2013

@Victor Viana

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

0 votes
Onder Yesil February 18, 2013

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

}

0 votes
Victor Viana January 20, 2013

Help !!!!!!!

0 votes
Victor Viana January 20, 2013

Anyone ?????

Please !!!!!!!!

0 votes
Victor Viana January 17, 2013

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

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 17, 2013

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

0 votes
Victor Viana January 15, 2013
Add annotaion:
...

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

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

...

0 votes
Victor Viana January 15, 2013

Anyone ?????

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2013

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

Victor Viana January 14, 2013

Sorry but i dont understand what you mean quiz!

what would this interface?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2013
Victor Viana January 14, 2013

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;

Victor Viana January 14, 2013

????????????

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events