use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class CloneCloudRepositoryDialog method updateButtons.
/**
* Check fields and display error in the wrapper if there is a problem.
*/
private void updateButtons() {
CloudProject selectedProject = projectSelector.getSelectedProject();
Optional<CredentialedUser> selectedUser = selectedProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(selectedProject.googleUsername());
if (selectedProject != null && !selectedUser.isPresent()) {
setErrorText(GctBundle.message("cloud.repository.dialog.invalid.project"));
setOKActionEnabled(false);
return;
}
if (!StringUtil.isEmpty(repositorySelector.getText()) && StringUtil.isEmpty(repositorySelector.getSelectedRepository())) {
setErrorText(GctBundle.message("cloud.repository.dialog.invalid.repository"));
setOKActionEnabled(false);
return;
}
if (!selectedUser.isPresent() || StringUtil.isEmpty(repositorySelector.getSelectedRepository())) {
setErrorText(null);
setOKActionEnabled(false);
return;
}
if (StringUtil.isEmpty(parentDirectory.getText()) || StringUtil.isEmpty(directoryName.getText())) {
setErrorText(null);
setOKActionEnabled(false);
return;
}
File file = new File(parentDirectory.getText(), directoryName.getText());
if (file.exists()) {
setErrorText(GctBundle.message("clonefromgcp.destination.exists.error"));
setOKActionEnabled(false);
return;
}
if (!file.getParentFile().exists()) {
setErrorText(GctBundle.message("clonefromgcp.parent.missing.error"));
setOKActionEnabled(false);
return;
}
setErrorText(null);
setOKActionEnabled(true);
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class RepositorySelector method showPopup.
@Override
public void showPopup(RelativePoint showTarget) {
Optional<CredentialedUser> user = cloudProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(cloudProject.googleUsername());
if (user.isPresent()) {
if (popup == null || popup.isDisposed()) {
panel = new RepositoryPanel();
ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
popup = popupBuilder.createPopup();
}
if (!popup.isVisible()) {
popup.show(showTarget);
}
} else {
panel = new ProjectNotSelectedPanel();
ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
popup = popupBuilder.createPopup();
popup.show(showTarget);
}
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class SetupCloudRepositoryAction method uploadProjectToGoogleCloud.
private static void uploadProjectToGoogleCloud(@NotNull final Project project, @Nullable final VirtualFile file) {
BasicAction.saveAll();
project.save();
final GitRepository gitRepository = getGitRepository(project, file);
final boolean gitDetected = gitRepository != null;
final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir();
SetupCloudRepositoryDialog dialog = new SetupCloudRepositoryDialog(project, gitRepository, GctBundle.message("uploadtogcp.title"), GctBundle.message("uploadtogcp.oktext"));
DialogManager.show(dialog);
if (!dialog.isOK() || dialog.getCredentialedUser() == null || Strings.isNullOrEmpty(dialog.getProjectId())) {
return;
}
String remoteName = dialog.getRemoteName();
if (gitRepository != null && hasRemote(gitRepository.getRemotes(), remoteName)) {
Notification notification = new Notification(NOTIFICATION_GROUP_ID, GctBundle.message("uploadtogcp.remotename.collision.title"), GctBundle.message("uploadtogcp.remotename.collision", remoteName), NotificationType.ERROR);
notification.notify(project);
return;
}
final String projectId = dialog.getProjectId();
final String repositoryId = dialog.getRepositoryId();
final CredentialedUser user = dialog.getCredentialedUser();
// finish the job in background
new Task.Backgroundable(project, GctBundle.message("uploadtogcp.backgroundtitle")) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
// creating empty git repo if git is not initialized
LOG.info("Binding local project with Git");
if (!gitDetected) {
LOG.info("No git detected, creating empty git repo");
indicator.setText(GctBundle.message("uploadtogcp.indicatorinit"));
if (!createEmptyGitRepository(project, root, indicator)) {
return;
}
}
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
final GitRepository repository = repositoryManager.getRepositoryForRoot(root);
if (repository == null) {
SwingUtilities.invokeLater(() -> {
Notification notification = new Notification(NOTIFICATION_GROUP_ID, GctBundle.message("uploadtogcp.generic.failure.title"), GctBundle.message("uploadtogcp.failedtocreategit"), NotificationType.ERROR);
notification.notify(project);
});
LOG.error("GitRepository is null for root " + root);
return;
}
final String remoteUrl = GcpHttpAuthDataProvider.getGcpUrl(projectId, repositoryId);
LOG.info("Adding Google as a remote host");
indicator.setText(GctBundle.message("uploadtogcp.addingremote"));
if (!addGitRemote(project, repository, remoteName, remoteUrl)) {
return;
}
boolean succeeded = false;
try {
PropertiesComponent.getInstance(project).setValue(GcpHttpAuthDataProvider.GCP_USER, user.getEmail());
LOG.info("Fetching from Google remote");
indicator.setText(GctBundle.message("uploadtogcp.fetching"));
if (!fetchGit(project, indicator, repository, remoteName)) {
return;
}
// create sample commit for binding project
if (!performFirstCommitIfRequired(project, root, repository, indicator)) {
return;
}
// git push origin master
LOG.info("Pushing to Google master");
indicator.setText(GctBundle.message("uploadtogcp.pushingtotgcp"));
if (!pushCurrentBranch(project, repository, remoteName, remoteUrl)) {
return;
}
succeeded = true;
} finally {
if (!succeeded) {
// remove the remote if possible on a failure, so the user can try again.
removeGitRemote(project, repository, remoteName);
}
}
showInfoUrl(project, remoteName, GctBundle.message("uploadtogcp.success"), remoteUrl);
}
}.queue();
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class RepositorySelectorTest method createInitializedSelector.
private RepositorySelector createInitializedSelector() {
String mockUserId = "mockUser";
CredentialedUser mockUser = mock(CredentialedUser.class);
when(googleLoginService.getLoggedInUser(mockUserId)).thenReturn(Optional.of(mockUser));
return new RepositorySelector(CloudProject.create("my-project", "my-project", mockUserId), false);
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessHandlerTest method setupMocks.
private void setupMocks() {
GoogleLoginState googleLoginState = mock(GoogleLoginState.class);
CredentialedUser credentialedUser = mock(CredentialedUser.class);
when(credentialedUser.getGoogleLoginState()).thenReturn(googleLoginState);
LinkedHashMap<String, CredentialedUser> users = new LinkedHashMap<String, CredentialedUser>();
users.put("mockUser@foo.bar", credentialedUser);
when(mockLoginService.getAllUsers()).thenReturn(users);
CloudDebugProcessState cloudDebugProcessState = mock(CloudDebugProcessState.class);
when(cloudDebugProcessState.getUserEmail()).thenReturn("mockUser@foo.bar");
CloudDebugProcess cloudDebugProcess = mock(CloudDebugProcess.class);
when(cloudDebugProcess.getProcessState()).thenReturn(cloudDebugProcessState);
handler = new CloudDebugProcessHandler(cloudDebugProcess);
}
Aggregations