Search in sources :

Example 31 with BlazeCommandRunConfigurationCommonState

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

the class BlazeScalaMainClassRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    ScObject mainObject = getMainObject(context);
    if (mainObject == null) {
        return false;
    }
    Option<PsiMethod> mainMethod = ScalaMainMethodUtil.findMainMethod(mainObject);
    if (mainMethod.isEmpty()) {
        sourceElement.set(mainObject);
    } else {
        sourceElement.set(mainMethod.get());
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainObject);
    if (target == null) {
        return false;
    }
    configuration.setTargetInfo(target.toTargetInfo());
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiMethod(com.intellij.psi.PsiMethod) ScObject(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject)

Example 32 with BlazeCommandRunConfigurationCommonState

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

the class BlazeScalaMainClassRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN)) {
        return false;
    }
    ScObject mainObject = getMainObject(context);
    if (mainObject == null) {
        return false;
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainObject);
    return target != null && Objects.equals(configuration.getTarget(), target.key.label);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ScObject(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject)

Example 33 with BlazeCommandRunConfigurationCommonState

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

the class BlazePyBinaryConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null || !BlazeCommandName.RUN.equals(handlerState.getCommandState().getCommand())) {
        return false;
    }
    Location<?> location = context.getLocation();
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiFile file = element.getContainingFile();
    if (!(file instanceof PyFile)) {
        return false;
    }
    TargetInfo binaryTarget = getTargetLabel(file);
    if (binaryTarget == null) {
        return false;
    }
    return binaryTarget.label.equals(configuration.getTarget());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 34 with BlazeCommandRunConfigurationCommonState

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

the class BlazePyTestConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiElement element = selectedPsiElement(context);
    if (element == null) {
        return false;
    }
    PsiFile file = element.getContainingFile();
    if (!(file instanceof PyFile) || !PyTestUtils.isTestFile((PyFile) file)) {
        return false;
    }
    TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
    if (testTarget == null) {
        return false;
    }
    configuration.setTargetInfo(testTarget);
    TestLocation testLocation = testLocation(element);
    sourceElement.set(testLocation.sourceElement(file));
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    // remove conflicting flags from initial configuration
    List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
    flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
    String filter = testLocation.testFilter();
    if (filter != null) {
        flags.add(BlazeFlags.TEST_FILTER + "=" + filter);
    }
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(filter != null ? String.format("%s (%s)", filter, testTarget.label.toString()) : testTarget.label.toString());
    configuration.setName(nameBuilder.build());
    // don't revert to generated name
    configuration.setNameChangedByUser(true);
    return true;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 35 with BlazeCommandRunConfigurationCommonState

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

the class AllInPackageBlazeConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiDirectory dir = getTestDirectory(context);
    if (dir == null) {
        return false;
    }
    WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
    WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
    if (packagePath == null) {
        return false;
    }
    sourceElement.set(dir);
    configuration.setTarget(TargetExpression.allFromPackageRecursive(packagePath));
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    configuration.setGeneratedName();
    return true;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Aggregations

BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)52 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)9 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)8 PsiFile (com.intellij.psi.PsiFile)8 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 PsiElement (com.intellij.psi.PsiElement)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)5 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 PsiMethod (com.intellij.psi.PsiMethod)4 PyFile (com.jetbrains.python.psi.PyFile)4 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)3 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)3 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 PsiClass (com.intellij.psi.PsiClass)3 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2