Unverified Commit 7dc7b2c2 authored by andrewbwogi's avatar andrewbwogi Committed by GitHub
Browse files

fix: custom URLClassLoaders are now actually used (#3818)

parent 24514373
......@@ -424,7 +424,6 @@ private transient ClassLoader inputClassloader;
throw new SpoonException("Spoon does not support a URLClassLoader containing other resources than local file.");
this.classloader = aClassLoader;
......@@ -458,16 +458,30 @@ public class CompilationTest {
public void testURLClassLoader() throws Exception {
// contract: Spoon handles URLClassLoader and retrieves path elements
// contract: Spoon uses the manually set and not the default URLClassLoader
Launcher launcher = new Launcher();
String classpath = "src/test/resources/classloader-test/";
URL url = new File(classpath).toURI().toURL();
URL[] urls = new URL[]{url};
URLClassLoader urlClassloaderNullParent = new URLClassLoader(urls,null);
CtModel model = launcher.buildModel();
List<CtType> ctTypeList = model.getElements(new TypeFilter(CtType.class));
CtTypeReference launcherField = ctTypeList.get(0).getField("launcher").getType();
assertEquals(0, launcherField.getTypeDeclaration().getFields().size());
public void testPathRetrievalFromURLClassLoader() throws Exception {
// contract: Spoon retrieves path elements from a manually set URLClassloader
String expected = "target/classes/";
File f = new File(expected);
URL[] urls = {f.toURL()};
URL[] urls = {f.toURI().toURL()};
URLClassLoader urlClassLoader = new URLClassLoader(urls);
Launcher launcher = new Launcher();
String[] sourceClassPath = launcher.getEnvironment().getSourceClasspath();
assertEquals(1, sourceClassPath.length);
String tail = sourceClassPath[0].substring(sourceClassPath[0].length() - expected.length());
import spoon.Launcher;
public class LauncherUser {
Launcher launcher;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment