Search in sources :

Example 1 with GenfilesPath

use of com.google.idea.blaze.android.projectview.GenfilesPath in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesPartlyWhitelisted.

@Test
public void testMixingGeneratedAndNonGeneratedSourcesPartlyWhitelisted() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example"))).add(DirectoryEntry.include(new WorkspacePath("java/example2"))).add(DirectoryEntry.include(new WorkspacePath("java/uninterestingdir")))).add(ListSection.builder(GeneratedAndroidResourcesSection.KEY).add(new GenfilesPath("java/example/res")).add(new GenfilesPath("unused/whitelisted/path/res"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).addResource(gen("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example2:lib").setBuildFile(source("java/example2/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example2/AndroidManifest.xml")).addResource(source("java/example2/res")).addResource(gen("java/example2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example2")).build()).addTarget(TargetIdeInfo.builder().setLabel("//java/uninterestingdir:lib").setBuildFile(source("java/uninterestingdir/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/uninterestingdir/AndroidManifest.xml")).addResource(source("java/uninterestingdir/res")).addResource(gen("java/uninterestingdir/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.uninterestingdir")).build());
    importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertIssues("Dropping 1 generated resource directories.\n" + "R classes will not contain resources from these directories.\n" + "Double-click to add to project view if needed to resolve references.", "Dropping generated resource directory " + String.format("'%s/java/example2/res'", FAKE_GEN_ROOT_EXECUTION_PATH_FRAGMENT) + " w/ 2 subdirs", "1 unused entries in project view section \"generated_android_resource_directories\":\n" + "unused/whitelisted/path/res");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) Test(org.junit.Test)

Example 2 with GenfilesPath

use of com.google.idea.blaze.android.projectview.GenfilesPath in project intellij by bazelbuild.

the class AddGeneratedResourceDirectoryNavigatable method addDirectoryToProjectView.

private static void addDirectoryToProjectView(Project project, File projectViewFile, ArtifactLocation generatedResDir) {
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<GenfilesPath> existingSection = builder.getLast(GeneratedAndroidResourcesSection.KEY);
        ListSection.Builder<GenfilesPath> directoryBuilder = ListSection.update(GeneratedAndroidResourcesSection.KEY, existingSection);
        directoryBuilder.add(new GenfilesPath(generatedResDir.getRelativePath()));
        builder.replace(existingSection, directoryBuilder);
        return true;
    });
    if (edit == null) {
        Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
        return;
    }
    edit.apply();
    VirtualFile projectView = VfsUtil.findFileByIoFile(projectViewFile, false);
    if (projectView != null) {
        FileEditorManager.getInstance(project).openEditor(new OpenFileDescriptor(project, projectView), true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath)

Example 3 with GenfilesPath

use of com.google.idea.blaze.android.projectview.GenfilesPath in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesWhitelisted.

@Test
public void testMixingGeneratedAndNonGeneratedSourcesWhitelisted() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).add(ListSection.builder(GeneratedAndroidResourcesSection.KEY).add(new GenfilesPath("java/example/res"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).addResource(gen("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build());
    BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.androidResourceModules).containsExactly(AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/example:lib"))).addResourceAndTransitiveResource(source("java/example/res")).addResourceAndTransitiveResource(gen("java/example/res")).build());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) Test(org.junit.Test)

Aggregations

GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)3 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)2 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)2 Test (org.junit.Test)2 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)1 ProjectViewEdit (com.google.idea.blaze.base.projectview.ProjectViewEdit)1 ListSection (com.google.idea.blaze.base.projectview.section.ListSection)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1