Search in sources :

Example 6 with AndroidModuleModel

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

the class AndroidModuleModelDataService method importData.

@Override
protected void importData(@NotNull Collection<DataNode<AndroidModuleModel>> toImport, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Map<String, AndroidModuleModel> modelsByName) {
    AndroidModuleValidator moduleValidator = myModuleValidatorFactory.create(project);
    for (Module module : modelsProvider.getModules()) {
        AndroidModuleModel androidModel = modelsByName.get(module.getName());
        setUpModule(module, moduleValidator, modelsProvider, androidModel);
    }
    if (!modelsByName.isEmpty()) {
        moduleValidator.fixAndReportFoundIssues();
    }
}
Also used : AndroidModuleValidator(com.android.tools.idea.gradle.project.sync.validation.android.AndroidModuleValidator) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module)

Example 7 with AndroidModuleModel

use of com.android.tools.idea.gradle.project.model.AndroidModuleModel 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 8 with AndroidModuleModel

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

the class ModuleTypeComparator method compare.

@Override
public int compare(Module m1, Module m2) {
    AndroidModuleModel gm1 = AndroidModuleModel.get(m1);
    AndroidModuleModel gm2 = AndroidModuleModel.get(m2);
    return compareModules(m1, m2, gm1, gm2);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel)

Example 9 with AndroidModuleModel

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

the class GradleUtil method getAndroidGradleModelVersionInUse.

/**
   * Determines version of the Android gradle plugin (and model) used by the project. The result can be absent if there are no android
   * modules in the project or if the last sync has failed.
   */
@Nullable
public static GradleVersion getAndroidGradleModelVersionInUse(@NotNull Project project) {
    Set<String> foundInLibraries = Sets.newHashSet();
    Set<String> foundInApps = Sets.newHashSet();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        AndroidModuleModel androidModel = AndroidModuleModel.get(module);
        if (androidModel != null) {
            AndroidProject androidProject = androidModel.getAndroidProject();
            String modelVersion = androidProject.getModelVersion();
            if (androidModel.getProjectType() == PROJECT_TYPE_APP) {
                foundInApps.add(modelVersion);
            } else {
                foundInLibraries.add(modelVersion);
            }
        }
    }
    String found = null;
    // Prefer the version in app.
    if (foundInApps.size() == 1) {
        found = getOnlyElement(foundInApps);
    } else if (foundInApps.isEmpty() && foundInLibraries.size() == 1) {
        found = getOnlyElement(foundInLibraries);
    }
    return found != null ? GradleVersion.tryParse(found) : null;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AndroidModuleModel

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

the class ConflictResolution method solveSelectionConflict.

private static boolean solveSelectionConflict(@NotNull Conflict conflict, boolean showConflictResolutionDialog) {
    AndroidFacet facet = AndroidFacet.getInstance(conflict.getSource());
    if (facet == null || !facet.requiresAndroidModel()) {
        // project structure may have changed and the conflict is not longer applicable.
        return true;
    }
    AndroidModuleModel source = AndroidModuleModel.get(facet);
    if (source == null) {
        return false;
    }
    Collection<String> variants = conflict.getVariants();
    if (variants.size() == 1) {
        String expectedVariant = getFirstItem(variants);
        if (isNotEmpty(expectedVariant)) {
            source.setSelectedVariantName(expectedVariant);
            source.syncSelectedVariantAndTestArtifact(facet);
            return true;
        }
    } else if (showConflictResolutionDialog) {
        ConflictResolutionDialog dialog = new ConflictResolutionDialog(conflict);
        if (dialog.showAndGet()) {
            String selectedVariant = dialog.getSelectedVariant();
            if (isNotEmpty(selectedVariant)) {
                source.setSelectedVariantName(selectedVariant);
                source.syncSelectedVariantAndTestArtifact(facet);
                return true;
            }
        }
    }
    return false;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)117 Module (com.intellij.openapi.module.Module)54 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)26 File (java.io.File)24 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)18 AndroidProject (com.android.builder.model.AndroidProject)12 GradleVersion (com.android.ide.common.repository.GradleVersion)11 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)10 Project (com.intellij.openapi.project.Project)9 Variant (com.android.builder.model.Variant)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 PsiFile (com.intellij.psi.PsiFile)5 AndroidArtifact (com.android.builder.model.AndroidArtifact)4 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)4 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)4 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 AndroidVersion (com.android.sdklib.AndroidVersion)3