-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39bf72b
commit 872146d
Showing
7 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
documentation/src/test/java/example/CustomLauncherInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example; | ||
|
||
// tag::user_guide[] | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
|
||
import org.junit.platform.launcher.LauncherInterceptor; | ||
|
||
public class CustomLauncherInterceptor implements LauncherInterceptor { | ||
|
||
private final URLClassLoader customClassLoader; | ||
|
||
public CustomLauncherInterceptor() throws Exception { | ||
ClassLoader parent = Thread.currentThread().getContextClassLoader(); | ||
customClassLoader = new URLClassLoader(new URL[] { URI.create("some.jar").toURL() }, parent); | ||
} | ||
|
||
@Override | ||
public <T> T intercept(Invocation<T> invocation) { | ||
Thread currentThread = Thread.currentThread(); | ||
ClassLoader originalClassLoader = currentThread.getContextClassLoader(); | ||
currentThread.setContextClassLoader(customClassLoader); | ||
try { | ||
return invocation.proceed(); | ||
} | ||
finally { | ||
currentThread.setContextClassLoader(originalClassLoader); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
customClassLoader.close(); | ||
} | ||
catch (IOException e) { | ||
throw new UncheckedIOException("Failed to close custom class loader", e); | ||
} | ||
} | ||
} | ||
// end::user_guide[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters