Skip to content

Commit

Permalink
Do not suggest to add .ijwb and others to project view. (#5168)
Browse files Browse the repository at this point in the history
* Do not suggest to add `.ijwb` and others to project view.

* fix(base): Add ignore for other jetbrains directories on bazel sync (#73)

---------

Co-authored-by: Victoria-Rose Burke <vburke@apple.com>
  • Loading branch information
dkashyn-sfdc and victoriaroseb authored Aug 7, 2023
1 parent b322d9e commit 1bec01e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> ALL_PROJECT_SUBDIRECTORIES = ImmutableMap.<String, String>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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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<File, SourceFolder> sourceFolders =
provider.initializeSourceFolders(contentEntry);
SourceFolder rootSource = sourceFolders.get(rootFile);
Expand Down

0 comments on commit 1bec01e

Please sign in to comment.