use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class QualifiedClassNameHeuristicTest method testDoesNotMatchQualifiedClassNameWithAdditionalPathPrefix.
@Test
public void testDoesNotMatchQualifiedClassNameWithAdditionalPathPrefix() {
PsiFile psiFile = workspace.createPsiFile(new WorkspacePath("com/google/lib/JavaClass.java"), "package com.google.lib;", "public class JavaClass {}");
File file = new File(psiFile.getVirtualFile().getPath());
TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:foo.com.google.lib.JavaClass").setKind("java_test").build().toTargetInfo();
assertThat(new QualifiedClassNameHeuristic().matchesSource(getProject(), target, psiFile, file, null)).isFalse();
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducer method getTestLocation.
@Nullable
private static TestLocation getTestLocation(ConfigurationContext context) {
if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
// handled by a different producer
return null;
}
PsiElement location = context.getPsiLocation();
if (location instanceof PsiDirectory) {
PsiDirectory dir = (PsiDirectory) location;
TargetInfo target = getTestTargetIfUnique(dir);
return target != null ? TestLocation.fromDirectory(target, dir) : null;
}
Set<PsiClass> testClasses = selectedTestClasses(context);
if (testClasses.size() < 2) {
return null;
}
TargetInfo target = getTestTargetIfUnique(testClasses);
if (target == null) {
return null;
}
testClasses = ProducerUtils.includeInnerTestClasses(testClasses);
return TestLocation.fromClasses(target, testClasses);
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeKotlinTestClassConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation testLocation = TestLocation.from(context);
if (testLocation == null) {
return false;
}
sourceElement.set(testLocation.getSourceElement());
TargetInfo targetInfo = testLocation.getTargetInfo();
if (targetInfo == null) {
return false;
}
configuration.setTargetInfo(targetInfo);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
String testFilter = testLocation.getTestFilterFlag();
if (testFilter != null) {
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(testFilter);
handlerState.getBlazeFlagsState().setRawFlags(flags);
}
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(testLocation.getDisplayName());
configuration.setName(nameBuilder.build());
configuration.setNameChangedByUser(true);
return true;
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeIntellijPluginConfiguration method checkConfiguration.
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
super.checkConfiguration();
Label label = getTarget();
if (label == null) {
throw new RuntimeConfigurationError("Select a target to run");
}
TargetInfo target = TargetFinder.findTargetInfo(getProject(), label);
if (target == null) {
throw new RuntimeConfigurationError("The selected target does not exist.");
}
if (!IntellijPluginRule.isPluginTarget(target)) {
throw new RuntimeConfigurationError("The selected target is not an intellij_plugin");
}
if (!IdeaJdkHelper.isIdeaJdk(pluginSdk)) {
throw new RuntimeConfigurationError("Select an IntelliJ Platform Plugin SDK");
}
}
use of com.google.idea.blaze.base.dependencies.TargetInfo 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());
}
Aggregations