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

Exchange data between v1 and v2 plugin

m.stelzner September 15, 2011

Hi,

is there a way to exchange data between a v1 and a v2 plugin? Any clue how to do this?

Thanks!

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Radu Dumitriu
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.
September 15, 2011

Yes, of course.

1) Setting the correct class loader (usually belonging to a class in the WEB-INF/lib helps)

2) If you cannot go past beyond the class loader issues (may happen in some special cases) just remember: reflection is always good ;)

#ifdef _UNSAFE_

clz = Class.forName("my.innaccessible.clazz", true, com.atlassian.jira.ComponentManager.class.getClassLoader());
Method m = clz.getMethod("executeTheDamnMethod", String.class, Integer.class);

m.invoke(null, "string here", -1); //this is a static one

.....................

#endif

m.stelzner September 15, 2011

thx

how about the other way: Access a component of a v2- from a v1-plugin?

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.
September 15, 2011

so evil yet so easy ;-)

Radu Dumitriu
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.
September 15, 2011

@Michael Stelzner.

It's a bit harder because you have to determine in which class loader the class was loaded (go up in the hierarchy of the OSGI bundles). Once you figure it out, same stuff.

BUT: You can always do a callback: Like for instance, the V2 plugin "registers" itself (calls back with 'this' ) a method on the V1 :)) hehe

m.stelzner September 18, 2011

Hi Radu,

thanks for the classloader hint. I was able to connect my v2 to the v1 and execute some methods.

Haven't tried the other way yet.

Dieter
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.
October 16, 2012

Hi Radu,

thanks so much ... this saved me a lot of time today :-)

Regards,

Dieter

Nahn Yanootz
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.
May 15, 2013

Hey

I exported my component in a V1 plugin using the <component> declaration in atlassian-plugin.xml. After that, I tried the following from a V2 plugin:

Class&lt;?&gt; clz = Class.forName("com.myplugin.MyComponentInterface.class", true,com.atlassian.jira.ComponentManager.class.getClassLoader());
			Method m = clz.getMethod("sayHello", String.class);
			m.invoke("John");

and it gives me a java.lang.ClassNotFoundException.

Nahn Yanootz
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.
May 15, 2013

What if I export a component from a V1 plugin, and it doesn't have a static method?

The m.invoke(...) method takes an object as the first parameter (null if it is static). How do I get that object?

I tried doing the following:

Class&lt;?&gt; clz = Class.forName("com.myplugin.MyComponentInterface", true, com.atlassian.jira.ComponentManager.class.getClassLoader());
			Method m = clz.getMethod("sayHello", String.class);
			m.invoke(ComponentManager.getComponent(MyComponentInterface.class), "John");

I tried using ComponentManager.getComponent(...) to get my object, but it gives me a NullPointerException.

Any idea how to access V1 components from V2, without using static methods?

Thanks

TAGS
AUG Leaders

Atlassian Community Events