Search in sources :

Example 1 with TargetMap

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

the class FastBuildCompilerFactoryImplTest method configureTestForTargetMap.

private void configureTestForTargetMap(Map<TargetKey, TargetIdeInfo> targetMap) {
    BlazeProjectData projectData = new BlazeProjectData(0, new TargetMap(ImmutableMap.copyOf(targetMap)), null, null, null, artifact -> new File(artifact.relativePath), null, null, null);
    BlazeProjectDataManager projectDataManager = new MockBlazeProjectDataManager(projectData);
    compilerFactory = new FastBuildCompilerFactoryImpl(projectDataManager);
}
Also used : MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager)

Example 2 with TargetMap

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

the class PluginDevSyncTest method testRunConfigurationCreatedDuringSync.

@Test
public void testRunConfigurationCreatedDuringSync() throws Exception {
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "  //java/com/google:plugin", "workspace_type: intellij_plugin");
    workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName1.java"), "package com.google;", "public class ClassWithUniqueName1 {}");
    workspace.createFile(new WorkspacePath("java/com/google/ClassWithUniqueName2.java"), "package com.google;", "public class ClassWithUniqueName2 {}");
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("java_library").addSource(sourceRoot("java/com/google/ClassWithUniqueName1.java")).addSource(sourceRoot("java/com/google/ClassWithUniqueName2.java"))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:plugin").setKind("intellij_plugin_debug_target")).build();
    setTargetMap(targetMap);
    runBlazeSync(new BlazeSyncParams.Builder("Sync", SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
    errorCollector.assertNoIssues();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
    assertThat(blazeProjectData).isNotNull();
    assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
    assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.INTELLIJ_PLUGIN);
    List<RunConfiguration> runConfigs = RunManager.getInstance(getProject()).getAllConfigurationsList();
    assertThat(runConfigs).hasSize(1);
    assertThat(runConfigs.get(0)).isInstanceOf(BlazeIntellijPluginConfiguration.class);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 3 with TargetMap

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

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

the class AndroidSyncTest method testSimpleSync.

@Test
public void testSimpleSync() throws Exception {
    setProjectView("directories:", "  java/com/google", "targets:", "  //java/com/google:lib", "android_sdk_platform: android-25");
    workspace.createFile(new WorkspacePath("java/com/google/Source.java"), "package com.google;", "public class Source {}");
    workspace.createFile(new WorkspacePath("java/com/google/Other.java"), "package com.google;", "public class Other {}");
    VirtualFile javaRoot = workspace.createDirectory(new WorkspacePath("java/com/google"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("java/com/google/BUILD")).setLabel("//java/com/google:lib").setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(sourceRoot("java/com/google/AndroidManifest.xml")).addResource(sourceRoot("java/com/google/res/values/strings.xml")).setResourceJavaPackage("com.google").setGenerateResourceClass(true)).addSource(sourceRoot("java/com/google/Source.java")).addSource(sourceRoot("java/com/google/Other.java"))).build();
    setTargetMap(targetMap);
    runBlazeSync(new BlazeSyncParams.Builder("Sync", SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
    errorCollector.assertNoIssues();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
    assertThat(blazeProjectData).isNotNull();
    assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
    assertThat(blazeProjectData.workspaceLanguageSettings.getWorkspaceType()).isEqualTo(WorkspaceType.ANDROID);
    ImmutableList<ContentEntry> contentEntries = getWorkspaceContentEntries();
    assertThat(contentEntries).hasSize(1);
    assertThat(findContentEntry(javaRoot)).isNotNull();
    assertThat(findContentEntry(javaRoot).getSourceFolders()).hasLength(1);
    // Check that the workspace is set to android
    Module workspaceModule = ModuleFinder.getInstance(getProject()).findModuleByName(BlazeDataStorage.WORKSPACE_MODULE_NAME);
    assertThat(workspaceModule).isNotNull();
    assertThat(AndroidFacet.getInstance(workspaceModule)).isNotNull();
    // Check that a resource module was created
    Module resourceModule = ModuleFinder.getInstance(getProject()).findModuleByName("java.com.google.lib");
    assertThat(resourceModule).isNotNull();
    assertThat(AndroidFacet.getInstance(resourceModule)).isNotNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Module(com.intellij.openapi.module.Module) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 5 with TargetMap

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

the class BlazeBuildSystemServiceTest method createMockBlazeProjectData.

private BlazeProjectData createMockBlazeProjectData() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(Label.create("//foo:bar")).setBuildFile(ArtifactLocation.builder().setRelativePath("foo/BUILD").build()).build()).build();
    ArtifactLocationDecoder decoder = (location) -> new File("/", location.getRelativePath());
    return MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(targetMap).setArtifactLocationDecoder(decoder).build();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) MockModule(com.intellij.mock.MockModule) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) BlazeBuildService(com.google.idea.blaze.base.actions.BlazeBuildService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) VirtualFileSystemProvider(com.google.idea.blaze.base.io.VirtualFileSystemProvider) Module(com.intellij.openapi.module.Module) Blaze(com.google.idea.blaze.base.settings.Blaze) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) BuildReferenceManager(com.google.idea.blaze.base.lang.buildfile.references.BuildReferenceManager) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) BuildSystemService(com.android.tools.idea.project.BuildSystemService) MockVirtualFile(com.intellij.mock.MockVirtualFile) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) Mockito.mock(org.mockito.Mockito.mock) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) LazyRangeMarkerFactory(com.intellij.openapi.editor.LazyRangeMarkerFactory) RunWith(org.junit.runner.RunWith) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ArgumentCaptor(org.mockito.ArgumentCaptor) BlazeSyncManager(com.google.idea.blaze.base.sync.BlazeSyncManager) PsiElement(com.intellij.psi.PsiElement) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) PsiFile(com.intellij.psi.PsiFile) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) LazyRangeMarkerFactoryImpl(com.intellij.openapi.editor.impl.LazyRangeMarkerFactoryImpl) Nullable(javax.annotation.Nullable) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) TempFileSystem(com.intellij.openapi.vfs.ex.temp.TempFileSystem) Label(com.google.idea.blaze.base.model.primitives.Label) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7