Search in sources :

Example 21 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeClassJarProviderIntegrationTest method doSetup.

@Before
public void doSetup() {
    module = testFixture.getModule();
    ArtifactLocationDecoder decoder = (location) -> new File("/src", location.getExecutionRootRelativePath());
    BlazeProjectData blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(buildTargetMap()).setArtifactLocationDecoder(decoder).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
    classJarProvider = new BlazeClassJarProvider(getProject());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) RunWith(org.junit.runner.RunWith) ClassJarProvider(com.android.tools.idea.model.ClassJarProvider) AndroidIntegrationTestSetupRule(com.google.idea.blaze.android.AndroidIntegrationTestSetupRule) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeIntegrationTestCase(com.google.idea.blaze.base.BlazeIntegrationTestCase) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) Module(com.intellij.openapi.module.Module) Before(org.junit.Before) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) ResourceClassRegistry(com.android.tools.idea.res.ResourceClassRegistry) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) IOException(java.io.IOException) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FacetManager(com.intellij.facet.FacetManager) AndroidFacetConfiguration(org.jetbrains.android.facet.AndroidFacetConfiguration) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) Label(com.google.idea.blaze.base.model.primitives.Label) ApplicationManager(com.intellij.openapi.application.ApplicationManager) 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) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Example 22 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeGoRootsProviderTest method testPackageToTargetMap.

@Test
public void testPackageToTargetMap() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).addSource(src("one/two/three/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"), src("one/two/three/library.go"))).setImportPath("prefix/one/two/library"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, null, null, new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
    assertThat(BlazeGoRootsProvider.getPackageToTargetMap(getProject())).containsExactly("prefix/foo/bar/binary", TargetKey.forPlainTarget(Label.create("//foo/bar:binary")), "prefix/one/two/library", TargetKey.forPlainTarget(Label.create("//one/two:library")));
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 23 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeGoTestConfigurationProducerTest method testProducedFromTestCase.

@Test
public void testProducedFromTestCase() {
    PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_test").setLabel("//foo/bar:foo_test").addSource(sourceRoot("foo/bar/foo_test.go")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    List<GoFunctionDeclaration> functions = PsiUtils.findAllChildrenOfClassRecursive(goFile, GoFunctionDeclaration.class);
    assertThat(functions).hasSize(1);
    GoFunctionDeclaration function = functions.get(0);
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeGoTestConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//foo/bar:foo_test"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=^TestFoo$");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 24 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testNoResultForObjectWithoutMainMethod.

@Test
public void testNoResultForObjectWithoutMainMethod() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary { object MainClass {} }", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    assertThat(createConfigurationFromLocation(scalaFile)).isNull();
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 25 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testScalaBinaryWithMatchingNameChosen.

@Test
public void testScalaBinaryWithMatchingNameChosen() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", "  object MainClass {", "    def main(args: Array[String]) {}", "  }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    RunConfiguration config = createConfigurationFromLocation(scalaFile);
    assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
    BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
    assertThat(blazeConfig).isNotNull();
    assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:MainClass"));
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Aggregations

MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)68 Test (org.junit.Test)48 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)43 PsiFile (com.intellij.psi.PsiFile)37 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)27 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)23 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)21 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)14 Before (org.junit.Before)14 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)13 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)10 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 PsiClass (com.intellij.psi.PsiClass)7 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)6 WorkspacePathResolverImpl (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl)5 PsiDirectory (com.intellij.psi.PsiDirectory)5 GoFile (com.goide.psi.GoFile)4 EditorTestHelper (com.google.idea.blaze.base.EditorTestHelper)4