Duplicate ProjectEvent

Hello,

I’ve tried to create a ProjectEvent listener and it seems that the @EventListener method is being called twice.

Sample class used:

import com.atlassian.bitbucket.event.ApplicationEvent
import com.atlassian.bitbucket.event.project.ProjectEvent
import com.atlassian.bitbucket.event.server.BaseUrlChangedEvent
import com.atlassian.event.api.EventListener
import com.atlassian.event.api.EventPublisher
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport
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("ApplicationEventListener")
class ApplicationEventListener {
    private static final Logger log = LoggerFactory.getLogger(ApplicationEventListener)

    private final EventPublisher eventPublisher

    @Inject
    ApplicationEventListener(@ComponentImport EventPublisher eventPublisher) {
        this.eventPublisher = eventPublisher
    }

    @PostConstruct
    void init() {
        // Called after the instance is created (when the plugin is started)
        eventPublisher.register(this)
    }

    @PreDestroy
    void destroy() {
        // Called just before the instance is destroyed (when the plugin is stopped)
        eventPublisher.unregister(this)
    }

    @EventListener
    void onProjectEvent(ProjectEvent projectEvent) {
        System.out.println "\n\nA projectEvent: " + projectEvent + " - " + System.currentTimeMillis();
    }
}

Output from the logs:

A projectEvent: com.atlassian.bitbucket.event.project.ProjectCreationRequestedEvent[source=com.atlassian.stash.internal.project.DefaultProjectService@3fc21671] - 1567106642933
2019-08-29 19:24:02,936 INFO [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.p.DefaultProjectService Created new project: (NEWA) NewProjectTest
2019-08-29 19:24:02,936 DEBUG [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.e.TransactionAwareEventPublisher Deferring publishing for ProjectPermissionGrantedEvent until AFTER_COMMIT
2019-08-29 19:24:02,936 DEBUG [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.p.DefaultProjectService Granted PROJECT_ADMIN to admin for project NEWA
2019-08-29 19:24:02,936 DEBUG [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.e.TransactionAwareEventPublisher Deferring publishing for ProjectCreatedEvent until AFTER_COMMIT
2019-08-29 19:24:02,941 DEBUG [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.e.TransactionAwareEventPublisher Publishing ProjectPermissionGrantedEvent after commit
2019-08-29 19:24:02,941 DEBUG [http-nio-7990-exec-9] admin @7O10BRx1164x1667x0 1002hy1 192.168.100.6 "POST /projects HTTP/1.1" c.a.s.i.e.TransactionAwareEventPublisher Publishing ProjectCreatedEvent after commit
A projectEvent: com.atlassian.bitbucket.event.project.ProjectCreatedEvent[source=com.atlassian.stash.internal.project.DefaultProjectService@3fc21671] - 1567106642944

Some logs after installing the plugin:

2019-08-29 19:23:12,067 INFO [ThreadPoolAsyncTaskExecutor::Thread 104] o.e.g.b.e.i.s.ExtenderConfiguration Application context successfully refreshed (NonValidatingOsgiBundleXmlApplicationContext(bundle=com.test.bitbucket.event-tester, config=osgibundle:/META-INF/spring/*.xml))
2019-08-29 19:23:12,767 DEBUG [http-nio-7990-exec-1] @7O10BRx1163x1643x0 192.168.100.6 "GET /rest/plugins/1.0/pending/df460cd7-2f4f-431a-b3ae-7921ccedfca8 HTTP/1.1" c.a.b.i.c.s.CrowdSsoAuthenticationHandler Skipping Crowd SSO as it is not enabled
2019-08-29 19:23:12,854 INFO [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.plugin.manager.PluginEnabler Plugin 'com.test.bitbucket.event-tester' is now ENABLED
2019-08-29 19:23:12,857 INFO [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.p.o.f.ModuleDescriptorServiceTrackerCustomizer Dynamically registered new module descriptor: com.test.bitbucket.event-tester:event-tester-rest-filter
2019-08-29 19:23:12,864 DEBUG [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.s.i.i18n.I18nClasspathScanner Adding plugin Event Tester with [event-tester]
2019-08-29 19:23:12,953 DEBUG [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.s.s.a.l.PatchedLifecycleManager Calling LifecycleAware.onStart() 'com.atlassian.bitbucket.internal.plugin.extender.BeanEventListenerScanner$EventListenerLifecycle@13470168' from plugin 'com.test.bitbucket.event-tester'
2019-08-29 19:23:12,953 DEBUG [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.b.i.p.e.BeanEventListenerScanner com.test.bitbucket.event-tester: registered [ApplicationEventListener] as event listener
2019-08-29 19:23:12,978 INFO [UpmAsynchronousTaskManager:thread-4] admin @7O10BRx1163x1641x0 192.168.100.6 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.u.c.l.PluginSettingsAuditLogService Thu Aug 29 19:23:12 GMT 2019 1: Installed app Event Tester (com.test.bitbucket.event-tester version 1.0.0-SNAPSHOT)

Any ideas why this event listener is called twice? I read the other thread regarding the duplicate RepositoryEvent event being broadcast (https://stackoverflow.com/questions/44208503/bitbucket-branch-create-and-delete-events-fired-multiple-times/44221619#44221619) , followed the official documentation and didn’t add anything extra in the atlassian-plugin.xml file.

Regards,

Razvan