Search in sources :

Example 1 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class CoverageUtils method isApplicableTo.

public static boolean isApplicableTo(RunProfile runProfile) {
    BlazeCommandRunConfiguration config = toBlazeConfig(runProfile);
    if (config == null) {
        return false;
    }
    if (Blaze.getBuildSystem(config.getProject()) != BuildSystem.Blaze) {
        // file locations
        return false;
    }
    BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    BlazeCommandName command = handlerState.getCommandState().getCommand();
    return BlazeCommandName.TEST.equals(command) || BlazeCommandName.COVERAGE.equals(command);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName)

Example 2 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BuildTarget target = getBuildTarget(context);
    if (target == null) {
        return false;
    }
    if (!Objects.equals(configuration.getTarget(), target.label)) {
        return false;
    }
    // We don't know any details about how the various factories set up configurations from here.
    // Simply returning true at this point would be overly broad
    // (all configs with a matching target would be identified).
    // A complete equality check, meanwhile, would be too restrictive
    // (things like config name and user flags shouldn't count)
    // - not to mention we lack the equals() implementations needed to perform such a check!
    // So we compromise: if the target, suggested name, and command name match,
    // we consider it close enough. The suggested name is checked because it tends
    // to cover what the handler considers important,
    // and ignores changes the user may have made to the name.
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
    if (blazeProjectData == null) {
        return false;
    }
    BlazeCommandRunConfiguration generatedConfiguration = new BlazeCommandRunConfiguration(configuration.getProject(), configuration.getFactory(), configuration.getName());
    setupConfiguration(configuration.getProject(), blazeProjectData, generatedConfiguration, target);
    // ignore filtered test configs, produced by other configuration producers.
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState != null && handlerState.getTestFilterFlag() != null) {
        return false;
    }
    return Objects.equals(configuration.suggestedName(), generatedConfiguration.suggestedName()) && Objects.equals(configuration.getHandler().getCommandName(), generatedConfiguration.getHandler().getCommandName());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 3 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class RunConfigurationSerializerTest method testConvertAbsolutePathToWorkspacePathVariableWhenSerializing.

@Test
public void testConvertAbsolutePathToWorkspacePathVariableWhenSerializing() {
    if (isAndroidStudio()) {
        // #api171: disable for android studio -- path variable substitution isn't working in 2017.1
        return;
    }
    WorkspacePath binaryPath = WorkspacePath.createIfValid("path/to/binary/blaze");
    String absoluteBinaryPath = workspaceRoot.fileForPath(binaryPath).getPath();
    setBlazeBinaryPath(configuration, absoluteBinaryPath);
    Element element = RunConfigurationSerializer.writeToXml(configuration);
    assertThat(element.getAttribute("blaze-binary").getValue()).isEqualTo(String.format("$%s$/%s", RunConfigurationSerializer.WORKSPACE_ROOT_VARIABLE_NAME, binaryPath));
    // remove configuration from project
    clearRunManager();
    RunConfigurationSerializer.loadFromXmlElementIgnoreExisting(getProject(), element);
    RunConfiguration config = runManager.getAllConfigurations()[0];
    assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
    assertThat(getBlazeBinaryPath((BlazeCommandRunConfiguration) config)).isEqualTo(absoluteBinaryPath);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Element(org.jdom.Element) Test(org.junit.Test)

Example 4 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testProducedWhenInsideFuncallExpression.

@Test
public void testProducedWhenInsideFuncallExpression() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    assertThat(nameString).isNotNull();
    ConfigurationContext context = createContextFromPsi(nameString);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 5 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testConfigWithTestFilterIgnored.

@Test
public void testConfigWithTestFilterIgnored() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    ConfigurationContext context = createContextFromPsi(nameString);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    handlerState.getBlazeFlagsState().setRawFlags(ImmutableList.of(BlazeFlags.TEST_FILTER + "=com.google.test.SingleTestClass#"));
    assertThat(new BlazeBuildFileRunConfigurationProducer().isConfigurationFromContext(config, context)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeBuildFileRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)52 Test (org.junit.Test)36 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)29 PsiFile (com.intellij.psi.PsiFile)26 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)24 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)23 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)23 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)9 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)8 PsiClass (com.intellij.psi.PsiClass)8 PsiMethod (com.intellij.psi.PsiMethod)5 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)4 PsiDirectory (com.intellij.psi.PsiDirectory)4 Nullable (javax.annotation.Nullable)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 BlazeBuildFileRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer)3 File (java.io.File)3 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)2