Search in sources :

Example 36 with BlazeProjectData

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

the class FastBuildCompilerFactoryImpl method getJavacJar.

private File getJavacJar(TargetIdeInfo targetIdeInfo) throws FastBuildException {
    BlazeProjectData projectData = projectDataManager.getBlazeProjectData();
    checkState(projectData != null, "not a blaze project");
    List<JavaToolchainIdeInfo> javaToolchains = new ArrayList<>();
    for (Dependency dependency : targetIdeInfo.dependencies) {
        TargetIdeInfo depInfo = projectData.targetMap.get(dependency.targetKey);
        if (depInfo != null && depInfo.javaToolchainIdeInfo != null) {
            javaToolchains.add(depInfo.javaToolchainIdeInfo);
        }
    }
    if (javaToolchains.isEmpty()) {
        throw new FastBuildException("Couldn't find a Java toolchain for target " + targetIdeInfo.key.label);
    }
    if (javaToolchains.size() > 1) {
        throw new FastBuildException("Found multiple Java toolchains for target " + targetIdeInfo.key.label);
    }
    return projectData.artifactLocationDecoder.decode(javaToolchains.get(0).javacJar);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) JavaToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArrayList(java.util.ArrayList) Dependency(com.google.idea.blaze.base.ideinfo.Dependency)

Example 37 with BlazeProjectData

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

the class BlazeCreateResourceUtils method setupResDirectoryChoices.

static void setupResDirectoryChoices(Project project, @Nullable VirtualFile contextFile, JBLabel resDirLabel, ComboboxWithBrowseButton resDirComboAndBrowser) {
    // Reset the item list before filling it back up.
    resDirComboAndBrowser.getComboBox().removeAllItems();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData != null) {
        BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
        if (syncData != null) {
            ImmutableCollection<TargetKey> rulesRelatedToContext = null;
            File fileFromContext = null;
            if (contextFile != null) {
                fileFromContext = VfsUtilCore.virtualToIoFile(contextFile);
                rulesRelatedToContext = SourceToTargetMap.getInstance(project).getRulesForSourceFile(fileFromContext);
                if (rulesRelatedToContext.isEmpty()) {
                    rulesRelatedToContext = null;
                }
            }
            ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
            // Sort:
            // - contextFile/res if contextFile is a directory,
            // to optimize the right click on directory case, or the "closest" string
            // match to the contextFile from the res directories known to blaze
            // - the rest of the direct dirs, then transitive dirs of the context rules,
            // then any known res dir in the project
            // as a backup, in alphabetical order.
            Set<File> resourceDirs = Sets.newTreeSet();
            Set<File> transitiveDirs = Sets.newTreeSet();
            Set<File> allResDirs = Sets.newTreeSet();
            for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
                Collection<File> resources = artifactLocationDecoder.decodeAll(androidResourceModule.resources);
                Collection<File> transitiveResources = artifactLocationDecoder.decodeAll(androidResourceModule.transitiveResources);
                // labelsRelatedToContext should include deps,
                // but as a first pass we only check the rules themselves
                // for resources. If we come up empty, then have anyResDir as a backup.
                allResDirs.addAll(transitiveResources);
                if (rulesRelatedToContext != null && !rulesRelatedToContext.contains(androidResourceModule.targetKey)) {
                    continue;
                }
                resourceDirs.addAll(resources);
                transitiveDirs.addAll(transitiveResources);
            }
            // No need to show some directories twice.
            transitiveDirs.removeAll(resourceDirs);
            JComboBox resDirCombo = resDirComboAndBrowser.getComboBox();
            // Allow the user to browse and overwrite some of the entries,
            // in case our inference is wrong.
            resDirCombo.setEditable(true);
            // After the use confirms the choice, a directory will be created if it is missing.
            if (fileFromContext != null && fileFromContext.isDirectory()) {
                File closestDirToContext = new File(fileFromContext.getPath(), "res");
                resDirCombo.setSelectedItem(closestDirToContext);
            } else {
                // If we're not completely sure, let people know there are options
                // via the placeholder text, and put the most likely on top.
                String placeHolder = PLACEHOLDER_TEXT;
                resDirCombo.addItem(placeHolder);
                resDirCombo.setSelectedItem(placeHolder);
                if (fileFromContext != null) {
                    File closestDirToContext = findClosestDirToContext(fileFromContext.getPath(), resourceDirs);
                    closestDirToContext = closestDirToContext != null ? closestDirToContext : findClosestDirToContext(fileFromContext.getPath(), transitiveDirs);
                    if (closestDirToContext != null) {
                        resDirCombo.addItem(closestDirToContext);
                        resourceDirs.remove(closestDirToContext);
                        transitiveDirs.remove(closestDirToContext);
                    }
                }
            }
            if (!resourceDirs.isEmpty() || !transitiveDirs.isEmpty()) {
                for (File resourceDir : resourceDirs) {
                    resDirCombo.addItem(resourceDir);
                }
                for (File resourceDir : transitiveDirs) {
                    resDirCombo.addItem(resourceDir);
                }
            } else {
                for (File resourceDir : allResDirs) {
                    resDirCombo.addItem(resourceDir);
                }
            }
            resDirComboAndBrowser.setVisible(true);
            resDirLabel.setVisible(true);
        }
    }
}
Also used : AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) JComboBox(javax.swing.JComboBox) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 38 with BlazeProjectData

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

the class BlazeBuildSystemService method addDependency.

@Override
public void addDependency(Module module, String artifact) {
    Project project = module.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
    TargetIdeInfo targetIdeInfo = blazeProjectData.targetMap.get(registry.getTargetKey(module));
    if (targetIdeInfo == null || targetIdeInfo.buildFile == null) {
        return;
    }
    // TODO: automagically edit deps instead of just opening the BUILD file?
    // Need to translate Gradle coordinates into blaze targets.
    // Will probably need to hardcode for each dependency.
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    PsiElement buildTargetPsi = BuildReferenceManager.getInstance(project).resolveLabel(targetIdeInfo.key.label);
    if (buildTargetPsi != null) {
        // If we can find a PSI for the target,
        // then we can jump straight to the target in the build file.
        fileEditorManager.openTextEditor(new OpenFileDescriptor(project, buildTargetPsi.getContainingFile().getVirtualFile(), buildTargetPsi.getTextOffset()), true);
    } else {
        // If not, just the build file is good enough.
        File buildIoFile = blazeProjectData.artifactLocationDecoder.decode(targetIdeInfo.buildFile);
        VirtualFile buildVirtualFile = VfsUtils.resolveVirtualFile(buildIoFile);
        if (buildVirtualFile != null) {
            fileEditorManager.openFile(buildVirtualFile, true);
        }
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Example 39 with BlazeProjectData

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

the class BlazeRenderErrorContributor method reportIssues.

@Override
public Collection<RenderErrorModel.Issue> reportIssues() {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null || !logger.hasErrors()) {
        return getIssues();
    }
    TargetMap targetMap = blazeProjectData.targetMap;
    ArtifactLocationDecoder decoder = blazeProjectData.artifactLocationDecoder;
    AndroidResourceModule resourceModule = AndroidResourceModuleRegistry.getInstance(project).get(module);
    if (resourceModule == null) {
        return getIssues();
    }
    TargetIdeInfo target = targetMap.get(resourceModule.targetKey);
    if (target == null) {
        return getIssues();
    }
    reportGeneratedResources(resourceModule, targetMap, decoder);
    reportNonStandardAndroidManifestName(target, decoder);
    reportResourceTargetShouldDependOnClassTarget(target, targetMap, decoder);
    return getIssues();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 40 with BlazeProjectData

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

the class SyncCache method get.

/**
 * Computes a value derived from the sync project data and caches it until the next sync.
 */
@Nullable
@SuppressWarnings("unchecked")
public synchronized <T> T get(Object key, SyncCacheComputable<T> computable) {
    T value = (T) cache.get(key);
    if (value == null) {
        BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
        if (blazeProjectData != null) {
            value = computable.compute(project, blazeProjectData);
            cache.put(key, value);
        }
    }
    return value;
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Nullable(javax.annotation.Nullable)

Aggregations

BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)82 File (java.io.File)31 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)28 Nullable (javax.annotation.Nullable)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)23 Test (org.junit.Test)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)17 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)15 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)13 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)13 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)13 Project (com.intellij.openapi.project.Project)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)11 ImmutableList (com.google.common.collect.ImmutableList)10 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)10 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 List (java.util.List)8 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)7