Search in sources :

Example 51 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testScalaBinaryWithMultipleLibraries.

@Test
public void testScalaBinaryWithMultipleLibraries() {
    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")))).addDependency("//src/main/scala/some/library1:library1").addDependency("//src/main/java/other/library2:library2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library1:library1").setBuildFile(source("src/main/scala/some/library1/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library1/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library1/library1_ijar.jar")).setClassJar(gen("src/main/scala/some/library1/library1.jar")))).addDependency("//src/main/java/other/import:import")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/library2:library2").setBuildFile(source("src/main/java/other/library2/BUILD")).setKind("java_library").addSource(source("src/main/java/other/library2/Library.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/library2/liblibrary2-ijar.jar")).setClassJar(gen("src/main/java/other/library2/liblibrary2.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/import:import").setBuildFile(source("src/main/java/other/import/BUILD")).setKind("java_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/import/libimport-ijar.jar")).setClassJar(gen("src/main/java/other/import/libimport.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());
    // Direct library deps will be double counted.
    assertThat(javaImportResult.libraries).hasSize(2);
    assertThat(hasLibrary(javaImportResult.libraries, "library1_ijar")).isTrue();
    assertThat(hasLibrary(javaImportResult.libraries, "library2-ijar")).isTrue();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"));
    assertThat(scalaImportResult.libraries).hasSize(3);
    assertThat(hasLibrary(scalaImportResult.libraries, "library1_ijar")).isTrue();
    assertThat(hasLibrary(scalaImportResult.libraries, "library2-ijar")).isTrue();
    assertThat(hasLibrary(scalaImportResult.libraries, "import-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 52 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testSourceTargetsWithoutNonGeneratedSourcesAddedToLibraries.

@Test
public void testSourceTargetsWithoutNonGeneratedSourcesAddedToLibraries() {
    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/some/library")))).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/some/library:library").setBuildFile(source("src/main/scala/some/library/BUILD")).setKind("scala_library").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();
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(scalaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(scalaImportResult.libraries, "library_ijar")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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 53 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testSourceRulesNotInLibraries.

@Test
public void testSourceRulesNotInLibraries() {
    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/some/library1"))).add(DirectoryEntry.include(new WorkspacePath("src/main/java/other/library2")))).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/library1:library1").addDependency("//src/main/java/other/library2:library2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library1:library1").setBuildFile(source("src/main/scala/some/library1/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library1/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library1/library1_ijar.jar")).setClassJar(gen("src/main/scala/some/library1/library1.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/library2:library2").setBuildFile(source("src/main/java/other/library2/BUILD")).setKind("java_library").addSource(source("src/main/java/other/library2/Library.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/library2/libibrary2-ijar.jar")).setClassJar(gen("src/main/java/other/library2/liblibrary2.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/some/library1").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/some/library1").setPackagePrefix("some.library1").build()).build(), BlazeContentEntry.builder("/root/src/main/java/other/library2").addSource(BlazeSourceDirectory.builder("/root/src/main/java/other/library2").setPackagePrefix("other.library2").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/scala/some/library1/Library.scala"), source("src/main/java/other/library2/Library.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 54 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testDuplicateScalaLibraries.

@Test
public void testDuplicateScalaLibraries() {
    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").setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.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/imports:import1").addDependency("//src/main/scala/imports:import2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/imports:import1").setKind("scala_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/imports/import.jar")).setClassJar(gen("src/main/scala/imports/import.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/imports:import2").setKind("scala_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/imports/import.jar")).setClassJar(gen("src/main/scala/imports/import.jar"))))).build();
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(scalaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(scalaImportResult.libraries, "import")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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 55 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method importJava.

private BlazeJavaImportResult importJava(ProjectView projectView, TargetMap targetMap) {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    WorkspaceLanguageSettings languageSettings = new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.SCALA, LanguageClass.JAVA));
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    JdepsMap jdepsMap = key -> ImmutableList.of();
    ArtifactLocationDecoder decoder = location -> new File(location.getRelativePath());
    return new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, languageSettings, targetMap, sourceFilter, jdepsMap, null, decoder).importWorkspace(context);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Map(java.util.Map) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScalaJavaLikeLanguage(com.google.idea.blaze.scala.sync.source.ScalaJavaLikeLanguage) NotNull(org.jetbrains.annotations.NotNull) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) File(java.io.File)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7