use of com.android.tools.idea.gradle.project.model.GradleModuleModel 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;
}
use of com.android.tools.idea.gradle.project.model.GradleModuleModel in project android by JetBrains.
the class GradleModuleSetup method createGradleModel.
@NotNull
private static GradleModuleModel createGradleModel(@NotNull Module module, @NotNull SyncAction.ModuleModels models) {
GradleProject gradleProject = models.getModule().getGradleProject();
GradleScript buildScript = null;
try {
buildScript = gradleProject.getBuildScript();
} catch (Throwable e) {
// Ignored. We got here because the project is using Gradle 1.8 or older.
}
File buildFilePath = buildScript != null ? buildScript.getSourceFile() : null;
BuildScriptClasspathModel classpathModel = models.findModel(BuildScriptClasspathModel.class);
String gradleVersion = classpathModel != null ? classpathModel.getGradleVersion() : null;
return new GradleModuleModel(module.getName(), gradleProject, buildFilePath, gradleVersion);
}
use of com.android.tools.idea.gradle.project.model.GradleModuleModel in project android by JetBrains.
the class ProjectSubset method findAndIncludeModules.
public void findAndIncludeModules(@NotNull Collection<String> moduleGradlePaths) {
DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
if (projectInfo == null) {
return;
}
Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
if (!moduleInfos.isEmpty()) {
Project project = myProject;
new Task.Modal(project, "Finding Missing Modules", false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
String[] originalSelection = getSelection();
Set<String> selection = originalSelection != null ? Sets.newHashSet(originalSelection) : Sets.newHashSet();
List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
boolean found = false;
int doneCount = 0;
for (DataNode<ModuleData> moduleInfo : moduleInfos) {
indicator.setFraction(++doneCount / moduleInfos.size());
String name = getNameOf(moduleInfo);
if (selection.contains(name)) {
selectedModules.add(moduleInfo);
continue;
}
DataNode<GradleModuleModel> gradleProjectNode = find(moduleInfo, GRADLE_MODULE_MODEL);
if (gradleProjectNode != null) {
GradleModuleModel gradleModuleModel = gradleProjectNode.getData();
if (moduleGradlePaths.contains(gradleModuleModel.getGradlePath())) {
selection.add(name);
selectedModules.add(moduleInfo);
found = true;
}
}
}
if (!selectedModules.isEmpty() && found) {
setSelection(selectedModules);
populate(project, projectInfo, selectedModules, DEFAULT_REQUEST);
}
}
}.queue();
}
}
use of com.android.tools.idea.gradle.project.model.GradleModuleModel in project android by JetBrains.
the class AndroidGradleModuleUtils method getContainingModule.
/**
* Given a file and a project, return the Module corresponding to the containing Gradle project for the file. If the file is not
* contained by any project then return null
*/
@Nullable
public static Module getContainingModule(File file, Project project) {
VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
if (vFile == null) {
return null;
}
Module bestMatch = null;
int bestMatchValue = Integer.MAX_VALUE;
for (Module module : ModuleManager.getInstance(project).getModules()) {
GradleFacet facet = GradleFacet.getInstance(module);
if (facet != null) {
GradleModuleModel gradleModuleModel = facet.getGradleModuleModel();
assert gradleModuleModel != null;
VirtualFile buildFile = gradleModuleModel.getBuildFile();
if (buildFile != null) {
VirtualFile root = buildFile.getParent();
if (VfsUtilCore.isAncestor(root, vFile, true)) {
String relativePath = VfsUtilCore.getRelativePath(vFile, root, '/');
if (relativePath != null) {
int value = Iterables.size(Splitter.on('/').split(relativePath));
if (value < bestMatchValue) {
bestMatch = module;
bestMatchValue = value;
}
}
}
}
}
}
return bestMatch;
}
use of com.android.tools.idea.gradle.project.model.GradleModuleModel 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);
}
}
Aggregations