[jbosstools-commits] JBoss Tools SVN: r35724 - in trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Oct 17 10:34:29 EDT 2011


Author: adietish
Date: 2011-10-17 10:34:29 -0400 (Mon, 17 Oct 2011)
New Revision: 35724

Modified:
   trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenshiftUIActivator.java
   trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java
Log:
[JBIDE-9889] catching transport exception and reporting in a error dialog

Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenshiftUIActivator.java
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenshiftUIActivator.java	2011-10-17 14:09:22 UTC (rev 35723)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenshiftUIActivator.java	2011-10-17 14:34:29 UTC (rev 35724)
@@ -57,4 +57,9 @@
 		log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
 	}
 
+	public static IStatus createErrorStatus(String message, Throwable throwable) {
+		return new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
+				message, throwable);
+	}
+	
 }

Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java	2011-10-17 14:09:22 UTC (rev 35723)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java	2011-10-17 14:34:29 UTC (rev 35724)
@@ -22,6 +22,7 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.errors.TransportException;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.jboss.tools.common.ui.WizardUtils;
@@ -48,39 +49,43 @@
 	public boolean performFinish() {
 		try {
 			WizardUtils.runInWizard(
-					new Job("Creating local git repo...") {
+					new Job("Cloning local git repo...") {
 
 						@Override
 						protected IStatus run(IProgressMonitor monitor) {
 							IStatus status = Status.OK_STATUS;
+							String errorMessage = null;
 							try {
 								File repositoryFile = model.cloneRepository(monitor);
 								model.importProject(repositoryFile, monitor);
 							} catch (OpenshiftException e) {
-								status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
-										"An exception occurred while creating local git repository.", e);
+								errorMessage = "An exception occurred while creating local git repository.";
+								status = OpenshiftUIActivator.createErrorStatus(e.getMessage(), e);
 							} catch (URISyntaxException e) {
-								status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
-										"The url of the remote git repository is not valid", e);
+								errorMessage = "The url of the remote git repository is not valid";
+								status = OpenshiftUIActivator.createErrorStatus(e.getMessage(), e);
 							} catch (InvocationTargetException e) {
-								if (e.getTargetException() instanceof JGitInternalException) {
-									status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
-											"Could not clone the repository. Authentication failed.", e
-													.getTargetException());
+								if (isTransportException(e)) {
+									errorMessage = "Could not clone the repository. Authentication failed.\n"
+											+ " Please make sure that you added your private key to the ssh preferences.";
+									TransportException te = getTransportException(e);
+									status = OpenshiftUIActivator.createErrorStatus(te.getMessage(), te);
 								} else {
-									status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
-											"An exception occurred while creating local git repository.", e);
+									errorMessage = "An exception occurred while creating local git repository.";
+									status = OpenshiftUIActivator.createErrorStatus(e.getMessage(), e);
 								}
 							} catch (Exception e) {
-								status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
-										"An exception occurred while creating local git repository.", e);
+								errorMessage = "An exception occurred while creating local git repository.";
+								status = OpenshiftUIActivator.createErrorStatus(e.getMessage(), e);
 							}
 
 							if (!status.isOK()) {
 								OpenshiftUIActivator.log(status);
+								openErrorDialog(errorMessage, status);
 							}
 							return status;
 						}
+
 					}, getContainer());
 			return true;
 		} catch (Exception e) {
@@ -98,4 +103,27 @@
 		addPage(new ApplicationWizardPage(this, model));
 		addPage(new AdapterWizardPage(this, model));
 	}
+
+	private boolean isTransportException(InvocationTargetException e) {
+		return e.getTargetException() instanceof JGitInternalException
+				&& e.getTargetException().getCause() instanceof TransportException;
+	}
+
+	private TransportException getTransportException(InvocationTargetException e) {
+		if (isTransportException(e)) {
+			return (TransportException) ((JGitInternalException) e.getTargetException()).getCause();
+		}
+		return null;
+	}
+
+	private void openErrorDialog(final String errorMessage, final IStatus status) {
+		getShell().getDisplay().syncExec(new Runnable() {
+
+			@Override
+			public void run() {
+				ErrorDialog.openError(getShell(), "Error cloning the git repo", errorMessage, status);
+			}
+		});
+	}
+
 }



More information about the jbosstools-commits mailing list