Author: fbricon
Date: 2011-10-05 08:36:31 -0400 (Wed, 05 Oct 2011)
New Revision: 35365
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
Log:
JBIDE-9821 : Don't automatically delete existing projects when (re)creating an
archetype-based example. Let the user change the project name instead
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2011-10-05
11:53:53 UTC (rev 35364)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/ImportMavenArchetypeProjectExample.java 2011-10-05
12:36:31 UTC (rev 35365)
@@ -39,8 +39,6 @@
private static final String JBOSS_TOOLS_MAVEN_PROJECTS =
"/.JBossToolsMavenProjects"; //$NON-NLS-1$
- private boolean confirm;
-
@Override
public List<Project> importProject(final Project projectDescription, File file,
IProgressMonitor monitor) throws Exception {
@@ -54,48 +52,7 @@
}
IPath path = mavenProjectsRoot.append(projectName);
final File destination = new File(path.toOSString());
- if (destination.exists()) {
- final List<IProject> existingProjects = getExistingProjects(destination);
- if (existingProjects.size() > 0) {
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- String title = "Overwrite";
- String msg = getMessage(destination, existingProjects);
- confirm = MessageDialog.openQuestion(getActiveShell(),
- title, msg);
- }
- });
- if (confirm) {
- monitor.setTaskName("Deleting ...");
- for (IProject project : existingProjects) {
- monitor.setTaskName("Deleting " + project.getName());
- project.delete(false, true, monitor);
- }
- } else {
- return projects;
- }
- }
- boolean deleted = deleteDirectory(destination, monitor);
- if (monitor.isCanceled()) {
- return projects;
- }
- if (!deleted) {
- Display.getDefault().syncExec(new Runnable() {
- @Override
- public void run() {
- MessageDialog.openError(getActiveShell(), "Error",
- "Cannot delete the '" + destination + "' file.");
- }
- });
- return projects;
- }
- }
- monitor.setTaskName("");
- if (monitor.isCanceled()) {
- return projects;
- }
-
Display.getDefault().syncExec(new Runnable() {
@Override
@@ -113,78 +70,4 @@
private static Shell getActiveShell() {
return Display.getDefault().getActiveShell();
}
-
- private static boolean deleteDirectory(File path, IProgressMonitor monitor) {
- if (path.exists()) {
- File[] files = path.listFiles();
- for (File file : files) {
- if (monitor.isCanceled()) {
- return false;
- }
- monitor.setTaskName("Deleting " + file);
- if (file.isDirectory()) {
- deleteDirectory(file, monitor);
- } else {
- file.delete();
- }
- }
- }
- return (path.delete());
- }
-
- private List<IProject> getExistingProjects(final File destination) {
- List<IProject> existingProjects = new ArrayList<IProject>();
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
- .getProjects();
- for (IProject project : projects) {
- if (project != null && project.exists()) {
- File projectFile = project.getLocation().toFile();
- if (projectFile.getAbsolutePath().startsWith(
- destination.getAbsolutePath())) {
- existingProjects.add(project);
- }
- }
- }
- return existingProjects;
- }
-
- private String getMessage(final File destination, List<IProject> projects) {
- if (projects.size() > 0) {
- StringBuilder builder = new StringBuilder();
- if (projects.size() == 1) {
- builder.append("\nThere is the '" + projects.get(0).getName()
- + "' project on the destination location:\n\n");
- builder.append("Would you like to overwrite it?");
- } else {
- builder.append("\nThere are the following projects on the destination
location:\n\n");
- for (IProject project : projects) {
- builder.append(project.getName());
- builder.append("\n"); //$NON-NLS-1$
- }
- builder.append("\n"); //$NON-NLS-1$
- builder.append("Would you like to overwrite them?");
- }
- return builder.toString();
- }
- return null;
- }
-
- private String getWorkspaceMessage(final List<IProject> existingProjects) {
- StringBuilder builder = new StringBuilder();
- if (existingProjects.size() == 1) {
- builder.append("There is the '" + existingProjects.get(0).getName()
- + "' project in the workspace.\n\n");
- builder.append("Would you like to delete it?");
- } else {
- builder.append("There are the following projects in the workspace:\n\n");
- for (IProject project : existingProjects) {
- builder.append(project.getName());
- builder.append("\n"); //$NON-NLS-1$
- }
- builder.append("\n"); //$NON-NLS-1$
- builder.append("Would you like to delete them?");
- }
- return builder.toString();
- }
-
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2011-10-05
11:53:53 UTC (rev 35364)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardPage.java 2011-10-05
12:36:31 UTC (rev 35365)
@@ -22,6 +22,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
@@ -87,7 +88,16 @@
// It needs to be called AFTER setArchetype(archetype) !!!
archetypeChanged = false;
+ //Use archetype/example name by default
artifactIdCombo.setText(artifactId);
+
+ //Check if project already exists
+ IStatus nameStatus = getImportConfiguration().validateProjectName(getModel());
+ if(!nameStatus.isOK()) {
+ //Force the user to change the name if the project exists
+ artifactIdCombo.setText("");//$NON-NLS-1$
+ }
+
groupIdCombo.setText(groupId);
versionCombo.setText(version);
packageCombo.setText(javaPackage);
Show replies by date