Search in sources :

Example 1 with TargetExpression

use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.

the class BlazeCommandRunConfiguration method updateTargetKindAsync.

/**
 * Queries the kind of the current target pattern, possibly asynchronously.
 *
 * @param asyncCallback if the kind is updated asynchronously, this will be run after the kind is
 *     updated. If it's updated synchronously, this will not be run.
 */
void updateTargetKindAsync(@Nullable Runnable asyncCallback) {
    TargetExpression expr = parseTarget(targetPattern);
    if (!(expr instanceof Label)) {
        updateTargetKind(null);
        return;
    }
    Label label = (Label) expr;
    ListenableFuture<TargetInfo> future = TargetFinder.findTargetInfoFuture(getProject(), label);
    if (future.isDone()) {
        updateTargetKind(FuturesUtil.getIgnoringErrors(future));
    } else {
        updateTargetKind(null);
        future.addListener(() -> {
            updateTargetKind(FuturesUtil.getIgnoringErrors(future));
            if (asyncCallback != null) {
                asyncCallback.run();
            }
        }, MoreExecutors.directExecutor());
    }
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 2 with TargetExpression

use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.

the class BlazeCommandRunConfiguration method getTargetKindName.

/**
 * @return The {@link Kind} name, if the target is a known rule. Otherwise, "target pattern" if it
 *     is a general {@link TargetExpression}, "unknown rule" if it is a {@link Label} without a
 *     known rule, and "unknown target" if there is no target.
 */
private String getTargetKindName() {
    Kind kind = targetKind;
    if (kind != null) {
        return kind.toString();
    }
    TargetExpression target = parseTarget(targetPattern);
    if (target instanceof Label) {
        return "unknown rule";
    } else if (target != null) {
        return "target pattern";
    } else {
        return "unknown target";
    }
}
Also used : Kind(com.google.idea.blaze.base.model.primitives.Kind) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 3 with TargetExpression

use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.

the class BlazeRunConfigurationSyncListener method labelsWithConfigs.

/**
 * Collects a set of all the Blaze labels that have an associated run configuration.
 */
private static Set<Label> labelsWithConfigs(Project project) {
    List<RunConfiguration> configurations = RunManager.getInstance(project).getAllConfigurationsList();
    Set<Label> labelsWithConfigs = Sets.newHashSet();
    for (RunConfiguration configuration : configurations) {
        if (configuration instanceof BlazeRunConfiguration) {
            BlazeRunConfiguration blazeRunConfiguration = (BlazeRunConfiguration) configuration;
            TargetExpression target = blazeRunConfiguration.getTarget();
            if (target instanceof Label) {
                labelsWithConfigs.add((Label) target);
            }
        }
    }
    return labelsWithConfigs;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 4 with TargetExpression

use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.

the class WildcardTargetPatternTest method testRecursiveWildcardPatternAllTargets.

@Test
public void testRecursiveWildcardPatternAllTargets() {
    TargetExpression target = TargetExpression.fromStringSafe("//java/com/google/...:all-targets");
    WildcardTargetPattern wildcardPattern = WildcardTargetPattern.fromExpression(target);
    assertThat(wildcardPattern).isNotNull();
    assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google"))).isTrue();
    assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google/foo"))).isTrue();
    assertThat(wildcardPattern.isRecursive()).isTrue();
    assertThat(wildcardPattern.getBasePackage()).isEqualTo(new WorkspacePath("java/com/google"));
    assertThat(wildcardPattern.rulesOnly()).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WildcardTargetPattern(com.google.idea.blaze.base.model.primitives.WildcardTargetPattern) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Example 5 with TargetExpression

use of com.google.idea.blaze.base.model.primitives.TargetExpression in project intellij by bazelbuild.

the class WildcardTargetPatternTest method testNonRecursiveAllTargetsWildcardPattern.

@Test
public void testNonRecursiveAllTargetsWildcardPattern() {
    TargetExpression target = TargetExpression.fromStringSafe("//java/com/google:*");
    WildcardTargetPattern wildcardPattern = WildcardTargetPattern.fromExpression(target);
    assertThat(wildcardPattern).isNotNull();
    assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google"))).isTrue();
    assertThat(wildcardPattern.coversPackage(new WorkspacePath("java/com/google/foo"))).isFalse();
    assertThat(wildcardPattern.isRecursive()).isFalse();
    assertThat(wildcardPattern.getBasePackage()).isEqualTo(new WorkspacePath("java/com/google"));
    assertThat(wildcardPattern.rulesOnly()).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WildcardTargetPattern(com.google.idea.blaze.base.model.primitives.WildcardTargetPattern) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Aggregations

TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)31 Test (org.junit.Test)11 WildcardTargetPattern (com.google.idea.blaze.base.model.primitives.WildcardTargetPattern)10 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)8 File (java.io.File)6 Label (com.google.idea.blaze.base.model.primitives.Label)5 ImmutableList (com.google.common.collect.ImmutableList)3 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)2 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)2 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)2 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2