summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml
diff options
context:
space:
mode:
authorThomas Wolf <twolf@apache.org>2024-03-08 19:48:27 +0100
committerThomas Wolf <twolf@apache.org>2024-03-08 20:41:24 +0100
commitbf7dd9add2f7115cb988d582da7e8943c3f5fbbf (patch)
treeda68855740aaaf97a241639286a2ede8e17fe380 /org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml
parent819c5bcc8b2a2685c20e5b8e568f776b19f7db63 (diff)
downloadjgit-bf7dd9add2f7115cb988d582da7e8943c3f5fbbf.tar.gz
jgit-bf7dd9add2f7115cb988d582da7e8943c3f5fbbf.zip
ShutdownHook: run on bundle deactivation if in OSGi
Running as a JVM shutdown hook is far too late in an OSGi framework; by the time the JVM shuts down, the OSGi framework will normally already have deactivated and unloaded bundles, and thus the JGit cleanup code may try to work with unloaded classes for which there will be no classloader anymore. When JGit is used in an OSGi framework, the cleanups must run on bundle deactivation, not on JVM shut down. Add a declarative OSGi service CleanupService. This is a normal Java class that has no dependencies on any OSGi bundle or interface, but that is declared in the MANIFEST.MF and in an OSGi Service XML as an OSGi immediate component. Set the bundle activation policy to "lazy". (A declarative service is used instead of a bundle activator because the latter would need to implement the OSGi interface BundleActivator, but JGit should not have dependencies on OSGi.) When JGit runs in an OSGi framework, the framework will create an instance of CleanupService through the no-args constructor when (and before) the first class from this bundle is loaded. This instance thus knows that it is operating in OSGi, and will run the ShutdownHook when the bundle is deactivated: bundle deactivation will deactivate the CleanupService instance. When JGit does not run in an OSGi framework, the OSGi service declaration will be ignored, and there will be no already existing CleanupService instance. We create one lazily, which thus knows that it is not operating in OSGi, and which will use a JVM shutdown hook to run the ShutdownHook. This also reverts commit e6d83d61eade6dee223757d149a4df9650752a55. Bug: jgit-36 Change-Id: I9c621b0707453c087f638974312ea1bf8ec30c31 Signed-off-by: Thomas Wolf <twolf@apache.org>
Diffstat (limited to 'org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml')
-rw-r--r--org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml4
1 files changed, 4 insertions, 0 deletions
diff --git a/org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml b/org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml
new file mode 100644
index 0000000000..8d97374c66
--- /dev/null
+++ b/org.eclipse.jgit/OSGI-INF/org.eclipse.jgit.internal.util.CleanupService.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="shutDown" name="org.eclipse.jgit.internal.util.CleanupService">
+ <implementation class="org.eclipse.jgit.internal.util.CleanupService"/>
+</scr:component> \ No newline at end of file