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;
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class JavaFacetModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull JavaModuleModel javaModuleModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
JavaFacet facet = setAndGetJavaGradleFacet(module, ideModelsProvider);
GradleFacet gradleFacet = findFacet(module, ideModelsProvider, GradleFacet.getFacetTypeId());
if (gradleFacet != null) {
// This is an actual Gradle module, because it has the GradleFacet. Top-level modules in a multi-module project usually don't
// have this facet.
facet.setJavaModuleModel(javaModuleModel);
}
File buildFolderPath = javaModuleModel.getBuildFolderPath();
JavaFacetConfiguration facetProperties = facet.getConfiguration();
facetProperties.BUILD_FOLDER_PATH = buildFolderPath != null ? toSystemIndependentName(buildFolderPath.getPath()) : "";
facetProperties.BUILDABLE = javaModuleModel.isBuildable();
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class GradleProjectSyncData method createFrom.
@Nullable
@VisibleForTesting
static GradleProjectSyncData createFrom(@NotNull Project project) throws IOException {
GradleProjectSyncData data = new GradleProjectSyncData();
File rootDirPath = getBaseDirPath(project);
Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet != null) {
GradleModuleModel gradleModuleModel = gradleFacet.getGradleModuleModel();
if (gradleModuleModel != null) {
data.addFileChecksum(rootDirPath, gradleModuleModel.getBuildFile());
} else {
LOG.warn(String.format("Trying to create project data from a not initialized project '%1$s'. Abort.", project.getName()));
return null;
}
}
if (isGradleProjectModule(module)) {
data.addFileChecksum(rootDirPath, getGradleBuildFile(module));
data.addFileChecksum(rootDirPath, getGradleSettingsFile(rootDirPath));
data.addFileChecksum(rootDirPath, new File(rootDirPath, FN_GRADLE_PROPERTIES));
data.addFileChecksum(rootDirPath, new File(rootDirPath, FN_LOCAL_PROPERTIES));
data.addFileChecksum(rootDirPath, getGradleUserSettingsFile());
}
NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
if (ndkModuleModel != null) {
for (File externalBuildFile : ndkModuleModel.getAndroidProject().getBuildFiles()) {
data.addFileChecksum(rootDirPath, externalBuildFile);
}
}
}
GradleSyncState syncState = GradleSyncState.getInstance(project);
data.myLastGradleSyncTimestamp = syncState.getSummary().getSyncTimestamp();
return data;
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class NewProjectImportGradleSyncListener method createTopLevelModule.
@VisibleForTesting
public static void createTopLevelModule(@NotNull Project project) {
ModuleManager moduleManager = ModuleManager.getInstance(project);
File projectRootDir = getBaseDirPath(project);
VirtualFile contentRoot = findFileByIoFile(projectRootDir, true);
if (contentRoot != null) {
File moduleFile = new File(projectRootDir, projectRootDir.getName() + ".iml");
Module module = moduleManager.newModule(moduleFile.getPath(), JAVA.getId());
// This prevents the balloon "Unsupported Modules detected".
ExternalSystemModulePropertyManager.getInstance(module).setExternalId(GRADLE_SYSTEM_ID);
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addContentEntry(contentRoot);
if (IdeInfo.getInstance().isAndroidStudio()) {
// If sync fails, make sure that the project has a JDK, otherwise Groovy indices won't work (a common scenario where
// users will update build.gradle files to fix Gradle sync.)
// See: https://code.google.com/p/android/issues/detail?id=194621
Sdk jdk = IdeSdks.getInstance().getJdk();
if (jdk != null) {
model.setSdk(jdk);
}
}
model.commit();
FacetManager facetManager = FacetManager.getInstance(module);
ModifiableFacetModel facetModel = facetManager.createModifiableModel();
try {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
// Add "gradle" facet, to avoid balloons about unsupported compilation of modules.
gradleFacet = facetManager.createFacet(GradleFacet.getFacetType(), GradleFacet.getFacetName(), null);
facetModel.addFacet(gradleFacet);
}
gradleFacet.getConfiguration().GRADLE_PROJECT_PATH = GRADLE_PATH_SEPARATOR;
// Add "android" facet to avoid the balloon "Android Framework detected".
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet == null) {
androidFacet = facetManager.createFacet(AndroidFacet.getFacetType(), AndroidFacet.NAME, null);
facetModel.addFacet(androidFacet);
}
// This is what actually stops Studio from showing the balloon.
androidFacet.getProperties().ALLOW_USER_CONFIGURATION = false;
} finally {
facetModel.commit();
}
}
}
use of com.android.tools.idea.gradle.project.facet.gradle.GradleFacet in project android by JetBrains.
the class GradleBuildInvoker method findCleanTasksForModules.
@NotNull
public static List<String> findCleanTasksForModules(@NotNull Module[] modules) {
List<String> tasks = new ArrayList<>();
for (Module module : modules) {
GradleFacet gradleFacet = GradleFacet.getInstance(module);
if (gradleFacet == null) {
continue;
}
String gradlePath = gradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
addTaskIfSpecified(tasks, gradlePath, CLEAN_TASK_NAME);
}
return tasks;
}
Aggregations