Search in sources :

Example 1 with ProjectDataDirectoryValidator

use of com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator 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)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)1 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)1 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)1 BlazeValidationError (com.google.idea.blaze.base.ui.BlazeValidationError)1 BlazeValidationResult (com.google.idea.blaze.base.ui.BlazeValidationResult)1 ProjectDataDirectoryValidator (com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator)1 File (java.io.File)1