Author: koen.aers(a)jboss.com
Date: 2012-01-17 03:16:44 -0500 (Tue, 17 Jan 2012)
New Revision: 37888
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java
Log:
JBIDE-8911: Forge should not swallow errors
Modified:
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java
===================================================================
---
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java 2012-01-17
02:55:58 UTC (rev 37887)
+++
trunk/forge/plugins/org.jboss.tools.forge.ui/src/org/jboss/tools/forge/ui/console/NewProjectPostProcessor.java 2012-01-17
08:16:44 UTC (rev 37888)
@@ -1,8 +1,16 @@
package org.jboss.tools.forge.ui.console;
+import java.io.File;
import java.util.Map;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.jboss.tools.forge.core.process.ForgeRuntime;
import org.jboss.tools.forge.importer.ProjectImporter;
+import org.jboss.tools.forge.ui.part.ForgeView;
+import org.jboss.tools.forge.ui.util.ForgeHelper;
public class NewProjectPostProcessor implements ForgeCommandPostProcessor {
@@ -10,11 +18,56 @@
@Override
public void postProcess(Map<String, String> commandDetails) {
String projectPath = commandDetails.get("cpn");
- int index = projectPath.lastIndexOf('/');
- String projectDirName = projectPath.substring(index + 1);
- String projectBaseDirPath = projectPath.substring(0, index);
- ProjectImporter importer = new ProjectImporter(projectBaseDirPath, projectDirName);
- importer.importProject();
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ String workspacePath = workspaceRoot.getLocation().toOSString();
+ if (workspacePath.equals(projectPath)) {
+ if (MessageDialog.open(
+ MessageDialog.QUESTION,
+ null,
+ "Project Import Failed",
+ "The Forge runtime created the project in the workspace root. " +
+ "Such a project cannot be imported.\n" +
+ "Do you want to remove the created artifacts?",
+ SWT.NONE)) {
+ String fileSeparator = System.getProperty("file.separator");
+ String pomPath = projectPath + fileSeparator + "pom.xml";
+ File pomFile = new File(pomPath);
+ if (pomFile.exists()) {
+ delete(pomFile);
+ }
+ String srcPath = projectPath + fileSeparator + "src";
+ File srcDir = new File(srcPath);
+ if (srcDir.exists()) {
+ delete(srcDir);
+ }
+ resetRuntime();
+ }
+ } else {
+ int index = projectPath.lastIndexOf('/');
+ String projectDirName = projectPath.substring(index + 1);
+ String projectBaseDirPath = projectPath.substring(0, index);
+ ProjectImporter importer = new ProjectImporter(projectBaseDirPath, projectDirName);
+ importer.importProject();
+ }
}
+
+ private void delete(File f) {
+ if (f.isDirectory()) {
+ for (String s : f.list()) {
+ delete(new File(f, s));
+ }
+ }
+ f.delete();
+ }
+
+ private void resetRuntime() {
+ ForgeView forgeView = ForgeHelper.getForgeView();
+ if (forgeView != null) {
+ ForgeRuntime runtime = forgeView.getRuntime();
+ if (runtime != null && ForgeRuntime.STATE_RUNNING.equals(runtime.getState()))
{
+ runtime.sendInput("reset\n");
+ }
+ }
+ }
}
Show replies by date