Search in sources :

Example 1 with BlazeSyncParams

use of com.google.idea.blaze.base.sync.BlazeSyncParams in project intellij by bazelbuild.

the class JavaSyncTest method testTestSourcesUpdateCorrectlyOnSubsequentSync.

@Test
public void testTestSourcesUpdateCorrectlyOnSubsequentSync() {
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "test_sources:", "  java/com/google/tests/*");
    VirtualFile root = workspace.createDirectory(new WorkspacePath("java/com/google"));
    VirtualFile testsDir = workspace.createDirectory(new WorkspacePath("java/com/google/tests"));
    VirtualFile moreTestsDir = workspace.createDirectory(new WorkspacePath("java/com/google/moretests"));
    BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
    runBlazeSync(syncParams);
    errorCollector.assertNoIssues();
    ContentEntry contentEntry = findContentEntry(root);
    assertThat(findSourceFolder(contentEntry, testsDir).isTestSource()).isTrue();
    assertThat(findSourceFolder(contentEntry, moreTestsDir)).isNull();
    // unmark one test source, mark another.
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "test_sources:", "  java/com/google/moretests/*");
    runBlazeSync(syncParams);
    contentEntry = findContentEntry(root);
    assertThat(findSourceFolder(contentEntry, testsDir)).isNull();
    assertThat(findSourceFolder(contentEntry, moreTestsDir).isTestSource()).isTrue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 2 with BlazeSyncParams

use of com.google.idea.blaze.base.sync.BlazeSyncParams in project intellij by bazelbuild.

the class JavaSyncTest method testSimpleTestSourcesIdentified.

@Test
public void testSimpleTestSourcesIdentified() {
    setProjectView("directories:", "  java/com/google", "  javatests/com/google", "targets:", "  //java/com/google:lib", "test_sources:", "  javatests/*");
    VirtualFile javaRoot = workspace.createDirectory(new WorkspacePath("java/com/google"));
    VirtualFile javatestsRoot = workspace.createDirectory(new WorkspacePath("javatests/com/google"));
    BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
    runBlazeSync(syncParams);
    errorCollector.assertNoIssues();
    ImmutableList<ContentEntry> contentEntries = getWorkspaceContentEntries();
    assertThat(contentEntries).hasSize(2);
    assertThat(findContentEntry(javaRoot)).isNotNull();
    assertThat(findContentEntry(javaRoot).getSourceFolders()).hasLength(1);
    assertThat(findContentEntry(javaRoot).getSourceFolders()[0].isTestSource()).isFalse();
    assertThat(findContentEntry(javatestsRoot)).isNotNull();
    assertThat(findContentEntry(javatestsRoot).getSourceFolders()).hasLength(1);
    assertThat(findContentEntry(javatestsRoot).getSourceFolders()[0].isTestSource()).isTrue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 3 with BlazeSyncParams

use of com.google.idea.blaze.base.sync.BlazeSyncParams in project intellij by bazelbuild.

the class JavaSyncTest method testTestSourceRelativePackagePrefixCalculation.

@Test
public void testTestSourceRelativePackagePrefixCalculation() {
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "test_sources:", "  java/com/google/tests/*");
    VirtualFile javatestsRoot = workspace.createDirectory(new WorkspacePath("java/com/google/tests"));
    BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
    runBlazeSync(syncParams);
    errorCollector.assertNoIssues();
    ContentEntry root = findContentEntry(javatestsRoot.getParent());
    SourceFolder rootSource = findSourceFolder(root, javatestsRoot.getParent());
    assertThat(rootSource.isTestSource()).isFalse();
    assertThat(rootSource.getPackagePrefix()).isEqualTo("com.google");
    SourceFolder childTestSource = findSourceFolder(root, javatestsRoot);
    assertThat(childTestSource.isTestSource()).isTrue();
    assertThat(childTestSource.getPackagePrefix()).isEqualTo("com.google.tests");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 4 with BlazeSyncParams

use of com.google.idea.blaze.base.sync.BlazeSyncParams in project intellij by bazelbuild.

the class KotlinSyncTest method testKotlinClassesPresentInClassPath.

@Test
public void testKotlinClassesPresentInClassPath() {
    setProjectView("directories:", "  src/main/kotlin/com/google", "targets:", "  //src/main/kotlin/com/google:lib", "additional_languages:", "  kotlin");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName1.kt"), "package com.google;", "public class ClassWithUniqueName1 {}");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName2.kt"), "package com.google;", "public class ClassWithUniqueName2 {}");
    workspace.createDirectory(new WorkspacePath("external/com_github_jetbrains_kotlin"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/kotlin/com/google/BUILD")).setLabel("//src/main/kotlin/com/google:lib").setKind("kt_jvm_library").addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName2.scala")).setJavaInfo(JavaIdeInfo.builder())).build();
    setTargetMap(targetMap);
    BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
    runBlazeSync(syncParams);
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
    assertThat(blazeProjectData).isNotNull();
    assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
    assertThat(blazeProjectData.workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.JAVA, LanguageClass.KOTLIN)));
    BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
    assertThat(javaSyncData).isNotNull();
    List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
    assertThat(contentEntries).hasSize(1);
    BlazeContentEntry contentEntry = contentEntries.get(0);
    assertThat(contentEntry.contentRoot.getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
    assertThat(contentEntry.sources).hasSize(1);
    BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
    assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
    assertThat(sourceDir.getDirectory().getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 5 with BlazeSyncParams

use of com.google.idea.blaze.base.sync.BlazeSyncParams in project intellij by bazelbuild.

the class JavascriptSyncTest method testTestSourceChildrenAreNotAddedAsSourceFolders.

@Test
public void testTestSourceChildrenAreNotAddedAsSourceFolders() {
    TestUtils.setPlatformPrefix(getTestRootDisposable(), PlatformUtils.IDEA_PREFIX);
    // child directories of test sources are always test sources, so they should never
    // appear as separate SourceFolders.
    setProjectView("directories:", "  common/jslayout", "targets:", "  //common/jslayout/...:all", "test_sources:", "  */tests/*", "workspace_type: javascript");
    VirtualFile rootDir = workspace.createDirectory(new WorkspacePath("common/jslayout"));
    VirtualFile nestedTestDir = workspace.createDirectory(new WorkspacePath("common/jslayout/tests/foo"));
    BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
    runBlazeSync(syncParams);
    errorCollector.assertNoIssues();
    ImmutableList<ContentEntry> contentEntries = getWorkspaceContentEntries();
    assertThat(contentEntries).hasSize(1);
    SourceFolder root = findSourceFolder(contentEntries.get(0), rootDir);
    assertThat(root.isTestSource()).isFalse();
    SourceFolder child = findSourceFolder(contentEntries.get(0), nestedTestDir);
    assertThat(child).isNull();
    SourceFolder testRoot = findSourceFolder(contentEntries.get(0), nestedTestDir.getParent());
    assertThat(testRoot).isNotNull();
    assertThat(testRoot.isTestSource()).isTrue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Aggregations

WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)12 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)12 Test (org.junit.Test)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)8 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)8 ContentEntry (com.intellij.openapi.roots.ContentEntry)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 SourceFolder (com.intellij.openapi.roots.SourceFolder)6 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 BlazeJavaSyncData (com.google.idea.blaze.java.sync.model.BlazeJavaSyncData)3 BlazeSourceDirectory (com.google.idea.blaze.java.sync.model.BlazeSourceDirectory)3 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)2