Skip to content

Commit 531b21a

Browse files
Add command to resolve the project build files (#301)
* Add command to resolve the project build files Signed-off-by: Jinbo Wang <[email protected]> * Fix checkstyle failure Signed-off-by: Jinbo Wang <[email protected]>
1 parent f4ad19a commit 531b21a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

com.microsoft.java.debug.plugin/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<command id="vscode.java.inferLaunchCommandLength"/>
1515
<command id="vscode.java.checkProjectSettings"/>
1616
<command id="vscode.java.resolveElementAtSelection"/>
17+
<command id="vscode.java.resolveBuildFiles"/>
1718
</delegateCommandHandler>
1819
</extension>
1920
</plugin>

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugDelegateCommandHandler.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@
1111

1212
package com.microsoft.java.debug.plugin.internal;
1313

14+
import java.util.ArrayList;
1415
import java.util.List;
1516

17+
import org.eclipse.core.resources.IFile;
18+
import org.eclipse.core.resources.ResourcesPlugin;
1619
import org.eclipse.core.runtime.IProgressMonitor;
20+
import org.eclipse.jdt.core.IJavaProject;
1721
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
22+
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
23+
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
1824

1925
import com.microsoft.java.debug.core.UsageDataStore;
2026
import com.microsoft.java.debug.core.protocol.JsonUtils;
@@ -32,6 +38,7 @@ public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler
3238
public static final String INFER_LAUNCH_COMMAND_LENGTH = "vscode.java.inferLaunchCommandLength";
3339
public static final String CHECK_PROJECT_SETTINGS = "vscode.java.checkProjectSettings";
3440
public static final String RESOLVE_ELEMENT_AT_SELECTION = "vscode.java.resolveElementAtSelection";
41+
public static final String RESOLVE_BUILD_FILES = "vscode.java.resolveBuildFiles";
3542

3643
@Override
3744
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor progress) throws Exception {
@@ -63,11 +70,31 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
6370
return ProjectSettingsChecker.check(JsonUtils.fromJson((String) arguments.get(0), ProjectSettingsChecker.ProjectSettingsCheckerParams.class));
6471
case RESOLVE_ELEMENT_AT_SELECTION:
6572
return ResolveElementHandler.resolveElementAtSelection(arguments, progress);
73+
case RESOLVE_BUILD_FILES:
74+
return getBuildFiles();
6675
default:
6776
break;
6877
}
6978

7079
throw new UnsupportedOperationException(String.format("Java debug plugin doesn't support the command '%s'.", commandId));
7180
}
7281

82+
private List<String> getBuildFiles() {
83+
List<String> result = new ArrayList<>();
84+
List<IJavaProject> javaProjects = JdtUtils.listJavaProjects(ResourcesPlugin.getWorkspace().getRoot());
85+
for (IJavaProject javaProject : javaProjects) {
86+
IFile buildFile = null;
87+
if (ProjectUtils.isMavenProject(javaProject.getProject())) {
88+
buildFile = javaProject.getProject().getFile("pom.xml");
89+
} else if (ProjectUtils.isGradleProject(javaProject.getProject())) {
90+
buildFile = javaProject.getProject().getFile("build.gradle");
91+
}
92+
93+
if (buildFile != null && buildFile.exists() && buildFile.getLocationURI() != null) {
94+
result.add(ResourceUtils.fixURI(buildFile.getLocationURI()));
95+
}
96+
}
97+
98+
return result;
99+
}
73100
}

0 commit comments

Comments
 (0)