Search in sources :

Example 1 with Section

use of com.google.idea.blaze.base.projectview.section.Section in project intellij by bazelbuild.

the class ProjectViewParser method parseProjectView.

private void parseProjectView(ParseContext parseContext) {
    ImmutableList.Builder<Section<?>> sections = ImmutableList.builder();
    List<SectionParser> sectionParsers = Sections.getParsers();
    while (!parseContext.atEnd()) {
        Section section = null;
        for (SectionParser sectionParser : sectionParsers) {
            section = sectionParser.parse(this, parseContext);
            if (section != null) {
                sections.add(section);
                break;
            }
        }
        if (section == null) {
            if (parseContext.current().indent != 0) {
                parseContext.addError(String.format("Invalid indentation on line: '%s'", parseContext.current().text));
                skipSection(parseContext);
            } else {
                parseContext.addError(String.format("Could not parse: '%s'", parseContext.current().text));
                parseContext.consume();
                // Skip past the entire section
                skipSection(parseContext);
            }
        }
    }
    ProjectView projectView = new ProjectView(sections.build());
    projectViewFiles.add(new ProjectViewSet.ProjectViewFile(projectView, parseContext.getProjectViewFile()));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImmutableList(com.google.common.collect.ImmutableList) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Section(com.google.idea.blaze.base.projectview.section.Section) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser)

Example 2 with Section

use of com.google.idea.blaze.base.projectview.section.Section in project intellij by bazelbuild.

the class ProjectViewSetTest method testProjectViewSetSerializable.

@Test
public void testProjectViewSetSerializable() throws Exception {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("test")))).add(ListSection.builder(TargetSection.KEY).add(TargetExpression.fromStringSafe("//test:all"))).add(ScalarSection.builder(ImportSection.KEY).set(new WorkspacePath("test"))).add(ListSection.builder(TestSourceSection.KEY).add(new Glob("javatests/*"))).add(ListSection.builder(ExcludedSourceSection.KEY).add(new Glob("*.java"))).add(ListSection.builder(BuildFlagsSection.KEY).add("--android_sdk=abcd")).add(ListSection.builder(SyncFlagsSection.KEY).add("--config=arm")).add(ListSection.builder(ImportTargetOutputSection.KEY).add(Label.create("//test:test"))).add(ListSection.builder(ExcludeTargetSection.KEY).add(Label.create("//test:test"))).add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA)).add(ListSection.builder(AdditionalLanguagesSection.KEY).add(LanguageClass.JAVA)).add(TextBlockSection.of(TextBlock.newLine())).add(ListSection.builder(RunConfigurationsSection.KEY).add(new WorkspacePath("test"))).add(ScalarSection.builder(ShardBlazeBuildsSection.KEY).set(false)).add(ScalarSection.builder(TargetShardSizeSection.KEY).set(500)).build()).build();
    // Assert we have all sections
    assert projectViewSet.getTopLevelProjectViewFile() != null;
    ProjectView projectView = projectViewSet.getTopLevelProjectViewFile().projectView;
    for (SectionParser parser : Sections.getParsers()) {
        ImmutableList<Section<?>> sections = projectView.getSections();
        assertThat(sections.stream().anyMatch(section -> section.isSectionType(parser.getSectionKey()))).isTrue();
    }
    TestUtils.assertIsSerializable(projectViewSet);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Glob(com.google.idea.blaze.base.projectview.section.Glob) RunConfigurationsSection(com.google.idea.blaze.base.projectview.section.sections.RunConfigurationsSection) TargetShardSizeSection(com.google.idea.blaze.base.projectview.section.sections.TargetShardSizeSection) ImportTargetOutputSection(com.google.idea.blaze.base.projectview.section.sections.ImportTargetOutputSection) ScalarSection(com.google.idea.blaze.base.projectview.section.ScalarSection) ExcludeTargetSection(com.google.idea.blaze.base.projectview.section.sections.ExcludeTargetSection) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) TextBlockSection(com.google.idea.blaze.base.projectview.section.sections.TextBlockSection) ShardBlazeBuildsSection(com.google.idea.blaze.base.projectview.section.sections.ShardBlazeBuildsSection) AdditionalLanguagesSection(com.google.idea.blaze.base.projectview.section.sections.AdditionalLanguagesSection) WorkspaceTypeSection(com.google.idea.blaze.base.projectview.section.sections.WorkspaceTypeSection) SyncFlagsSection(com.google.idea.blaze.base.projectview.section.sections.SyncFlagsSection) TestSourceSection(com.google.idea.blaze.base.projectview.section.sections.TestSourceSection) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) Section(com.google.idea.blaze.base.projectview.section.Section) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) BuildFlagsSection(com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ExcludedSourceSection(com.google.idea.blaze.base.projectview.section.sections.ExcludedSourceSection) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) Test(org.junit.Test)

Aggregations

Section (com.google.idea.blaze.base.projectview.section.Section)2 SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)2 ImmutableList (com.google.common.collect.ImmutableList)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 Glob (com.google.idea.blaze.base.projectview.section.Glob)1 ListSection (com.google.idea.blaze.base.projectview.section.ListSection)1 ScalarSection (com.google.idea.blaze.base.projectview.section.ScalarSection)1 AdditionalLanguagesSection (com.google.idea.blaze.base.projectview.section.sections.AdditionalLanguagesSection)1 BuildFlagsSection (com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection)1 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)1 ExcludeTargetSection (com.google.idea.blaze.base.projectview.section.sections.ExcludeTargetSection)1 ExcludedSourceSection (com.google.idea.blaze.base.projectview.section.sections.ExcludedSourceSection)1 ImportSection (com.google.idea.blaze.base.projectview.section.sections.ImportSection)1 ImportTargetOutputSection (com.google.idea.blaze.base.projectview.section.sections.ImportTargetOutputSection)1 RunConfigurationsSection (com.google.idea.blaze.base.projectview.section.sections.RunConfigurationsSection)1 ShardBlazeBuildsSection (com.google.idea.blaze.base.projectview.section.sections.ShardBlazeBuildsSection)1 SyncFlagsSection (com.google.idea.blaze.base.projectview.section.sections.SyncFlagsSection)1 TargetSection (com.google.idea.blaze.base.projectview.section.sections.TargetSection)1