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);
}
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();
}
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;
}
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();
}
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"));
}
Aggregations