Search in sources :

Example 41 with TargetMapBuilder

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

the class BlazeJavaWorkspaceImporterTest method testLibraryWithSourceJar.

/**
 * Test library with a source jar
 */
@Test
public void testLibraryWithSourceJar() {
    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")))).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(gen("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).addDependency("//thirdparty/some/library:library").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("//thirdparty/some/library:library").setBuildFile(source("/thirdparty/some/library/BUILD")).setKind("java_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/some/library.jar")).setClassJar(gen("thirdparty/some/library.jar")).addSourceJar(gen("thirdparty/some/library.srcjar")))));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    BlazeJarLibrary library = findLibrary(result.libraries, "library.jar");
    assertNotNull(library);
    assertThat(library.libraryArtifact.sourceJars).isNotEmpty();
}
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) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 42 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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 43 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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 44 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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 45 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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)

Aggregations

TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)49 Test (org.junit.Test)48 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)44 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)40 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)33 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)13 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)7 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)7 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)5 WorkingSet (com.google.idea.blaze.base.sync.workspace.WorkingSet)5 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)5 JavaWorkingSet (com.google.idea.blaze.java.sync.workingset.JavaWorkingSet)5 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 BlazeResourceLibrary (com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)3 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3