Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to have non-existent import entries in projectview that pointing to … #5689

Merged
merged 8 commits into from
Dec 11, 2023
1 change: 1 addition & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
<notificationGroup displayType="STICKY_BALLOON" id="QuerySyncPromo" />
<notificationGroup displayType="BALLOON" id="QuerySyncBuild" />
<registryKey defaultValue="false" description="Disable auto import of bazel projects" key="bazel.auto.import.disabled"/>
<registryKey defaultValue="false" description="Allow to have optional imports in project view" key="bazel.projectview.optional.imports"/>
<registryKey
key="bazel.sync.resolve.virtual.includes"
description="Apply heuristics to detect correct location of headers which are accessed from _virtual_includes during build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.google.idea.blaze.base.projectview.section.ScalarSectionParser;
import com.google.idea.blaze.base.projectview.section.SectionKey;
import com.google.idea.blaze.base.projectview.section.SectionParser;
import com.google.idea.blaze.base.scope.output.IssueOutput;
import com.intellij.openapi.util.registry.Registry;

import java.io.File;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -50,7 +53,14 @@ protected WorkspacePath parseItem(
if (parser.isRecursive()) {
File projectViewFile = parseContext.getWorkspacePathResolver().resolveToFile(workspacePath);
if (projectViewFile != null) {
parser.parseProjectView(projectViewFile);
boolean projectViewImportsMandatory = !Registry.is("bazel.projectview.optional.imports");
if (projectViewFile.exists() || projectViewImportsMandatory) {
dkashyn-sfdc marked this conversation as resolved.
Show resolved Hide resolved
parser.parseProjectView(projectViewFile);
} else {
IssueOutput.warn(
String.format("Could not load project view file: '%s'", projectViewFile.getPath()))
.submit(parseContext.getContext());
}
} else {
parseContext.addError("Could not resolve import: " + workspacePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import java.util.Collection;
import java.util.Map;
import javax.annotation.Nullable;

import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.registry.RegistryValue;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -303,11 +306,26 @@ public void testCanParseWithMissingCarriageReturnAtEndOfSection() {

@Test
public void testImportMissingFileResultsInIssue() {
Registry.get("bazel.projectview.optional.imports").setValue(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unable to make it work with Registry.is('bla', false) for tests.

projectViewStorageManager.add(".blazeproject", "import parent.blazeproject");
projectViewParser.parseProjectView(new File(".blazeproject"));
errorCollector.assertIssues("Could not load project view file: '/parent.blazeproject'");
}

@Test
public void testImportMissingFileResultsInWarning() {
RegistryValue importsTreatmentRegistryValue = Registry.get("bazel.projectview.optional.imports");
try {
importsTreatmentRegistryValue.setValue(true);
projectViewStorageManager.add(".blazeproject", "import parent.blazeproject");
projectViewParser.parseProjectView(new File(".blazeproject"));
errorCollector.assertIssues("Could not load project view file: '/parent.blazeproject'");
errorCollector.assertHasNoErrors();
} finally {
importsTreatmentRegistryValue.setValue(false);
}
}

@Test
public void testMissingSectionResultsInIssue() {
projectViewStorageManager.add(".blazeproject", "nosuchsection:", " java/com/google");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void assertHasErrors() {
assertThat(issues.stream().anyMatch(i -> i.getCategory() == Category.ERROR)).isTrue();
}

public void assertHasNoErrors() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in some cases there are issues but those are not errors.

assertThat(issues.stream().anyMatch(i -> i.getCategory() == Category.ERROR)).isFalse();
}

public void assertIssues(String... requiredMessages) {
List<String> messages = Lists.newArrayList();
for (IssueOutput issue : issues) {
Expand Down
Loading