use of com.android.tools.idea.gradle.project.facet.ndk.NdkFacet in project android by JetBrains.
the class BuildVariantView method updateContents.
public void updateContents() {
GradleSyncState syncState = GradleSyncState.getInstance(myProject);
if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
projectImportStarted();
return;
}
final List<Object[]> rows = Lists.newArrayList();
final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
for (Module module : getGradleModulesWithAndroidProjects()) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
NdkFacet ndkFacet = NdkFacet.getInstance(module);
// getGradleModules() returns only relevant modules.
assert androidFacet != null || ndkFacet != null;
String variantName = null;
if (androidFacet != null) {
JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
variantName = facetProperties.SELECTED_BUILD_VARIANT;
}
BuildVariantItem[] variantNames = getVariantItems(module);
if (variantNames != null) {
if (androidFacet != null) {
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
// AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
if (androidModel != null) {
variantName = androidModel.getSelectedVariant().getName();
}
} else {
// As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
// when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
variantName = ndkModuleModel.getSelectedVariant().getName();
}
}
variantNamesPerRow.add(variantNames);
}
if (variantName != null) {
Object[] row = { module, variantName };
rows.add(row);
}
}
Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
setModelTask.run();
} else {
application.invokeLater(setModelTask);
}
}
use of com.android.tools.idea.gradle.project.facet.ndk.NdkFacet in project android by JetBrains.
the class ContentRootsModuleSetupStepTest method addNativeAndroidFacet.
@NotNull
private NdkFacet addNativeAndroidFacet(@NotNull IdeModifiableModelsProvider modelsProvider) {
Module module = getModule();
ModifiableFacetModel model = modelsProvider.getModifiableFacetModel(module);
NdkFacetType facetType = NdkFacet.getFacetType();
NdkFacet facet = facetType.createFacet(module, NdkFacet.getFacetName(), facetType.createDefaultConfiguration(), null);
model.addFacet(facet);
return facet;
}
use of com.android.tools.idea.gradle.project.facet.ndk.NdkFacet in project android by JetBrains.
the class BuildVariantUpdater method doUpdate.
@Nullable
private Module doUpdate(@NotNull Project project, @NotNull String moduleName, @NotNull String variant, @NotNull List<AndroidFacet> affectedAndroidFacets, @NotNull List<NdkFacet> affectedNativeAndroidFacets) {
Module moduleToUpdate = findModule(project, moduleName);
if (moduleToUpdate == null) {
logAndShowUpdateFailure(variant, String.format("Cannot find module '%1$s'.", moduleName));
return null;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(moduleToUpdate);
NdkFacet ndkFacet = NdkFacet.getInstance(moduleToUpdate);
if (androidFacet == null && ndkFacet == null) {
String msg = String.format("Cannot find 'Android' or 'Native-Android-Gradle' facets in module '%1$s'.", moduleToUpdate.getName());
logAndShowUpdateFailure(variant, msg);
}
if (ndkFacet != null) {
NdkModuleModel ndkModuleModel = getNativeAndroidModel(ndkFacet, variant);
if (ndkModuleModel == null || !updateSelectedVariant(ndkFacet, ndkModuleModel, variant)) {
return null;
}
affectedNativeAndroidFacets.add(ndkFacet);
}
if (androidFacet != null) {
AndroidModuleModel androidModel = getAndroidModel(androidFacet, variant);
if (androidModel == null || !updateSelectedVariant(androidFacet, androidModel, variant, affectedAndroidFacets)) {
return null;
}
affectedAndroidFacets.add(androidFacet);
}
return moduleToUpdate;
}
use of com.android.tools.idea.gradle.project.facet.ndk.NdkFacet in project android by JetBrains.
the class BuildVariantView method getGradleModulesWithAndroidProjects.
@NotNull
private List<Module> getGradleModulesWithAndroidProjects() {
List<Module> gradleModules = Lists.newArrayList();
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null && androidFacet.requiresAndroidModel() && androidFacet.getAndroidModel() != null) {
gradleModules.add(module);
continue;
}
NdkFacet ndkFacet = NdkFacet.getInstance(module);
if (ndkFacet != null && ndkFacet.getNdkModuleModel() != null) {
gradleModules.add(module);
}
}
if (!gradleModules.isEmpty()) {
Collections.sort(gradleModules, ModuleTypeComparator.INSTANCE);
return gradleModules;
}
return Collections.emptyList();
}
use of com.android.tools.idea.gradle.project.facet.ndk.NdkFacet in project android by JetBrains.
the class AndroidViewProjectNode method getChildren.
@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
Project project = getProject();
assert project != null;
ViewSettings settings = getSettings();
// add a node for every module
// TODO: make this conditional on getSettings().isShowModules(), otherwise collapse them all at the root
List<Module> modules = Arrays.asList(ModuleManager.getInstance(project).getModules());
List<AbstractTreeNode> children = Lists.newArrayListWithExpectedSize(modules.size());
for (Module module : modules) {
if (isRootModuleWithNoSources(module)) {
// If we detect such a module, then we don't show it..
continue;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
NdkFacet ndkFacet = NdkFacet.getInstance(module);
if (androidFacet != null && androidFacet.getAndroidModel() != null) {
children.add(new AndroidModuleNode(project, module, settings, myProjectViewPane));
} else if (ndkFacet != null && ndkFacet.getNdkModuleModel() != null) {
children.add(new NdkModuleNode(project, module, settings));
} else {
children.add(new NonAndroidModuleNode(project, module, settings));
}
}
// are still visible. See https://code.google.com/p/android/issues/detail?id=76564
if (children.isEmpty() && isBuildWithGradle(project) && GradleSyncState.getInstance(project).lastSyncFailed()) {
PsiDirectory dir = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
if (dir != null) {
children.add(new PsiDirectoryNode(project, dir, settings));
}
}
if (isBuildWithGradle(project)) {
children.add(new AndroidBuildScriptsGroupNode(project, settings));
}
ExternalBuildFilesGroupNode externalBuildFilesNode = new ExternalBuildFilesGroupNode(project, settings);
if (!externalBuildFilesNode.getChildren().isEmpty()) {
children.add(externalBuildFilesNode);
}
return children;
}
Aggregations