use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class DataNodeCaches method isCacheMissingModels.
public boolean isCacheMissingModels(@NotNull DataNode<ProjectData> cache) {
Collection<DataNode<ModuleData>> moduleDataNodes = findAll(cache, MODULE);
if (!moduleDataNodes.isEmpty()) {
Map<String, DataNode<ModuleData>> moduleDataNodesByName = indexByModuleName(moduleDataNodes);
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
DataNode<ModuleData> moduleDataNode = moduleDataNodesByName.get(module.getName());
if (moduleDataNode == null) {
// When a Gradle facet is present, there should be a cache node for the module.
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
return true;
}
} else if (isCacheMissingModels(moduleDataNode, module)) {
return true;
}
}
return false;
}
return true;
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet 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.facet.gradle.GradleFacet in project android by JetBrains.
the class GradleUtil method getGradleBuildFile.
/**
* Returns the build.gradle file in the given module. This method first checks if the Gradle model has the path of the build.gradle
* file for the given module. If it doesn't find it, it tries to find a build.gradle inside the module's root directory.
*
* @param module the given module.
* @return the build.gradle file in the given module, or {@code null} if it cannot be found.
*/
@Nullable
public static VirtualFile getGradleBuildFile(@NotNull Module module) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null && gradleFacet.getGradleModuleModel() != null) {
return gradleFacet.getGradleModuleModel().getBuildFile();
}
// At the time we're called, module.getModuleFile() may be null, but getModuleFilePath returns the path where it will be created.
File moduleFilePath = new File(module.getModuleFilePath());
File parentFile = moduleFilePath.getParentFile();
return parentFile != null ? getGradleBuildFile(parentFile) : null;
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class GradleBuildInvoker method findAndAddGradleBuildTasks.
private static void findAndAddGradleBuildTasks(@NotNull Module module, @NotNull BuildMode buildMode, @NotNull List<String> tasks, @NotNull TestCompileType testCompileType) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
return;
}
String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
if (isEmpty(gradlePath)) {
// Gradle project path is never, ever null. If the path is empty, it shows as ":". We had reports of this happening. It is likely that
// users manually added the Android-Gradle facet to a project. After all it is likely not to be a Gradle module. Better quit and not
// build the module.
String msg = String.format("Module '%1$s' does not have a Gradle path. It is likely that this module was manually added by the user.", module.getName());
getLogger().info(msg);
return;
}
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet != null) {
JpsAndroidModuleProperties properties = androidFacet.getProperties();
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
switch(buildMode) {
// Intentional fall-through.
case CLEAN:
case SOURCE_GEN:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
break;
case ASSEMBLE:
tasks.add(createBuildTask(gradlePath, properties.ASSEMBLE_TASK_NAME));
// Add assemble tasks for tests.
if (testCompileType != TestCompileType.NONE) {
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getAssembleTaskName());
}
}
break;
default:
addAfterSyncTasks(tasks, gradlePath, properties);
addAfterSyncTasksForTestArtifacts(tasks, gradlePath, testCompileType, androidModel);
// no *.class files and would be just a waste of time.
if (testCompileType != TestCompileType.UNIT_TESTS) {
addTaskIfSpecified(tasks, gradlePath, properties.COMPILE_JAVA_TASK_NAME);
}
// Add compile tasks for tests.
for (BaseArtifact artifact : getArtifactsForTestCompileType(testCompileType, androidModel)) {
addTaskIfSpecified(tasks, gradlePath, artifact.getCompileTaskName());
}
break;
}
} else {
JavaFacet javaFacet = JavaFacet.getInstance(module);
if (javaFacet != null && javaFacet.getConfiguration().BUILDABLE) {
String gradleTaskName = javaFacet.getGradleTaskName(buildMode);
if (gradleTaskName != null) {
tasks.add(createBuildTask(gradlePath, gradleTaskName));
}
if (testCompileType == TestCompileType.UNIT_TESTS) {
tasks.add(createBuildTask(gradlePath, JavaFacet.TEST_CLASSES_TASK_NAME));
}
}
}
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet 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;
}
Aggregations