5050import org .rascalmpl .interpreter .env .ModuleEnvironment ;
5151import org .rascalmpl .interpreter .load .RascalSearchPath ;
5252import org .rascalmpl .interpreter .utils .RascalManifest ;
53+ import org .rascalmpl .library .util .PathConfig ;
54+ import org .rascalmpl .library .util .PathConfig .RascalConfigMode ;
5355import org .rascalmpl .uri .ProjectURIResolver ;
5456import org .rascalmpl .uri .URIResolverRegistry ;
5557import 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