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);
}
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());
}
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);
}
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);
}
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();
}
Aggregations