Skip to content

Commit

Permalink
[FIX JENKINS-4409] Release plugins and class loaders when JVM shuts d…
Browse files Browse the repository at this point in the history
…own.

Originally-Committed-As: 2b9a083fbf2b9f4946ffa01e35dffea2b20a98d1
  • Loading branch information
ikedam authored and kohsuke committed Jun 19, 2013
1 parent 5d3112c commit bfb7090
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/src/main/java/org/jvnet/hudson/test/TestPluginManager.java
Expand Up @@ -113,6 +113,8 @@ protected Collection<String> loadBundledPlugins() throws Exception {
return names;
}

// Overwrite PluginManager#stop, not to release plugins in each tests.
// Releasing plugins result fail to access files in webapp directory in following tests.
@Override
public void stop() {
for (PluginWrapper p : activePlugins)
Expand All @@ -126,6 +128,14 @@ public void stop() {
INSTANCE = new TestPluginManager();
Runtime.getRuntime().addShutdownHook(new Thread("delete " + INSTANCE.rootDir) {
@Override public void run() {
// Shutdown and release plugins as in PluginManager#stop
for(PluginWrapper p: INSTANCE.getPlugins()) {
p.stop();
p.releaseClassLoader();
}
INSTANCE.getPlugins().clear();
// allow JVM cleanup handles of jar files...
System.gc();
try {
Util.deleteRecursive(INSTANCE.rootDir);
} catch (IOException x) {
Expand Down

0 comments on commit bfb7090

Please sign in to comment.