use of com.google.idea.blaze.base.run.BlazeRunConfiguration in project intellij by bazelbuild.
the class RunConfigurationSerializer method shouldLoadConfiguration.
/**
* Returns true if there's either no matching configuration already in the project, or the
* matching configuration is marked as 'keep in sync'.
*/
@VisibleForTesting
static boolean shouldLoadConfiguration(Project project, Element element) throws InvalidDataException {
RunnerAndConfigurationSettings existing = findExisting(project, element);
if (existing == null) {
return true;
}
RunConfiguration config = existing.getConfiguration();
if (!(config instanceof BlazeRunConfiguration)) {
// always overwrite non-blaze run configurations
return true;
}
BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
Boolean keepInSync = blazeConfig.getKeepInSync();
if (keepInSync == null) {
// if the matching configuration was never previously imported, don't overwrite, but activate
// the UI option to keep it in sync.
blazeConfig.setKeepInSync(false);
return false;
}
return keepInSync;
}
use of com.google.idea.blaze.base.run.BlazeRunConfiguration in project intellij by bazelbuild.
the class BlazeJavaMainClassConfigurationProducerTest method testJavaBinaryWithMatchingMainClassChosen.
@Test
public void testJavaBinaryWithMatchingMainClassChosen() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.java")).build()).addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//com/google/binary:OtherName").setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).addSource(sourceRoot("com/google/binary/MainClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiFile javaClass = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.java"), "package com.google.binary;", "import java.lang.String;", "public class MainClass {", " public static void main(java.lang.String[] args) {}", "}");
RunConfiguration config = createConfigurationFromLocation(javaClass);
assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:OtherName"));
}
use of com.google.idea.blaze.base.run.BlazeRunConfiguration 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"));
}
use of com.google.idea.blaze.base.run.BlazeRunConfiguration 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.run.BlazeRunConfiguration in project intellij by bazelbuild.
the class RunConfigurationSerializer method loadFromXmlElementIgnoreExisting.
/**
* Parses a RunConfiguration from the given XML element, and adds it to the project, if there's
* not already a run configuration with the same name and type,
*/
@VisibleForTesting
static void loadFromXmlElementIgnoreExisting(Project project, Element element) throws InvalidDataException {
if (!shouldLoadConfiguration(project, element)) {
return;
}
runWithPathVariableSet(project, () -> {
RunnerAndConfigurationSettings settings = RunManagerImpl.getInstanceImpl(project).loadConfiguration(element, false);
RunConfiguration config = settings != null ? settings.getConfiguration() : null;
if (config instanceof BlazeRunConfiguration) {
((BlazeRunConfiguration) config).setKeepInSync(true);
}
});
}
Aggregations