Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get id of my plugin?

Alexey_Efimov
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.
November 28, 2015

Hello,

I need to use one common service class in several plugins. Within this service i need to get id of plugin, where this service is declared as component in atlassian-plugin.xml. So i have many plugins with this class declared as 'personal' service for each plugin. And i need to have cache in with service, located in different directories for each plugins where it declared.

Is it possible?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Alexey_Efimov
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 3, 2016

I found solution by myself:

URL descriptor = getClass().getClassLoader().getResource("atlassian-plugin.xml");
if (descriptor == null) {
    throw new IOException("Can't find atlassian-plugin.xml");
}
try (InputStream is = descriptor.openStream()) {
    XmlDescriptorParser parser = new XmlDescriptorParser(is, Collections.<Application>emptySet());
    String pluginKey = parser.getKey();
    String id = pluginKey.substring(pluginKey.lastIndexOf('.') + 1).replaceFirst("^stash-", "");
    
    // Do something with id
}
TAGS
AUG Leaders

Atlassian Community Events