Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support HCR for gradle build server projects
  • Loading branch information
jdneo committed Jun 3, 2024
commit 32960d613ad5d39dc7128a68395a1a311f8a46c3
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static Object compile(CompileParams params, IProgressMonitor monitor) {
}
}

if (isBspProject(mainProject) && !ProjectUtils.isGradleProject(mainProject)) {
if (JdtUtils.isBspProject(mainProject) && !ProjectUtils.isGradleProject(mainProject)) {
// Just need to trigger a build for the target project, the Gradle build server will
// handle the build dependencies for us.
try {
Expand Down Expand Up @@ -153,11 +153,6 @@ private static boolean isUnmanagedFolder(IProject project) {
&& ProjectUtils.isJavaProject(project);
}

private static boolean isBspProject(IProject project) {
return project != null && ProjectUtils.isJavaProject(project)
&& ProjectUtils.hasNature(project, "com.microsoft.gradle.bs.importer.GradleBuildServerProjectNature");
}

private static IProject getDefaultProject() {
return getWorkspaceRoot().getProject(ProjectsManager.DEFAULT_PROJECT_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
Expand All @@ -54,6 +58,7 @@
import org.eclipse.jdt.core.util.IClassFileReader;
import org.eclipse.jdt.core.util.ISourceAttribute;
import org.eclipse.jdt.internal.core.util.Util;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.JobHelpers;

import com.microsoft.java.debug.core.Configuration;
Expand Down Expand Up @@ -319,6 +324,25 @@ public void onClassRedefined(Consumer<List<String>> consumer) {

@Override
public CompletableFuture<List<String>> redefineClasses() {
try {
IProject mainProject = null;
List<IJavaProject> javaProjects = ResolveClasspathsHandler.getJavaProjectFromType(context.getMainClass());
Comment thread
jdneo marked this conversation as resolved.
Outdated
if (javaProjects.size() == 1) {
mainProject = javaProjects.get(0).getProject();
}

if (mainProject != null && JdtUtils.isBspProject(mainProject)) {
ResourcesPlugin.getWorkspace().build(
new IBuildConfiguration[]{mainProject.getActiveBuildConfig()},
IncrementalProjectBuilder.INCREMENTAL_BUILD,
false /*buildReference*/,
new NullProgressMonitor()
);
}
} catch (CoreException e) {
JavaLanguageServerPlugin.log(e);
}

JobHelpers.waitForBuildJobs(10 * 1000);
return CompletableFuture.supplyAsync(() -> {
List<String> classNames = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer;
import org.eclipse.jdt.launching.sourcelookup.containers.PackageFragmentRootSourceContainer;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;

import com.microsoft.java.debug.core.DebugException;
import com.microsoft.java.debug.core.StackFrameUtility;
Expand Down Expand Up @@ -415,4 +416,12 @@ public static boolean isSameFile(IResource resource1, IResource resource2) {

return Objects.equals(resource1.getLocation(), resource2.getLocation());
}

/**
* Check if the project is managed by Gradle Build Server
*/
public static boolean isBspProject(IProject project) {
return project != null && ProjectUtils.isJavaProject(project)
&& ProjectUtils.hasNature(project, "com.microsoft.gradle.bs.importer.GradleBuildServerProjectNature");
}
}