Search in sources :

Example 1 with SectionParser

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

the class ProjectViewDocumentationProvider method generateDoc.

@Nullable
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
    SectionParser section = getSection(element);
    if (section == null) {
        return null;
    }
    StringBuilder builder = new StringBuilder();
    String quickDocs = section.quickDocs();
    if (quickDocs != null) {
        builder.append(wrapInTag("<p>" + section.quickDocs(), "code"));
    }
    String url = getUrlFor(element.getProject(), section, false);
    if (url != null) {
        builder.append(String.format("<p><b>External documentation</b>:<br><a href=\"%s\">%s</a>", url, url));
    }
    return wrapInTag(wrapInTag(builder.toString(), "body"), "html");
}
Also used : SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) Nullable(javax.annotation.Nullable)

Example 2 with SectionParser

use of com.google.idea.blaze.base.projectview.section.SectionParser 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 3 with SectionParser

use of com.google.idea.blaze.base.projectview.section.SectionParser 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)

Example 4 with SectionParser

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

the class BlazeEditProjectViewControl method modifyInitialProjectView.

private static String modifyInitialProjectView(BuildSystem buildSystem, String initialProjectViewText, WorkspacePathResolver workspacePathResolver) {
    BlazeContext context = new BlazeContext();
    ProjectViewParser projectViewParser = new ProjectViewParser(context, workspacePathResolver);
    projectViewParser.parseProjectView(initialProjectViewText);
    ProjectViewSet projectViewSet = projectViewParser.getResult();
    ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
    if (projectViewFile == null) {
        return initialProjectViewText;
    }
    ProjectView projectView = projectViewFile.projectView;
    // Sort default value providers to match the section order
    List<SectionKey> sectionKeys = Sections.getParsers().stream().map(SectionParser::getSectionKey).collect(toList());
    List<ProjectViewDefaultValueProvider> defaultValueProviders = Lists.newArrayList(ProjectViewDefaultValueProvider.EP_NAME.getExtensions());
    defaultValueProviders.sort(Comparator.comparingInt(val -> sectionKeys.indexOf(val.getSectionKey())));
    for (ProjectViewDefaultValueProvider defaultValueProvider : defaultValueProviders) {
        projectView = defaultValueProvider.addProjectViewDefaultValue(buildSystem, projectViewSet, projectView);
    }
    return ProjectViewParser.projectViewToString(projectView);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ScalarSection(com.google.idea.blaze.base.projectview.section.ScalarSection) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) Sections(com.google.idea.blaze.base.projectview.section.sections.Sections) JBLabel(com.intellij.ui.components.JBLabel) JPanelProvidingProject(com.google.idea.blaze.base.settings.ui.JPanelProvidingProject) UiUtil(com.google.idea.blaze.base.ui.UiUtil) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) BorderLayout(java.awt.BorderLayout) ProgressManager(com.intellij.openapi.progress.ProgressManager) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) BlazeValidationResult(com.google.idea.blaze.base.ui.BlazeValidationResult) RecentProjectsManager(com.intellij.ide.RecentProjectsManager) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BorderFactory(javax.swing.BorderFactory) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) TextComponentAccessor(com.intellij.openapi.ui.TextComponentAccessor) Component(java.awt.Component) JRadioButton(javax.swing.JRadioButton) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) Propagation(com.google.idea.blaze.base.scope.OutputSink.Propagation) List(java.util.List) SystemProperties(com.intellij.util.SystemProperties) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) GridBagLayout(java.awt.GridBagLayout) NotNull(org.jetbrains.annotations.NotNull) JPanel(javax.swing.JPanel) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeSelectWorkspaceOption(com.google.idea.blaze.base.wizard2.BlazeSelectWorkspaceOption) JTextField(javax.swing.JTextField) Paths(com.intellij.history.core.Paths) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Hashing(com.google.common.hash.Hashing) Lists(com.google.common.collect.Lists) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) Scope(com.google.idea.blaze.base.scope.Scope) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) BoolExperiment(com.google.idea.common.experiments.BoolExperiment) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) Nullable(javax.annotation.Nullable) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) ProjectDataDirectoryValidator(com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator) ButtonGroup(javax.swing.ButtonGroup) HashCode(com.google.common.hash.HashCode) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser) StringUtil(com.intellij.openapi.util.text.StringUtil) BlazeSelectProjectViewOption(com.google.idea.blaze.base.wizard2.BlazeSelectProjectViewOption) IOException(java.io.IOException) BlazeNewProjectBuilder(com.google.idea.blaze.base.wizard2.BlazeNewProjectBuilder) ProjectViewStorageManager(com.google.idea.blaze.base.projectview.ProjectViewStorageManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) Category(com.google.idea.blaze.base.scope.output.IssueOutput.Category) JScrollPane(javax.swing.JScrollPane) Collectors.toList(java.util.stream.Collectors.toList) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) ProjectViewVerifier(com.google.idea.blaze.base.projectview.ProjectViewVerifier) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewUi(com.google.idea.blaze.base.settings.ui.ProjectViewUi) JLabel(javax.swing.JLabel) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser)

Example 5 with SectionParser

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

the class ProjectViewVerifier method warnAboutDeprecatedSections.

private static void warnAboutDeprecatedSections(BlazeContext context, ProjectViewSet projectViewSet) {
    List<SectionParser> deprecatedParsers = Sections.getParsers().stream().filter(SectionParser::isDeprecated).collect(toList());
    for (SectionParser sectionParser : deprecatedParsers) {
        for (ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
            ProjectView projectView = projectViewFile.projectView;
            if (projectView.getSections().stream().anyMatch(section -> section.isSectionType(sectionParser.getSectionKey()))) {
                String deprecationMessage = sectionParser.getDeprecationMessage();
                if (deprecationMessage == null) {
                    deprecationMessage = String.format("%s is deprecated", sectionParser.getName());
                }
                IssueOutput.warn(deprecationMessage).inFile(projectViewFile.projectViewFile).submit(context);
            }
        }
    }
}
Also used : ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser)

Aggregations

SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)2 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)2 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)2 ScalarSection (com.google.idea.blaze.base.projectview.section.ScalarSection)2 Section (com.google.idea.blaze.base.projectview.section.Section)2 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)2 ImportSection (com.google.idea.blaze.base.projectview.section.sections.ImportSection)2 TargetSection (com.google.idea.blaze.base.projectview.section.sections.TargetSection)2 Nullable (javax.annotation.Nullable)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 HashCode (com.google.common.hash.HashCode)1 Hashing (com.google.common.hash.Hashing)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 ProjectViewStorageManager (com.google.idea.blaze.base.projectview.ProjectViewStorageManager)1 ProjectViewVerifier (com.google.idea.blaze.base.projectview.ProjectViewVerifier)1 ProjectViewParser (com.google.idea.blaze.base.projectview.parser.ProjectViewParser)1 Glob (com.google.idea.blaze.base.projectview.section.Glob)1