boolean performClone() { final URIish uri = cloneSource.getSelection().getURI(); setWindowTitle(NLS.bind(UIText.GitCloneWizard_jobName, uri.toString())); final boolean allSelected; final Collection<Ref> selectedBranches; if (validSource.isSourceRepoEmpty()) { // fetch all branches of empty repo allSelected = true; selectedBranches = Collections.emptyList(); } else { allSelected = validSource.isAllSelected(); selectedBranches = validSource.getSelectedBranches(); } final File workdir = cloneDestination.getDestinationFile(); final Ref ref = cloneDestination.getInitialBranch(); final String remoteName = cloneDestination.getRemote(); boolean created = workdir.exists(); if (!created) created = workdir.mkdirs(); if (!created || !workdir.isDirectory()) { final String errorMessage = NLS.bind(UIText.GitCloneWizard_errorCannotCreate, workdir.getPath()); ErrorDialog.openError( getShell(), getWindowTitle(), UIText.GitCloneWizard_failed, new Status(IStatus.ERROR, Activator.getPluginId(), 0, errorMessage, null)); // let's give user a chance to fix this minor problem return false; } int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); final CloneOperation op = new CloneOperation( uri, allSelected, selectedBranches, workdir, ref != null ? ref.getName() : null, remoteName, timeout); if (gerritConfiguration.configureGerrit()) doGerritConfiguration(remoteName, op); UserPasswordCredentials credentials = cloneSource.getCredentials(); if (credentials != null) op.setCredentialsProvider( new UsernamePasswordCredentialsProvider( credentials.getUser(), credentials.getPassword())); alreadyClonedInto = workdir.getPath(); cloneSource.saveUriInPrefs(); if (!callerRunsCloneOperation) runAsJob(uri, op); else cloneOperation = op; return true; }
@Override public boolean get(final URIish uri, final CredentialItem... items) throws UnsupportedCredentialItem { if (items.length == 0) { return true; } CredentialItem.Username userItem = null; CredentialItem.Password passwordItem = null; boolean isSpecial = false; for (CredentialItem item : items) { if (item instanceof CredentialItem.Username) userItem = (CredentialItem.Username) item; else if (item instanceof CredentialItem.Password) passwordItem = (CredentialItem.Password) item; else isSpecial = true; } if (!isSpecial && (userItem != null || passwordItem != null)) { UserPasswordCredentials credentials = null; if ((user != null) && (password != null)) credentials = new UserPasswordCredentials(user, password); else credentials = SecureStoreUtils.getCredentialsQuietly(uri); if (credentials == null) { credentials = getCredentialsFromUser(uri); if (credentials == null) return false; } if (userItem != null) userItem.setValue(credentials.getUser()); if (passwordItem != null) passwordItem.setValue(credentials.getPassword().toCharArray()); return true; } // special handling for non-user,non-password type items final boolean[] result = new boolean[1]; PlatformUI.getWorkbench() .getDisplay() .syncExec( new Runnable() { @Override public void run() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); if (items.length == 1) { CredentialItem item = items[0]; result[0] = getSingleSpecial(shell, uri, item); } else { result[0] = getMultiSpecial(shell, uri, items); } } }); return result[0]; }
/** * The method shows a change credentials dialog for a given URI. The user field is taken from the * URI if a user is present in the URI. In this case the user is not editable. * * @param parent * @param uri * @return credentials, <code>null</code> if the user canceled the dialog. */ public static UserPasswordCredentials changeCredentials(Shell parent, URIish uri) { LoginDialog dialog = new LoginDialog(parent, uri); dialog.setChangeCredentials(true); UserPasswordCredentials oldCredentials = SecureStoreUtils.getCredentials(uri); if (oldCredentials != null) dialog.setOldUser(oldCredentials.getUser()); if (dialog.open() == Window.OK) { UserPasswordCredentials credentials = dialog.getCredentials(); if (credentials != null) SecureStoreUtils.storeCredentials(credentials, uri); return credentials; } return null; }
private void revalidateImpl(final RepositorySelection newRepoSelection) { final ListRemoteOperation listRemotesOp; try { final URIish uri; uri = newRepoSelection.getURI(pushPage); int timeout = Activator.getDefault() .getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); listRemotesOp = new ListRemoteOperation(local, uri, timeout); if (credentials != null) listRemotesOp.setCredentialsProvider( new UsernamePasswordCredentialsProvider( credentials.getUser(), credentials.getPassword())); getContainer() .run( true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { listRemotesOp.run(monitor); } }); } catch (InvocationTargetException e) { final Throwable cause = e.getCause(); transportError(cause.getMessage()); ErrorDialog.openError( getShell(), UIText.RefSpecPage_errorTransportDialogTitle, UIText.RefSpecPage_errorTransportDialogMessage, new Status(IStatus.ERROR, Activator.getPluginId(), 0, cause.getMessage(), cause)); return; } catch (InterruptedException e) { transportError(UIText.RefSpecPage_operationCancelled); return; } this.validatedRepoSelection = newRepoSelection; specsPanel.setAssistanceData( local, listRemotesOp.getRemoteRefs(), currentRepoSelection.getConfig()); if (newRepoSelection.isConfigSelected()) { saveButton.setVisible(true); saveButton.setText( NLS.bind(UIText.RefSpecPage_saveSpecifications, currentRepoSelection.getConfigName())); saveButton.getParent().layout(); if (!pushPage) { tagsAutoFollowButton.setSelection(false); tagsFetchTagsButton.setSelection(false); tagsNoTagsButton.setSelection(false); final TagOpt tagOpt = newRepoSelection.getConfig().getTagOpt(); switch (tagOpt) { case AUTO_FOLLOW: tagsAutoFollowButton.setSelection(true); break; case FETCH_TAGS: tagsFetchTagsButton.setSelection(true); break; case NO_TAGS: tagsNoTagsButton.setSelection(true); break; } } } else if (!pushPage) tagsAutoFollowButton.setSelection(true); checkPage(); }
/** Check the user input and set messages in case of invalid input. */ protected void checkPage() { if (isURISelected()) { assert uri != null; if (uriText.getText().length() == 0) { selectionIncomplete(null); return; } else if (uriText.getText().endsWith(" ")) { // $NON-NLS-1$ selectionIncomplete(UIText.RepositorySelectionPage_UriMustNotHaveTrailingSpacesMessage); return; } try { final URIish finalURI = new URIish(uriText.getText().trim()); String proto = finalURI.getScheme(); if (proto == null && scheme.getSelectionIndex() >= 0) proto = scheme.getItem(scheme.getSelectionIndex()); if (uri.getPath() == null) { selectionIncomplete( NLS.bind( UIText.RepositorySelectionPage_fieldRequired, unamp(UIText.RepositorySelectionPage_promptPath), proto)); return; } if (Protocol.FILE.handles(finalURI)) { String badField = null; if (uri.getHost() != null) badField = UIText.RepositorySelectionPage_promptHost; else if (uri.getUser() != null) badField = UIText.RepositorySelectionPage_promptUser; else if (uri.getPass() != null) badField = UIText.RepositorySelectionPage_promptPassword; if (badField != null) { selectionIncomplete( NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto)); return; } final File d = FS.DETECTED.resolve(new File("."), uri.getPath()); // $NON-NLS-1$ if (!d.exists()) { selectionIncomplete( NLS.bind(UIText.RepositorySelectionPage_fileNotFound, d.getAbsolutePath())); return; } selectionComplete(finalURI, null); return; } if (uri.getHost() == null) { selectionIncomplete( NLS.bind( UIText.RepositorySelectionPage_fieldRequired, unamp(UIText.RepositorySelectionPage_promptHost), proto)); return; } if (Protocol.GIT.handles(finalURI)) { String badField = null; if (uri.getUser() != null) badField = UIText.RepositorySelectionPage_promptUser; else if (uri.getPass() != null) badField = UIText.RepositorySelectionPage_promptPassword; if (badField != null) { selectionIncomplete( NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto)); return; } } if (Protocol.HTTP.handles(finalURI) || Protocol.HTTPS.handles(finalURI)) { UserPasswordCredentials credentials = getSecureStoreCredentials(finalURI); if (credentials != null) { String u = credentials.getUser(); String p = credentials.getPassword(); String uriUser = finalURI.getUser(); if (uriUser == null) { if (setSafeUser(u) || setSafePassword(p)) setStoreInSecureStore(true); } else if (uriUser.length() != 0 && uriUser.equals(u)) { if (setSafePassword(p)) setStoreInSecureStore(true); } } } selectionComplete(finalURI, null); return; } catch (URISyntaxException e) { selectionIncomplete(e.getReason()); return; } catch (Exception e) { Activator.logError( NLS.bind(UIText.RepositorySelectionPage_errorValidating, getClass().getName()), e); selectionIncomplete(UIText.RepositorySelectionPage_internalError); return; } } else { assert remoteButton.getSelection(); selectionComplete(null, remoteConfig); return; } }