Search in sources :

Example 6 with NdkFacet

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);
    }
}
Also used : NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) Application(com.intellij.openapi.application.Application)

Example 7 with NdkFacet

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;
}
Also used : NdkFacetType(com.android.tools.idea.gradle.project.facet.ndk.NdkFacetType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with NdkFacet

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;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with NdkFacet

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();
}
Also used : NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with NdkFacet

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;
}
Also used : ViewSettings(com.intellij.ide.projectView.ViewSettings) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)10 Module (com.intellij.openapi.module.Module)7 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)6 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)4 NotNull (org.jetbrains.annotations.NotNull)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 NdkFacetType (com.android.tools.idea.gradle.project.facet.ndk.NdkFacetType)2 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)2 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)1 JavaModuleModel (com.android.tools.idea.gradle.project.model.JavaModuleModel)1 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)1 PostSyncProjectSetup (com.android.tools.idea.gradle.project.sync.setup.post.PostSyncProjectSetup)1 ConflictSet (com.android.tools.idea.gradle.variant.conflict.ConflictSet)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Application (com.intellij.openapi.application.Application)1 Project (com.intellij.openapi.project.Project)1