Skip to content

Commit

Permalink
Only import when there is no workspace project yet
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Nov 16, 2023
1 parent f2b0ac3 commit ca69264
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.stream.Collectors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -38,6 +39,7 @@
import org.eclipse.jdt.ls.core.internal.ProjectUtils;

import com.salesforce.bazel.eclipse.core.BazelCore;
import com.salesforce.bazel.eclipse.core.model.BazelProject;
import com.salesforce.bazel.eclipse.core.model.BazelWorkspace;
import com.salesforce.bazel.eclipse.core.setup.DefaultProjectViewFileInitializer;
import com.salesforce.bazel.eclipse.core.setup.ImportBazelWorkspaceJob;
Expand Down Expand Up @@ -124,8 +126,29 @@ public void importToWorkspace(IProgressMonitor progress) throws OperationCancele

JavaLanguageServerPlugin.logInfo("Importing Bazel workspace(s)");
var monitor = SubMonitor.convert(progress, "Importing Bazel workspace(s)", directories.size() * 100);
var root = ResourcesPlugin.getWorkspace().getRoot();

for (Path directory : directories) {
var workspaceLocation = IPath.fromPath(directory);

// if there is a workspace project we do nothing because it is imported already
var workspaceContainer = root.getContainerForLocation(workspaceLocation);
if (workspaceContainer != null) {
var existingWorkspaceProject = workspaceContainer.getProject();
if (BazelProject.isBazelProject(existingWorkspaceProject)) {
var bazelProject = BazelCore.create(existingWorkspaceProject);
if (bazelProject.isWorkspaceProject()
&& bazelProject.getBazelWorkspace().getLocation().equals(workspaceLocation)) {
continue;
}
}
JavaLanguageServerPlugin.logError(
format(
"Found an exising project for workspace '%s', which is not a Bazel workspace (%s). Please consider resetting the workspace if the import fails.",
workspaceLocation,
workspaceContainer));
}

var workspace = BazelCore.createWorkspace(new org.eclipse.core.runtime.Path(directory.toString()));

// find or create project view
Expand Down

0 comments on commit ca69264

Please sign in to comment.