Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java (revision 37127) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizardModel.java (working copy) @@ -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 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 = Index: src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java (revision 37127) +++ src/org/jboss/tools/openshift/express/internal/ui/wizard/ImportProjectWizard.java (working copy) @@ -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(); Index: src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java (revision 0) +++ src/org/jboss/tools/openshift/express/internal/ui/common/MavenImportFailedException.java (revision 0) @@ -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); + } +} Index: src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java =================================================================== --- src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java (revision 0) +++ src/org/jboss/tools/openshift/express/internal/ui/common/WontOverwriteException.java (revision 0) @@ -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); + } + +}