Search in sources :

Example 1 with DataNodeCaches

use of com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches in project android by JetBrains.

the class IdeaGradleSync method sync.

@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
    // Prevent IDEA from syncing with Gradle. We want to have full control of syncing.
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
    if (SYNC_WITH_CACHED_MODEL_ONLY || request.isUseCachedGradleModels()) {
        GradleProjectSyncData syncData = GradleProjectSyncData.getInstance((project));
        if (syncData != null && syncData.canUseCachedProjectData()) {
            DataNodeCaches dataNodeCaches = DataNodeCaches.getInstance(project);
            DataNode<ProjectData> cache = dataNodeCaches.getCachedProjectData();
            if (cache != null && !dataNodeCaches.isCacheMissingModels(cache)) {
                PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
                // @formatter:off
                setupRequest.setUsingCachedGradleModels(true).setGenerateSourcesAfterSync(false).setLastSyncTimestamp(syncData.getLastGradleSyncTimestamp());
                // @formatter:on
                boolean newProject = request.isNewProject();
                ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, newProject, !newProject, true);
                setUpTask.onSuccess(cache);
                return;
            }
        }
    }
    PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
    // @formatter:off
    setupRequest.setGenerateSourcesAfterSync(request.isGenerateSourcesOnSuccess()).setCleanProjectAfterSync(request.isCleanProject());
    // @formatter:on
    String externalProjectPath = getBaseDirPath(project).getPath();
    ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, request.isNewProject(), false, false);
    ProgressExecutionMode executionMode = request.getProgressExecutionMode();
    refreshProject(project, GRADLE_SYSTEM_ID, externalProjectPath, setUpTask, false, /* resolve dependencies */
    executionMode, true);
}
Also used : GradleProjectSyncData(com.android.tools.idea.gradle.project.GradleProjectSyncData) PostSyncProjectSetup(com.android.tools.idea.gradle.project.sync.setup.post.PostSyncProjectSetup) DataNodeCaches(com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches) ProgressExecutionMode(com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with DataNodeCaches

use of com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches in project android by JetBrains.

the class GradleSyncIntegrationTest method testWithCacheMissingModules.

// Verifies that if syncing using cached model, and if the cached model is missing data, we fall back to a full Gradle sync.
// See: https://code.google.com/p/android/issues/detail?id=160899
public void testWithCacheMissingModules() throws Exception {
    Project project = getProject();
    myOriginalDataNodeCaches = DataNodeCaches.getInstance(project);
    loadSimpleApplication();
    // Simulate data node cache is missing modules.
    //noinspection unchecked
    DataNode<ProjectData> cache = mock(DataNode.class);
    DataNodeCaches dataNodeCaches = IdeComponents.replaceServiceWithMock(project, DataNodeCaches.class);
    when(dataNodeCaches.getCachedProjectData()).thenReturn(cache);
    when(dataNodeCaches.isCacheMissingModels(cache)).thenReturn(true);
    GradleSyncInvoker.Request request = new GradleSyncInvoker.Request();
    // @formatter:off
    request.setGenerateSourcesOnSuccess(false).setUseCachedGradleModels(true);
    // @formatter:on
    // Sync again, and a full sync should occur, since the cache is missing modules.
    // 'waitForGradleProjectSyncToFinish' will never finish and test will time out and fail if the IDE never gets notified that the sync
    // finished.
    requestSyncAndWait(request);
}
Also used : Project(com.intellij.openapi.project.Project) DataNodeCaches(com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Aggregations

DataNodeCaches (com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches)2 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 GradleProjectSyncData (com.android.tools.idea.gradle.project.GradleProjectSyncData)1 PostSyncProjectSetup (com.android.tools.idea.gradle.project.sync.setup.post.PostSyncProjectSetup)1 ProgressExecutionMode (com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode)1 Project (com.intellij.openapi.project.Project)1