Search in sources :

Example 11 with IssueOutput

use of com.google.idea.blaze.base.scope.output.IssueOutput in project intellij by bazelbuild.

the class ErrorCollector method assertIssues.

public void assertIssues(String... requiredMessages) {
    List<String> messages = Lists.newArrayList();
    for (IssueOutput issue : issues) {
        messages.add(issue.getMessage());
    }
    assertThat(messages).containsExactly((Object[]) requiredMessages);
}
Also used : IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput)

Example 12 with IssueOutput

use of com.google.idea.blaze.base.scope.output.IssueOutput in project intellij by bazelbuild.

the class BlazeEditProjectViewControl method validate.

public BlazeValidationResult validate() {
    // Validate project settings fields
    String projectName = projectNameField.getText().trim();
    if (StringUtil.isEmpty(projectName)) {
        return BlazeValidationResult.failure(new BlazeValidationError("Project name is not specified"));
    }
    String projectDataDirPath = projectDataDirField.getText().trim();
    if (StringUtil.isEmpty(projectDataDirPath)) {
        return BlazeValidationResult.failure(new BlazeValidationError("Project data directory is not specified"));
    }
    File projectDataDir = new File(projectDataDirPath);
    if (!projectDataDir.isAbsolute()) {
        return BlazeValidationResult.failure(new BlazeValidationError("Project data directory is not valid"));
    }
    for (ProjectDataDirectoryValidator validator : ProjectDataDirectoryValidator.EP_NAME.getExtensions()) {
        BlazeValidationResult result = validator.validateDataDirectory(projectDataDir);
        if (!result.success) {
            return result;
        }
    }
    File workspaceRootDirectory = workspaceRoot.directory();
    if (!workspaceOption.allowProjectDataInVcs() && FileUtil.isAncestor(workspaceRootDirectory, projectDataDir, false)) {
        return BlazeValidationResult.failure(new BlazeValidationError("Project data directory cannot be inside your workspace. " + "Please choose a directory outside your workspace."));
    }
    List<IssueOutput> issues = Lists.newArrayList();
    ProjectViewSet projectViewSet = projectViewUi.parseProjectView(issues);
    BlazeValidationError projectViewParseError = validationErrorFromIssueList(issues);
    if (projectViewParseError != null) {
        return BlazeValidationResult.failure(projectViewParseError);
    }
    ProjectViewValidator projectViewValidator = new ProjectViewValidator(workspacePathResolver, projectViewSet);
    ProgressManager.getInstance().runProcessWithProgressSynchronously(projectViewValidator, "Validating Project", false, null);
    if (!projectViewValidator.success) {
        if (!projectViewValidator.errors.isEmpty()) {
            return BlazeValidationResult.failure(validationErrorFromIssueList(projectViewValidator.errors));
        }
        return BlazeValidationResult.failure("Project view validation failed, but we couldn't find an error message. " + "Please report a bug.");
    }
    List<DirectoryEntry> directories = projectViewSet.listItems(DirectorySection.KEY);
    if (directories.isEmpty()) {
        String msg = "Add some directories to index in the 'directories' section.";
        if (projectViewSet.listItems(TargetSection.KEY).isEmpty()) {
            msg += "\nTargets are also generally required to resolve sources.";
        }
        return BlazeValidationResult.failure(msg);
    }
    return BlazeValidationResult.success();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeValidationResult(com.google.idea.blaze.base.ui.BlazeValidationResult) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) ProjectDataDirectoryValidator(com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator)

Example 13 with IssueOutput

use of com.google.idea.blaze.base.scope.output.IssueOutput in project intellij by bazelbuild.

the class BlazeEditProjectViewControl method validationErrorFromIssueList.

@Nullable
private static BlazeValidationError validationErrorFromIssueList(List<IssueOutput> issues) {
    List<IssueOutput> errors = issues.stream().filter(issue -> issue.getCategory() == IssueOutput.Category.ERROR).collect(toList());
    if (!errors.isEmpty()) {
        StringBuilder errorMessage = new StringBuilder();
        errorMessage.append("The following issues were found:\n\n");
        for (IssueOutput issue : errors) {
            errorMessage.append(issue.getMessage());
            errorMessage.append('\n');
        }
        return new BlazeValidationError(errorMessage.toString());
    }
    return null;
}
Also used : 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) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Nullable(javax.annotation.Nullable)

Example 14 with IssueOutput

use of com.google.idea.blaze.base.scope.output.IssueOutput in project intellij by bazelbuild.

the class BlazeProblemsView method addMessage.

public void addMessage(IssueOutput issue, @Nullable Navigatable openInConsole) {
    if (!problems.add(issue.toString())) {
        return;
    }
    int count = problemCount.incrementAndGet();
    if (count > MAX_ISSUES) {
        return;
    }
    if (count == MAX_ISSUES) {
        issue = IssueOutput.warn("Too many problems found. Only showing the first " + MAX_ISSUES).build();
    }
    VirtualFile file = issue.getFile() != null ? resolveVirtualFile(issue.getFile()) : null;
    Navigatable navigatable = issue.getNavigatable();
    if (navigatable == null && file != null) {
        navigatable = new OpenFileDescriptor(project, file, issue.getLine() - 1, issue.getColumn() - 1);
    }
    IssueOutput.Category category = issue.getCategory();
    int type = translateCategory(category);
    String[] text = convertMessage(issue);
    String groupName = file != null ? file.getPresentableUrl() : category.name();
    addMessage(type, text, groupName, file, navigatable, openInConsole, getExportTextPrefix(issue), getRenderTextPrefix(issue));
    if (focusProblemsViewOnIssue && !didFocusProblemsView.get()) {
        didFocusProblemsView.set(true);
        focusProblemsView();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Navigatable(com.intellij.pom.Navigatable)

Example 15 with IssueOutput

use of com.google.idea.blaze.base.scope.output.IssueOutput in project intellij by bazelbuild.

the class PyIssueParserProviderTest method testParsePyTypeError.

@Test
public void testParsePyTypeError() {
    BlazeIssueParser blazeIssueParser = new BlazeIssueParser(parsers);
    IssueOutput issue = blazeIssueParser.parseIssue("File \"dataset.py\", line 109, in Dataset: " + "Name 'function' is not defined [name-error]");
    assertThat(issue).isNotNull();
    assertThat(issue.getCategory()).isEqualTo(Category.ERROR);
    assertThat(issue.getNavigatable()).isNotNull();
    assertThat(issue.getConsoleHyperlinkRange()).isEqualTo(TextRange.create("File \"".length(), "File \"dataset.py\", line 109".length()));
}
Also used : BlazeIssueParser(com.google.idea.blaze.base.issueparser.BlazeIssueParser) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Test(org.junit.Test)

Aggregations

IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)27 Test (org.junit.Test)19 Nullable (javax.annotation.Nullable)4 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)3 File (java.io.File)3 List (java.util.List)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)2 ProjectViewParser (com.google.idea.blaze.base.projectview.parser.ProjectViewParser)2 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)2 Scope (com.google.idea.blaze.base.scope.Scope)2 BuildSystem (com.google.idea.blaze.base.settings.Blaze.BuildSystem)2 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)2 BlazeValidationError (com.google.idea.blaze.base.ui.BlazeValidationError)2 BlazeValidationResult (com.google.idea.blaze.base.ui.BlazeValidationResult)2 UiUtil (com.google.idea.blaze.base.ui.UiUtil)2 ProjectDataDirectoryValidator (com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator)2 Disposable (com.intellij.openapi.Disposable)2 Logger (com.intellij.openapi.diagnostic.Logger)2