Search in sources :

Example 1 with AndroidSdkPlatform

use of com.google.idea.blaze.android.sync.model.AndroidSdkPlatform in project intellij by bazelbuild.

the class BlazeAndroidProjectStructureSyncer method ensureRunConfigurationModule.

/**
 * Ensures a suitable module exists for the given android target.
 */
@Nullable
public static Module ensureRunConfigurationModule(Project project, Label label) {
    TargetKey targetKey = TargetKey.forPlainTarget(label);
    String moduleName = moduleNameForAndroidModule(targetKey);
    Module module = ModuleFinder.getInstance(project).findModuleByName(moduleName);
    if (module != null) {
        return module;
    }
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    AndroidSdkPlatform androidSdkPlatform = SdkUtil.getAndroidSdkPlatform(blazeProjectData);
    if (androidSdkPlatform == null) {
        return null;
    }
    TargetIdeInfo target = blazeProjectData.targetMap.get(targetKey);
    if (target == null) {
        return null;
    }
    if (target.androidIdeInfo == null) {
        return null;
    }
    // invokeAndWait it because the caller may have a read action.
    if (!ApplicationManager.getApplication().isDispatchThread()) {
        return null;
    }
    BlazeSyncPlugin.ModuleEditor moduleEditor = ModuleEditorProvider.getInstance().getModuleEditor(project, BlazeImportSettingsManager.getInstance(project).getImportSettings());
    Module newModule = moduleEditor.createModule(moduleName, StdModuleTypes.JAVA);
    ApplicationManager.getApplication().runWriteAction(() -> {
        AndroidFacetModuleCustomizer.createAndroidFacet(newModule);
        moduleEditor.commit();
    });
    File moduleDirectory = moduleDirectoryForAndroidTarget(WorkspaceRoot.fromProject(project), target);
    updateModuleFacetInMemoryState(project, androidSdkPlatform, newModule, moduleDirectory, manifestFileForAndroidTarget(blazeProjectData.artifactLocationDecoder, target.androidIdeInfo, moduleDirectory), target.androidIdeInfo.resourceJavaPackage, ImmutableList.of(), null);
    return newModule;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 2 with AndroidSdkPlatform

use of com.google.idea.blaze.android.sync.model.AndroidSdkPlatform in project intellij by bazelbuild.

the class AndroidSdkFromProjectView method getAndroidSdkPlatform.

@Nullable
public static AndroidSdkPlatform getAndroidSdkPlatform(BlazeContext context, ProjectViewSet projectViewSet) {
    List<Sdk> sdks = BlazeSdkProvider.getInstance().getAllAndroidSdks();
    if (sdks.isEmpty()) {
        IssueOutput.error("No Android SDK configured. Please use the SDK manager to configure.").navigatable(new Navigatable() {

            @Override
            public void navigate(boolean b) {
                SdkUtil.openSdkManager();
            }

            @Override
            public boolean canNavigate() {
                return true;
            }

            @Override
            public boolean canNavigateToSource() {
                return false;
            }
        }).submit(context);
        return null;
    }
    if (projectViewSet == null) {
        return null;
    }
    String androidSdk = projectViewSet.getScalarValue(AndroidSdkPlatformSection.KEY).orElse(null);
    Integer androidMinSdk = projectViewSet.getScalarValue(AndroidMinSdkSection.KEY).orElse(null);
    if (androidSdk == null) {
        ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
        IssueOutput.error(("No android_sdk_platform set. Please set to an android platform. " + "Available android_sdk_platforms are: " + getAvailableTargetHashesAsList(sdks))).inFile(projectViewFile != null ? projectViewFile.projectViewFile : null).submit(context);
        return null;
    }
    Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdk);
    if (sdk == null) {
        ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
        IssueOutput.error(("No such android_sdk_platform: '" + androidSdk + "'. " + "Available android_sdk_platforms are: " + getAvailableTargetHashesAsList(sdks) + ". " + "Please change android_sdk_platform or run SDK manager " + "to download missing SDK platforms.")).inFile(projectViewFile != null ? projectViewFile.projectViewFile : null).submit(context);
        return null;
    }
    if (androidMinSdk == null) {
        androidMinSdk = getAndroidSdkApiLevel(sdk);
    }
    return new AndroidSdkPlatform(androidSdk, androidMinSdk);
}
Also used : AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) Sdk(com.intellij.openapi.projectRoots.Sdk) Navigatable(com.intellij.pom.Navigatable) Nullable(javax.annotation.Nullable)

Example 3 with AndroidSdkPlatform

use of com.google.idea.blaze.android.sync.model.AndroidSdkPlatform in project intellij by bazelbuild.

the class SdkUtil method getAndroidPlatform.

@Nullable
public static AndroidPlatform getAndroidPlatform(@NotNull Project project) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return null;
    }
    AndroidSdkPlatform androidSdkPlatform = getAndroidSdkPlatform(blazeProjectData);
    if (androidSdkPlatform == null) {
        return null;
    }
    Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdkPlatform.androidSdk);
    if (sdk == null) {
        return null;
    }
    return AndroidPlatform.getInstance(sdk);
}
Also used : AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AndroidSdkPlatform

use of com.google.idea.blaze.android.sync.model.AndroidSdkPlatform in project intellij by bazelbuild.

the class BlazeAndroidSyncPlugin method updateProjectSdk.

@Override
public void updateProjectSdk(Project project, BlazeContext context, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, BlazeProjectData blazeProjectData) {
    if (!isAndroidWorkspace(blazeProjectData.workspaceLanguageSettings)) {
        return;
    }
    BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
    if (syncData == null) {
        return;
    }
    AndroidSdkPlatform androidSdkPlatform = syncData.androidSdkPlatform;
    if (androidSdkPlatform == null) {
        return;
    }
    Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdkPlatform.androidSdk);
    if (sdk == null) {
        IssueOutput.error(String.format("Android platform '%s' not found.", androidSdkPlatform.androidSdk)).submit(context);
        return;
    }
    LanguageLevel defaultLanguageLevel = BuildSystemAndroidJdkProvider.languageLevel(Blaze.getBuildSystem(project), blazeVersionData);
    LanguageLevel javaLanguageLevel = JavaLanguageLevelSection.getLanguageLevel(projectViewSet, defaultLanguageLevel);
    setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
Also used : AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) LanguageLevel(com.intellij.pom.java.LanguageLevel) Sdk(com.intellij.openapi.projectRoots.Sdk) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData)

Example 5 with AndroidSdkPlatform

use of com.google.idea.blaze.android.sync.model.AndroidSdkPlatform in project intellij by bazelbuild.

the class BlazeAndroidSyncPlugin method updateSyncState.

@Override
public void updateSyncState(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, WorkspaceLanguageSettings workspaceLanguageSettings, BlazeInfo blazeInfo, @Nullable WorkingSet workingSet, WorkspacePathResolver workspacePathResolver, ArtifactLocationDecoder artifactLocationDecoder, TargetMap targetMap, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    if (!isAndroidWorkspace(workspaceLanguageSettings)) {
        return;
    }
    AndroidSdkPlatform androidSdkPlatform = AndroidSdkFromProjectView.getAndroidSdkPlatform(context, projectViewSet);
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    BlazeAndroidWorkspaceImporter workspaceImporter = new BlazeAndroidWorkspaceImporter(project, context, workspaceRoot, projectViewSet, targetMap, sourceFilter, artifactLocationDecoder);
    BlazeAndroidImportResult importResult = Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("AndroidWorkspaceImporter", EventType.Other));
        return workspaceImporter.importWorkspace();
    });
    BlazeAndroidSyncData syncData = new BlazeAndroidSyncData(importResult, androidSdkPlatform);
    syncStateBuilder.put(BlazeAndroidSyncData.class, syncData);
}
Also used : BlazeAndroidWorkspaceImporter(com.google.idea.blaze.android.sync.importer.BlazeAndroidWorkspaceImporter) AndroidSdkPlatform(com.google.idea.blaze.android.sync.model.AndroidSdkPlatform) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData)

Aggregations

AndroidSdkPlatform (com.google.idea.blaze.android.sync.model.AndroidSdkPlatform)7 BlazeAndroidSyncData (com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData)4 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)3 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 Module (com.intellij.openapi.module.Module)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 File (java.io.File)3 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)2 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)2 Nullable (javax.annotation.Nullable)2 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