Search in sources :

Example 36 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.

the class FastGradleSync method requestProjectSync.

@NotNull
public Callback requestProjectSync(@NotNull Project project) {
    Callback callback = new Callback();
    GradleExecutionSettings settings = getGradleExecutionSettings(project);
    ExternalSystemTaskId id = ExternalSystemTaskId.create(GRADLE_SYSTEM_ID, RESOLVE_PROJECT, project);
    String projectPath = project.getBasePath();
    assert projectPath != null;
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            DataNode<ProjectData> projectDataNode = myProjectResolver.resolveProjectInfo(id, projectPath, false, settings, NULL_OBJECT);
            assert projectDataNode != null;
            invokeAndWaitIfNeeded((ThrowableRunnable) () -> populate(project, projectDataNode, null, false));
            callback.setDone();
        } catch (Throwable e) {
            callback.setRejected(e);
        }
    });
    return callback;
}
Also used : GradleExecutionSettings(org.jetbrains.plugins.gradle.settings.GradleExecutionSettings) GradleUtil.getGradleExecutionSettings(com.android.tools.idea.gradle.util.GradleUtil.getGradleExecutionSettings) ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) ActionCallback(com.intellij.openapi.util.ActionCallback) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method testPopulateModuleContentRootsWithJavaProject.

public void testPopulateModuleContentRootsWithJavaProject() {
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectNode = new DataNode<>(PROJECT, project, null);
    DataNode<ModuleData> moduleDataNode = myProjectResolver.createModule(myJavaModuleModel, projectNode);
    myProjectResolver.populateModuleContentRoots(myJavaModuleModel, moduleDataNode);
    // Verify module does not have AndroidGradleModel.
    Collection<DataNode<AndroidModuleModel>> androidModelNodes = getChildren(moduleDataNode, ANDROID_MODEL);
    assertThat(androidModelNodes).isEmpty();
    // Verify module has IdeaGradleProject.
    Collection<DataNode<GradleModuleModel>> gradleModelNodes = getChildren(moduleDataNode, GRADLE_MODULE_MODEL);
    assertThat(gradleModelNodes).hasSize(1);
    DataNode<GradleModuleModel> gradleModelNode = getFirstItem(gradleModelNodes);
    assertNotNull(gradleModelNode);
    assertEquals(myJavaModuleModel.getGradleProject().getPath(), gradleModelNode.getData().getGradlePath());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 38 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method testPopulateModuleContentRootsWithNativeAndroidProject.

public void testPopulateModuleContentRootsWithNativeAndroidProject() {
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectNode = new DataNode<>(PROJECT, project, null);
    DataNode<ModuleData> moduleDataNode = myProjectResolver.createModule(myNativeAndroidModuleModel, projectNode);
    myProjectResolver.populateModuleContentRoots(myNativeAndroidModuleModel, moduleDataNode);
    // Verify module does not have AndroidGradleModel.
    Collection<DataNode<AndroidModuleModel>> androidModelNodes = getChildren(moduleDataNode, ANDROID_MODEL);
    assertThat(androidModelNodes).isEmpty();
    // Verify module has NativeAndroidGradleModel.
    Collection<DataNode<NdkModuleModel>> ndkModuleModelNodes = getChildren(moduleDataNode, NDK_MODEL);
    assertThat(ndkModuleModelNodes).hasSize(1);
    DataNode<NdkModuleModel> nativeAndroidModelNode = getFirstItem(ndkModuleModelNodes);
    assertNotNull(nativeAndroidModelNode);
    assertSame(myNativeAndroidProject, nativeAndroidModelNode.getData().getAndroidProject());
    // Verify module has IdeaGradleProject.
    Collection<DataNode<GradleModuleModel>> gradleModelNodes = getChildren(moduleDataNode, GRADLE_MODULE_MODEL);
    assertThat(gradleModelNodes).hasSize(1);
    DataNode<GradleModuleModel> gradleModelNode = getFirstItem(gradleModelNodes);
    assertNotNull(gradleModelNode);
    assertEquals(myNativeAndroidModuleModel.getGradleProject().getPath(), gradleModelNode.getData().getGradlePath());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 39 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project android by JetBrains.

the class AndroidGradleProjectResolverIdeaTest method testPopulateModuleContentRootsWithAndroidProject.

public void testPopulateModuleContentRootsWithAndroidProject() {
    when(myVariantSelector.findVariantToSelect(myAndroidProject)).thenReturn(myAndroidProject.getFirstVariant());
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectNode = new DataNode<>(PROJECT, project, null);
    DataNode<ModuleData> moduleDataNode = myProjectResolver.createModule(myAndroidModuleModel, projectNode);
    myProjectResolver.populateModuleContentRoots(myAndroidModuleModel, moduleDataNode);
    // Verify module has AndroidGradleModel.
    Collection<DataNode<AndroidModuleModel>> androidModelNodes = getChildren(moduleDataNode, ANDROID_MODEL);
    assertThat(androidModelNodes).hasSize(1);
    DataNode<AndroidModuleModel> androidModelNode = getFirstItem(androidModelNodes);
    assertNotNull(androidModelNode);
    assertSame(myAndroidProject, androidModelNode.getData().getAndroidProject());
    // Verify module has IdeaGradleProject.
    Collection<DataNode<GradleModuleModel>> gradleModelNodes = getChildren(moduleDataNode, GRADLE_MODULE_MODEL);
    assertThat(gradleModelNodes).hasSize(1);
    DataNode<GradleModuleModel> gradleModelNode = getFirstItem(gradleModelNodes);
    assertNotNull(gradleModelNode);
    assertEquals(myAndroidModuleModel.getGradleProject().getPath(), gradleModelNode.getData().getGradlePath());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 40 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData 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)

Aggregations

ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)40 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)13 DataNode (com.intellij.openapi.externalSystem.model.DataNode)12 Project (com.intellij.openapi.project.Project)8 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MultiMap (com.intellij.util.containers.MultiMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)3 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 Module (com.intellij.openapi.module.Module)3 Task (com.intellij.openapi.progress.Task)3 DataNodeCaches (com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches)2 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2