use of com.android.tools.idea.gradle.parser.GradleSettingsFile in project android by JetBrains.
the class KeystoreUtils method getGradleDebugKeystore.
/**
* Gets a custom debug keystore defined in the build.gradle file for this module
*
* @return null if there is no custom debug keystore configured, or if the project is not a Gradle project.
*/
@Nullable
private static File getGradleDebugKeystore(@NotNull AndroidFacet facet) {
GradleSettingsFile gradleSettingsFile = GradleSettingsFile.get(facet.getModule().getProject());
if (gradleSettingsFile == null) {
return null;
}
String modulePath = GradleSettingsFile.getModuleGradlePath(facet.getModule());
if (modulePath == null) {
return null;
}
final GradleBuildFile moduleBuildFile = gradleSettingsFile.getModuleBuildFile(modulePath);
if (moduleBuildFile == null) {
return null;
}
Iterable<NamedObject> signingConfigs = ApplicationManager.getApplication().runReadAction(new Computable<Iterable<NamedObject>>() {
@Override
@SuppressWarnings("unchecked")
public Iterable<NamedObject> compute() {
return (Iterable<NamedObject>) moduleBuildFile.getValue(BuildFileKey.SIGNING_CONFIGS);
}
});
if (signingConfigs == null) {
return null;
}
for (NamedObject namedObject : signingConfigs) {
if (!"debug".equals(namedObject.getName())) {
continue;
}
File debugKey = (File) namedObject.getValue(BuildFileKey.STORE_FILE);
if (debugKey == null) {
continue;
}
// NOTE: debugKey.getParent() is the current working directory.
return new File(ModuleUtilCore.getModuleDirPath(facet.getModule()), debugKey.getPath());
}
return null;
}
use of com.android.tools.idea.gradle.parser.GradleSettingsFile in project android by JetBrains.
the class GradleModuleImporter method getSubProjects.
@NotNull
public static Map<String, VirtualFile> getSubProjects(@NotNull final VirtualFile settingsGradle, Project destinationProject) {
GradleSettingsFile settingsFile = new GradleSettingsFile(settingsGradle, destinationProject);
Map<String, File> allProjects = settingsFile.getModulesWithLocation();
return Maps.transformValues(allProjects, new ResolvePath(virtualToIoFile(settingsGradle.getParent())));
}
use of com.android.tools.idea.gradle.parser.GradleSettingsFile in project android by JetBrains.
the class GradleModuleImporter method copyAndRegisterModule.
/**
* Copy modules and adds it to settings.gradle
*/
private static void copyAndRegisterModule(@NotNull Object requestor, @NotNull Map<String, VirtualFile> modules, @NotNull Project project, @Nullable GradleSyncListener listener) throws IOException, ConfigurationException {
VirtualFile projectRoot = project.getBaseDir();
if (projectRoot.findChild(SdkConstants.FN_SETTINGS_GRADLE) == null) {
projectRoot.createChildData(requestor, SdkConstants.FN_SETTINGS_GRADLE);
}
GradleSettingsFile gradleSettingsFile = GradleSettingsFile.get(project);
assert gradleSettingsFile != null : "File should have been created";
for (Map.Entry<String, VirtualFile> module : modules.entrySet()) {
String name = module.getKey();
File targetFile = GradleUtil.getModuleDefaultPath(projectRoot, name);
VirtualFile moduleSource = module.getValue();
if (moduleSource != null) {
if (!isAncestor(projectRoot, moduleSource, true)) {
VirtualFile target = createDirectoryIfMissing(targetFile.getAbsolutePath());
if (target == null) {
throw new IOException(String.format("Unable to create directory %1$s", targetFile));
}
if (target.exists()) {
target.delete(requestor);
}
moduleSource.copy(requestor, target.getParent(), target.getName());
} else {
targetFile = virtualToIoFile(moduleSource);
}
}
gradleSettingsFile.addModule(name, targetFile);
}
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setGenerateSourcesOnSuccess(false);
GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
}
use of com.android.tools.idea.gradle.parser.GradleSettingsFile in project android by JetBrains.
the class GradleModuleImportTest method assertModuleInSettingsFile.
private static void assertModuleInSettingsFile(Project project, String name) throws IOException {
GradleSettingsFile settingsFile = GradleSettingsFile.get(project);
assertNotNull("Missing " + SdkConstants.FN_SETTINGS_GRADLE, settingsFile);
Iterable<String> modules = settingsFile.getModules();
if (!contains(modules, name)) {
fail(String.format("Subproject %s is not in %s. Found subprojects: %s", name, SdkConstants.FN_SETTINGS_GRADLE, Joiner.on(", ").join(modules)));
}
}
use of com.android.tools.idea.gradle.parser.GradleSettingsFile in project android by JetBrains.
the class ArchiveToGradleModuleModelTest method assertArchiveImportedCorrectly.
private void assertArchiveImportedCorrectly(@NotNull String newModuleGradlePath, @NotNull File archiveToImport) throws IOException {
Project project = getProject();
File defaultSubprojectLocation = GradleUtil.getModuleDefaultPath(project.getBaseDir(), newModuleGradlePath);
File importedArchive = new File(defaultSubprojectLocation, archiveToImport.getName());
assertWithMessage(String.format("File %s does not exist", importedArchive)).that(importedArchive.exists()).isTrue();
File buildGradle = new File(defaultSubprojectLocation, SdkConstants.FN_BUILD_GRADLE);
assertWithMessage(String.format("File %s does not exist", buildGradle)).that(buildGradle.exists()).isTrue();
VirtualFile vFile = VfsUtil.findFileByIoFile(buildGradle, true);
assertThat(vFile).isNotNull();
assertThat(CreateModuleFromArchiveAction.getBuildGradleText(archiveToImport)).isEqualTo(VfsUtilCore.loadText(vFile));
GradleSettingsFile settingsFile = GradleSettingsFile.get(project);
assertThat(settingsFile).isNotNull();
Iterable<String> modules = settingsFile.getModules();
assertWithMessage("{ " + Joiner.on(", ").join(modules) + " }").that(modules).contains(newModuleGradlePath);
}
Aggregations