Hello,
I have tried many ways to create and event listener for the 'issue create event'.
onIssueEvent() it does not get called.
Here's my code:
Any suggestion or help?
thanks,
George Nistor
package com.infineon.plugin.listeners;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.Issue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
@Named
public class IssueCreateEventListener {
private static final Logger log = LoggerFactory.getLogger(IssueCreateEventListener.class);
private final EventPublisher eventPublisher;
@Inject
public IssueCreateEventListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@PostConstruct
public void init() {
eventPublisher.register(this);
}
@PreDestroy
public void cleanup() {
eventPublisher.unregister(this);
}
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
System.out.println("Received event: " + issueEvent.getEventTypeId());
if (EventType.ISSUE_CREATED_ID.equals(issueEvent.getEventTypeId())) {
Issue issue = issueEvent.getIssue();
if (issue != null) {
log.warn("New issue created: {} - {}", issue.getKey(), issue.getSummary());
} else {
log.error("Received ISSUE_CREATED event, but Issue is null.");
}
}
}
}
The listener code seems structurally correct. If onIssueEvent is not being triggered, and as far as I see you use annotation-based scanning, you need to ensure that it's being scanned correctly. Check that the class is part of a package under the scanned component-scan base package, in spring-scanner settings. You can also manually register it in the atlasian-plugin.xml
<component key="issue-create-listener" class="com.infineon.plugin.listeners.IssueCreateEventListener"/>
Checking the logs will also give some clues, your plugin may not have loaded successfully meaning that during the startup it may have failed. So, check the JIRA_HOME/log/atlassian-jira.log file and see if there are any errors related to the plugin.
It still does not work.
Can you provide more tips, how do I need to change more.
I added "@Component" to my IssueCreatedEventListener class
I added this section in pom.xml:
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>2.2.5</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
</plugins>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried also to add:
<context:component-scan base-package="com.infineon.plugin.listeners" />
in plugin-context.xml
but my plugin does not start anymore!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Don't use the <component-scan> in plugin-context.xml with the Atlassian Spring scanner together. They are alternatives, sorry if I was misunderstood.
So, remove the context:component-scan from the plugin-context.xml file.
In your pom.xml add these dependencies
<dependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>2.2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>2.2.5</version>
</dependency>
</dependencies>
And the plugin section you've mentioned above looks good.
This way, there is no need to add to atlassian-plugin.xml.
run the cli command atlas-clean ant then atlas-run
Then check the atlassian-jira.log file. If you have any error logs, share them here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I do not have any errors on build but it still does not work.
Maybe I miss something:
package com.infineon.plugin.listeners;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@Component
public class IssueCreateEventListener {
private static final Logger log = LoggerFactory.getLogger(IssueCreateEventListener.class);
private final EventPublisher eventPublisher;
@Autowired
public IssueCreateEventListener(@ComponentImport EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@PostConstruct
public void init() {
System.out.println("IssueCreateEventListener init");
try {
eventPublisher.register(this);
log.info("IssueCreateEventListener registered successfully");
} catch (Exception e) {
log.error("Failed to register IssueCreateEventListener", e);
}
}
@PreDestroy
public void cleanup() {
try {
eventPublisher.unregister(this);
log.info("IssueCreateEventListener unregistered successfully");
} catch (Exception e) {
log.error("Failed to unregister IssueCreateEventListener", e);
}
}
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
System.out.println("IssueCreateEventListener onIssueEvent");
try {
// Only process issue creation events
if (!EventType.ISSUE_CREATED_ID.equals(issueEvent.getEventTypeId())) {
return;
}
Issue issue = issueEvent.getIssue();
if (issue == null) {
log.warn("Received ISSUE_CREATED event, but Issue is null");
return;
}
ApplicationUser user = issueEvent.getUser();
String userKey = user != null ? user.getKey() : "Unknown";
log.info("New issue created: {} - {} by user: {}",
issue.getKey(),
issue.getSummary(),
userKey);
// Add your custom logic here
handleIssueCreated(issue, user);
} catch (Exception e) {
log.error("Error processing issue creation event", e);
}
}
private void handleIssueCreated(Issue issue, ApplicationUser user) {
// Your custom business logic here
log.debug("Processing issue creation for: {}", issue.getKey());
// Example: Log issue details
log.info("Issue Details - Key: {}, Summary: {}, Project: {}, Issue Type: {}",
issue.getKey(),
issue.getSummary(),
issue.getProjectObject().getKey(),
issue.getIssueType().getName());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.infineon</groupId>
<artifactId>issuetagger</artifactId>
<version>1.0.0-SNAPSHOT</version>
<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>
<name>issuetagger</name>
<description>This is the com.infineon:issuetagger plugin for Atlassian JIRA.</description>
<packaging>atlassian-plugin</packaging>
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugins.rest</groupId>
<artifactId>atlassian-rest-common</artifactId>
<version>6.1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-javaconfig</artifactId>
<version>${osgi.javaconfig.version}</version>
</dependency>
<!-- OSGi Java Config dependencies -->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.cache</groupId>
<artifactId>atlassian-cache-api</artifactId>
<version>7.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>2.2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>2.2.5</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>jira-maven-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<enableQuickReload>true</enableQuickReload>
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>
com.infineon.plugin.api,
</Export-Package>
<!-- Add package import here -->
<Import-Package>
com.atlassian.event.api,
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
*
</Import-Package>
<!-- Ensure plugin is spring powered -->
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>2.2.5</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jira.version>9.12.2</jira.version>
<amps.version>9.1.1</amps.version>
<plugin.testrunner.version>2.0.9</plugin.testrunner.version>
<osgi.javaconfig.version>0.2.0</osgi.javaconfig.version>
<spring.version>5.3.34</spring.version>
<!-- This property ensures consistency between the key in atlassian-plugin.xml and the OSGi bundle's key. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<!-- TestKit version 6.x for JIRA 6.x -->
<testkit.version>6.3.11</testkit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am not saying the build errors; it's the atlassian-jira.log file where you can find the logs related to the plugin initilization and associated errors. Reviewing this log file will help a lot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I searched the logs:
It seems not event ini() is run.
I do not have anything related to:
IssueCreateEventListener
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, assuming there is nothing wrong in the atlassian-jira.log file, let's make sure that your atlassian-plugin.xml file includes the below line
<spring context="component-scan"/>
Then go to manage Apps > your plugin > plugin components and ensure that IssueCreateEventListener is listed and enabled there. If not listed, the component was not scanned.
If still not working attach your atlassian-plugin.xml file here so that we can check
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added the suggested line and the plugin is DISABLED.
here is my atlassian-plugin.xml
<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
<param name="plugin-icon">images/pluginIcon.png</param>
<param name="plugin-logo">images/pluginLogo.png</param>
</plugin-info>
<spring context="component-scan"/>
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="issuetagger"/>
<!-- add our web resources -->
<web-resource key="issuetagger-resources" name="issuetagger Web Resources">
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="issuetagger.css" location="/css/issuetagger.css"/>
<resource type="download" name="issuetagger.js" location="/js/issuetagger.js"/>
<resource type="download" name="images/" location="/images"/>
<context>issuetagger</context>
</web-resource>
<web-resource key="dashboard-resources" name="Dashboard Resources">
<resource type="download" name="dashboard.js" location="static/dashboard.js"/>
<context>jira.general</context>
</web-resource>
<web-item key="dashboard-navbar-button"
name="Dashboard Button"
section="system.top.navigation.bar"
weight="1000">
<label>IssueTagger Dashboard</label>
<link>#</link>
<tooltip>IssueTagger Dashboard</tooltip>
<dependency>com.infineon.issuetagger:dashboard-resources</dependency>
<styleClass>dashboard-open-btn</styleClass>
</web-item>
<rest key="admin-check-rest"
path="/dashboard-tagger"
version="1.0">
<description>Admin Check REST Module</description>
</rest>
</atlassian-plugin>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is solved!
I created this class in config folder:
package com.infineon.plugin.config;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.bc.user.search.UserSearchService;
import com.atlassian.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
@ComponentScan(basePackages = {
"com.infineon.plugin.events",
"com.infineon.plugin.rest",
})
public class PluginConfiguration {
/**
* JIRA Issue Manager Bean
* Provides access to JIRA's issue management functionality
*/
@Bean
@Scope("singleton")
public IssueManager issueManager() {
return ComponentAccessor.getIssueManager();
}
/**
* JIRA Project Manager Bean
* Provides access to JIRA's project management functionality
*/
@Bean
@Scope("singleton")
public ProjectManager projectManager() {
return ComponentAccessor.getProjectManager();
}
/**
* JIRA User Manager Bean (correct for JIRA 9.x)
* Provides access to JIRA's user management functionality
*/
@Bean
@Scope("singleton")
public UserManager userManager() {
return ComponentAccessor.getUserManager();
}
/**
* JIRA User Search Service Bean
* Provides user search functionality
*/
@Bean
@Scope("singleton")
public UserSearchService userSearchService() {
return ComponentAccessor.getComponent(UserSearchService.class);
}
/**
* JIRA Authentication Context Bean
* Provides access to current user context
*/
@Bean
@Scope("singleton")
public JiraAuthenticationContext authenticationContext() {
return ComponentAccessor.getJiraAuthenticationContext();
}
/**
* Cache Manager Bean
* Get CacheManager using ComponentAccessor.getComponent()
*/
@Bean
@Scope("singleton")
public CacheManager cacheManager() {
return ComponentAccessor.getComponent(CacheManager.class);
}
/**
* Plugin Properties Bean
* Configuration properties for the plugin
*/
@Bean
@Scope("singleton")
public PluginProperties pluginProperties() {
return new PluginProperties();
}
/**
* Custom configuration properties class
*/
public static class PluginProperties {
private String defaultTagColor = "#007cbb";
private int maxTagsPerIssue = 10;
private boolean enableAutoTagging = true;
public String getDefaultTagColor() {
return defaultTagColor;
}
public void setDefaultTagColor(String defaultTagColor) {
this.defaultTagColor = defaultTagColor;
}
public int getMaxTagsPerIssue() {
return maxTagsPerIssue;
}
public void setMaxTagsPerIssue(int maxTagsPerIssue) {
this.maxTagsPerIssue = maxTagsPerIssue;
}
public boolean isEnableAutoTagging() {
return enableAutoTagging;
}
public void setEnableAutoTagging(boolean enableAutoTagging) {
this.enableAutoTagging = enableAutoTagging;
}
}
@Bean
@Scope("singleton")
public EventPublisher eventPublisher() {
return ComponentAccessor.getComponent(EventPublisher.class);
}
}
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.