use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeScalaMainClassConfigurationProducerTest method testNoScalaBinaryChosenIfNotInRDeps.
@Test
public void testNoScalaBinaryChosenIfNotInRDeps() {
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/OtherClass.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 {} }");
assertThat(createConfigurationFromLocation(scalaFile)).isNotInstanceOf(BlazeRunConfiguration.class);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeScalaMainClassConfigurationProducerTest method testScalaBinaryWithMatchingMainClassChosen.
@Test
public void testScalaBinaryWithMatchingMainClassChosen() {
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:OtherName").setJavaInfo(JavaIdeInfo.builder().setMainClass("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:OtherName"));
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class TransitiveDependencyMapTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
super.initTest(applicationServices, projectServices);
projectServices.register(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(buildTargetMap()).build()));
projectServices.register(TransitiveDependencyMap.class, new TransitiveDependencyMap(project));
transitiveDependencyMap = TransitiveDependencyMap.getInstance(project);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeRunConfigurationProducerTestCase method doSetup.
@Before
public final void doSetup() {
BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
editorTest = new EditorTestHelper(getProject(), testFixture);
// IntelliJ replaces the normal DataManager with a mock version in headless environments.
// We rely on a functional DataManager in run configuration tests to recognize when multiple
// psi elements are selected.
DataManager dataManager = new MyDataManagerImpl() {
DataContext dataContext;
@Override
public <T> void saveInDataContext(DataContext dataContext, Key<T> dataKey, @Nullable T data) {
this.dataContext = dataContext;
super.saveInDataContext(dataContext, dataKey, data);
}
@Override
public DataContext getDataContext() {
return dataContext != null ? dataContext : super.getDataContext();
}
};
registerApplicationComponent(DataManager.class, dataManager);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class TestRecorderBlazeCommandRunConfigurationTest method doSetup.
@Before
public final void doSetup() {
runManager = RunManagerImpl.getInstanceImpl(getProject());
// Without BlazeProjectData, the configuration editor is always disabled.
BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
BlazeCommandRunConfigurationHandlerProvider mockHandler = new MockBlazeAndroidBinaryRunConfigurationHandlerProvider();
ExtensionPoint<BlazeCommandRunConfigurationHandlerProvider> ep = Extensions.getRootArea().getExtensionPoint(BlazeCommandRunConfigurationHandlerProvider.EP_NAME);
ep.registerExtension(mockHandler, LoadingOrder.FIRST);
Disposer.register(getTestRootDisposable(), () -> ep.unregisterExtension(mockHandler));
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind(Kind.ANDROID_BINARY).setLabel("//label:android_binary_rule").build()).addTarget(TargetIdeInfo.builder().setKind(Kind.ANDROID_TEST).setLabel("//label:android_test_rule").build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
}
Aggregations