Search in sources :

Example 1 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testSingleScalaBinary.

@Test
public void testSingleScalaBinary() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar"))))).build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build());
    assertThat(javaImportResult.libraries).isEmpty();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"));
    assertThat(scalaImportResult.libraries).isEmpty();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 2 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testTwoScalaBinariesWithSharedLibrary.

@Test
public void testTwoScalaBinariesWithSharedLibrary() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/other")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/some/library:library")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/other:other").setBuildFile(source("src/main/scala/apps/other/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/other/Main.scala")).addSource(source("src/main/scala/apps/other/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/other/other.jar")).setClassJar(gen("src/main/scala/apps/other/other.jar")))).addDependency("//src/main/scala/some/library:library")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library:library").setBuildFile(source("src/main/scala/some/library/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library/library_ijar.jar")).setClassJar(gen("src/main/scala/some/library/library.jar"))))).build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build(), BlazeContentEntry.builder("/root/src/main/scala/apps/other").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/other").setPackagePrefix("apps.other").build()).build());
    // Direct library deps will be double counted.
    assertThat(javaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(javaImportResult.libraries, "library_ijar")).isTrue();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"), source("src/main/scala/apps/other/Main.scala"), source("src/main/scala/apps/other/subdir/SubdirHelper.scala"));
    assertThat(scalaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(scalaImportResult.libraries, "library_ijar")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 3 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testEmptyProject.

@Test
public void testEmptyProject() {
    ProjectView projectView = ProjectView.builder().build();
    TargetMap targetMap = TargetMapBuilder.builder().build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.libraries).isEmpty();
    assertThat(javaImportResult.contentEntries).isEmpty();
    assertThat(javaImportResult.javaSourceFiles).isEmpty();
    assertThat(javaImportResult.libraries).isEmpty();
    assertThat(scalaImportResult.libraries).isEmpty();
}
Also used : BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 4 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testScalaAndJavaBinary.

@Test
public void testScalaAndJavaBinary() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("src/main/java/apps/example")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/apps/example:example").setBuildFile(source("src/main/java/apps/example/BUILD")).setKind("java_binary").addSource(source("src/main/java/apps/example/Main.java")).addSource(source("src/main/java/apps/example/subdir/SubdirHelper.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/apps/example/example.jar")).setClassJar(gen("src/main/java/apps/example/example.jar"))))).build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build(), BlazeContentEntry.builder("/root/src/main/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/java/apps/example").setPackagePrefix("apps.example").build()).build());
    assertThat(javaImportResult.libraries).isEmpty();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"), source("src/main/java/apps/example/Main.java"), source("src/main/java/apps/example/subdir/SubdirHelper.java"));
    assertThat(scalaImportResult.libraries).isEmpty();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 5 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaSyncPlugin 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, Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    if (!workspaceLanguageSettings.isLanguageActive(LanguageClass.SCALA)) {
        return;
    }
    BlazeScalaWorkspaceImporter blazeScalaWorkspaceImporter = new BlazeScalaWorkspaceImporter(project, workspaceRoot, projectViewSet, targetMap);
    BlazeScalaImportResult importResult = Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("ScalaWorkspaceImporter", EventType.Other));
        return blazeScalaWorkspaceImporter.importWorkspace();
    });
    BlazeScalaSyncData syncData = new BlazeScalaSyncData(importResult);
    syncStateBuilder.put(BlazeScalaSyncData.class, syncData);
}
Also used : BlazeScalaWorkspaceImporter(com.google.idea.blaze.scala.sync.importer.BlazeScalaWorkspaceImporter) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) BlazeScalaSyncData(com.google.idea.blaze.scala.sync.model.BlazeScalaSyncData)

Aggregations

BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)8 Test (org.junit.Test)8 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)7 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)6 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 LibraryKey (com.google.idea.blaze.base.model.LibraryKey)1 Kind (com.google.idea.blaze.base.model.primitives.Kind)1 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)1 ProjectViewTargetImportFilter (com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter)1 TransitiveDependencyMap (com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap)1 JavaSourceFilter (com.google.idea.blaze.java.sync.importer.JavaSourceFilter)1 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)1