Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 7889f8b

Browse files
committed
added feature to extract Rascal source modules from mvn dependency jars, and also add these jars and the jars they depend on to the classpath for reflective access
1 parent 9c664d9 commit 7889f8b

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

rascal-eclipse/src/org/rascalmpl/eclipse/nature/ProjectEvaluatorFactory.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.rascalmpl.interpreter.env.ModuleEnvironment;
5151
import org.rascalmpl.interpreter.load.RascalSearchPath;
5252
import org.rascalmpl.interpreter.utils.RascalManifest;
53+
import org.rascalmpl.library.util.PathConfig;
54+
import org.rascalmpl.library.util.PathConfig.RascalConfigMode;
5355
import org.rascalmpl.uri.ProjectURIResolver;
5456
import org.rascalmpl.uri.URIResolverRegistry;
5557
import org.rascalmpl.uri.URIUtil;
@@ -409,11 +411,33 @@ private static void collectClassPathForBundle(Bundle bundle, List<URL> classPath
409411
}
410412
}
411413

412-
private void collectClassPathForProject(IProject project, List<URL> classPath, List<String> compilerClassPath, Evaluator parser) {
414+
private void collectClassPathForProject(IProject project, List<URL> classPath, List<String> compilerClassPath, Evaluator eval) {
413415
if (project == null) {
414416
return;
415417
}
416418

419+
if (project.getFile("pom.xml").exists()) {
420+
// collect information from maven
421+
try {
422+
ISourceLocation ploc = URIUtil.createFileLocation(project.getRawLocation().makeAbsolute().toOSString());
423+
PathConfig pcfg = PathConfig.fromSourceProjectRascalManifest(ploc, RascalConfigMode.INTERPETER);
424+
425+
pcfg.getClassloaders().stream().map(v -> (ISourceLocation) v).forEach(cl -> {
426+
try {
427+
if ("file".equals(cl.getScheme())) {
428+
classPath.add(cl.getURI().toURL());
429+
addJarToSearchPath(cl, eval);
430+
}
431+
} catch (MalformedURLException e) {
432+
throw new RuntimeException(e);
433+
}
434+
});
435+
}
436+
catch (IOException | URISyntaxException e) {
437+
Activator.log(e.getMessage(), e);
438+
}
439+
}
440+
417441
try {
418442
IJavaProject jProject = JavaCore.create(project);
419443

@@ -422,7 +446,7 @@ private void collectClassPathForProject(IProject project, List<URL> classPath, L
422446
compilerClassPath.add(binLoc);
423447

424448
URL binURL = new URL("file", "", binLoc + "/");
425-
parser.addClassLoader(new URLClassLoader(new URL[] {binURL}, getClass().getClassLoader()));
449+
eval.addClassLoader(new URLClassLoader(new URL[] {binURL}, getClass().getClassLoader()));
426450
classPath.add(binURL);
427451

428452
if (!jProject.isOpen()) {
@@ -451,7 +475,7 @@ private void collectClassPathForProject(IProject project, List<URL> classPath, L
451475
}
452476
break;
453477
case IClasspathEntry.CPE_PROJECT:
454-
collectClassPathForProject((IProject) project.getWorkspace().getRoot().findMember(entry.getPath()), classPath, compilerClassPath, parser);
478+
collectClassPathForProject((IProject) project.getWorkspace().getRoot().findMember(entry.getPath()), classPath, compilerClassPath, eval);
455479
break;
456480
}
457481
}

0 commit comments

Comments
 (0)