Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 59327 Details for
Bug 172085
[api] generalize repository validation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
generalize repository validation
generalize-validation.patch (text/plain), 26.61 KB, created by
Steffen Pingel
on 2007-02-19 18:03:19 EST
(
hide
)
Description:
generalize repository validation
Filename:
MIME Type:
Creator:
Steffen Pingel
Created:
2007-02-19 18:03:19 EST
Size:
26.61 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylar.trac.tests >Index: src/org/eclipse/mylar/trac/tests/TracRepositorySettingsPageTest.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.trac.tests/src/org/eclipse/mylar/trac/tests/TracRepositorySettingsPageTest.java,v >retrieving revision 1.1 >diff -u -r1.1 TracRepositorySettingsPageTest.java >--- src/org/eclipse/mylar/trac/tests/TracRepositorySettingsPageTest.java 18 Jan 2007 00:47:22 -0000 1.1 >+++ src/org/eclipse/mylar/trac/tests/TracRepositorySettingsPageTest.java 19 Feb 2007 22:54:35 -0000 >@@ -13,12 +13,13 @@ > > import java.net.Proxy; > >+import org.eclipse.core.runtime.NullProgressMonitor; > import org.eclipse.mylar.internal.trac.core.ITracClient; > import org.eclipse.mylar.internal.trac.core.TracCorePlugin; > import org.eclipse.mylar.internal.trac.core.ITracClient.Version; > import org.eclipse.mylar.internal.trac.ui.TracRepositoryUi; > import org.eclipse.mylar.internal.trac.ui.wizard.TracRepositorySettingsPage; >-import org.eclipse.mylar.internal.trac.ui.wizard.TracRepositorySettingsPage.Validator; >+import org.eclipse.mylar.internal.trac.ui.wizard.TracRepositorySettingsPage.TracValidator; > import org.eclipse.mylar.tasks.ui.TasksUiPlugin; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.ui.PlatformUI; >@@ -30,7 +31,7 @@ > > private TracRepositoryUi connector; > private TracRepositorySettingsPage page; >- private Validator validator; >+ private TracValidator validator; > > public TracRepositorySettingsPageTest() { > super(null); >@@ -61,7 +62,7 @@ > page.setUserId(username); > page.setPassword(password); > page.setTracVersion(version); >- validator = page.new Validator(); >+ validator = page.new TracValidator(page.createTaskRepository(), version); > return null; > } > >@@ -69,7 +70,7 @@ > version = Version.XML_RPC; > connect010(); > >- validator.run(); >+ validator.run(new NullProgressMonitor()); > assertNull(validator.getResult()); > assertNull(validator.getStatus()); > } >@@ -78,7 +79,7 @@ > version = Version.TRAC_0_9; > connect010(); > >- validator.run(); >+ validator.run(new NullProgressMonitor()); > assertNull(validator.getResult()); > assertNull(validator.getStatus()); > } >@@ -87,7 +88,7 @@ > version = null; > connect010(); > >- validator.run(); >+ validator.run(new NullProgressMonitor()); > assertEquals(Version.XML_RPC, validator.getResult()); > assertNull(validator.getStatus()); > } >@@ -96,7 +97,7 @@ > version = null; > connect(Constants.TEST_TRAC_010_URL, "", ""); > >- validator.run(); >+ validator.run(new NullProgressMonitor()); > assertEquals(Version.TRAC_0_9, validator.getResult()); > assertNotNull(validator.getStatus()); > } >#P org.eclipse.mylar.tasks.web >Index: src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.tasks.web/src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java,v >retrieving revision 1.5 >diff -u -r1.5 WebRepositorySettingsPage.java >--- src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java 19 Dec 2006 23:05:50 -0000 1.5 >+++ src/org/eclipse/mylar/internal/tasks/web/WebRepositorySettingsPage.java 19 Feb 2007 22:54:35 -0000 >@@ -85,6 +85,8 @@ > > public WebRepositorySettingsPage(AbstractRepositoryConnectorUi repositoryUi) { > super(TITLE, DESCRIPTION, repositoryUi); >+ >+ setNeedsValidation(false); > } > > @Override >@@ -178,11 +180,6 @@ > return true; > } > >- @Override >- protected void validateSettings() { >- // ignore >- } >- > private Composite getParameterEditor(Composite parent) { > final Composite composite = new Composite(parent, SWT.NONE); > composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >@@ -377,4 +374,9 @@ > > } > >+ @Override >+ protected Validator getValidator(TaskRepository repository) { >+ return null; >+ } >+ > } >#P org.eclipse.mylar.jira.ui >Index: src/org/eclipse/mylar/internal/jira/ui/wizards/JiraRepositorySettingsPage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.jira.ui/src/org/eclipse/mylar/internal/jira/ui/wizards/JiraRepositorySettingsPage.java,v >retrieving revision 1.16 >diff -u -r1.16 JiraRepositorySettingsPage.java >--- src/org/eclipse/mylar/internal/jira/ui/wizards/JiraRepositorySettingsPage.java 1 Feb 2007 03:26:46 -0000 1.16 >+++ src/org/eclipse/mylar/internal/jira/ui/wizards/JiraRepositorySettingsPage.java 19 Feb 2007 22:54:36 -0000 >@@ -11,15 +11,17 @@ > > package org.eclipse.mylar.internal.jira.ui.wizards; > >-import java.lang.reflect.InvocationTargetException; > import java.net.MalformedURLException; > import java.net.URL; > >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >-import org.eclipse.jface.dialogs.IMessageProvider; >-import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; > import org.eclipse.mylar.internal.jira.ui.JiraServerFacade; >+import org.eclipse.mylar.internal.jira.ui.JiraUiPlugin; > import org.eclipse.mylar.tasks.core.RepositoryTemplate; >+import org.eclipse.mylar.tasks.core.TaskRepository; > import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi; > import org.eclipse.mylar.tasks.ui.wizards.AbstractRepositorySettingsPage; > import org.eclipse.swt.events.SelectionAdapter; >@@ -36,8 +38,6 @@ > */ > public class JiraRepositorySettingsPage extends AbstractRepositorySettingsPage { > >- private static final String MESSAGE_FAILURE_CONNECT = "Could not connect to the Jira server or the login was not accepted"; >- > private static final String TITLE = "Jira Repository Settings"; > > private static final String DESCRIPTION = "Example: http://developer.atlassian.com/jira"; >@@ -84,40 +84,35 @@ > } > > @Override >- protected void validateSettings() { >- final String serverUrl = getServerUrl(); >- final String userName = getUserName(); >- final String password = getPassword(); >- try { >- getWizard().getContainer().run(true, false, new IRunnableWithProgress() { >- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >- try { >- new URL(serverUrl); >- } catch (MalformedURLException ex) { >- throw new InvocationTargetException(new RuntimeException("Malformed server URL")); >- } >- monitor.beginTask("Validating repository settings", IProgressMonitor.UNKNOWN); >- try { >- String message = JiraServerFacade.getDefault().validateServerAndCredentials(serverUrl, >- userName, password); >- if (message != null) { >- throw new InvocationTargetException(new RuntimeException(message)); >- } >- } finally { >- monitor.done(); >- } >- } >- }); >- setErrorMessage(null); >- setMessage("Valid Jira server found and your login was accepted", IMessageProvider.INFORMATION); >- } catch (InvocationTargetException e) { >- // MessageDialog.openError(null, JiraUiPlugin.TITLE_MESSAGE_DIALOG, e.getTargetException().getMessage()); >- setErrorMessage(e.getTargetException().getMessage()); >- setMessage(null); >- } catch (InterruptedException e) { >- // MessageDialog.openError(null, JiraUiPlugin.TITLE_MESSAGE_DIALOG, MESSAGE_FAILURE_CONNECT); >- setErrorMessage(MESSAGE_FAILURE_CONNECT); >- setMessage(null); >+ protected Validator getValidator(TaskRepository repository) { >+ return new JiraValidator(repository); >+ } >+ >+ private class JiraValidator extends Validator { >+ >+ final TaskRepository repository; >+ >+ public JiraValidator(TaskRepository repository) { >+ this.repository = repository; >+ } >+ >+ @Override >+ public void run(IProgressMonitor monitor) throws CoreException { >+ try { >+ new URL(repository.getUrl()); >+ } catch (MalformedURLException ex) { >+ throw new CoreException(new Status(IStatus.ERROR, JiraUiPlugin.PLUGIN_ID, INVALID_REPOSITORY_URL)); >+ } >+ >+ String message = JiraServerFacade.getDefault().validateServerAndCredentials(repository.getUrl(), >+ repository.getUserName(), repository.getPassword()); >+ if (message != null) { >+ throw new CoreException(new Status(IStatus.ERROR, JiraUiPlugin.PLUGIN_ID, message)); >+ } >+ >+ setStatus(new Status(IStatus.OK, JiraUiPlugin.PLUGIN_ID, "Valid JIRA server found and your login was accepted")); > } >+ > } >+ > } >Index: src/org/eclipse/mylar/internal/jira/ui/JiraUiPlugin.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.jira.ui/src/org/eclipse/mylar/internal/jira/ui/JiraUiPlugin.java,v >retrieving revision 1.2 >diff -u -r1.2 JiraUiPlugin.java >--- src/org/eclipse/mylar/internal/jira/ui/JiraUiPlugin.java 13 Feb 2007 05:13:18 -0000 1.2 >+++ src/org/eclipse/mylar/internal/jira/ui/JiraUiPlugin.java 19 Feb 2007 22:54:36 -0000 >@@ -22,6 +22,8 @@ > */ > public class JiraUiPlugin extends AbstractUIPlugin { > >+ public static final String PLUGIN_ID = "org.eclipse.mylar.jira.ui"; >+ > private static JiraUiPlugin INSTANCE; > > public final static String REPOSITORY_KIND = "jira"; >#P org.eclipse.mylar.tasks.tests >Index: src/org/eclipse/mylar/tasks/tests/RepositorySettingsPageTest.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.tasks.tests/src/org/eclipse/mylar/tasks/tests/RepositorySettingsPageTest.java,v >retrieving revision 1.9 >diff -u -r1.9 RepositorySettingsPageTest.java >--- src/org/eclipse/mylar/tasks/tests/RepositorySettingsPageTest.java 13 Feb 2007 23:10:08 -0000 1.9 >+++ src/org/eclipse/mylar/tasks/tests/RepositorySettingsPageTest.java 19 Feb 2007 22:54:37 -0000 >@@ -164,6 +164,12 @@ > Composite getParent() { > return parent; > } >+ >+ @Override >+ protected Validator getValidator(TaskRepository repository) { >+ // ignore >+ return null; >+ } > } > > } >#P org.eclipse.mylar.bugzilla.ui >Index: src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.bugzilla.ui/src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java,v >retrieving revision 1.52 >diff -u -r1.52 BugzillaRepositorySettingsPage.java >--- src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java 17 Feb 2007 01:57:18 -0000 1.52 >+++ src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java 19 Feb 2007 22:54:37 -0000 >@@ -278,4 +278,10 @@ > } > MylarStatusHandler.displayStatus("Validation failed", status); > } >+ >+ @Override >+ protected Validator getValidator(TaskRepository repository) { >+ // ignore >+ return null; >+ } > } >\ No newline at end of file >#P org.eclipse.mylar.tasks.ui >Index: src/org/eclipse/mylar/tasks/ui/wizards/AbstractRepositorySettingsPage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.tasks.ui/src/org/eclipse/mylar/tasks/ui/wizards/AbstractRepositorySettingsPage.java,v >retrieving revision 1.4 >diff -u -r1.4 AbstractRepositorySettingsPage.java >--- src/org/eclipse/mylar/tasks/ui/wizards/AbstractRepositorySettingsPage.java 7 Feb 2007 15:18:47 -0000 1.4 >+++ src/org/eclipse/mylar/tasks/ui/wizards/AbstractRepositorySettingsPage.java 19 Feb 2007 22:54:38 -0000 >@@ -11,12 +11,18 @@ > > package org.eclipse.mylar.tasks.ui.wizards; > >+import java.lang.reflect.InvocationTargetException; > import java.nio.charset.Charset; > import java.util.HashSet; > import java.util.List; > import java.util.Set; > >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; > import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.preference.StringFieldEditor; > import org.eclipse.jface.wizard.WizardPage; > import org.eclipse.mylar.core.MylarStatusHandler; >@@ -49,6 +55,7 @@ > /** > * @author Mik Kersten > * @author Rob Elves >+ * @author Steffen Pingel > */ > public abstract class AbstractRepositorySettingsPage extends WizardPage { > >@@ -64,6 +71,10 @@ > > protected static final String URL_PREFIX_HTTP = "http://"; > >+ protected static final String INVALID_REPOSITORY_URL = "Repository url is invalid."; >+ >+ protected static final String INVALID_LOGIN = "Unable to authenticate with repository. Login credentials invalid."; >+ > protected AbstractRepositoryConnector connector; > > protected StringFieldEditor repositoryLabelEditor; >@@ -116,6 +127,8 @@ > > private boolean needsHttpAuth; > >+ private boolean needsValidation; >+ > private Composite container; > > private Composite httpAuthComp; >@@ -164,6 +177,7 @@ > setNeedsEncoding(true); > setNeedsTimeZone(true); > setNeedsProxy(true); >+ setNeedsValidation(true); > } > > public void createControl(Composite parent) { >@@ -459,17 +473,19 @@ > addProxySection(); > } > >- validateServerButton = new Button(container, SWT.PUSH); >- GridDataFactory.swtDefaults().span(2, SWT.DEFAULT).grab(false, false).applyTo(validateServerButton); >- validateServerButton.setText("Validate Settings"); >- validateServerButton.addSelectionListener(new SelectionAdapter() { >- >- @Override >- public void widgetSelected(SelectionEvent e) { >- validateSettings(); >- } >- }); >+ if (needsValidation()) { >+ validateServerButton = new Button(container, SWT.PUSH); >+ GridDataFactory.swtDefaults().span(2, SWT.DEFAULT).grab(false, false).applyTo(validateServerButton); >+ validateServerButton.setText("Validate Settings"); >+ validateServerButton.addSelectionListener(new SelectionAdapter() { > >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ validateSettings(); >+ } >+ }); >+ } >+ > setControl(container); > } > >@@ -695,8 +711,6 @@ > > protected abstract void createAdditionalControls(Composite parent); > >- protected abstract void validateSettings(); >- > protected abstract boolean isValidUrl(String name); > > /* Public for testing. */ >@@ -964,6 +978,14 @@ > this.needsAnonymousLogin = needsAnonymousLogin; > } > >+ public void setNeedsValidation(boolean needsValidation) { >+ this.needsValidation = needsValidation; >+ } >+ >+ public boolean needsValidation() { >+ return needsValidation; >+ } >+ > public void updateProperties(TaskRepository repository) { > // none > } >@@ -982,4 +1004,89 @@ > public void setPassword(String pass) { > repositoryPasswordEditor.setStringValue(pass); > } >-} >\ No newline at end of file >+ >+ protected void validateSettings() { >+ final Validator validator = getValidator(createTaskRepository()); >+ if (validator == null) { >+ return; >+ } >+ >+ try { >+ getWizard().getContainer().run(true, false, new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >+ monitor.beginTask("Validating server settings", IProgressMonitor.UNKNOWN); >+ try { >+ validator.run(monitor); >+ if (validator.getStatus() == null) { >+ validator.setStatus(Status.OK_STATUS); >+ } >+ } catch (CoreException e) { >+ validator.setStatus(e.getStatus()); >+ } catch (Exception e) { >+ throw new InvocationTargetException(e); >+ } finally { >+ monitor.done(); >+ } >+ } >+ }); >+ } catch (InvocationTargetException e) { >+ MylarStatusHandler.fail(e.getCause(), "Internal error validating repository", true); >+ return; >+ } catch (InterruptedException e) { >+ // canceled >+ return; >+ } >+ >+ applyValidatorResult(validator); >+ getWizard().getContainer().updateButtons(); >+ } >+ >+ protected void applyValidatorResult(Validator validator) { >+ IStatus status = validator.getStatus(); >+ String message = status.getMessage(); >+ if (message == null || message.length() == 0) >+ message = null; >+ switch (status.getSeverity()) { >+ case IStatus.OK: >+ if (status == Status.OK_STATUS) { >+ if (getUserName().length() > 0) { >+ message = "Authentication credentials are valid."; >+ } else { >+ message = "Repository is valid."; >+ } >+ } >+ setMessage(message, WizardPage.INFORMATION); >+ break; >+ case IStatus.INFO: >+ setMessage(message, WizardPage.INFORMATION); >+ break; >+ case IStatus.WARNING: >+ setMessage(message, WizardPage.WARNING); >+ break; >+ default: >+ setMessage(message, WizardPage.ERROR); >+ break; >+ } >+ setErrorMessage(null); >+ } >+ >+ protected abstract Validator getValidator(TaskRepository repository); >+ >+ // public for testing >+ public abstract class Validator { >+ >+ private IStatus status; >+ >+ public abstract void run(IProgressMonitor monitor) throws CoreException; >+ >+ public IStatus getStatus() { >+ return status; >+ } >+ >+ public void setStatus(IStatus status) { >+ this.status = status; >+ } >+ >+ } >+ >+} >#P org.eclipse.mylar.trac.core >Index: src/org/eclipse/mylar/internal/trac/core/TracCorePlugin.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.trac.core/src/org/eclipse/mylar/internal/trac/core/TracCorePlugin.java,v >retrieving revision 1.4 >diff -u -r1.4 TracCorePlugin.java >--- src/org/eclipse/mylar/internal/trac/core/TracCorePlugin.java 14 Feb 2007 01:56:19 -0000 1.4 >+++ src/org/eclipse/mylar/internal/trac/core/TracCorePlugin.java 19 Feb 2007 22:54:38 -0000 >@@ -10,6 +10,8 @@ > *******************************************************************************/ > package org.eclipse.mylar.internal.trac.core; > >+import java.net.MalformedURLException; >+ > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Platform; >@@ -91,6 +93,8 @@ > return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, e.getMessage()); > } else if (e instanceof ClassCastException) { > return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, "Unexpected server response: " + e.getMessage(), e); >+ } else if (e instanceof MalformedURLException) { >+ return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.IO_ERROR, "Repository URL is invalid", e); > } else { > return new TracStatus(Status.ERROR, PLUGIN_ID, TracStatus.INTERNAL_ERROR, "Unexpected error", e); > } >#P org.eclipse.mylar.trac.ui >Index: src/org/eclipse/mylar/internal/trac/ui/wizard/TracRepositorySettingsPage.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.mylar/org.eclipse.mylar.trac.ui/src/org/eclipse/mylar/internal/trac/ui/wizard/TracRepositorySettingsPage.java,v >retrieving revision 1.20 >diff -u -r1.20 TracRepositorySettingsPage.java >--- src/org/eclipse/mylar/internal/trac/ui/wizard/TracRepositorySettingsPage.java 18 Jan 2007 00:47:11 -0000 1.20 >+++ src/org/eclipse/mylar/internal/trac/ui/wizard/TracRepositorySettingsPage.java 19 Feb 2007 22:54:39 -0000 >@@ -11,25 +11,23 @@ > > package org.eclipse.mylar.internal.trac.ui.wizard; > >-import java.lang.reflect.InvocationTargetException; > import java.net.MalformedURLException; > import java.net.Proxy; > import java.net.URL; > >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >-import org.eclipse.jface.dialogs.IMessageProvider; >-import org.eclipse.jface.dialogs.MessageDialog; >-import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.mylar.internal.trac.core.ITracClient; > import org.eclipse.mylar.internal.trac.core.TracClientFactory; > import org.eclipse.mylar.internal.trac.core.TracException; > import org.eclipse.mylar.internal.trac.core.TracLoginException; > import org.eclipse.mylar.internal.trac.core.TracPermissionDeniedException; >+import org.eclipse.mylar.internal.trac.core.TracStatus; > import org.eclipse.mylar.internal.trac.core.ITracClient.Version; > import org.eclipse.mylar.internal.trac.ui.TracUiPlugin; > import org.eclipse.mylar.tasks.core.RepositoryTemplate; >+import org.eclipse.mylar.tasks.core.TaskRepository; > import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi; > import org.eclipse.mylar.tasks.ui.wizards.AbstractRepositorySettingsPage; > import org.eclipse.swt.SWT; >@@ -45,8 +43,6 @@ > */ > public class TracRepositorySettingsPage extends AbstractRepositorySettingsPage { > >- private static final String MESSAGE_FAILURE_UNKNOWN = "Unknown error occured. Check that server url and credentials are valid."; >- > private static final String TITLE = "Trac Repository Settings"; > > private static final String DESCRIPTION = "Example: http://trac.edgewall.org"; >@@ -161,106 +157,78 @@ > } > > @Override >- protected void validateSettings() { >- >- try { >- final Validator validator = new Validator(); >- getWizard().getContainer().run(true, false, new IRunnableWithProgress() { >- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { >- monitor.beginTask("Validating server settings", IProgressMonitor.UNKNOWN); >- try { >- validator.run(); >- } catch (Exception e) { >- throw new InvocationTargetException(e); >- } finally { >- monitor.done(); >- } >- } >- }); >- >- if (validator.getStatus() != null) { >- setMessage(validator.getStatus().getMessage(), IMessageProvider.WARNING); >- } else { >- setMessage(null); >- } >- >- if (getUserName().length() > 0) { >- MessageDialog.openInformation(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, >- "Authentication credentials are valid."); >- } else { >- MessageDialog.openInformation(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, "Repository is valid."); >- } >+ protected void applyValidatorResult(Validator validator) { >+ super.applyValidatorResult(validator); > >- if (validator.getResult() != null) { >- setTracVersion(validator.getResult()); >- } >- } catch (InvocationTargetException e) { >- if (e.getCause() instanceof MalformedURLException) { >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, "Repository url is invalid."); >- } else if (e.getCause() instanceof TracLoginException) { >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, >- "Unable to authenticate with repository. Login credentials invalid."); >- } else if (e.getCause() instanceof TracPermissionDeniedException) { >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, >- "Insufficient permissions for selected access type."); >- } else if (e.getCause() instanceof TracException) { >- String message = "No Trac repository found at url"; >- if (e.getCause().getMessage() != null) { >- message += ": " + e.getCause().getMessage(); >- } >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, message); >- } else { >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, MESSAGE_FAILURE_UNKNOWN); >- } >- } catch (InterruptedException e) { >- MessageDialog.openWarning(null, TracUiPlugin.TITLE_MESSAGE_DIALOG, MESSAGE_FAILURE_UNKNOWN); >+ if (((TracValidator) validator).getResult() != null) { >+ setTracVersion(((TracValidator) validator).getResult()); > } >- >- super.getWizard().getContainer().updateButtons(); > } > > // public for testing >- public class Validator { >+ public class TracValidator extends Validator { >+ >+ final String serverUrl; >+ >+ final Version version; > >- final String serverUrl = getServerUrl(); >- final Version version = getTracVersion(); >- final String username = getUserName(); >- final String password = getPassword(); >- // TODO is there a way to get the proxy without duplicating code and >- // creating a task repository? >- final Proxy proxy = createTaskRepository().getProxy(); >+ final String username; >+ >+ final String password; >+ >+ final Proxy proxy; > > private Version result; >- private IStatus status; > >- >- public void run() throws MalformedURLException, TracException { >+ public TracValidator(TaskRepository repository, Version version) { >+ this.serverUrl = repository.getUrl(); >+ this.username = repository.getUserName(); >+ this.password = repository.getPassword(); >+ this.proxy = repository.getProxy(); >+ this.version = version; >+ } >+ >+ public void run(IProgressMonitor monitor) throws CoreException { >+ try { >+ validate(); >+ } catch (MalformedURLException e) { >+ throw new CoreException(new TracStatus(IStatus.ERROR, TracUiPlugin.PLUGIN_ID, 0, INVALID_REPOSITORY_URL)); >+ } catch (TracLoginException e) { >+ throw new CoreException(new TracStatus(IStatus.ERROR, TracUiPlugin.PLUGIN_ID, 0, INVALID_LOGIN)); >+ } catch(TracPermissionDeniedException e) { >+ throw new CoreException(new TracStatus(IStatus.ERROR, TracUiPlugin.PLUGIN_ID, 0, >+ "Insufficient permissions for selected access type.")); >+ } catch (TracException e) { >+ String message = "No Trac repository found at url"; >+ if (e.getMessage() != null) { >+ message += ": " + e.getCause().getMessage(); >+ } >+ throw new CoreException(new TracStatus(IStatus.ERROR, TracUiPlugin.PLUGIN_ID, 0, message)); >+ } >+ } >+ >+ public void validate() throws MalformedURLException, TracException { > if (version != null) { >- ITracClient client = TracClientFactory.createClient(serverUrl, version, username, password, >- proxy); >+ ITracClient client = TracClientFactory.createClient(serverUrl, version, username, password, proxy); > client.validate(); > } else { > // probe version: XML-RPC access first, then web > // access > try { >- ITracClient client = TracClientFactory.createClient(serverUrl, Version.XML_RPC, >- username, password, proxy); >+ ITracClient client = TracClientFactory.createClient(serverUrl, Version.XML_RPC, username, password, >+ proxy); > client.validate(); > result = Version.XML_RPC; > } catch (TracException e) { > try { >- ITracClient client = TracClientFactory.createClient(serverUrl, Version.TRAC_0_9, >- username, password, proxy); >+ ITracClient client = TracClientFactory.createClient(serverUrl, Version.TRAC_0_9, username, >+ password, proxy); > client.validate(); > result = Version.TRAC_0_9; > > if (e instanceof TracPermissionDeniedException) { >- status = new Status( >- IStatus.INFO, >- TracUiPlugin.PLUGIN_ID, >- IStatus.OK, >- "Insufficient permissions for XML-RPC access, falling back to web access.", >- null); >+ setStatus(new TracStatus(IStatus.INFO, TracUiPlugin.PLUGIN_ID, IStatus.OK, >+ "Authentication credentials are valid. Note: Insufficient permissions for XML-RPC access, falling back to web access.")); > } > } catch (TracLoginException e2) { > throw e; >@@ -270,15 +238,16 @@ > } > } > } >- >+ > public Version getResult() { > return result; > } >- >- public IStatus getStatus() { >- return status; >- } >- >+ > } >- >+ >+ @Override >+ protected Validator getValidator(TaskRepository repository) { >+ return new TracValidator(repository, getTracVersion()); >+ } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 172085
: 59327 |
59328