Search in sources :

Example 36 with TargetInfo

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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Test(org.junit.Test)

Example 37 with TargetInfo

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);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiDirectory(com.intellij.psi.PsiDirectory) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 38 with TargetInfo

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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)

Example 39 with TargetInfo

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");
    }
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) Label(com.google.idea.blaze.base.model.primitives.Label) JLabel(javax.swing.JLabel) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 40 with TargetInfo

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

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5