Search in sources :

Example 31 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method testCreateModuleWithOldModelVersion.

public void testCreateModuleWithOldModelVersion() {
    AndroidProject androidProject = mock(AndroidProject.class);
    ProjectImportAction.AllModels allModels = new ProjectImportAction.AllModels(myProjectModel);
    allModels.addExtraProject(androidProject, AndroidProject.class, myAndroidModuleModel);
    myResolverCtx.setModels(allModels);
    when(androidProject.getModelVersion()).thenReturn("0.0.1");
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectDataNode = new DataNode<>(PROJECT, project, null);
    try {
        myProjectResolver.createModule(myAndroidModuleModel, projectDataNode);
        fail("Expecting IllegalStateException to be thrown");
    } catch (IllegalStateException e) {
        assertThat(e.getMessage()).startsWith("The project is using an unsupported version of the Android Gradle plug-in (0.0.1)");
    }
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) NativeAndroidProject(com.android.builder.model.NativeAndroidProject) AndroidProject(com.android.builder.model.AndroidProject) ProjectImportAction(org.jetbrains.plugins.gradle.model.ProjectImportAction) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 32 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class SyncActionTest method executeWithExistingModel.

@Test
public void executeWithExistingModel() {
    SyncAction action = new SyncAction(Lists.newArrayList(AndroidProject.class));
    when(myBuildController.getModel(IdeaProject.class)).thenReturn(myProject);
    when(myBuildController.findModel(myModule, AndroidProject.class)).thenReturn(myAndroidProject);
    SyncAction.ProjectModels projectModels = action.execute(myBuildController);
    assertNotNull(projectModels);
    SyncAction.ModuleModels moduleModels = projectModels.getModels(myModule);
    AndroidProject actual = moduleModels.findModel(AndroidProject.class);
    assertSame(myAndroidProject, actual);
}
Also used : AndroidProject(com.android.builder.model.AndroidProject) Test(org.junit.Test)

Example 33 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class SyncActionTest method executeWithNotExistingModel.

@SuppressWarnings("deprecation")
@Test
public void executeWithNotExistingModel() {
    SyncAction action = new SyncAction(Lists.newArrayList(ModuleExtendedModel.class));
    when(myBuildController.getModel(IdeaProject.class)).thenReturn(myProject);
    when(myBuildController.findModel(myModule, ModuleExtendedModel.class)).thenReturn(null);
    SyncAction.ProjectModels projectModels = action.execute(myBuildController);
    assertNotNull(projectModels);
    SyncAction.ModuleModels moduleModels = projectModels.getModels(myModule);
    AndroidProject actual = moduleModels.findModel(AndroidProject.class);
    assertNull(actual);
}
Also used : ModuleExtendedModel(org.jetbrains.plugins.gradle.model.ModuleExtendedModel) AndroidProject(com.android.builder.model.AndroidProject) Test(org.junit.Test)

Example 34 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class BuildTools23Rc1ValidationStrategyTest method mockAndroidModel.

@NotNull
private static AndroidModuleModel mockAndroidModel(@Nullable String modelVersion, int apiVersion) {
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getModelVersion()).thenReturn(modelVersion);
    when(androidProject.getApiVersion()).thenReturn(apiVersion);
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.getAndroidProject()).thenReturn(androidProject);
    return androidModel;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class DependenciesModuleSetupStepTest method testUpdateLibraryDependencyWithLibraryInModule.

public void testUpdateLibraryDependencyWithLibraryInModule() throws IOException {
    Module module = getModule();
    createContentRoot(module);
    VirtualFile moduleFolder = getModuleFolder(module);
    // Create "build" folder inside the module.
    String name = "build";
    VirtualFile buildFolder = createFolder(moduleFolder, name);
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getBuildFolder()).thenReturn(virtualToIoFile(buildFolder));
    // Create "jars" folder inside the module's "build" folder.
    VirtualFile jarsFolder = createFolder(buildFolder, "jars");
    File jarsFolderPath = virtualToIoFile(jarsFolder);
    // We simulate the dependency to set up being inside the "jars" folder. We expect the "jars" folder to be excluded to avoid unnecessary
    // indexing of the jar files.
    LibraryDependency dependency = createFakeLibraryDependency(jarsFolderPath);
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    mySetupStep.updateLibraryDependency(module, modelsProvider, dependency, androidProject);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Make sure DependenciesSetup#setUpLibraryDependency was invoked.
    verify(myDependenciesSetup).setUpLibraryDependency(module, modelsProvider, "myLibrary", COMPILE, dependency.getArtifactPath(), dependency.getPaths(BINARY), dependency.getPaths(DOCUMENTATION));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)35 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)12 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)7 File (java.io.File)7 Variant (com.android.builder.model.Variant)6 Module (com.intellij.openapi.module.Module)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 NotNull (org.jetbrains.annotations.NotNull)6 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NonNull (com.android.annotations.NonNull)3 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 LintOptions (com.android.builder.model.LintOptions)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)2 GradleUtil.getAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)2 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)2