@@ -280,7 +280,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav
280280 sourcePathEnabled = true ;
281281 }
282282 if (!sourcePathEnabled ) {
283- fileManager .setLocation (StandardLocation .SOURCE_PATH , classpathEntriesToFiles (javaProject , entry -> entry . getEntryKind () == IClasspathEntry . CPE_SOURCE && (isTest || !entry .isTest ())));
283+ fileManager .setLocation (StandardLocation .SOURCE_PATH , classpathEntriesToFiles (javaProject , true , entry -> (isTest || !entry .isTest ())));
284284 }
285285
286286 boolean classpathEnabled = false ;
@@ -315,7 +315,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav
315315 })
316316 .collect (Collectors .toSet ());
317317
318- Collection <File > classpathFiles = classpathEntriesToFiles (javaProject , entry -> isTest || !entry .isTest ());
318+ Collection <File > classpathFiles = classpathEntriesToFiles (javaProject , false , entry -> isTest || !entry .isTest ());
319319 Collection <File > filteredFiles = classpathFiles .stream ().filter (x -> x .length () != 0 ).toList ();
320320 fileManager .setLocation (StandardLocation .CLASS_PATH , filteredFiles );
321321 classpathFiles .addAll (outDirectories (javaProject , entry -> isTest || !entry .isTest ()));
@@ -368,7 +368,7 @@ public static <T> boolean isEmpty(List<T> list) {
368368 return list == null || list .isEmpty ();
369369 }
370370
371- private static Collection <File > classpathEntriesToFiles (JavaProject project , Predicate <IClasspathEntry > select ) {
371+ private static Collection <File > classpathEntriesToFiles (JavaProject project , boolean source , Predicate <IClasspathEntry > select ) {
372372 try {
373373 LinkedHashSet <File > res = new LinkedHashSet <>();
374374 ArrayList <IClasspathEntry > seen = new ArrayList <>();
@@ -395,13 +395,25 @@ private static Collection<File> classpathEntriesToFiles(JavaProject project, Pre
395395 }
396396 if (moduleDescription == null ) {
397397 IPath path = referencedJavaProject .getOutputLocation ();
398- addPath (referencedJavaProject , path , res );
398+ if (!source ) {
399+ addPath (referencedJavaProject , path , res );
400+ }
399401 IClasspathEntry [] resolved = referencedJavaProject .resolveClasspath (referencedJavaProject .getExpandedClasspath ());
400402 for (IClasspathEntry transitiveEntry : resolved ) {
401403 if (transitiveEntry .getEntryKind () == IClasspathEntry .CPE_SOURCE ) {
402- IPath outputLocation = transitiveEntry .getOutputLocation ();
403- if (outputLocation != null && select .test (transitiveEntry )) {
404- addPath (referencedJavaProject , outputLocation , res );
404+ if (select .test (transitiveEntry )) {
405+ if (!source ) {
406+ IPath outputLocation = transitiveEntry .getOutputLocation ();
407+ if (outputLocation != null ) {
408+ addPath (referencedJavaProject , outputLocation , res );
409+ }
410+ }
411+ if (source ) {
412+ IPath sourceLocation = transitiveEntry .getPath ();
413+ if (sourceLocation != null ) {
414+ addPath (referencedJavaProject , sourceLocation , res );
415+ }
416+ }
405417 }
406418 } else if (transitiveEntry .isExported () && !seen .contains (transitiveEntry )) {
407419 toProcess .add (transitiveEntry );
@@ -411,7 +423,8 @@ private static Collection<File> classpathEntriesToFiles(JavaProject project, Pre
411423 }
412424 }
413425 }
414- } else if (select .test (current )) {
426+ } else if (select .test (current ) &&
427+ ((source && current .getEntryKind () == IClasspathEntry .CPE_SOURCE ) || (!source && current .getEntryKind () != IClasspathEntry .CPE_SOURCE ))) {
415428 IPath path = current .getPath ();
416429 addPath (project , path , res );
417430 }
0 commit comments