-
Notifications
You must be signed in to change notification settings - Fork 304
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
Changes from 5 commits
a23d29a
54a1ff2
9215b8a
1fabf5d
ae15030
841a9aa
f1377b5
b174bc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.google.idea.blaze.base.projectview.section.sections; | ||
|
||
import com.google.idea.blaze.base.model.primitives.WorkspacePath; | ||
import com.google.idea.blaze.base.projectview.parser.ParseContext; | ||
import com.google.idea.blaze.base.projectview.parser.ProjectViewParser; | ||
import com.google.idea.blaze.base.projectview.section.ScalarSection; | ||
import com.google.idea.blaze.base.projectview.section.SectionKey; | ||
import com.google.idea.blaze.base.projectview.section.SectionParser; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class TryImportSection extends ImportSection { | ||
|
||
public static final SectionKey<WorkspacePath, ScalarSection<WorkspacePath>> KEY = | ||
SectionKey.of("try-import"); | ||
|
||
public static final SectionParser PARSER = new TryImportSectionParser(); | ||
|
||
private static class TryImportSectionParser extends ImportSectionParser { | ||
|
||
public TryImportSectionParser() { | ||
super(KEY, ' '); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected WorkspacePath parseItem( | ||
ProjectViewParser parser, ParseContext parseContext, String text) { | ||
return parseItem(parser, parseContext, text, false); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
import com.google.idea.blaze.base.projectview.section.sections.ImportSection; | ||
import com.google.idea.blaze.base.projectview.section.sections.Sections; | ||
import com.google.idea.blaze.base.projectview.section.sections.TargetSection; | ||
import com.google.idea.blaze.base.projectview.section.sections.TryImportSection; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.base.scope.OutputSink.Propagation; | ||
import com.google.idea.blaze.base.scope.Scope; | ||
|
@@ -599,6 +600,9 @@ public void updateBuilder(BlazeNewProjectBuilder builder) { | |
.add( | ||
ScalarSection.builder(ImportSection.KEY) | ||
.set(selectProjectViewOption.getSharedProjectView())) | ||
.add( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this needed? It results in having both import and try_import sections in the generated local projectview file even with the flag disabled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is ok to use both Could you please share more context for your inquiry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know why it is needed to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mai93 there might be "mandatory" and "optional" imports in any project view. One example of optional would be
(let's assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I'm still not sure what the effect of having something like:
will this provide a different result from only
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is rather for
That can result in:
Optional imports will allow engineers to have pre-defined custom import files both present or missing. Now it is possible for some of the users to benefit from custom contents while other users not affected even if they have no local customizations. For both groups of users the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so there is no additional value for having:
right? If so, then the change in this line can be reverted because it adds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
ScalarSection.builder(TryImportSection.KEY) | ||
.set(selectProjectViewOption.getSharedProjectView())) | ||
.build(); | ||
projectViewSet = | ||
ProjectViewSet.builder() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import com.google.idea.blaze.base.projectview.section.sections.TestSourceSection; | ||
import com.google.idea.blaze.base.projectview.section.sections.TextBlock; | ||
import com.google.idea.blaze.base.projectview.section.sections.TextBlockSection; | ||
import com.google.idea.blaze.base.projectview.section.sections.TryImportSection; | ||
import com.google.idea.blaze.base.projectview.section.sections.WorkspaceTypeSection; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.base.scope.ErrorCollector; | ||
|
@@ -51,6 +52,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; | ||
|
@@ -190,6 +194,9 @@ public void testPrint() { | |
.add( | ||
ScalarSection.builder(ImportSection.KEY) | ||
.set(new WorkspacePath("some/file.blazeproject"))) | ||
.add( | ||
ScalarSection.builder(TryImportSection.KEY) | ||
.set(new WorkspacePath("some/file.blazeproject.optional"))) | ||
.build(); | ||
String text = ProjectViewParser.projectViewToString(projectView); | ||
assertThat(text) | ||
|
@@ -202,7 +209,8 @@ public void testPrint() { | |
"targets:", | ||
" //java/com/google:one", | ||
" //java/com/google:two", | ||
"import some/file.blazeproject")); | ||
"import some/file.blazeproject", | ||
"try-import some/file.blazeproject.optional")); | ||
} | ||
|
||
@Test | ||
|
@@ -303,11 +311,26 @@ public void testCanParseWithMissingCarriageReturnAtEndOfSection() { | |
|
||
@Test | ||
public void testImportMissingFileResultsInIssue() { | ||
Registry.get("bazel.projectview.optional.imports").setValue(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was unable to make it work with |
||
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"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,10 @@ public void assertHasErrors() { | |
assertThat(issues.stream().anyMatch(i -> i.getCategory() == Category.ERROR)).isTrue(); | ||
} | ||
|
||
public void assertHasNoErrors() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure whether this is a good idea so can redo if someone have strong opinions against this way