Search in sources :

Example 1 with Glob

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

the class ProjectViewSetTest method testProjectViewSetSerializable.

@Test
public void testProjectViewSetSerializable() throws Exception {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("test")))).add(ListSection.builder(TargetSection.KEY).add(TargetExpression.fromStringSafe("//test:all"))).add(ScalarSection.builder(ImportSection.KEY).set(new WorkspacePath("test"))).add(ListSection.builder(TestSourceSection.KEY).add(new Glob("javatests/*"))).add(ListSection.builder(ExcludedSourceSection.KEY).add(new Glob("*.java"))).add(ListSection.builder(BuildFlagsSection.KEY).add("--android_sdk=abcd")).add(ListSection.builder(SyncFlagsSection.KEY).add("--config=arm")).add(ListSection.builder(ImportTargetOutputSection.KEY).add(Label.create("//test:test"))).add(ListSection.builder(ExcludeTargetSection.KEY).add(Label.create("//test:test"))).add(ScalarSection.builder(WorkspaceTypeSection.KEY).set(WorkspaceType.JAVA)).add(ListSection.builder(AdditionalLanguagesSection.KEY).add(LanguageClass.JAVA)).add(TextBlockSection.of(TextBlock.newLine())).add(ListSection.builder(RunConfigurationsSection.KEY).add(new WorkspacePath("test"))).add(ScalarSection.builder(ShardBlazeBuildsSection.KEY).set(false)).add(ScalarSection.builder(TargetShardSizeSection.KEY).set(500)).build()).build();
    // Assert we have all sections
    assert projectViewSet.getTopLevelProjectViewFile() != null;
    ProjectView projectView = projectViewSet.getTopLevelProjectViewFile().projectView;
    for (SectionParser parser : Sections.getParsers()) {
        ImmutableList<Section<?>> sections = projectView.getSections();
        assertThat(sections.stream().anyMatch(section -> section.isSectionType(parser.getSectionKey()))).isTrue();
    }
    TestUtils.assertIsSerializable(projectViewSet);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Glob(com.google.idea.blaze.base.projectview.section.Glob) RunConfigurationsSection(com.google.idea.blaze.base.projectview.section.sections.RunConfigurationsSection) TargetShardSizeSection(com.google.idea.blaze.base.projectview.section.sections.TargetShardSizeSection) ImportTargetOutputSection(com.google.idea.blaze.base.projectview.section.sections.ImportTargetOutputSection) ScalarSection(com.google.idea.blaze.base.projectview.section.ScalarSection) ExcludeTargetSection(com.google.idea.blaze.base.projectview.section.sections.ExcludeTargetSection) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) TextBlockSection(com.google.idea.blaze.base.projectview.section.sections.TextBlockSection) ShardBlazeBuildsSection(com.google.idea.blaze.base.projectview.section.sections.ShardBlazeBuildsSection) AdditionalLanguagesSection(com.google.idea.blaze.base.projectview.section.sections.AdditionalLanguagesSection) WorkspaceTypeSection(com.google.idea.blaze.base.projectview.section.sections.WorkspaceTypeSection) SyncFlagsSection(com.google.idea.blaze.base.projectview.section.sections.SyncFlagsSection) TestSourceSection(com.google.idea.blaze.base.projectview.section.sections.TestSourceSection) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) Section(com.google.idea.blaze.base.projectview.section.Section) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) BuildFlagsSection(com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ExcludedSourceSection(com.google.idea.blaze.base.projectview.section.sections.ExcludedSourceSection) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) Test(org.junit.Test)

Example 2 with Glob

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

the class ExcludeLibraryAction method actionPerformedInBlazeProject.

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    Library library = LibraryActionHelper.findLibraryForAction(e);
    if (library == null) {
        return;
    }
    BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
    if (blazeLibrary == null) {
        Messages.showErrorDialog(project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
        return;
    }
    final LibraryArtifact libraryArtifact = blazeLibrary.libraryArtifact;
    final String path = libraryArtifact.jarForIntellijLibrary().getRelativePath();
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<Glob> existingSection = builder.getLast(ExcludeLibrarySection.KEY);
        builder.replace(existingSection, ListSection.update(ExcludeLibrarySection.KEY, existingSection).add(new Glob(path)));
        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();
    BlazeSyncManager.getInstance(project).incrementalProjectSync();
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) Glob(com.google.idea.blaze.base.projectview.section.Glob) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 3 with Glob

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

the class BlazeJavaWorkspaceImporterTest method testProjectAndTests.

/**
 * Import a project and its tests
 */
@Test
public void testProjectAndTests() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("javatests/apps/example")))).add(ListSection.builder(TestSourceSection.KEY).add(new Glob("javatests/*"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("android_binary").addSource(source("java/apps/example/MainActivity.java")).addSource(source("java/apps/example/subdir/SubdirHelper.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//javatests/apps/example:example").setBuildFile(source("javatests/apps/example/BUILD")).setKind("android_test").addSource(source("javatests/apps/example/ExampleTests.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("com.google.android.apps.example")).addDependency("//java/apps/example:example_debug").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("javatests/apps/example/example.jar")).setClassJar(gen("javatests/apps/example/example.jar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.contentEntries).containsExactly(BlazeContentEntry.builder("/root/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/java/apps/example").setPackagePrefix("apps.example").build()).build(), BlazeContentEntry.builder("/root/javatests/apps/example").addSource(BlazeSourceDirectory.builder("/root/javatests/apps/example").setPackagePrefix("apps.example").build()).build());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) Glob(com.google.idea.blaze.base.projectview.section.Glob) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 4 with Glob

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

the class BlazeJavaWorkspaceImporterTest method testJavaTestTarget.

/**
 * Test a project with a java test rule
 */
@Test
public void testJavaTestTarget() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("javatests/apps/example")))).add(ListSection.builder(TestSourceSection.KEY).add(new Glob("javatests/*"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("android_binary").addSource(source("java/apps/example/MainActivity.java")).addSource(source("java/apps/example/subdir/SubdirHelper.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//javatests/apps/example:example").setBuildFile(source("javatests/apps/example/BUILD")).setKind("java_test").addSource(source("javatests/apps/example/ExampleTests.java")).addDependency("//java/apps/example:example_debug").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("javatests/apps/example/example.jar")).setClassJar(gen("javatests/apps/example/example.jar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.contentEntries).containsExactly(BlazeContentEntry.builder("/root/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/java/apps/example").setPackagePrefix("apps.example").build()).build(), BlazeContentEntry.builder("/root/javatests/apps/example").addSource(BlazeSourceDirectory.builder("/root/javatests/apps/example").setPackagePrefix("apps.example").build()).build());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) Glob(com.google.idea.blaze.base.projectview.section.Glob) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 5 with Glob

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

the class BlazeJavaSyncPlugin method updateSyncState.

@Override
public void updateSyncState(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, WorkspaceLanguageSettings workspaceLanguageSettings, BlazeInfo blazeInfo, @Nullable WorkingSet workingSet, WorkspacePathResolver workspacePathResolver, ArtifactLocationDecoder artifactLocationDecoder, TargetMap targetMap, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    JavaWorkingSet javaWorkingSet = null;
    if (workingSet != null) {
        javaWorkingSet = new JavaWorkingSet(workspaceRoot, workingSet, Blaze.getBuildSystemProvider(project)::isBuildFile);
    }
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    JdepsMap jdepsMap = jdepsFileReader.loadJdepsFiles(project, context, artifactLocationDecoder, sourceFilter.getSourceTargets(), syncStateBuilder, previousSyncState);
    if (context.isCancelled()) {
        return;
    }
    BlazeJavaWorkspaceImporter blazeJavaWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, javaWorkingSet, artifactLocationDecoder);
    BlazeJavaImportResult importResult = Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("JavaWorkspaceImporter", EventType.Other));
        return blazeJavaWorkspaceImporter.importWorkspace(childContext);
    });
    Glob.GlobSet excludedLibraries = new Glob.GlobSet(ImmutableList.<Glob>builder().addAll(projectViewSet.listItems(ExcludeLibrarySection.KEY)).addAll(projectViewSet.listItems(ExcludedLibrarySection.KEY)).build());
    BlazeJavaSyncData syncData = new BlazeJavaSyncData(importResult, excludedLibraries);
    syncStateBuilder.put(BlazeJavaSyncData.class, syncData);
}
Also used : JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) Glob(com.google.idea.blaze.base.projectview.section.Glob) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter)

Aggregations

Glob (com.google.idea.blaze.base.projectview.section.Glob)6 Test (org.junit.Test)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)3 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)2 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)2 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 ProjectViewEdit (com.google.idea.blaze.base.projectview.ProjectViewEdit)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 ListSection (com.google.idea.blaze.base.projectview.section.ListSection)1 ScalarSection (com.google.idea.blaze.base.projectview.section.ScalarSection)1 Section (com.google.idea.blaze.base.projectview.section.Section)1 SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)1 AdditionalLanguagesSection (com.google.idea.blaze.base.projectview.section.sections.AdditionalLanguagesSection)1 BuildFlagsSection (com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection)1 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)1 ExcludeTargetSection (com.google.idea.blaze.base.projectview.section.sections.ExcludeTargetSection)1 ExcludedSourceSection (com.google.idea.blaze.base.projectview.section.sections.ExcludedSourceSection)1 ImportSection (com.google.idea.blaze.base.projectview.section.sections.ImportSection)1