This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-maven-launchpad-plugin.git
commit e7bad3a8885aeeeae855d9b221604767550b8268 Author: Chetan Mehrotra <[email protected]> AuthorDate: Tue Jan 6 10:19:53 2015 +0000 SLING-4284 - Support nested config path in BundleListContentProvider git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1649770 13f79535-47bb-0310-9956-ffa450edef68 --- .../projectsupport/BundleListContentProvider.java | 29 ++++++------ .../BundleListContentProviderTest.java | 52 ++++++++++++++++++---- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java b/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java index 64442fc..e2fdbbe 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java @@ -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 implements LaunchpadContentProvider { 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 implements LaunchpadContentProvider { } 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) { diff --git a/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java b/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java index 8041a56..6d5e66f 100644 --- a/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java +++ b/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java @@ -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 BundleListContentProviderTest { 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 BundleListContentProviderTest { @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 BundleListContentProviderTest { 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 BundleListContentProviderTest { 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 BundleListContentProviderTest { 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 -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
