Search in sources :

Example 1 with GlobSet

use of com.google.idea.blaze.base.projectview.section.Glob.GlobSet 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 2 with GlobSet

use of com.google.idea.blaze.base.projectview.section.Glob.GlobSet 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)

Example 3 with GlobSet

use of com.google.idea.blaze.base.projectview.section.Glob.GlobSet 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

WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)3 GlobSet (com.google.idea.blaze.base.projectview.section.Glob.GlobSet)3 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)3 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)3 BlazeJavaSyncData (com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)3 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 Test (org.junit.Test)3 ContentEntry (com.intellij.openapi.roots.ContentEntry)2