Search in sources :

Example 1 with ModuleFinder

use of com.google.idea.blaze.base.sync.projectstructure.ModuleFinder in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method updateInMemoryState.

private static void updateInMemoryState(Project project, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, Module workspaceModule, AndroidResourceModuleRegistry registry, LightResourceClassService.Builder rClassBuilder) {
    BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
    if (syncData == null) {
        return;
    }
    AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
    if (androidSdkPlatform == null) {
        return;
    }
    updateWorkspaceModuleFacetInMemoryState(project, workspaceRoot, workspaceModule, androidSdkPlatform);
    ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
    ModuleFinder moduleFinder = ModuleFinder.getInstance(project);
    Executor resourceRepositoryExecutor = Executors.newSingleThreadExecutor();
    Module libraryResourcesModule = moduleFinder.findModuleByName(LIBRARY_RESOURCES_MODULE_NAME);
    if (libraryResourcesModule != null) {
        updateLibraryResourcesModuleFacetInMemoryState(project, workspaceRoot, libraryResourcesModule, androidSdkPlatform, syncData.importResult.resourceLibrary == null ? ImmutableList.of() : artifactLocationDecoder.decodeAll(syncData.importResult.resourceLibrary.sources), resourceRepositoryExecutor);
    } else if (useLibraryResourcesModule.getValue()) {
        logger.warn("Library resources module missing.");
    }
    for (AndroidResourceModule androidResourceModule : syncData.importResult.androidResourceModules) {
        TargetIdeInfo target = blazeProjectData.targetMap.get(androidResourceModule.targetKey);
        String moduleName = moduleNameForAndroidModule(target.key);
        Module module = moduleFinder.findModuleByName(moduleName);
        if (module == null) {
            logger.warn("No module found for resource target: " + target.key);
            continue;
        }
        registry.put(module, androidResourceModule);
        AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
        assert androidIdeInfo != null;
        updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, artifactLocationDecoder.decodeAll(useLibraryResourcesModule.getValue() ? androidResourceModule.resources : androidResourceModule.transitiveResources), resourceRepositoryExecutor);
        rClassBuilder.addRClass(androidIdeInfo.resourceJavaPackage, module);
    }
    Set<TargetKey> androidResourceModules = syncData.importResult.androidResourceModules.stream().map(androidResourceModule -> androidResourceModule.targetKey).collect(toSet());
    List<TargetIdeInfo> runConfigurationTargets = getRunConfigurationTargets(project, projectViewSet, blazeProjectData, androidResourceModules);
    for (TargetIdeInfo target : runConfigurationTargets) {
        String moduleName = moduleNameForAndroidModule(target.key);
        Module module = moduleFinder.findModuleByName(moduleName);
        if (module == null) {
            logger.warn("No module found for run configuration target: " + target.key);
            continue;
        }
        AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
        assert androidIdeInfo != null;
        updateModuleFacetInMemoryState(project, androidSdkPlatform, module, moduleDirectoryForAndroidTarget(workspaceRoot, target), manifestFileForAndroidTarget(artifactLocationDecoder, androidIdeInfo, moduleDirectoryForAndroidTarget(workspaceRoot, target)), androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
    }
}
Also used : SdkUtil(com.google.idea.blaze.android.sync.sdk.SdkUtil) GeneratedAndroidResourcesSection(com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection) ModuleFinder(com.google.idea.blaze.base.sync.projectstructure.ModuleFinder) LightResourceClassService(com.google.idea.blaze.android.resources.LightResourceClassService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) MultiResourceRepository(com.android.tools.idea.res.MultiResourceRepository) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Collectors.toSet(java.util.stream.Collectors.toSet) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) DumbService(com.intellij.openapi.project.DumbService) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) Collection(java.util.Collection) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Sets(com.google.common.collect.Sets) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Executors(java.util.concurrent.Executors) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) SourceProviderImpl(com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl) List(java.util.List) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ApplicationManager(com.intellij.openapi.application.ApplicationManager) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ModuleResourceRepository(com.android.tools.idea.res.ModuleResourceRepository) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BoolExperiment(com.google.idea.common.experiments.BoolExperiment) ModuleEditorProvider(com.google.idea.blaze.base.sync.projectstructure.ModuleEditorProvider) RunManager(com.intellij.execution.RunManager) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) SourceProvider(com.android.builder.model.SourceProvider) Nullable(javax.annotation.Nullable) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeAndroidRunConfigurationHandler(com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler) Executor(java.util.concurrent.Executor) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Maps(com.google.common.collect.Maps) File(java.io.File) BlazeAndroidModel(com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel) Label(com.google.idea.blaze.base.model.primitives.Label) ModuleFinder(com.google.idea.blaze.base.sync.projectstructure.ModuleFinder) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) Executor(java.util.concurrent.Executor) 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) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)

Aggregations

SourceProvider (com.android.builder.model.SourceProvider)1 ModuleResourceRepository (com.android.tools.idea.res.ModuleResourceRepository)1 MultiResourceRepository (com.android.tools.idea.res.MultiResourceRepository)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 GeneratedAndroidResourcesSection (com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection)1 LightResourceClassService (com.google.idea.blaze.android.resources.LightResourceClassService)1 BlazeAndroidRunConfigurationHandler (com.google.idea.blaze.android.run.BlazeAndroidRunConfigurationHandler)1 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)1 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)1 AndroidSdkPlatform (com.google.idea.blaze.android.sync.model.AndroidSdkPlatform)1 BlazeAndroidSyncData (com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData)1 BlazeAndroidModel (com.google.idea.blaze.android.sync.model.idea.BlazeAndroidModel)1 SourceProviderImpl (com.google.idea.blaze.android.sync.model.idea.SourceProviderImpl)1 SdkUtil (com.google.idea.blaze.android.sync.sdk.SdkUtil)1 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)1 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1