|
34 | 34 | import java.util.logging.Level; |
35 | 35 | import java.util.logging.Logger; |
36 | 36 |
|
| 37 | +import org.apache.commons.lang3.StringUtils; |
37 | 38 | import org.eclipse.core.resources.IBuildConfiguration; |
38 | 39 | import org.eclipse.core.resources.IFile; |
39 | 40 | import org.eclipse.core.resources.IMarker; |
|
60 | 61 | import org.eclipse.jdt.internal.core.util.Util; |
61 | 62 | import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; |
62 | 63 | import org.eclipse.jdt.ls.core.internal.JobHelpers; |
| 64 | +import org.eclipse.jdt.ls.core.internal.ProjectUtils; |
63 | 65 |
|
64 | 66 | import com.microsoft.java.debug.core.Configuration; |
65 | 67 | import com.microsoft.java.debug.core.DebugException; |
|
68 | 70 | import com.microsoft.java.debug.core.IDebugSession; |
69 | 71 | import com.microsoft.java.debug.core.StackFrameUtility; |
70 | 72 | import com.microsoft.java.debug.core.adapter.AdapterUtils; |
| 73 | +import com.microsoft.java.debug.core.adapter.Constants; |
71 | 74 | import com.microsoft.java.debug.core.adapter.ErrorCode; |
72 | 75 | import com.microsoft.java.debug.core.adapter.HotCodeReplaceEvent; |
73 | 76 | import com.microsoft.java.debug.core.adapter.IDebugAdapterContext; |
@@ -109,6 +112,8 @@ public class JavaHotCodeReplaceProvider implements IHotCodeReplaceProvider, IRes |
109 | 112 |
|
110 | 113 | private List<String> deltaClassNames = new ArrayList<>(); |
111 | 114 |
|
| 115 | + private String mainProject = ""; |
| 116 | + |
112 | 117 | /** |
113 | 118 | * Visitor for resource deltas. |
114 | 119 | */ |
@@ -274,6 +279,7 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> options |
274 | 279 | } |
275 | 280 | this.context = context; |
276 | 281 | currentDebugSession = context.getDebugSession(); |
| 282 | + this.mainProject = ((String) options.get(Constants.PROJECT_NAME)); |
277 | 283 | } |
278 | 284 |
|
279 | 285 | @Override |
@@ -324,25 +330,7 @@ public void onClassRedefined(Consumer<List<String>> consumer) { |
324 | 330 |
|
325 | 331 | @Override |
326 | 332 | public CompletableFuture<List<String>> redefineClasses() { |
327 | | - try { |
328 | | - IProject mainProject = null; |
329 | | - List<IJavaProject> javaProjects = ResolveClasspathsHandler.getJavaProjectFromType(context.getMainClass()); |
330 | | - if (javaProjects.size() == 1) { |
331 | | - mainProject = javaProjects.get(0).getProject(); |
332 | | - } |
333 | | - |
334 | | - if (mainProject != null && JdtUtils.isBspProject(mainProject)) { |
335 | | - ResourcesPlugin.getWorkspace().build( |
336 | | - new IBuildConfiguration[]{mainProject.getActiveBuildConfig()}, |
337 | | - IncrementalProjectBuilder.INCREMENTAL_BUILD, |
338 | | - false /*buildReference*/, |
339 | | - new NullProgressMonitor() |
340 | | - ); |
341 | | - } |
342 | | - } catch (CoreException e) { |
343 | | - JavaLanguageServerPlugin.log(e); |
344 | | - } |
345 | | - |
| 333 | + triggerBuildForBspProject(); |
346 | 334 | JobHelpers.waitForBuildJobs(10 * 1000); |
347 | 335 | return CompletableFuture.supplyAsync(() -> { |
348 | 336 | List<String> classNames = new ArrayList<>(); |
@@ -761,4 +749,39 @@ private List<StackFrame> getStackFrames(ThreadReference thread, boolean refresh) |
761 | 749 | } |
762 | 750 | }); |
763 | 751 | } |
| 752 | + |
| 753 | + /** |
| 754 | + * Trigger build separately if the main project is a BSP project. |
| 755 | + * This is because auto build for BSP project will not update the class files to disk. |
| 756 | + */ |
| 757 | + private void triggerBuildForBspProject() { |
| 758 | + // check if the workspace contains BSP project first. This is for performance consideration. |
| 759 | + // Due to that getJavaProjectFromType() is a heavy operation. |
| 760 | + if (!containsBspProjects()) { |
| 761 | + return; |
| 762 | + } |
| 763 | + |
| 764 | + IProject mainProject = JdtUtils.getMainProject(this.mainProject, context.getMainClass()); |
| 765 | + if (mainProject != null && JdtUtils.isBspProject(mainProject)) { |
| 766 | + try { |
| 767 | + ResourcesPlugin.getWorkspace().build( |
| 768 | + new IBuildConfiguration[]{mainProject.getActiveBuildConfig()}, |
| 769 | + IncrementalProjectBuilder.INCREMENTAL_BUILD, |
| 770 | + false /*buildReference*/, |
| 771 | + new NullProgressMonitor() |
| 772 | + ); |
| 773 | + } catch (CoreException e) { |
| 774 | + // ignore compilation errors |
| 775 | + } |
| 776 | + } |
| 777 | + } |
| 778 | + |
| 779 | + private boolean containsBspProjects() { |
| 780 | + for (IJavaProject javaProject : ProjectUtils.getJavaProjects()) { |
| 781 | + if (JdtUtils.isBspProject(javaProject.getProject())) { |
| 782 | + return true; |
| 783 | + } |
| 784 | + } |
| 785 | + return false; |
| 786 | + } |
764 | 787 | } |
0 commit comments