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?????????
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.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Victor Viana
You add <Export-Package> element in atlassian-plugin.xml as specified in the comments of link
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
eventPublisher.register( this);
System.out.println("REGISTERED");
}
/**
* Called when the plugin is being disabled or removed.
*
@throws
Exception
*/
System.out.println("DESTROYED");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because I thought for sure would work, but when I test it did not work!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Why did you remove your answer where you said this was working through use of annotations?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
... @PreDestroy public void destroy() throws Exception ...{} @PostConstruct public void afterPropertiesSet() throws Exception {...} ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your component xml should have an <interface> node under <component>... does it work aside from the afterPropertiesSet not being called?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry but i dont understand what you mean quiz!
what would this interface?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look at the xml here: https://developer.atlassian.com/display/JIRADEV/Component+Plugin+Module
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I modified my file Atlassian-plugin.xml, but still not working:
<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" /> <component key="eventListener" class="com.suati.jira.listener.IssueListener"> <interface>com.atlassian.event.api.EventPublisher</interface> <interface>com.atlassian.jira.issue.CustomFieldManager</interface> <interface>com.atlassian.jira.issue.fields.screen.FieldScreenManager</interface> <description>Class that processes the incoming JIRA events.</description> </component> </atlassian-plugin>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.