1111
1212package com .microsoft .java .debug .plugin .internal ;
1313
14+ import java .util .ArrayList ;
1415import java .util .List ;
1516
17+ import org .eclipse .core .resources .IFile ;
18+ import org .eclipse .core .resources .ResourcesPlugin ;
1619import org .eclipse .core .runtime .IProgressMonitor ;
20+ import org .eclipse .jdt .core .IJavaProject ;
1721import 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
1925import com .microsoft .java .debug .core .UsageDataStore ;
2026import 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