diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/BazelCoreSharedContstants.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/BazelCoreSharedContstants.java index 29c2572a..b11b918a 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/BazelCoreSharedContstants.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/BazelCoreSharedContstants.java @@ -26,15 +26,18 @@ public interface BazelCoreSharedContstants { /** the Bazel classpath container ID */ String CLASSPATH_CONTAINER_ID = "com.salesforce.bazel.eclipse.BAZEL_CONTAINER"; + /** {@code REPO.bazel} */ + String FILE_NAME_REPO_BAZEL = "REPO.bazel"; + + /** {@code MODULE.bazel} */ + String FILE_NAME_MODULE_BAZEL = "MODULE.bazel"; + /** {@code WORKSPACE.bazel} */ String FILE_NAME_WORKSPACE_BAZEL = "WORKSPACE.bazel"; /** {@code WORKSPACE} */ String FILE_NAME_WORKSPACE = "WORKSPACE"; - /** {@code WORKSPACE.bzlmod} */ - String FILE_NAME_WORKSPACE_BZLMOD = "WORKSPACE.bzlmod"; - /** {@code BUILD.bazel} */ String FILE_NAME_BUILD_BAZEL = "BUILD.bazel"; diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspace.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspace.java index d77c1516..5c23e8a9 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspace.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/BazelWorkspace.java @@ -13,11 +13,10 @@ */ package com.salesforce.bazel.eclipse.core.model; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_BUILD; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_BUILD_BAZEL; +import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_MODULE_BAZEL; +import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_REPO_BAZEL; import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE; import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BAZEL; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BZLMOD; import static com.salesforce.bazel.eclipse.core.model.BazelPackageInfo.queryForTargets; import static java.lang.String.format; import static java.nio.file.Files.isDirectory; @@ -62,8 +61,24 @@ public final class BazelWorkspace extends BazelElementWORKSPACE.bazel, WORKSPACE or WORKSPACE.bzlmod - * file in a directory. + * List of files defining the boundary of a workspace as defined in Bazel's + * workspace_layout.cc + *

+ * Workspace boundary files are: + *

+ *

+ */ + public static final List WORKSPACE_BOUNDARY_FILES = + List.of(FILE_NAME_MODULE_BAZEL, FILE_NAME_REPO_BAZEL, FILE_NAME_WORKSPACE_BAZEL, FILE_NAME_WORKSPACE); + + /** + * Utility function to find a {@link #WORKSPACE_BOUNDARY_FILES workspace boundary file} in a directory. *

* This method is used by {@link BazelWorkspace#exists()} to determine whether a workspace exists. *

@@ -71,14 +86,11 @@ public final class BazelWorkspace extends BazelElementnull if none exist) - * @see #isWorkspaceFileName(String) + * @see #isWorkspaceBoundaryFileName(String) */ public static Path findWorkspaceFile(Path path) { - for (String workspaceFile : List.of( // - FILE_NAME_WORKSPACE_BAZEL, // prefer WORKSPACE.bazel - FILE_NAME_WORKSPACE, // then WORKSPACE - FILE_NAME_WORKSPACE_BZLMOD /* bzlmod is last */)) { - var workspaceFilePath = path.resolve(workspaceFile); + for (String workspaceBoundaryFile : WORKSPACE_BOUNDARY_FILES) { + var workspaceFilePath = path.resolve(workspaceBoundaryFile); if (isRegularFile(workspaceFilePath)) { return workspaceFilePath; } @@ -87,8 +99,16 @@ public static Path findWorkspaceFile(Path path) { } /** - * Utility function to check whether a given file name is WORKSPACE.bazel, WORKSPACE or - * WORKSPACE.bzlmod. + * Utility function to check whether a given file name is workspace boundary file name. + *

+ * Workspace boundary files are: + *

    + *
  • MODULE.bazel
  • + *
  • REPO.bazel
  • + *
  • WORKSPACE.bazel
  • + *
  • WORKSPACE
  • + *
+ *

* * @param fileName * the file name to check @@ -96,9 +116,9 @@ public static Path findWorkspaceFile(Path path) { * WORKSPACE.bzlmod, false otherwise * @see #findWorkspaceFile(Path) */ - public static boolean isWorkspaceFileName(String fileName) { - for (String packageFile : List.of(FILE_NAME_BUILD_BAZEL, FILE_NAME_BUILD)) { - if (packageFile.equals(fileName)) { + public static boolean isWorkspaceBoundaryFileName(String fileName) { + for (String workspaceBoundaryFile : WORKSPACE_BOUNDARY_FILES) { + if (workspaceBoundaryFile.equals(fileName)) { return true; } } diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/ResourceChangeProcessor.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/ResourceChangeProcessor.java index ddf2c41e..a77aba82 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/ResourceChangeProcessor.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/ResourceChangeProcessor.java @@ -24,11 +24,8 @@ package com.salesforce.bazel.eclipse.core.model; import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.BAZEL_NATURE_ID; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_BUILD; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_BUILD_BAZEL; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BAZEL; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BZLMOD; +import static com.salesforce.bazel.eclipse.core.model.BazelPackage.isBuildFileName; +import static com.salesforce.bazel.eclipse.core.model.BazelWorkspace.isWorkspaceBoundaryFileName; import java.util.HashSet; import java.util.Set; @@ -44,8 +41,6 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import com.salesforce.bazel.eclipse.core.classpath.InitializeOrRefreshClasspathJob; - /** * Global change listener for Eclipse Workspaces used by the Bazel model. */ @@ -69,13 +64,14 @@ private void checkProjectsAndClasspathChanges(IResourceDelta delta) { // if we have some, we need to refresh classpaths // but we do this asynchronously and *only* when the workspace is in auto-build mode - if ((affectedProjects.size() > 0) && isAutoBuilding()) { - var classpathJob = new InitializeOrRefreshClasspathJob( - affectedProjects.toArray(new IProject[affectedProjects.size()]), - modelManager.getClasspathManager(), - true /* force refresh */); - classpathJob.schedule(); - } + // TODO: disabled because this behavior is annoying/too disruptive (we need a better thing, potentially delay, configurable, notification only) + // if ((affectedProjects.size() > 0) && isAutoBuilding()) { + // var classpathJob = new InitializeOrRefreshClasspathJob( + // affectedProjects.toArray(new IProject[affectedProjects.size()]), + // modelManager.getClasspathManager(), + // true /* force refresh */); + // classpathJob.schedule(); + // } } private void collectProjectsAffectedByPossibleClasspathChange(IResourceDelta delta, @@ -127,9 +123,7 @@ private void collectProjectsAffectedByPossibleClasspathChange(IResourceDelta del /* check BUILD files change */ var file = (IFile) resource; var fileName = file.getName(); - if (fileName.equals(FILE_NAME_BUILD_BAZEL) || fileName.equals(FILE_NAME_BUILD) - || fileName.equals(FILE_NAME_WORKSPACE_BAZEL) || fileName.equals(FILE_NAME_WORKSPACE) - || fileName.equals(FILE_NAME_WORKSPACE_BZLMOD)) { + if (isBuildFileName(fileName) || isWorkspaceBoundaryFileName(fileName)) { affectedProjectsWithClasspathChange.add(file.getProject()); } var fileExtension = file.getFileExtension(); diff --git a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelBuildSupport.java b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelBuildSupport.java index 67870979..092326f5 100644 --- a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelBuildSupport.java +++ b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelBuildSupport.java @@ -81,12 +81,12 @@ public List getWatchPatterns() { public boolean isBuildFile(IResource resource) { return (resource != null) && (resource.getProject() != null) && (resource.getType() == IResource.FILE) && (BazelPackage.isBuildFileName(resource.getName()) - || BazelWorkspace.isWorkspaceFileName(resource.getName())); + || BazelWorkspace.isWorkspaceBoundaryFileName(resource.getName())); } @Override public boolean isBuildLikeFileName(String fileName) { - return BazelPackage.isBuildFileName(fileName) || BazelWorkspace.isWorkspaceFileName(fileName); + return BazelPackage.isBuildFileName(fileName) || BazelWorkspace.isWorkspaceBoundaryFileName(fileName); } @Override diff --git a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelFileDetector.java b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelFileDetector.java index 4563f6ad..b6271897 100644 --- a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelFileDetector.java +++ b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelFileDetector.java @@ -70,9 +70,9 @@ public class BazelFileDetector { * @param fileNames * the names of the file to search */ - public BazelFileDetector(Path rootDir, String... fileNames) { + public BazelFileDetector(Path rootDir, List fileNames) { this.rootDir = rootDir; - this.fileNames = fileNames == null ? new ArrayList<>() : Arrays.asList(fileNames); + this.fileNames = fileNames; directories = new ArrayList<>(); addExclusions(METADATA_FOLDER); var javaImportExclusions = diff --git a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelProjectImporter.java b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelProjectImporter.java index 834505ef..773b498b 100644 --- a/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelProjectImporter.java +++ b/bundles/com.salesforce.bazel.eclipse.jdtls/src/main/java/com/salesforce/bazel/eclipse/jdtls/managers/BazelProjectImporter.java @@ -15,9 +15,7 @@ package com.salesforce.bazel.eclipse.jdtls.managers; import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.BAZEL_NATURE_ID; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BAZEL; -import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BZLMOD; +import static com.salesforce.bazel.eclipse.core.model.BazelWorkspace.WORKSPACE_BOUNDARY_FILES; import static java.lang.String.format; import static java.nio.file.Files.isRegularFile; import static java.nio.file.Files.writeString; @@ -26,7 +24,6 @@ import java.nio.file.Path; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -62,7 +59,7 @@ public boolean applies(Collection projectConfigurations, IProgressMonitor throws OperationCanceledException, CoreException { var configurationDirs = findProjectPathByConfigurationName( projectConfigurations, - List.of(FILE_NAME_WORKSPACE_BAZEL, FILE_NAME_WORKSPACE, FILE_NAME_WORKSPACE_BZLMOD), + WORKSPACE_BOUNDARY_FILES, false /*includeNested*/); if ((configurationDirs == null) || configurationDirs.isEmpty()) { return false; @@ -86,11 +83,8 @@ public boolean applies(Collection projectConfigurations, IProgressMonitor @Override public boolean applies(IProgressMonitor monitor) throws OperationCanceledException, CoreException { if (directories == null) { - var bazelDetector = new BazelFileDetector( - rootFolder.toPath(), - FILE_NAME_WORKSPACE_BAZEL, - FILE_NAME_WORKSPACE, - FILE_NAME_WORKSPACE_BZLMOD).includeNested(false); + var bazelDetector = + new BazelFileDetector(rootFolder.toPath(), WORKSPACE_BOUNDARY_FILES).includeNested(false); // exclude all existing non Bazel projects for (IProject project : ProjectUtils.getAllProjects()) {