Author: max.andersen(a)jboss.com
Date: 2011-12-08 19:32:45 -0500 (Thu, 08 Dec 2011)
New Revision: 37138
Added:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java
Modified:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
Log:
JBIDE-9934 safeguard if openshift clone directory already exists and error info if maven
fails import
Added:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java
===================================================================
---
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java
(rev 0)
+++
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java 2011-12-09
00:32:45 UTC (rev 37138)
@@ -0,0 +1,11 @@
+package org.jboss.tools.openshift.express.internal.ui.common;
+
+
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+
+public class MavenImportFailedException extends OpenShiftException {
+
+ public MavenImportFailedException(String bind) {
+ super(bind);
+ }
+}
Added:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java
===================================================================
---
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java
(rev 0)
+++
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java 2011-12-09
00:32:45 UTC (rev 37138)
@@ -0,0 +1,13 @@
+package org.jboss.tools.openshift.express.internal.ui.common;
+
+import java.io.IOException;
+
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+
+public class WontOverwriteException extends OpenShiftException {
+
+ public WontOverwriteException(String bind) {
+ super(bind);
+ }
+
+}
Modified:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java
===================================================================
---
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java 2011-12-09
00:23:00 UTC (rev 37137)
+++
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java 2011-12-09
00:32:45 UTC (rev 37138)
@@ -33,6 +33,8 @@
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.common.MavenImportFailedException;
+import org.jboss.tools.openshift.express.internal.ui.common.WontOverwriteException;
/**
* @author André Dietisheim
@@ -79,34 +81,38 @@
model.addToExistingProject(monitor);
}
return Status.OK_STATUS;
+ } catch (final WontOverwriteException e) {
+ openWarning("Project already present", e.getMessage());
+ return Status.CANCEL_STATUS;
+ } catch (final MavenImportFailedException e) {
+ openWarning("Maven Import failed", e.getMessage());
+ return Status.CANCEL_STATUS;
} catch (IOException e) {
- status = OpenShiftUIActivator.createErrorStatus(
+ return OpenShiftUIActivator.createErrorStatus(
"Could not copy openshift configuration files to project {0}", e,
model.getProjectName());
- return status;
} catch (OpenShiftException e) {
- status = OpenShiftUIActivator.createErrorStatus(
+ return OpenShiftUIActivator.createErrorStatus(
"Could not import project to the workspace.", e);
} catch (URISyntaxException e) {
- status = OpenShiftUIActivator.createErrorStatus(
+ return OpenShiftUIActivator.createErrorStatus(
"The url of the remote git repository is not valid", e);
} catch (InvocationTargetException e) {
if (isTransportException(e)) {
TransportException te = getTransportException(e);
- status = OpenShiftUIActivator
+ return OpenShiftUIActivator
.createErrorStatus(
"Could not clone the repository. Authentication failed.\n"
+ " Please make sure that you added your private key to the ssh
preferences.",
te);
} else {
- status = OpenShiftUIActivator.createErrorStatus(
+ return OpenShiftUIActivator.createErrorStatus(
"An exception occurred while creating local git repository.", e);
}
} catch (Exception e) {
- status = OpenShiftUIActivator.createErrorStatus(
+ return OpenShiftUIActivator.createErrorStatus(
"Could int import project to the workspace.", e);
}
- return status;
}
}, getContainer());
IStatus status = queue.poll(10, TimeUnit.SECONDS);
@@ -136,6 +142,16 @@
return confirmed[0];
}
+ private void openWarning(final String title, final String message) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openWarning(getShell(), title, message);
+ }
+ });
+ }
+
@Override
public void addPages() {
this.model = new ImportProjectWizardModel();
Modified:
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java
===================================================================
---
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-12-09
00:23:00 UTC (rev 37137)
+++
branches/jbosstools-3.3.0.M5/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java 2011-12-09
00:32:45 UTC (rev 37138)
@@ -57,6 +57,7 @@
import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.common.FileUtils;
+import org.jboss.tools.openshift.express.internal.ui.common.WontOverwriteException;
import
org.jboss.tools.openshift.express.internal.ui.wizard.projectimport.GeneralProjectImportOperation;
import
org.jboss.tools.openshift.express.internal.ui.wizard.projectimport.MavenProjectImportOperation;
@@ -152,6 +153,25 @@
return (String) getProperty(REPOSITORY_PATH);
}
+ /**
+ * Returns the destination folder that the OpenShift application will get
+ * cloned to.
+ *
+ * @return the destination that the application will get cloned to.
+ */
+ private File getCloneDestination() {
+ String repositoryPath = getRepositoryPath();
+ if (repositoryPath == null
+ || repositoryPath.length() == 0) {
+ return null;
+ }
+ IApplication application = getApplication();
+ if (application == null) {
+ return null;
+ }
+ return new File(getRepositoryPath(), application.getName());
+ }
+
public boolean isNewProject() {
return (Boolean) getProperty(NEW_PROJECT);
}
@@ -241,8 +261,24 @@
public void importProject(IProgressMonitor monitor)
throws OpenShiftException, CoreException, InterruptedException, URISyntaxException,
InvocationTargetException {
+ File cloneDestination = getCloneDestination();
+ if (cloneDestination != null
+ && cloneDestination.exists()) {
+ throw new WontOverwriteException(
+ NLS.bind(
+ "There is already a folder at {0}. The new OpenShift project would overwrite
it. " +
+ "Please choose another destination to clone to.",
+ cloneDestination.getAbsolutePath()));
+ }
File repositoryFolder = cloneRepository(monitor);
List<IProject> importedProjects = importMavenProject(repositoryFolder, monitor);
+ if (importedProjects.size() == 0) {
+ throw new OpenShiftException(
+ "The maven import failed. One of the possible reasons is that already is a
project " +
+ "in your workspace that matches the maven name of the OpenShift
application." +
+ "Please rename your workspace project in that case and start over
again.");
+ }
+
connectToGitRepo(importedProjects, repositoryFolder, monitor);
createServerAdapterIfRequired(importedProjects, monitor);
}
@@ -307,6 +343,15 @@
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
+ private boolean doesProjectExist(String name) {
+ if (name == null) {
+ return false;
+ }
+ IProject project = getProject(name);
+ return project != null
+ && project.exists();
+ }
+
public boolean projectExists(final File gitProjectFolder) {
String projectName = gitProjectFolder.getName();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
@@ -351,9 +396,7 @@
*/
private File cloneRepository(IProgressMonitor monitor)
throws OpenShiftException, InvocationTargetException, InterruptedException,
URISyntaxException {
- IApplication application = getApplication();
- File destination = new File(getRepositoryPath(), application.getName());
- return cloneRepository(destination, monitor);
+ return cloneRepository(getCloneDestination(), monitor);
}
private File cloneRepository(File destination, IProgressMonitor monitor)
@@ -366,9 +409,6 @@
private void cloneRepository(String uri, File destination, IProgressMonitor monitor)
throws OpenShiftException, URISyntaxException, InvocationTargetException,
InterruptedException {
- if (destination.exists()) {
- FileUtil.completeDelete(destination);
- }
ensureEgitUIIsStarted();
URIish gitUri = new URIish(uri);
CloneOperation cloneOperation =