TIBCOSoftware / jasperreports

JasperReports® - Free Java Reporting Library
https://community.jaspersoft.com/downloads/community-edition/
GNU Lesser General Public License v3.0
1.06k stars 404 forks source link

For OSGI, it is necessary to redo the system for determining the current ClassLoader #404

Open alexinsmail opened 11 months ago

alexinsmail commented 11 months ago

For OSGI, it is necessary to redo the system for determining the current ClassLoader.

The construction is almost universally used

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

For OSGI, this does not work correctly. Each OSGI Bundle has its own ClassLoader that protects the private part from outsiders. The logical solution is to transfer the ClassLoader to the local JasperReportsContext.

It is necessary to find all the methods where the above construction is used. All resources and classes must be raised using JRClassLoader. JRClassLoader should get the current ClassLoader from JasperReportsContext.

If you haven't installed ClassLoader in JasperReportsContext, you should use the above construction.

In JRGroovyCompiler, when creating a GroovyClassLoader, it is necessary to give the ClassLoader from JasperReportsContext. Old code

CompilationUnit unit = new CompilationUnit(config);

New code

ClassLoader classLoader = jasperReportsContext.getDefaultClassLoader();
GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader, config);
CompilationUnit unit = new CompilationUnit(config, null, groovyClassLoader);

By default, groovy does not see JasperReport classes.