Search in sources :

Example 16 with Label

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

the class BlazeRenderErrorContributorTest method createTargetMapWithMissingClassDependency.

private void createTargetMapWithMissingClassDependency() {
    Label parentTarget = Label.create("//com/google/example:app");
    Label independentLibraryTarget = Label.create("//com/google/example/independent:library");
    Label independentLibrary2Target = Label.create("//com/google/example/independent:library2");
    Label dependentLibraryTarget = Label.create("//com/google/example/dependent:library");
    Label resourcesTarget = Label.create("//com/google/example:resources");
    ArtifactLocation manifest = artifact("com/google/example/AndroidManifest.xml", true);
    ArtifactLocation resources = artifact("com/google/example/res", true);
    ArtifactLocation buildFile = artifact("com/google/example/BUILD", true);
    AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
    registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(resourcesTarget)).addResource(resources).build());
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(parentTarget).setBuildFile(buildFile).addDependency(independentLibraryTarget).addDependency(resourcesTarget)).addTarget(TargetIdeInfo.builder().setLabel(independentLibraryTarget).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder()).addDependency(independentLibrary2Target)).addTarget(TargetIdeInfo.builder().setLabel(independentLibrary2Target).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder())).addTarget(TargetIdeInfo.builder().setLabel(resourcesTarget).setBuildFile(buildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(manifest).addResource(resources)).addDependency(dependentLibraryTarget)).addTarget(TargetIdeInfo.builder().setLabel(dependentLibraryTarget).setBuildFile(buildFile).setJavaInfo(JavaIdeInfo.builder())).build();
    projectDataManager.setTargetMap(targetMap);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 17 with Label

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

the class BlazeAndroidProjectStructureSyncer method getRunConfigurationTargets.

// Collect potential android run configuration targets
private static List<TargetIdeInfo> getRunConfigurationTargets(Project project, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Set<TargetKey> androidResourceModules) {
    List<TargetIdeInfo> result = Lists.newArrayList();
    Set<Label> runConfigurationModuleTargets = Sets.newHashSet();
    // Doing this now will cut down on root changes later
    for (TargetExpression targetExpression : projectViewSet.listItems(TargetSection.KEY)) {
        if (!(targetExpression instanceof Label)) {
            continue;
        }
        Label label = (Label) targetExpression;
        runConfigurationModuleTargets.add(label);
    }
    // Get any pre-existing targets
    for (RunConfiguration runConfiguration : RunManager.getInstance(project).getAllConfigurationsList()) {
        BlazeAndroidRunConfigurationHandler handler = BlazeAndroidRunConfigurationHandler.getHandlerFrom(runConfiguration);
        if (handler == null) {
            continue;
        }
        runConfigurationModuleTargets.add(handler.getLabel());
    }
    for (Label label : runConfigurationModuleTargets) {
        TargetKey targetKey = TargetKey.forPlainTarget(label);
        // If it's a resource module, it will already have been created
        if (androidResourceModules.contains(targetKey)) {
            continue;
        }
        // Ensure the label is a supported android rule that exists
        TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
        if (target == null) {
            continue;
        }
        if (!target.kindIsOneOf(Kind.ANDROID_BINARY, Kind.ANDROID_TEST)) {
            continue;
        }
        result.add(target);
    }
    return result;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeAndroidRunConfigurationHandler(com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 18 with Label

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

the class BuildFileUtils method findBuildTarget.

@Nullable
static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, File file) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    File parentFile = parentPackage.buildFile.getFile().getParentFile();
    WorkspacePath packagePath = parentFile != null ? blazeProjectData.workspacePathResolver.getWorkspacePath(parentFile) : null;
    if (packagePath == null) {
        return null;
    }
    Label label = SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(file).stream().filter(l -> l.blazePackage().equals(packagePath)).findFirst().orElse(null);
    if (label == null) {
        return null;
    }
    return BuildReferenceManager.getInstance(project).resolveLabel(label);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Label(com.google.idea.blaze.base.model.primitives.Label) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 19 with Label

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

the class CopyBlazeTargetPathAction method updateForBlazeProject.

@Override
protected void updateForBlazeProject(Project project, AnActionEvent e) {
    Label label = findTarget(project, e);
    ActionPresentationHelper.of(e).hideIf(label == null).commit();
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label)

Example 20 with Label

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

the class BlazeGoTestLocator method getGoTestTarget.

@Nullable
private static TargetIdeInfo getGoTestTarget(Project project, String path) {
    WorkspacePath targetPackage = WorkspacePath.createIfValid(PathUtil.getParentPath(path));
    if (targetPackage == null) {
        return null;
    }
    TargetName targetName = TargetName.createIfValid(PathUtil.getFileName(path));
    if (targetName == null) {
        return null;
    }
    Label label = Label.create(targetPackage, targetName);
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    TargetIdeInfo target = projectData.targetMap.get(TargetKey.forPlainTarget(label));
    if (target != null && target.kind.languageClass.equals(LanguageClass.GO) && target.kind.ruleType.equals(RuleType.TEST)) {
        return target;
    }
    return null;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) Nullable(javax.annotation.Nullable)

Aggregations

Label (com.google.idea.blaze.base.model.primitives.Label)48 File (java.io.File)15 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)8 BlazeTestResults (com.google.idea.blaze.base.run.testlogs.BlazeTestResults)7 BuildEventStreamProtos (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos)6 BlazeTestResult (com.google.idea.blaze.base.run.testlogs.BlazeTestResult)6 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent)3 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)3 SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)3