diff --git a/base/src/com/google/idea/blaze/base/dependencies/ExternalFileProjectManagementHelper.java b/base/src/com/google/idea/blaze/base/dependencies/ExternalFileProjectManagementHelper.java index 33f30632047..67c143d944b 100644 --- a/base/src/com/google/idea/blaze/base/dependencies/ExternalFileProjectManagementHelper.java +++ b/base/src/com/google/idea/blaze/base/dependencies/ExternalFileProjectManagementHelper.java @@ -33,6 +33,7 @@ import com.google.idea.blaze.base.sync.SyncListener; import com.google.idea.blaze.base.sync.SyncMode; import com.google.idea.blaze.base.sync.SyncResult; +import com.google.idea.blaze.base.sync.data.BlazeDataStorage; import com.google.idea.blaze.base.sync.projectview.LanguageSupport; import com.google.idea.common.experiments.BoolExperiment; import com.intellij.ide.actions.ShowSettingsUtilImpl; @@ -124,7 +125,13 @@ public EditorNotificationPanel createNotificationPanel(VirtualFile vf, FileEdito } boolean inProjectDirectories = AddSourceToProjectHelper.sourceInProjectDirectories(context); boolean alreadyBuilt = AddSourceToProjectHelper.sourceCoveredByProjectViewTargets(context); - if (alreadyBuilt && inProjectDirectories) { + // We do not want to add `/.ijwb` (neither `.clwb` or `.aswb`) to the project view since it has no BUILD files + // This helps to avoid `ERROR: Skipping '//.ijwb/...:all': no targets found beneath '.ijwb'` + boolean inProjectDataDir = + BlazeDataStorage.ALL_PROJECT_SUBDIRECTORIES.values() + .stream() + .anyMatch(dataDirName -> context.file.getPath().contains(String.format("/%s/", dataDirName))); + if (inProjectDataDir || (alreadyBuilt && inProjectDirectories)) { return null; } diff --git a/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java b/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java index a4c6d0ef11b..f8d803c46b1 100644 --- a/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java +++ b/base/src/com/google/idea/blaze/base/sync/data/BlazeDataStorage.java @@ -16,6 +16,7 @@ package com.google.idea.blaze.base.sync.data; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; import com.google.idea.blaze.base.logging.LoggedDirectoryProvider; import com.google.idea.blaze.base.settings.Blaze; import com.google.idea.blaze.base.settings.BlazeImportSettings; @@ -31,20 +32,19 @@ public class BlazeDataStorage { public static final String WORKSPACE_MODULE_NAME = ".workspace"; public static final String BLAZE_DATA_SUBDIRECTORY = ".blaze"; + public static final ImmutableMap ALL_PROJECT_SUBDIRECTORIES = ImmutableMap.builder() + .put("IJ", ".ijwb") + .put("CL", ".clwb") + .put("AI", ".aswb") + .build(); public static final String PROJECT_DATA_SUBDIRECTORY = getProjectDataSubdirectory(); + private static String getProjectDataSubdirectory() { if (ApplicationManager.getApplication().isUnitTestMode()) { return ".ijwb"; } - switch (ApplicationInfo.getInstance().getBuild().getProductCode()) { - case "CL": // CLion - return ".clwb"; - case "AI": // Android Studio - return ".aswb"; - default: - return ".ijwb"; - } + return ALL_PROJECT_SUBDIRECTORIES.getOrDefault(ApplicationInfo.getInstance().getBuild().getProductCode(), ".ijwb"); } public static File getProjectDataDir(BlazeImportSettings importSettings) { diff --git a/base/src/com/google/idea/blaze/base/sync/projectstructure/ContentEntryEditor.java b/base/src/com/google/idea/blaze/base/sync/projectstructure/ContentEntryEditor.java index faa7e4dcbf3..8b4a25d51e4 100644 --- a/base/src/com/google/idea/blaze/base/sync/projectstructure/ContentEntryEditor.java +++ b/base/src/com/google/idea/blaze/base/sync/projectstructure/ContentEntryEditor.java @@ -24,14 +24,17 @@ import com.google.idea.blaze.base.projectview.ProjectViewSet; import com.google.idea.blaze.base.settings.Blaze; import com.google.idea.blaze.base.sync.SourceFolderProvider; +import com.google.idea.blaze.base.sync.data.BlazeDataStorage; import com.google.idea.blaze.base.sync.projectview.ImportRoots; import com.google.idea.blaze.base.sync.projectview.SourceTestConfig; +import com.google.idea.blaze.base.sync.projectview.WorkspaceFileFinder; import com.google.idea.blaze.base.util.UrlUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.SourceFolder; import java.io.File; +import java.io.FilenameFilter; import java.util.Collection; import java.util.Map; import javax.annotation.Nullable; @@ -57,6 +60,7 @@ public static void createContentEntries( SourceTestConfig testConfig = new SourceTestConfig(projectViewSet); SourceFolderProvider provider = SourceFolderProvider.getSourceFolderProvider(blazeProjectData); + WorkspaceFileFinder finder = WorkspaceFileFinder.Provider.getInstance(project).getWorkspaceFileFinder(); for (WorkspacePath rootDirectory : rootDirectories) { File rootFile = workspaceRoot.fileForPath(rootDirectory); @@ -68,6 +72,16 @@ public static void createContentEntries( contentEntry.addExcludeFolder(UrlUtil.fileToIdeaUrl(excludeFolder)); } + File directory = new File(workspaceRoot.toString()); + File[] files = directory + .listFiles((dir, name) -> + finder != null && finder.isInProject(dir) && BlazeDataStorage.ALL_PROJECT_SUBDIRECTORIES.containsValue(name)); + if (files != null) { + for (File file : files) { + contentEntry.addExcludeFolder(UrlUtil.fileToIdeaUrl(file)); + } + } + ImmutableMap sourceFolders = provider.initializeSourceFolders(contentEntry); SourceFolder rootSource = sourceFolders.get(rootFile);