Search in sources :

Example 11 with BlazeJavaImportResult

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

the class BlazeJavaWorkspaceImporterTest method testEmptyProject.

/**
 * Ensure an empty response results in an empty import result.
 */
@Test
public void testEmptyProject() {
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, TargetMapBuilder.builder(), ProjectView.builder().build());
    errorCollector.assertNoIssues();
    assertThat(result.contentEntries).isEmpty();
}
Also used : BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) Test(org.junit.Test)

Example 12 with BlazeJavaImportResult

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

the class BlazeJavaWorkspaceImporterTest method testNormalJavaLibraryPackage.

/*
   * Test that the non-android libraries can be imported.
   */
@Test
public void testNormalJavaLibraryPackage() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("java/library/something")))).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")).setJavaInfo(JavaIdeInfo.builder()).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).addDependency("//java/library/something:something")).addTarget(TargetIdeInfo.builder().setLabel("//java/library/something:something").setBuildFile(source("java/library/something/BUILD")).setKind("java_library").addSource(source("java/library/something/SomeJavaFile.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/library/something/something.jar")).setClassJar(gen("java/library/something/something.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/java/library/something").addSource(BlazeSourceDirectory.builder("/root/java/library/something").setPackagePrefix("library.something").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) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 13 with BlazeJavaImportResult

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

the class BlazeJavaWorkspaceImporterTest method testJarsGeneratedFromProjectSourcesExcluded.

@Test
public void testJarsGeneratedFromProjectSourcesExcluded() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("thirdparty")))).build();
    TargetMapBuilder targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("java_library").addSource(source("java/apps/example/Test.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/a:a")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty:jars").setKind("java_library").addSource(source("thirdparty/Other.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("thirdparty/a.jar"))).addJar(LibraryArtifact.builder().setClassJar(gen("thirdparty/c.jar")))).build());
    jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/apps/example:example_debug")), Lists.newArrayList(jdepsPath("thirdparty/a.jar"), jdepsPath("thirdparty/c.jar")));
    BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMap, projectView);
    assertThat(result.libraries).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 14 with BlazeJavaImportResult

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

the class JavaSourceFolderProviderTest method testInitializeSourceFolders.

@Test
public void testInitializeSourceFolders() {
    ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java/apps").addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps").setPackagePrefix("apps").build()).addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps/gen").setPackagePrefix("apps.gen").setGenerated(true).build()).addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps/resources").setPackagePrefix("apps.resources").setResource(true).build()).build(), BlazeContentEntry.builder("/src/workspace/javatests/apps/example").addSource(BlazeSourceDirectory.builder("/src/workspace/javatests/apps/example").setPackagePrefix("apps.example").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/apps"));
    VirtualFile gen = workspace.createDirectory(new WorkspacePath("java/apps/gen"));
    VirtualFile res = workspace.createDirectory(new WorkspacePath("java/apps/resources"));
    ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(getContentEntry(root));
    assertThat(sourceFolders).hasSize(3);
    SourceFolder rootSource = sourceFolders.get(new File(root.getPath()));
    assertThat(rootSource.getPackagePrefix()).isEqualTo("apps");
    assertThat(JavaSourceFolderProvider.isGenerated(rootSource)).isFalse();
    assertThat(JavaSourceFolderProvider.isResource(rootSource)).isFalse();
    SourceFolder genSource = sourceFolders.get(new File(gen.getPath()));
    assertThat(genSource.getPackagePrefix()).isEqualTo("apps.gen");
    assertThat(JavaSourceFolderProvider.isGenerated(genSource)).isTrue();
    assertThat(JavaSourceFolderProvider.isResource(genSource)).isFalse();
    SourceFolder resSource = sourceFolders.get(new File(res.getPath()));
    assertThat(JavaSourceFolderProvider.isGenerated(resSource)).isFalse();
    assertThat(JavaSourceFolderProvider.isResource(resSource)).isTrue();
    VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("javatests/apps/example"));
    sourceFolders = provider.initializeSourceFolders(getContentEntry(testRoot));
    assertThat(sourceFolders).hasSize(1);
    assertThat(sourceFolders.get(new File(testRoot.getPath())).getPackagePrefix()).isEqualTo("apps.example");
}
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) 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)

Example 15 with BlazeJavaImportResult

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

the class JavaSourceFolderProviderTest method testRelativePackagePrefix.

@Test
public void testRelativePackagePrefix() {
    ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java/apps").addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps").setPackagePrefix("apps").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/apps"));
    ContentEntry contentEntry = getContentEntry(root);
    ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry);
    assertThat(sourceFolders).hasSize(1);
    VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("java/apps/tests/model"));
    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.model");
}
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