use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class ProjectSetupImplTest method SetUpProjectWithAndroidModule.
// Test fails in build server, but not locally.
public void SetUpProjectWithAndroidModule() throws Exception {
// Obtain models for 'simpleApplication' from Gradle.
prepareProjectForImport(SIMPLE_APPLICATION);
Project project = getProject();
// Sync with Gradle.
NewGradleSync gradleSync = new NewGradleSync();
CountDownLatch latch = new CountDownLatch(1);
NewGradleSync.Callback sync = gradleSync.sync(project);
sync.doWhenRejected(() -> {
latch.countDown();
Throwable error = sync.getSyncError();
if (error != null) {
rethrowAllAsUnchecked(error);
}
throw new RuntimeException("Sync failed");
});
sync.doWhenDone(latch::countDown);
if (!sync.isProcessed()) {
latch.await();
}
SyncAction.ProjectModels projectModels = sync.getModels();
assertNotNull("Gradle models", projectModels);
Map<String, IdeaModule> moduleModelsByName = getModuleModelsByName(projectModels);
// 2 modules: root and "app"
assertThat(moduleModelsByName).hasSize(2);
// Simulate ModuleFactory create root module from Gradle models.
Module rootModule = simulateModelCreation(projectModels, moduleModelsByName.get(project.getName()));
// Simulate ModuleFactory create "app" module from Gradle models.
Module appModule = simulateModelCreation(projectModels, moduleModelsByName.get("app"));
Module[] modules = { rootModule, appModule };
when(myModelsProvider.getModules()).thenReturn(modules);
// Add AndroidFacet and AndroidGradleModel to "app" module, to ensure that the validator gets invoked.
AndroidModuleModel appAndroidModel = mock(AndroidModuleModel.class);
AndroidFacet appAndroidFacet = createAndAddAndroidFacet(appModule);
appAndroidFacet.setAndroidModel(appAndroidModel);
// This happens before AndroidModuleValidator gets invoked. AndroidFacet and AndroidGradleModel need to be set in the module to
// participate in validation.
simulateAndroidFacetLookup(rootModule, null);
simulateAndroidFacetLookup(appModule, appAndroidFacet);
myProjectSetup.setUpProject(projectModels, myProgressIndicator);
verify(myModuleSetup).setUpModule(rootModule, projectModels.getModels(":"), myProgressIndicator);
verify(myModuleSetup).setUpModule(appModule, projectModels.getModels(":app"), myProgressIndicator);
verify(myAndroidModuleValidator).validate(appModule, appAndroidModel);
verify(myAndroidModuleValidator).fixAndReportFoundIssues();
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class PluginVersionUpgradeTest method simulateAndroidModule.
private static void simulateAndroidModule(@NotNull Module module, int pluginGeneration) {
AndroidProject androidProject = mock(AndroidProject.class);
when(androidProject.getPluginGeneration()).thenReturn(pluginGeneration);
AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
when(androidModel.getAndroidProject()).thenReturn(androidProject);
AndroidFacet facet = createAndAddAndroidFacet(module);
facet.setAndroidModel(androidModel);
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class JavaLanguageLevelModuleSetupStepTest method createAndroidModule.
private void createAndroidModule(@NotNull String name, @NotNull LanguageLevel languageLevel) {
AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
when(androidModel.getJavaLanguageLevel()).thenReturn(languageLevel);
Module module = createModule(name);
AndroidFacet facet = createAndAddAndroidFacet(module);
facet.setAndroidModel(androidModel);
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class ProjectSubset method containsSourceFile.
/**
* Checks in the Android and Java models to see if the module contains the given file.
*
* @param moduleInfos represents the module that is not included yet in the IDE.
* @param file the given file.
* @param selected indicates whether the module is included in the project.
* @return the result of the search, or {@code null} if this module does not contain the given file.
*/
@Nullable
private static ModuleSearchResult containsSourceFile(@NotNull DataNode<ModuleData> moduleInfos, @NotNull File file, boolean selected) {
DataNode<AndroidModuleModel> androidProjectNode = find(moduleInfos, ANDROID_MODEL);
if (androidProjectNode != null) {
AndroidModuleModel androidModel = androidProjectNode.getData();
SourceFileContainerInfo result = androidModel.containsSourceFile(file);
if (result != null) {
return new ModuleSearchResult(moduleInfos, result, selected);
}
}
DataNode<JavaModuleModel> javaProjectNode = find(moduleInfos, JAVA_MODULE_MODEL);
if (javaProjectNode != null) {
JavaModuleModel javaModuleModel = javaProjectNode.getData();
if (javaModuleModel.containsSourceFile(file)) {
return new ModuleSearchResult(moduleInfos, null, selected);
}
}
return null;
}
use of com.android.tools.idea.gradle.project.model.AndroidModuleModel in project android by JetBrains.
the class PsAndroidDependencyCollection method collectDependencies.
private void collectDependencies(@NotNull PsAndroidArtifact artifact) {
BaseArtifact resolvedArtifact = artifact.getResolvedModel();
if (resolvedArtifact == null) {
return;
}
AndroidModuleModel gradleModel = artifact.getGradleModel();
Dependencies dependencies = GradleUtil.getDependencies(resolvedArtifact, gradleModel.getModelVersion());
for (AndroidLibrary androidLibrary : dependencies.getLibraries()) {
String gradlePath = androidLibrary.getProject();
if (gradlePath != null) {
String projectVariant = androidLibrary.getProjectVariant();
addModule(gradlePath, artifact, projectVariant);
} else {
// This is an AAR
addLibrary(androidLibrary, artifact);
}
}
for (JavaLibrary javaLibrary : dependencies.getJavaLibraries()) {
addLibrary(javaLibrary, artifact);
}
}
Aggregations