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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations