Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public ProjectViewParser(BlazeContext context, WorkspacePathResolver workspacePa
}

public void parseProjectView(File projectViewFile) {
parseProjectView(projectViewFile, Sections.getParsers());
}

public void parseProjectView(File projectViewFile, List<SectionParser> sectionParsers) {
if (!encounteredProjectViewFiles.add(projectViewFile)) {
return;
}
Expand All @@ -64,22 +68,25 @@ public void parseProjectView(File projectViewFile) {
return;
}
parseProjectView(
new ParseContext(context, workspacePathResolver, projectViewFile, projectViewText));
new ParseContext(context, workspacePathResolver, projectViewFile, projectViewText), sectionParsers);
}

public void parseProjectView(String text) {
public void parseProjectView(String text, List<SectionParser> sectionParsers) {
if (text.isEmpty()) {
ProjectView projectView = new ProjectView(ImmutableList.of());
projectViewFiles.add(new ProjectViewSet.ProjectViewFile(projectView, null));
return;
}
parseProjectView(new ParseContext(context, workspacePathResolver, null, text));
parseProjectView(new ParseContext(context, workspacePathResolver, null, text), sectionParsers);
}

private void parseProjectView(ParseContext parseContext) {
public void parseProjectView(String text) {
parseProjectView(text, Sections.getParsers());
}

private void parseProjectView(ParseContext parseContext, List<SectionParser> sectionParsers) {
ImmutableList.Builder<Section<?>> sections = ImmutableList.builder();

List<SectionParser> sectionParsers = Sections.getParsers();
while (!parseContext.atEnd()) {
Section<?> section = null;
for (SectionParser sectionParser : sectionParsers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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.UseQuerySyncSection;
import com.google.idea.blaze.base.projectview.section.sections.TryImportSection;
import com.google.idea.blaze.base.projectview.section.sections.ViewProjectRootSection;
import com.google.idea.blaze.base.projectview.section.sections.WorkspaceTypeSection;
Expand Down Expand Up @@ -519,6 +520,21 @@ public void testCommentsAndWhitespacePreserved() throws Exception {
assertThat(outputString).isEqualTo(text);
}

@Test
public void testParsersSubset() throws Exception {
projectViewStorageManager.add(
".blazeproject",
"workspace_type: c",
"use_query_sync: compatibility");
projectViewParser.parseProjectView(new File(".blazeproject"), List.of(WorkspaceTypeSection.PARSER));
// Parser errors are expected from the parsers not included in the parsers list

ProjectViewSet projectViewSet = projectViewParser.getResult();
assertThat(projectViewSet.getScalarValue(WorkspaceTypeSection.KEY)).hasValue(WorkspaceType.C);
// Value will not be parsed for the parsers not in the provided list
assertThat(projectViewSet.getScalarValue(UseQuerySyncSection.KEY)).isEqualTo(Optional.empty());
}

@Test
public void testParserParsesVieProjectRootSection() throws Exception {
String text =
Expand Down