499979: Deployment of nested plans fails 

Re-apply some lost changes.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=499979
diff --git a/org.eclipse.virgo.ide.manifest.core/src/org/eclipse/virgo/ide/module/core/ServerModuleDelegate.java b/org.eclipse.virgo.ide.manifest.core/src/org/eclipse/virgo/ide/module/core/ServerModuleDelegate.java
index 412cf1e..00f7b52 100644
--- a/org.eclipse.virgo.ide.manifest.core/src/org/eclipse/virgo/ide/module/core/ServerModuleDelegate.java
+++ b/org.eclipse.virgo.ide.manifest.core/src/org/eclipse/virgo/ide/module/core/ServerModuleDelegate.java
@@ -217,16 +217,8 @@
                     folder.setMembers(getMembers(childModule.getProject(), moduleRelativePath).toArray(new IModuleResource[0]));
                     resources.add(folder);
                 } else if (FacetUtils.isPlanProject(childModule.getProject())) {
-                    // this new case makes sure the plan file itself is copied to the staging folder
-                    IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(childModule.getName()));
-                    ModuleFile mfile = new ModuleFile(file2, file2.getName(), Path.EMPTY);
-                    resources.add(mfile);
-
-                    // recursion to collect nested plans and bundles
-                    ModuleDelegate delegate3 = (ModuleDelegate) childModule.loadAdapter(ModuleDelegate.class, null);
-                    for (IModule aChild : delegate3.getChildModules()) {
-                        deepGetMembers(aChild, resources);
-                    }
+                    // enter recursion
+                    deepGetMembers(childModule, resources);
                 } else if (FacetUtils.isParProject(childModule.getProject())) {
                     moduleRelativePath = new Path(childModule.getProject().getName() + ".par");
                     ModuleDelegate delegate2 = (ModuleDelegate) childModule.loadAdapter(ModuleDelegate.class, null);
diff --git a/org.eclipse.virgo.ide.runtime.core/src/org/eclipse/virgo/ide/runtime/internal/core/Server.java b/org.eclipse.virgo.ide.runtime.core/src/org/eclipse/virgo/ide/runtime/internal/core/Server.java
index d4811d1..e02fdbe 100644
--- a/org.eclipse.virgo.ide.runtime.core/src/org/eclipse/virgo/ide/runtime/internal/core/Server.java
+++ b/org.eclipse.virgo.ide.runtime.core/src/org/eclipse/virgo/ide/runtime/internal/core/Server.java
@@ -140,7 +140,7 @@
 
         IModuleType moduleType = module[0].getModuleType();
 
-        if (module.length == 1 && moduleType != null) {
+        if (module.length > 0 && moduleType != null) {
             if (FacetCorePlugin.WEB_FACET_ID.equals(moduleType.getId())) {
                 IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, null);
                 if (webModule != null) {
@@ -153,22 +153,29 @@
                     return parModule.getChildModules();
                 }
             } else if (FacetCorePlugin.PLAN_FACET_ID.equals(moduleType.getId())) {
-                ServerModuleDelegate planModule = (ServerModuleDelegate) module[0].loadAdapter(ServerModuleDelegate.class, null);
+                /*
+                 * To support nested plans now the tooling creates an IModule tree where top level plans have nested
+                 * plans or bundles as children. WTP is passing back the path from the root to a given module as a
+                 * parameter to this method to get the children, so here children are computed only for the last item in
+                 * the list (module.length -1)
+                 **/
+                ServerModuleDelegate planModule = (ServerModuleDelegate) module[module.length - 1].loadAdapter(ServerModuleDelegate.class, null);
                 if (planModule != null) {
                     return planModule.getChildModules();
                 }
             }
-        } else if (FacetCorePlugin.PLAN_FACET_ID.equals(moduleType.getId())) {
-            /*
-             * To support nested plans now the tooling creates an IModule tree where top level plans have nested plans
-             * or bundles as children. WTP is passing back the path from the root to a given module as a parameter to
-             * this method to get the children, so here children are computed only for the last item in the list
-             * (module.length -1)
-             **/
-            ServerModuleDelegate planModule = (ServerModuleDelegate) module[module.length - 1].loadAdapter(ServerModuleDelegate.class, null);
-            if (planModule != null) {
-                return planModule.getChildModules();
-            }
+            // } else if (FacetCorePlugin.PLAN_FACET_ID.equals(moduleType.getId())) {
+            // /*
+            // * To support nested plans now the tooling creates an IModule tree where top level plans have nested plans
+            // * or bundles as children. WTP is passing back the path from the root to a given module as a parameter to
+            // * this method to get the children, so here children are computed only for the last item in the list
+            // * (module.length -1)planModule.getChildModules();
+            // **/
+            // ServerModuleDelegate planModule = (ServerModuleDelegate) module[module.length -
+            // 1].loadAdapter(ServerModuleDelegate.class, null);
+            // if (planModule != null) {
+            // return planModule.getChildModules();
+            // }
         }
 
         return new IModule[0];