|
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,55 @@ 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 = null; |
| 765 | + if (StringUtils.isNotEmpty(this.mainProject)) { |
| 766 | + mainProject = ProjectUtils.getProject(this.mainProject); |
| 767 | + } |
| 768 | + |
| 769 | + if (mainProject == null) { |
| 770 | + try { |
| 771 | + List<IJavaProject> javaProjects = ResolveClasspathsHandler.getJavaProjectFromType(context.getMainClass()); |
| 772 | + if (javaProjects.size() == 1) { |
| 773 | + mainProject = javaProjects.get(0).getProject(); |
| 774 | + } |
| 775 | + } catch (CoreException e) { |
| 776 | + JavaLanguageServerPlugin.log(e); |
| 777 | + } |
| 778 | + } |
| 779 | + |
| 780 | + if (mainProject != null && JdtUtils.isBspProject(mainProject)) { |
| 781 | + try { |
| 782 | + ResourcesPlugin.getWorkspace().build( |
| 783 | + new IBuildConfiguration[]{mainProject.getActiveBuildConfig()}, |
| 784 | + IncrementalProjectBuilder.INCREMENTAL_BUILD, |
| 785 | + false /*buildReference*/, |
| 786 | + new NullProgressMonitor() |
| 787 | + ); |
| 788 | + } catch (CoreException e) { |
| 789 | + // TODO Auto-generated catch block |
| 790 | + e.printStackTrace(); |
| 791 | + } |
| 792 | + } |
| 793 | + } |
| 794 | + |
| 795 | + private boolean containsBspProjects() { |
| 796 | + for (IJavaProject javaProject : ProjectUtils.getJavaProjects()) { |
| 797 | + if (JdtUtils.isBspProject(javaProject.getProject())) { |
| 798 | + return true; |
| 799 | + } |
| 800 | + } |
| 801 | + return false; |
| 802 | + } |
764 | 803 | }
|
0 commit comments