Search in sources :

Example 1 with ProjectRepositoryValidator

use of com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudAttachDialog method checkSyncStashState.

/**
 * Checks whether a stash or sync is needed based on the chosen target and local state.
 */
private void checkSyncStashState() {
    if (processResultState == null) {
        LOG.error("unexpected result state during a check sync stash state");
        return;
    }
    syncResult = projectRepositoryValidator == null ? new ProjectRepositoryValidator(processResultState).checkSyncStashState() : projectRepositoryValidator.checkSyncStashState();
    // reset state
    syncStashCheckbox.setVisible(false);
    syncStashCheckbox.setSelected(false);
    warningHeader.setVisible(false);
    warningMessage.setVisible(false);
    checkBackgroundSessions();
    if (syncResult.needsStash() && syncResult.needsSync()) {
        setOkText(false);
        syncStashCheckbox.setVisible(true);
        assert syncResult.getTargetSyncSha() != null;
        syncStashCheckbox.setText(GctBundle.getString("clouddebug.stash.local.changes.and.sync", syncResult.getTargetSyncSha().substring(0, 7)));
        syncStashCheckbox.setSelected(true);
    } else if (syncResult.needsStash()) {
        setOkText(false);
        syncStashCheckbox.setVisible(true);
        syncStashCheckbox.setText(GctBundle.getString("clouddebug.stashbuttontext"));
        syncStashCheckbox.setSelected(true);
    } else if (syncResult.needsSync() && syncResult.getTargetSyncSha() == null) {
        setOkText(true);
        warningHeader.setVisible(true);
        warningMessage.setVisible(true);
        warningMessage.setText(GctBundle.getString("clouddebug.no.matching.sha"));
    } else if (syncResult.needsSync()) {
        setOkText(false);
        syncStashCheckbox.setVisible(true);
        assert syncResult.getTargetSyncSha() != null;
        syncStashCheckbox.setText("Sync to " + syncResult.getTargetSyncSha().substring(0, 7));
        syncStashCheckbox.setSelected(true);
    } else if (!syncResult.hasRemoteRepository()) {
        setOkText(true);
        warningHeader.setVisible(true);
        warningMessage.setVisible(true);
        if (syncResult.getRepositoryType() != null) {
            warningMessage.setText(GctBundle.getString("clouddebug.repositories.are.not.supported", syncResult.getRepositoryType()));
        } else {
            warningMessage.setText(GctBundle.getString("clouddebug.no.remote.repository"));
        }
    } else {
        setOkText(false);
    }
}
Also used : ProjectRepositoryValidator(com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator)

Example 2 with ProjectRepositoryValidator

use of com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudAttachDialogTest method testDebuggableModuleSelected.

public void testDebuggableModuleSelected() {
    mockLoggedInUser();
    binding = mock(ProjectDebuggeeBinding.class);
    when(binding.buildResult(any(Project.class))).thenReturn(new CloudDebugProcessState());
    ProjectRepositoryValidator repositoryValidator = mock(ProjectRepositoryValidator.class);
    SyncResult syncResult = mockSyncResult(false, true);
    when(repositoryValidator.checkSyncStashState()).thenReturn(syncResult);
    CloudAttachDialog dialog = initDialog();
    dialog.setProjectRepositoryValidator(repositoryValidator);
    selectProjectWithDebuggableModules();
    ValidationInfo error = dialog.doValidate();
    assertNull(error);
    assertFalse(warningMessage.isVisible());
    assertFalse(warningHeader.isVisible());
    assertFalse(syncStashCheckbox.isVisible());
    assertTrue(targetSelector.isEnabled());
    dialog.close(0);
}
Also used : CloudDebugProcessState(com.google.cloud.tools.intellij.debugger.CloudDebugProcessState) Project(com.intellij.openapi.project.Project) CloudProject(com.google.cloud.tools.intellij.project.CloudProject) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) ProjectRepositoryValidator(com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator) SyncResult(com.google.cloud.tools.intellij.debugger.SyncResult)

Example 3 with ProjectRepositoryValidator

use of com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudAttachDialogTest method testSyncStashReset.

/**
 * After selecting a module that requires sync/stash, any subsequent module that is selected that
 * has no remote repository is shown the sync/stash checkbox regardless of its state. The
 * visibility of this option needs to be properly reset.
 */
public void testSyncStashReset() {
    mockLoggedInUser();
    binding = mock(ProjectDebuggeeBinding.class);
    when(binding.buildResult(any(Project.class))).thenReturn(new CloudDebugProcessState());
    // Step 1 - select a debuggable module that requires stashing
    // The stash checkbox should be visible to the user
    boolean needsStash = true;
    boolean hasRemoteRepository = true;
    ProjectRepositoryValidator repositoryValidator = mock(ProjectRepositoryValidator.class);
    SyncResult syncResult = mockSyncResult(needsStash, hasRemoteRepository);
    when(repositoryValidator.checkSyncStashState()).thenReturn(syncResult);
    CloudAttachDialog dialog = initDialog();
    dialog.setProjectRepositoryValidator(repositoryValidator);
    selectProjectWithDebuggableModules();
    assertTrue(syncStashCheckbox.isVisible());
    // Step 2 - select a project with no remote repo that does NOT require stashing
    // The stash checkbox should now be hidden from the user
    needsStash = false;
    hasRemoteRepository = false;
    syncResult = mockSyncResult(needsStash, hasRemoteRepository);
    when(repositoryValidator.checkSyncStashState()).thenReturn(syncResult);
    selectEmptyProject();
    assertFalse(syncStashCheckbox.isVisible());
    dialog.close(0);
}
Also used : CloudDebugProcessState(com.google.cloud.tools.intellij.debugger.CloudDebugProcessState) Project(com.intellij.openapi.project.Project) CloudProject(com.google.cloud.tools.intellij.project.CloudProject) ProjectRepositoryValidator(com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator) SyncResult(com.google.cloud.tools.intellij.debugger.SyncResult)

Aggregations

ProjectRepositoryValidator (com.google.cloud.tools.intellij.debugger.ProjectRepositoryValidator)3 CloudDebugProcessState (com.google.cloud.tools.intellij.debugger.CloudDebugProcessState)2 SyncResult (com.google.cloud.tools.intellij.debugger.SyncResult)2 CloudProject (com.google.cloud.tools.intellij.project.CloudProject)2 Project (com.intellij.openapi.project.Project)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1