Search in sources :

Example 11 with DirectoryEntry

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

the class ProjectViewParserTest method testMultipleSections.

@Test
public void testMultipleSections() throws Exception {
    projectViewStorageManager.add(".blazeproject", "directories:", "  java/com/google", "directories:", "  java/com/google2", "", "workspace_type: java", "workspace_type: android");
    projectViewParser.parseProjectView(new File(".blazeproject"));
    errorCollector.assertNoIssues();
    ProjectViewSet projectViewSet = projectViewParser.getResult();
    assertThat(projectViewSet.listItems(DirectorySection.KEY)).containsExactly(new DirectoryEntry(new WorkspacePath("java/com/google"), true), new DirectoryEntry(new WorkspacePath("java/com/google2"), true));
    assertThat(projectViewSet.listScalarItems(WorkspaceTypeSection.KEY)).containsExactly(WorkspaceType.JAVA, WorkspaceType.ANDROID);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Example 12 with DirectoryEntry

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

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

the class ProjectViewVerifier method verifyIncludedPackagesExistOnDisk.

private static boolean verifyIncludedPackagesExistOnDisk(BlazeContext context, WorkspacePathResolver workspacePathResolver, ProjectViewSet projectViewSet) {
    boolean ok = true;
    FileOperationProvider fileOperationProvider = FileOperationProvider.getInstance();
    for (ProjectViewSet.ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
        List<DirectoryEntry> directoryEntries = Lists.newArrayList();
        for (ListSection<DirectoryEntry> section : projectViewFile.projectView.getSectionsOfType(DirectorySection.KEY)) {
            directoryEntries.addAll(section.items());
        }
        for (DirectoryEntry entry : directoryEntries) {
            if (!entry.included) {
                continue;
            }
            WorkspacePath workspacePath = entry.directory;
            File file = workspacePathResolver.resolveToFile(workspacePath);
            if (!fileOperationProvider.exists(file)) {
                IssueOutput.error(String.format("Directory '%s' specified in project view not found.", workspacePath)).inFile(projectViewFile.projectViewFile).submit(context);
                ok = false;
            } else if (!fileOperationProvider.isDirectory(file)) {
                IssueOutput.error(String.format("Directory '%s' specified in project view is a file.", workspacePath)).inFile(projectViewFile.projectViewFile).submit(context);
                ok = false;
            }
        }
    }
    return ok;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)

Example 14 with DirectoryEntry

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

the class ImportRootsTest method testAllLabelsIncludedUnderWorkspaceRoot.

// if the workspace root is an included directory, all rules should be imported as sources.
@Test
public void testAllLabelsIncludedUnderWorkspaceRoot() {
    ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(new DirectoryEntry(new WorkspacePath(""), true)).build();
    assertThat(importRoots.importAsSource(Label.create("//:target"))).isTrue();
    assertThat(importRoots.importAsSource(Label.create("//foo/bar:target"))).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) Test(org.junit.Test)

Example 15 with DirectoryEntry

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

the class ProjectViewParserTest method testRootDirectory.

@Test
public void testRootDirectory() throws Exception {
    projectViewStorageManager.add(".blazeproject", "directories:", "  .", "  -java/com/google/android/notme", "", "targets:", "  //java/com/google:all");
    projectViewParser.parseProjectView(new File(".blazeproject"));
    errorCollector.assertNoIssues();
    ProjectViewSet projectViewSet = projectViewParser.getResult();
    ProjectViewSet.ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
    assertThat(projectViewFile).isNotNull();
    assertThat(projectViewFile.projectViewFile).isEqualTo(new File(".blazeproject"));
    assertThat(projectViewSet.getProjectViewFiles()).containsExactly(projectViewFile);
    ProjectView projectView = projectViewFile.projectView;
    assertThat(projectView.getSectionsOfType(DirectorySection.KEY).get(0).items()).containsExactly(new DirectoryEntry(new WorkspacePath(""), true), new DirectoryEntry(new WorkspacePath("java/com/google/android/notme"), false));
    assertThat(projectView.getSectionsOfType(TargetSection.KEY).get(0).items()).containsExactly(TargetExpression.fromStringSafe("//java/com/google:all"));
    String text = ProjectViewParser.projectViewToString(projectView);
    assertThat(text).isEqualTo(Joiner.on('\n').join("directories:", "  .", "  -java/com/google/android/notme", "", "targets:", "  //java/com/google:all"));
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) File(java.io.File) Test(org.junit.Test)

Aggregations

DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)20 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 Test (org.junit.Test)16 File (java.io.File)10 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)9 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)7 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)4 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)3 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)2 ListSection (com.google.idea.blaze.base.projectview.section.ListSection)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 Lists (com.google.common.collect.Lists)1 ProjectViewEdit (com.google.idea.blaze.base.projectview.ProjectViewEdit)1 SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)1 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)1 Sections (com.google.idea.blaze.base.projectview.section.sections.Sections)1 TextBlock (com.google.idea.blaze.base.projectview.section.sections.TextBlock)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)1 LanguageSupport (com.google.idea.blaze.base.sync.projectview.LanguageSupport)1