11/*******************************************************************************
2- * Copyright (c) 2017-2021 Microsoft Corporation and others.
2+ * Copyright (c) 2017-2023 Microsoft Corporation and others.
33* All rights reserved. This program and the accompanying materials
44* are made available under the terms of the Eclipse Public License v1.0
55* which accompanies this distribution, and is available at
1111
1212package com .microsoft .java .test .plugin .util ;
1313
14+ import org .eclipse .core .resources .IProject ;
1415import org .eclipse .core .runtime .IPath ;
1516import org .eclipse .core .runtime .IProgressMonitor ;
1617import org .eclipse .jdt .core .IClasspathAttribute ;
@@ -111,13 +112,13 @@ public static List<TestSourcePath> getTestSourcePaths(IJavaProject project) thro
111112 }
112113
113114 if (isTestEntry (entry )) {
114- paths . add ( new TestSourcePath ( parseTestSourcePathString ( entry , project ), true ) );
115+ addTestSourcePath ( paths , project . getProject ( ), entry , true );
115116 continue ;
116117 }
117118
118119 // Always return true Eclipse & invisible project
119120 if (ProjectUtils .isGeneralJavaProject (project .getProject ())) {
120- paths . add ( new TestSourcePath ( parseTestSourcePathString ( entry , project ), false ) );
121+ addTestSourcePath ( paths , project . getProject ( ), entry , false );
121122 }
122123 }
123124 return paths ;
@@ -134,14 +135,20 @@ public static Set<IJavaProject> parseProjects(String uriStr) {
134135 .collect (Collectors .toSet ());
135136 }
136137
137- private static String parseTestSourcePathString (IClasspathEntry entry , IJavaProject project ) {
138- final IPath relativePath = entry .getPath ().makeRelativeTo (project .getPath ());
138+ private static void addTestSourcePath (List <TestSourcePath > paths , IProject project ,
139+ IClasspathEntry entry , boolean isStrict ) {
140+ final IPath relativePath = entry .getPath ().makeRelativeTo (project .getFullPath ());
141+ final IPath testSourcePath ;
139142 // Eclipse project that source files stored directly at project root
140143 if (relativePath .isEmpty ()) {
141- return project .getProject ().getLocation ().toOSString ();
144+ testSourcePath = project .getLocation ();
145+ } else {
146+ testSourcePath = project .getFolder (relativePath ).getLocation ();
142147 }
143148
144- return project .getProject ().getFolder (relativePath ).getLocation ().toOSString ();
149+ if (testSourcePath != null ) {
150+ paths .add (new TestSourcePath (testSourcePath .toOSString (), isStrict ));
151+ }
145152 }
146153
147154 public static boolean isTest (IJavaProject project , IPath path , boolean containsGeneral ) {
0 commit comments