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();
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations