I'm developing a plugin and I am using the junit-rt.jar plugin from Intellij IDEA. I am using some methods from classes present in this jar but some of these methods are private. My question is: should I use reflection to call those methods or should I copy the source code of these methods into my custom plugin and use them like they were part of my plugin itself?
The problem with reflection, in my opinion, is that the private methods can be changed inside these classes(their name or signature can change). In this case my plugin won't work. On the other hand, if I copy the source code everything will work even if the private methods are changed, BUT in this case:
- I don't reuse existing code
- Problems can arise from the fact that different versions of Intellij use the same JUnit plugin code(I am not sure about this one??)
- if there are some bug fixes, then I will have to manually apply them to my sources
Also, there is a third option, which is the best in my opinion: Copy the whole classes which I want to use into my custom plugin, but DO not modify anything in the source code. Then, change every method to be public or package-private and extend these classes and override only those methods which need to be changed.
- Applying bug fixes manually is a breeze because I do not have classes mixed with my own code and plugin code at the same time. So, I can just copy-paste the new source code from the Github repo and hope that it works. If it doesn't work, no worries, I can just change my custom plugin a little bit to make it work
- Same as second solution.
UPDATE: after checking the JUnitStarter code I've found that its source code has changed considerably since 2010. For example:
Code from my installation:
private static int prepareStreamsAndStart(String args, String agentName, ArrayList listeners, String name)
Code from 2010:
private static int prepareStreamsAndStart(String args, final boolean isJUnit4, ArrayList listeners, SegmentedOutputStream out,
UPDATE2: I've noticed that 4 days ago, the JUnitStarter's package was changed from com.intellij.rt.execution.junit to com.intellij.rt.junit. So, my plugin will break just from this update!!!