Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,024
Community Members
 
Community Events
165
Community Groups

Use of a thirdparty jar which used ServiceLoader to load some dependent services not working

I am trying to develop a bamboo task for one of my project. The purpose of this jar is to parse the working directory and create a JSON output. For this purpose, I have also developed a java library which will take the working directory as input and provide a parsed output in JSON. Now, this java library uses java's ServiceLoader to load some dependent service classes. Independently, this library works as expected and loads all the dependencies and does its work. However, on using this library as a third party lib in the plugin, the library is not loading the dependent classes. In some post i saw the loading classes in  atlassian sdk is triky. Please advise what I am doing wrong or missing. 

the pom at the pluging:

 <dependency>
<groupId>com.abd.plug</groupId>
<artifactId>buildInspLib</artifactId>
<version>1</version>
<scope>compile</scope>
</dependency>



 

The dependencies which would be loaded by serviceLoader at the pom at the buildIspLib: 

 

 <dependency>
<groupId>com.abd.parser</groupId>
<artifactId>parser1</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.abd.parser</groupId>
<artifactId>parser2</artifactId>
<version>1</version>
</dependency>

 

The code to load the service implementations. the buildInspLib has the META-INF directory which has the file with the implementing classes in it. Please note, this library works as expected if run outside of the atlassian sdk

//loads all the classes implementing ParserService
ServiceLoader<ParserService> loader = ServiceLoader.load(ParserService.class);

ExecutorService exec = Executors.newCachedThreadPool();

List<Future<ComputedData>> analysersOutput = new ArrayList<>();

System.out.println(" before distribution.."); //THIS LINE GETS PRINTED IN THE PLUGIN

for (ParserService serv : loader) {

try {

System.out.println(" distributing for : "+serv.getAnalyserType()+" );
//THIS LINE NEVER GETS PRINTED IN THE PLUGIN
....

...

How am I using this thirdparty lib?

new ParserInspector().inspect(taskContext.getWorkingDirectory().getAbsolutePath())

Please note: the library is being loaded. I can say that because, i could see the logs being printed. However, the service loader is not able to find the implementation classes  

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo Data Center on Kubernetes

Hi, If you are running self-managed environments and looking to adopt modern infrastructure, Bamboo Data Center can now be deployed in a Kubernetes cluster. By leveraging Kubernetes, you can easily...

954 views 3 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you