Skip to content

Commit 05bd09d

Browse files
committed
Address comments
1 parent b09c23b commit 05bd09d

File tree

1 file changed

+58
-19
lines changed

1 file changed

+58
-19
lines changed

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

+58-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.logging.Level;
3535
import java.util.logging.Logger;
3636

37+
import org.apache.commons.lang3.StringUtils;
3738
import org.eclipse.core.resources.IBuildConfiguration;
3839
import org.eclipse.core.resources.IFile;
3940
import org.eclipse.core.resources.IMarker;
@@ -60,6 +61,7 @@
6061
import org.eclipse.jdt.internal.core.util.Util;
6162
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
6263
import org.eclipse.jdt.ls.core.internal.JobHelpers;
64+
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
6365

6466
import com.microsoft.java.debug.core.Configuration;
6567
import com.microsoft.java.debug.core.DebugException;
@@ -68,6 +70,7 @@
6870
import com.microsoft.java.debug.core.IDebugSession;
6971
import com.microsoft.java.debug.core.StackFrameUtility;
7072
import com.microsoft.java.debug.core.adapter.AdapterUtils;
73+
import com.microsoft.java.debug.core.adapter.Constants;
7174
import com.microsoft.java.debug.core.adapter.ErrorCode;
7275
import com.microsoft.java.debug.core.adapter.HotCodeReplaceEvent;
7376
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
@@ -109,6 +112,8 @@ public class JavaHotCodeReplaceProvider implements IHotCodeReplaceProvider, IRes
109112

110113
private List<String> deltaClassNames = new ArrayList<>();
111114

115+
private String mainProject = "";
116+
112117
/**
113118
* Visitor for resource deltas.
114119
*/
@@ -274,6 +279,7 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> options
274279
}
275280
this.context = context;
276281
currentDebugSession = context.getDebugSession();
282+
this.mainProject = ((String) options.get(Constants.PROJECT_NAME));
277283
}
278284

279285
@Override
@@ -324,25 +330,7 @@ public void onClassRedefined(Consumer<List<String>> consumer) {
324330

325331
@Override
326332
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();
346334
JobHelpers.waitForBuildJobs(10 * 1000);
347335
return CompletableFuture.supplyAsync(() -> {
348336
List<String> classNames = new ArrayList<>();
@@ -761,4 +749,55 @@ private List<StackFrame> getStackFrames(ThreadReference thread, boolean refresh)
761749
}
762750
});
763751
}
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+
}
764803
}

0 commit comments

Comments
 (0)