sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
Subject svn commit: r1649770 - in /sling/trunk/tooling/maven/maven-launchpad-plugin/src: main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java
Date Tue, 06 Jan 2015 10:19:54 GMT
Author: chetanm
Date: Tue Jan  6 10:19:53 2015
New Revision: 1649770

URL: http://svn.apache.org/r1649770
Log:
SLING-4284 - Support nested config path in BundleListContentProvider

Modified:
    sling/trunk/tooling/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java
    sling/trunk/tooling/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java

Modified: sling/trunk/tooling/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java?rev=1649770&r1=1649769&r2=1649770&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java
(original)
+++ sling/trunk/tooling/maven/maven-launchpad-plugin/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java
Tue Jan  6 10:19:53 2015
@@ -33,6 +33,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
@@ -71,18 +72,11 @@ abstract class BundleListContentProvider
     
     private Iterator<String> handleConfigPath() {
         if (getConfigDirectory().exists() && getConfigDirectory().isDirectory())
{
-            File[] configFiles = getConfigDirectory().listFiles(new FileFilter() {
-
-                public boolean accept(File file) {
-                    return file.isFile();
-                }
-            });
+            File[] configFiles = getConfigDirectory().listFiles();
 
             List<String> fileNames = new ArrayList<String>();
             for (File cfgFile : configFiles) {
-                if (cfgFile.isFile()) {
                     fileNames.add(CONFIG_PATH_PREFIX + "/" + cfgFile.getName());
-                }
             }
 
             return fileNames.iterator();
@@ -223,18 +217,27 @@ abstract class BundleListContentProvider
     }
     
     private Iterator<String> handleConfigSubpath(String path) {
-        // We don't handle config subpaths for now, but do not 
-        // warn if we're asked for the children of a file, just
-        // return empty in that case
         final File f = getConfigFile(path);
         if(!f.exists()) {
             getLog().warn("BundleListContentProvider cannot get children of config path:
" + path);
+            return EMPTY_STRING_LIST.iterator();
+        }
+
+        if (f.isFile()){
+            return EMPTY_STRING_LIST.iterator();
         }
-        return EMPTY_STRING_LIST.iterator();
+
+        File[] configFiles = f.listFiles();
+        List<String> fileNames = new ArrayList<String>();
+        for (File cfgFile : configFiles) {
+            fileNames.add(path + "/" + cfgFile.getName());
+        }
+
+        return fileNames.iterator();
     }
     
     private File getConfigFile(String path) {
-        return new File(getConfigDirectory(), path.substring(CONFIG_PATH_PREFIX.length()
+ 1));
+        return new File(FilenameUtils.concat(getConfigDirectory().getAbsolutePath(), path.substring(CONFIG_PATH_PREFIX.length()
+ 1)));
     }
 
     public Iterator<String> getChildren(String path) {

Modified: sling/trunk/tooling/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java?rev=1649770&r1=1649769&r2=1649770&view=diff
==============================================================================
--- sling/trunk/tooling/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java
(original)
+++ sling/trunk/tooling/maven/maven-launchpad-plugin/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java
Tue Jan  6 10:19:53 2015
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
@@ -68,7 +69,9 @@ public class BundleListContentProviderTe
     private static final String [] CONFIG_FILES = {
         "file1.txt",
         "file2.cfg",
-        "someFile.properties"
+        "someFile.properties",
+        "dir1/file1.txt",
+        "dir1/dir2/file1.txt",
     };
     
     @BeforeClass
@@ -85,12 +88,14 @@ public class BundleListContentProviderTe
     
     @Before
     public void setupTemporaryFiles() throws IOException {
+        TemporaryFolder configRoot = new TemporaryFolder(tempFolder.getRoot());
+        configRoot.create();
         for(String filename: CONFIG_FILES) {
-            final File f = getConfigFile(filename);
+            final File f = getConfigFile(configRoot, filename);
             f.createNewFile();
             assertTrue("Expecting temporary config file to have been created: " + f.getAbsolutePath(),
f.exists());
         }
-        configDirectory = tempFolder.getRoot();
+        configDirectory = configRoot.getRoot();
 
         resourceProviderRoot = new File(tempFolder.getRoot(), "RESOURCE_PROVIDER_ROOT");
         resourceProviderRoot.mkdirs();
@@ -98,9 +103,19 @@ public class BundleListContentProviderTe
         resourceProviderFile.createNewFile();
         fakeBundlePath = getFakeBundlePath();
     }
+
+    private File getConfigFile(File configRoot, String name) throws IOException {
+        return new File(FilenameUtils.concat(configRoot.getAbsolutePath(), name));
+    }
     
-    private File getConfigFile(String name) {
-        return new File(tempFolder.getRoot(), name);
+    private File getConfigFile(TemporaryFolder configRoot, String name) throws IOException
{
+        File parentFolder = configRoot.getRoot();
+        if (name.contains("/")){
+            String parentPath = name.substring(0, name.lastIndexOf('/'));
+            name = name.substring(name.lastIndexOf('/') + 1);
+            parentFolder = configRoot.newFolder(parentPath.split("/"));
+        }
+        return new File(parentFolder, name);
     }
 
     private String getFakeBundlePath() {
@@ -252,14 +267,28 @@ public class BundleListContentProviderTe
         assertChildren("resources/config", 
                 "resources/config/file1.txt", 
                 "resources/config/file2.cfg", 
-                "resources/config/someFile.properties"); 
+                "resources/config/someFile.properties",
+                "resources/config/dir1");
     }
-    
+
+    @Test
+    public void testNestedConfig() {
+        assertChildren("resources/config/dir1",
+                "resources/config/dir1/file1.txt",
+                "resources/config/dir1/dir2");
+    }
+
     @Test
     public void testConfigFile() {
         assertChildren("resources/config/file1.txt");
         assertEquals("Expecting no warnings", 0, logWarningsCount);
     }
+
+    @Test
+    public void testNestedConfigFile() {
+        assertChildren("resources/config/dir1/file1.txt");
+        assertEquals("Expecting no warnings", 0, logWarningsCount);
+    }
     
     @Test
     public void testConfigSubpath() {
@@ -342,7 +371,14 @@ public class BundleListContentProviderTe
     public void testConfigResource() throws Exception {
         final URL url = provider.getResource("resources/config/file1.txt");
         assertNotNull("Expecting config resource to be found", url);
-        assertEquals(getConfigFile("file1.txt").toURI().toURL().toExternalForm(), url.toExternalForm());
+        assertEquals(getConfigFile(configDirectory, "file1.txt").toURI().toURL().toExternalForm(),
url.toExternalForm());
+    }
+
+    @Test
+    public void testNestedConfigResource() throws Exception {
+        final URL url = provider.getResource("resources/config/dir1/file1.txt");
+        assertNotNull("Expecting config resource to be found", url);
+        assertEquals(getConfigFile(configDirectory, "dir1/file1.txt").toURI().toURL().toExternalForm(),
url.toExternalForm());
     }
     
     @Test



Mime
View raw message