Search in sources :

Example 1 with NdkModuleModel

use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.

the class InternalAndroidModelView method updateContents.

private void updateContents() {
    myTree.setRootVisible(true);
    if (GradleSyncState.getInstance(myProject).isSyncInProgress()) {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Gradle project sync in progress ...")));
        return;
    } else {
        myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Loading ...")));
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(myProject.getName());
        for (Module module : ModuleManager.getInstance(myProject).getModules()) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(module);
            if (androidModel != null) {
                DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module.getName());
                AndroidProject androidProject = androidModel.waitForAndGetProxyAndroidProject();
                addProxyObject(moduleNode, androidProject);
                rootNode.add(moduleNode);
            }
            NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
            if (ndkModuleModel != null) {
                String nodeName = androidModel == null ? module.getName() : module.getName() + " (native)";
                DefaultMutableTreeNode nativeModuleNode = new DefaultMutableTreeNode(nodeName);
                NativeAndroidProject nativeAndroidProject = ndkModuleModel.waitForAndGetProxyAndroidProject();
                addProxyObject(nativeModuleNode, nativeAndroidProject);
                rootNode.add(nativeModuleNode);
            }
        }
        invokeLaterIfNeeded(() -> {
            DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
            renderer.setOpenIcon(AllIcons.Nodes.NewFolder);
            renderer.setClosedIcon(AllIcons.Nodes.NewFolder);
            renderer.setLeafIcon(AllIcons.ObjectBrowser.ShowModules);
            myTree.setCellRenderer(renderer);
            DefaultTreeModel model = new DefaultTreeModel(rootNode);
            myTree.setRootVisible(false);
            myTree.setModel(model);
        });
    });
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 2 with NdkModuleModel

use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.

the class DataNodeCaches method isCacheMissingModels.

private static boolean isCacheMissingModels(@NotNull DataNode<ModuleData> cache, @NotNull Module module) {
    GradleFacet gradleFacet = GradleFacet.getInstance(module);
    if (gradleFacet != null) {
        DataNode<GradleModuleModel> gradleDataNode = find(cache, GRADLE_MODULE_MODEL);
        if (gradleDataNode == null) {
            return true;
        }
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        if (androidFacet != null) {
            DataNode<AndroidModuleModel> androidDataNode = find(cache, ANDROID_MODEL);
            if (androidDataNode == null || !isValidProxyObject(androidDataNode.getData().getAndroidProject())) {
                return true;
            }
        } else {
            JavaFacet javaFacet = JavaFacet.getInstance(module);
            if (javaFacet != null) {
                DataNode<JavaModuleModel> javaProjectDataNode = find(cache, JAVA_MODULE_MODEL);
                if (javaProjectDataNode == null) {
                    return true;
                }
            }
        }
    }
    NdkFacet ndkFacet = NdkFacet.getInstance(module);
    if (ndkFacet != null) {
        DataNode<NdkModuleModel> ndkModuleModelDataNode = find(cache, NDK_MODEL);
        if (ndkModuleModelDataNode == null || !isValidProxyObject(ndkModuleModelDataNode.getData().getAndroidProject())) {
            return true;
        }
    }
    return false;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 3 with NdkModuleModel

use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.

the class ModuleSetup method setUpModule.

public void setUpModule(@NotNull Module module, @NotNull SyncAction.ModuleModels models, @NotNull ProgressIndicator indicator) {
    boolean isProjectRootFolder = false;
    File gradleSettingsFile = new File(getModulePath(module), FN_SETTINGS_GRADLE);
    if (gradleSettingsFile.isFile() && !models.hasModel(AndroidProject.class) && !models.hasModel(NativeAndroidProject.class)) {
        // This is just a root folder for a group of Gradle projects. We don't set an IdeaGradleProject so the JPS builder won't try to
        // compile it using Gradle. We still need to create the module to display files inside it.
        isProjectRootFolder = true;
    }
    myGradleModuleSetup.setUpModule(module, myIdeModelsProvider, models);
    AndroidProject androidProject = models.findModel(AndroidProject.class);
    if (androidProject != null) {
        AndroidModuleModel androidModel = createAndroidModel(module, androidProject);
        if (androidModel != null) {
            // This is an Android module without variants.
            myAndroidModuleSetup.setUpModule(module, myIdeModelsProvider, androidModel, models, indicator);
        } else {
            // This is an Android module without variants. Treat as a non-buildable Java module.
            removeAndroidFacetFrom(module);
            setUpJavaModule(module, models, indicator, true);
        }
        return;
    }
    // This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
    removeAndroidFacetFrom(module);
    NativeAndroidProject nativeAndroidProject = models.findModel(NativeAndroidProject.class);
    if (nativeAndroidProject != null) {
        NdkModuleModel ndkModuleModel = new NdkModuleModel(module.getName(), getModulePath(module), nativeAndroidProject);
        myNdkModuleSetup.setUpModule(module, myIdeModelsProvider, ndkModuleModel, models, indicator);
        return;
    }
    // This is not an Android module. Remove any AndroidFacet set in a previous sync operation.
    removeAllFacets(myIdeModelsProvider.getModifiableFacetModel(module), NdkFacet.getFacetTypeId());
    if (!isProjectRootFolder) {
        setUpJavaModule(module, models, indicator, false);
    }
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) File(java.io.File)

Example 4 with NdkModuleModel

use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.

the class LinkExternalCppProjectAction method isValidAndroidGradleModuleSelected.

private static boolean isValidAndroidGradleModuleSelected(@NotNull DataContext dataContext) {
    Module module = getSelectedModule(dataContext);
    if (module == null) {
        return false;
    }
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel == null || !androidModel.getFeatures().isExternalBuildSupported()) {
        return false;
    }
    AndroidPluginGeneration pluginGeneration = AndroidPluginGeneration.find(module);
    if (pluginGeneration == COMPONENT) {
        // Updating experimental plugin DSL is not yet supported.
        return false;
    }
    NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
    if (ndkModuleModel != null) {
        // Some external native project is already linked to this module.
        return false;
    }
    if (GradleBuildModel.get(module) == null) {
        // This should never for an fully synced module, but checking for just in case.
        return false;
    }
    return true;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) AndroidPluginGeneration(com.android.tools.idea.gradle.plugin.AndroidPluginGeneration)

Example 5 with NdkModuleModel

use of com.android.tools.idea.gradle.project.model.NdkModuleModel in project android by JetBrains.

the class GradleFiles method areGradleFilesModified.

/**
   * Indicates whether a project sync with Gradle is needed if the following files:
   * <ul>
   *   <li>gradle.properties</li>
   *   <li>build.gradle</li>
   *   <li>settings.gradle</li>
   *   <li>external build files (e.g. cmake files)</li>
   * </ul>
   * were modified after the given time.
   *
   * @param referenceTimeInMillis the given time, in milliseconds.
   * @return {@code true} if any of the Gradle files changed, {@code false} otherwise.
   * @throws IllegalArgumentException if the given time is less than or equal to zero.
   */
public boolean areGradleFilesModified(long referenceTimeInMillis) {
    if (referenceTimeInMillis <= 0) {
        throw new IllegalArgumentException("Reference time (in milliseconds) should be greater than zero");
    }
    setExternalBuildFilesModified(false);
    if (areFilesInProjectRootFolderModified(referenceTimeInMillis, FN_GRADLE_PROPERTIES, FN_SETTINGS_GRADLE)) {
        return true;
    }
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        VirtualFile buildFile = getGradleBuildFile(module);
        if (buildFile != null) {
            if (myDocumentManager.isFileModified(buildFile)) {
                return true;
            }
            File buildFilePath = virtualToIoFile(buildFile);
            if (buildFilePath.lastModified() > referenceTimeInMillis) {
                return true;
            }
        }
        NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
        if (ndkModuleModel != null) {
            for (File externalBuildFile : ndkModuleModel.getAndroidProject().getBuildFiles()) {
                if (externalBuildFile.lastModified() > referenceTimeInMillis) {
                    setExternalBuildFilesModified(true);
                    return true;
                }
                // TODO find a better way to find a VirtualFile without refreshing the file systerm. It is expensive.
                VirtualFile virtualFile = findFileByIoFile(externalBuildFile, true);
                if (virtualFile != null && myDocumentManager.isFileModified(virtualFile)) {
                    setExternalBuildFilesModified(true);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) PsiFile(com.intellij.psi.PsiFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)

Aggregations

NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)18 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)10 Module (com.intellij.openapi.module.Module)9 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)4 NdkFacet (com.android.tools.idea.gradle.project.facet.ndk.NdkFacet)4 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)4 AndroidProject (com.android.builder.model.AndroidProject)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 Nullable (org.jetbrains.annotations.Nullable)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)2 GradleSyncState (com.android.tools.idea.gradle.project.sync.GradleSyncState)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 NotNull (org.jetbrains.annotations.NotNull)2 NativeArtifact (com.android.builder.model.NativeArtifact)1