Skip to content

Commit 7ff7a32

Browse files
authored
fix: Parse the project in path correctly (#708)
1 parent 9c4c5f2 commit 7ff7a32

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/ProjectTestUtils.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static Set<IJavaProject> parseProjects(String uriStr) {
7676
return Collections.emptySet();
7777
}
7878
return Arrays.stream(ProjectUtils.getJavaProjects())
79-
.filter(p -> belongToProject(parentPath, p.getProject()))
79+
.filter(p -> isProjectBelongToPath(p.getProject(), parentPath))
8080
.collect(Collectors.toSet());
8181
}
8282

@@ -135,7 +135,23 @@ public static boolean isTest(IClasspathEntry entry) {
135135
return entry.isTest();
136136
}
137137

138-
public static boolean belongToProject(IPath testPath, IProject project) {
138+
public static boolean isProjectBelongToPath(IProject project, IPath path) {
139+
// Check for visible project
140+
if (project.getLocation() != null && path.isPrefixOf(project.getLocation())) {
141+
return true;
142+
}
143+
144+
145+
// Check for invisible project
146+
final IPath linkedLocation = project.getFolder(WORKSPACE_LINK).getLocation();
147+
if (linkedLocation != null && path.isPrefixOf(linkedLocation)) {
148+
return true;
149+
}
150+
151+
return false;
152+
}
153+
154+
public static boolean isPathBelongToProject(IPath testPath, IProject project) {
139155
// Check if the path belongs to visible project
140156
if (project.getLocation() != null && project.getLocation().isPrefixOf(testPath)) {
141157
return true;

java-extension/com.microsoft.java.test.plugin/src/main/java/com/microsoft/java/test/plugin/util/RuntimeClassPathUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static String[] resolveRuntimeClassPath(List<Object> arguments) throws Co
4949
while (iterator.hasNext()) {
5050
final IJavaProject javaProject = iterator.next();
5151
final IProject project = javaProject.getProject();
52-
if (ProjectTestUtils.belongToProject(testPath, project)) {
52+
if (ProjectTestUtils.isPathBelongToProject(testPath, project)) {
5353
projectsToTest.add(javaProject);
5454
iterator.remove();
5555
}

0 commit comments

Comments
 (0)