You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2015/09/29 17:50:58 UTC

svn commit: r1705882 - /sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java

Author: rombert
Date: Tue Sep 29 15:50:58 2015
New Revision: 1705882

URL: http://svn.apache.org/viewvc?rev=1705882&view=rev
Log:
SLING-4988 - Not all folders are displayed in Project Explorer 

Added ProjectAdapter.ensureDirectoryExists

Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java?rev=1705882&r1=1705881&r2=1705882&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java Tue Sep 29 15:50:58 2015
@@ -124,31 +124,13 @@ public class ProjectAdapter {
             throw new IllegalArgumentException("resourceAsStream may not be null");
         }
 
-        IContainer current = project;
-
         try {
-            for (int i = 0; i < fileLocation.segmentCount() - 1; i++) {
-
-                String currentSegment = fileLocation.segment(i);
-                IResource container = current.findMember(currentSegment);
-
-                if (container != null) {
-                    if (container.getType() != IContainer.FOLDER) {
-                        throw new IllegalArgumentException("Resource " + container
-                                + " exists and is not a folder; unable to create file at path " + fileLocation);
-                    }
-
-                    current = (IContainer) container;
-                } else {
-
-                    IFolder newFolder = ((IContainer) current).getFolder(Path.fromPortableString(currentSegment));
-                    newFolder.create(true, true, new NullProgressMonitor());
-                    current = newFolder;
-                }
-            }
+            
+            IContainer holder = ensureDirectoryExists(fileLocation.removeLastSegments(1));
 
-            IFile file = current.getFile(Path.fromPortableString(fileLocation.segments()[fileLocation
-                    .segmentCount() - 1]));
+            
+            IPath fileName = Path.fromPortableString(fileLocation.lastSegment());
+            IFile file = holder.getFile(fileName);
             if (file.exists()) {
                 file.setContents(contents, true, true, new NullProgressMonitor());
             } else {
@@ -159,6 +141,40 @@ public class ProjectAdapter {
         }
 
     }
+    
+    /**
+     * Ensures that the specified directory exists
+     * 
+     * @param path the path where the directory should exist
+     * @return the created or existing directory
+     * @throws CoreException
+     */
+    public IContainer ensureDirectoryExists(IPath path) throws CoreException {
+        
+        IContainer current = project;
+        
+        for (int i = 0; i < path.segmentCount(); i++) {
+
+            String currentSegment = path.segment(i);
+            IResource container = current.findMember(currentSegment);
+
+            if (container != null) {
+                if (container.getType() != IContainer.FOLDER) {
+                    throw new IllegalArgumentException("Resource " + container
+                            + " exists and is not a folder; unable to create file at path " + path);
+                }
+
+                current = (IContainer) container;
+            } else {
+
+                IFolder newFolder = ((IContainer) current).getFolder(Path.fromPortableString(currentSegment));
+                newFolder.create(true, true, new NullProgressMonitor());
+                current = newFolder;
+            }
+        }
+        
+        return current;
+    }
 
     public void createVltFilterWithRoots(String... roots) throws CoreException {