Search in sources :

Example 1 with BlazeRunConfiguration

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;
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BlazeRunConfiguration

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"));
}
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)

Example 3 with BlazeRunConfiguration

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"));
}
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)

Example 4 with BlazeRunConfiguration

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"));
}
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)

Example 5 with BlazeRunConfiguration

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);
        }
    });
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)8 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)6 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)6 PsiFile (com.intellij.psi.PsiFile)6 Test (org.junit.Test)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2