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());
}
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();
}
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);
}
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();
}
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");
}
Aggregations