Search in sources :

Example 36 with BlazeJavaImportResult

use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult 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 37 with BlazeJavaImportResult

use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method testExcludeTarget.

/*
   * Test the exclude_target section
   */
@Test
public void testExcludeTarget() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example")))).add(ListSection.builder(ExcludeTargetSection.KEY).add(Label.create("//java/apps/example:example"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example").setBuildFile(source("java/apps/example/BUILD")).setKind("java_library").addSource(source("java/apps/example/Example.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("example.jar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.javaSourceFiles).isEmpty();
}
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) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 38 with BlazeJavaImportResult

use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method testImportAsLibraryTagLegacy.

@Test
public void testImportAsLibraryTagLegacy() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("lib"))).add(DirectoryEntry.include(new WorkspacePath("lib2")))).build();
    TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//lib:lib").setBuildFile(source("lib/BUILD")).setKind("java_library").addSource(source("lib/Lib.java")).addDependency("//lib2:lib2").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("lib/lib.jar")).setClassJar(gen("lib/lib.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//lib2:lib2").setBuildFile(source("lib2/BUILD")).setKind("java_library").addSource(source("lib2/Lib2.java")).addTag("aswb-import-as-library").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("lib2/lib2.jar")).setClassJar(gen("lib2/lib2.jar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, response, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.libraries).hasSize(1);
}
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) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 39 with BlazeJavaImportResult

use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method testTargetWithMixedGeneratedSourcesAddsFilteredGenJar.

@Test
public void testTargetWithMixedGeneratedSourcesAddsFilteredGenJar() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("import")))).build();
    TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//import:lib").setBuildFile(source("import/BUILD")).setKind("java_library").addSource(source("import/Import.java")).addSource(gen("import/Import.java")).setJavaInfo(JavaIdeInfo.builder().setFilteredGenJar(LibraryArtifact.builder().setInterfaceJar(gen("import/filtered-gen.jar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, response, projectView);
    errorCollector.assertNoIssues();
    assertThat(findLibrary(result.libraries, "filtered-gen.jar")).isNotNull();
}
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) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 40 with BlazeJavaImportResult

use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.

the class JavaSourceFolderProviderTest method testRelativePackagePrefixWithoutParentPrefix.

@Test
public void testRelativePackagePrefixWithoutParentPrefix() {
    ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java").addSource(BlazeSourceDirectory.builder("/src/workspace/java").setPackagePrefix("").build()).build());
    JavaSourceFolderProvider provider = new JavaSourceFolderProvider(new BlazeJavaSyncData(new BlazeJavaImportResult(contentEntries, ImmutableMap.of(), ImmutableList.of(), ImmutableSet.of(), null), new GlobSet(ImmutableList.of())));
    VirtualFile root = workspace.createDirectory(new WorkspacePath("java"));
    ContentEntry contentEntry = getContentEntry(root);
    ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry);
    assertThat(sourceFolders).hasSize(1);
    VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("java/apps/tests"));
    SourceFolder testSourceChild = provider.setSourceFolderForLocation(contentEntry, sourceFolders.get(new File(root.getPath())), new File(testRoot.getPath()), true);
    assertThat(testSourceChild.isTestSource()).isTrue();
    assertThat(testSourceChild.getPackagePrefix()).isEqualTo("apps.tests");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) SourceFolder(com.intellij.openapi.roots.SourceFolder) GlobSet(com.google.idea.blaze.base.projectview.section.Glob.GlobSet) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Aggregations

BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)44 Test (org.junit.Test)42 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)39 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)38 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)32 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)7 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)7 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)5 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)5 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)5 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)5 BlazeJavaSyncData (com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)4 JavaWorkingSet (com.google.idea.blaze.java.sync.workingset.JavaWorkingSet)4 File (java.io.File)4 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)3 Glob (com.google.idea.blaze.base.projectview.section.Glob)3 GlobSet (com.google.idea.blaze.base.projectview.section.Glob.GlobSet)3 WorkingSet (com.google.idea.blaze.base.sync.workspace.WorkingSet)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)2