Search in sources :

Example 1 with NativeAndroidProject

use of com.android.builder.model.NativeAndroidProject 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 NativeAndroidProject

use of com.android.builder.model.NativeAndroidProject 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 3 with NativeAndroidProject

use of com.android.builder.model.NativeAndroidProject in project android by JetBrains.

the class AndroidGradleProjectResolver method populateModuleContentRoots.

@Override
public void populateModuleContentRoots(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
    ImportedModule importedModule = new ImportedModule(gradleModule);
    ideModule.createChild(IMPORTED_MODULE, importedModule);
    GradleProject gradleProject = gradleModule.getGradleProject();
    GradleScript buildScript = null;
    try {
        buildScript = gradleProject.getBuildScript();
    } catch (UnsupportedOperationException ignore) {
    }
    if (buildScript == null || !isAndroidGradleProject()) {
        nextResolver.populateModuleContentRoots(gradleModule, ideModule);
        return;
    }
    // do not derive module root dir based on *.iml file location
    File moduleRootDirPath = new File(toSystemDependentName(ideModule.getData().getLinkedExternalProjectPath()));
    AndroidProject androidProject = resolverCtx.getExtraProject(gradleModule, AndroidProject.class);
    boolean androidProjectWithoutVariants = false;
    String moduleName = gradleModule.getName();
    if (androidProject != null) {
        Variant selectedVariant = myVariantSelector.findVariantToSelect(androidProject);
        if (selectedVariant == null) {
            // If an Android project does not have variants, it would be impossible to build. This is a possible but invalid use case.
            // For now we are going to treat this case as a Java library module, because everywhere in the IDE (e.g. run configurations,
            // editors, test support, variants tool window, project building, etc.) we have the assumption that there is at least one variant
            // per Android project, and changing that in the code base is too risky, for very little benefit.
            // See https://code.google.com/p/android/issues/detail?id=170722
            androidProjectWithoutVariants = true;
        } else {
            String variantName = selectedVariant.getName();
            AndroidModuleModel model = new AndroidModuleModel(moduleName, moduleRootDirPath, androidProject, variantName);
            ideModule.createChild(ANDROID_MODEL, model);
        }
    }
    NativeAndroidProject nativeAndroidProject = resolverCtx.getExtraProject(gradleModule, NativeAndroidProject.class);
    if (nativeAndroidProject != null) {
        NdkModuleModel ndkModuleModel = new NdkModuleModel(moduleName, moduleRootDirPath, nativeAndroidProject);
        ideModule.createChild(NDK_MODEL, ndkModuleModel);
    }
    File gradleSettingsFile = new File(moduleRootDirPath, FN_SETTINGS_GRADLE);
    if (gradleSettingsFile.isFile() && androidProject == null && nativeAndroidProject == null) {
        // 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.
        createJavaProject(gradleModule, ideModule, false);
        return;
    }
    BuildScriptClasspathModel buildScriptModel = resolverCtx.getExtraProject(BuildScriptClasspathModel.class);
    String gradleVersion = buildScriptModel != null ? buildScriptModel.getGradleVersion() : null;
    File buildFilePath = buildScript.getSourceFile();
    GradleModuleModel gradleModuleModel = new GradleModuleModel(moduleName, gradleProject, buildFilePath, gradleVersion);
    ideModule.createChild(GRADLE_MODULE_MODEL, gradleModuleModel);
    if (nativeAndroidProject == null && (androidProject == null || androidProjectWithoutVariants)) {
        // This is a Java lib module.
        createJavaProject(gradleModule, ideModule, androidProjectWithoutVariants);
    }
}
Also used : BuildScriptClasspathModel(org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel) ImportedModule(com.android.tools.idea.gradle.ImportedModule) AndroidProject(com.android.builder.model.AndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) Variant(com.android.builder.model.Variant) GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) GradleScript(org.gradle.tooling.model.gradle.GradleScript) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GradleProject(org.gradle.tooling.model.GradleProject) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) File(java.io.File)

Example 4 with NativeAndroidProject

use of com.android.builder.model.NativeAndroidProject in project android by JetBrains.

the class ProjectStructureCleanupStep method cleanUpProject.

@Override
public void cleanUpProject(@NotNull Project project, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @Nullable ProgressIndicator indicator) {
    Set<Sdk> androidSdks = new HashSet<>();
    for (Module module : ideModifiableModelsProvider.getModules()) {
        ModifiableRootModel rootModel = ideModifiableModelsProvider.getModifiableRootModel(module);
        adjustInterModuleDependencies(module, ideModifiableModelsProvider);
        Sdk sdk = rootModel.getSdk();
        if (sdk != null) {
            if (myAndroidSdks.isAndroidSdk(sdk)) {
                androidSdks.add(sdk);
            }
            continue;
        }
        NativeAndroidProject nativeAndroidProject = getNativeAndroidProject(module);
        if (nativeAndroidProject != null) {
            // Native modules does not need any jdk entry.
            continue;
        }
        Sdk jdk = IdeSdks.getInstance().getJdk();
        rootModel.setSdk(jdk);
    }
    for (Sdk sdk : androidSdks) {
        myAndroidSdks.refreshLibrariesIn(sdk);
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) GradleUtil.getNativeAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) HashSet(java.util.HashSet)

Example 5 with NativeAndroidProject

use of com.android.builder.model.NativeAndroidProject in project android by JetBrains.

the class NdkModuleNode method getNativeSourceNodes.

@NotNull
public static Collection<AbstractTreeNode> getNativeSourceNodes(@NotNull Project project, @NotNull NdkModuleModel ndkModuleModel, @NotNull ViewSettings viewSettings) {
    NativeAndroidProject nativeAndroidProject = ndkModuleModel.getAndroidProject();
    Collection<String> sourceFileExtensions = nativeAndroidProject.getFileExtensions().keySet();
    NdkModuleModel.NdkVariant variant = ndkModuleModel.getSelectedVariant();
    Multimap<String, NativeArtifact> nativeLibraries = HashMultimap.create();
    for (NativeArtifact artifact : variant.getArtifacts()) {
        String artifactOutputFileName = artifact.getOutputFile().getName();
        nativeLibraries.put(artifactOutputFileName, artifact);
    }
    if (nativeLibraries.keySet().size() == 1) {
        return getSourceDirectoryNodes(project, nativeLibraries.values(), viewSettings, sourceFileExtensions);
    }
    List<AbstractTreeNode> children = Lists.newArrayList();
    for (String name : nativeLibraries.keySet()) {
        String nativeLibraryType = "";
        String nativeLibraryName = trimEnd(name, ".so");
        if (nativeLibraryName.length() < name.length()) {
            nativeLibraryType = "Shared Library";
        } else {
            nativeLibraryName = trimEnd(name, ".a");
            if (nativeLibraryName.length() < name.length()) {
                nativeLibraryType = "Static Library";
            }
        }
        nativeLibraryName = trimStart(nativeLibraryName, "lib");
        children.add(new NativeAndroidLibraryNode(project, nativeLibraryName, nativeLibraryType, nativeLibraries.get(name), viewSettings, sourceFileExtensions));
    }
    return children;
}
Also used : NativeAndroidProject(com.android.builder.model.NativeAndroidProject) NativeArtifact(com.android.builder.model.NativeArtifact) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NativeAndroidProject (com.android.builder.model.NativeAndroidProject)5 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)4 AndroidProject (com.android.builder.model.AndroidProject)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 Module (com.intellij.openapi.module.Module)2 File (java.io.File)2 NativeArtifact (com.android.builder.model.NativeArtifact)1 Variant (com.android.builder.model.Variant)1 ImportedModule (com.android.tools.idea.gradle.ImportedModule)1 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)1 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 HashSet (java.util.HashSet)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 GradleProject (org.gradle.tooling.model.GradleProject)1 GradleScript (org.gradle.tooling.model.gradle.GradleScript)1