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 805488f5eaa0c38499c10d88c5e7b3e7ed56e3ad Author: Bertrand Delacretaz <[email protected]> AuthorDate: Mon Oct 28 14:07:46 2013 +0000 SLING-3205 - avoid confusing warning on config files git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1536357 13f79535-47bb-0310-9956-ffa450edef68 --- .../projectsupport/BundleListContentProvider.java | 21 ++++++++++++++-- .../BundleListContentProviderTest.java | 28 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 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 eb34f54..64442fc 100644 --- a/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java +++ b/src/main/java/org/apache/sling/maven/projectsupport/BundleListContentProvider.java @@ -221,6 +221,21 @@ abstract class BundleListContentProvider implements LaunchpadContentProvider { return result.iterator(); } + + 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(); + } + + private File getConfigFile(String path) { + return new File(getConfigDirectory(), path.substring(CONFIG_PATH_PREFIX.length() + 1)); + } public Iterator<String> getChildren(String path) { Iterator<String> result = null; @@ -230,6 +245,8 @@ abstract class BundleListContentProvider implements LaunchpadContentProvider { result = EMPTY_STRING_LIST.iterator(); } else if (path.equals(CONFIG_PATH_PREFIX)) { result = handleConfigPath(); + } else if (path.startsWith(CONFIG_PATH_PREFIX)) { + result = handleConfigSubpath(path); } else if (path.startsWith(BUNDLE_PATH_PREFIX)) { result = handleBundlesSubfolder(path); } else if (path.startsWith(INSTALL_PATH_PREFIX)) { @@ -241,7 +258,7 @@ abstract class BundleListContentProvider implements LaunchpadContentProvider { // as our file URLs point to Maven artifacts result = EMPTY_STRING_LIST.iterator(); } else { - getLog().warn("BundleListContentProvider cannot handle path: " + path); + getLog().warn("BundleListContentProvider cannot get children of path: " + path); } return result; @@ -249,7 +266,7 @@ abstract class BundleListContentProvider implements LaunchpadContentProvider { public URL getResource(String path) { if (path.startsWith(CONFIG_PATH_PREFIX)) { - File configFile = new File(getConfigDirectory(), path.substring(CONFIG_PATH_PREFIX.length() + 1)); + final File configFile = getConfigFile(path); if (configFile.exists()) { try { return configFile.toURI().toURL(); 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 21cbe53..056c018 100644 --- a/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java +++ b/src/test/java/org/apache/sling/maven/projectsupport/BundleListContentProviderTest.java @@ -42,7 +42,10 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.mockito.Matchers; import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; /** Test the BundleListContentProvider */ public class BundleListContentProviderTest { @@ -55,6 +58,7 @@ public class BundleListContentProviderTest { private File resourceProviderRoot; private File resourceProviderFile; private File configDirectory; + private int logWarningsCount; @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); @@ -99,6 +103,18 @@ public class BundleListContentProviderTest { @Before public void setupProvider() { final Log log = Mockito.mock(Log.class); + final Answer<Void> countWarningAnswers = new Answer<Void>() { + + public Void answer(InvocationOnMock invocation) throws Throwable { + logWarningsCount++; + return null; + } + + }; + Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class)); + Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(Throwable.class)); + Mockito.doAnswer(countWarningAnswers).when(log).warn(Matchers.any(String.class), Matchers.any(Throwable.class)); + provider = new BundleListContentProvider(resourceProviderRoot) { @Override @@ -229,6 +245,18 @@ public class BundleListContentProviderTest { } @Test + public void testConfigFile() { + assertChildren("resources/config/file1.txt"); + assertEquals("Expecting no warnings", 0, logWarningsCount); + } + + @Test + public void testConfigSubpath() { + assertChildren("resources/config/someFolder/someSubFolder"); + assertEquals("Expecting a warning", 1, logWarningsCount); + } + + @Test public void testNonExistentConfigDirectory() { configDirectory = new File("/NON_EXISTENT_" + System.currentTimeMillis()); assertChildren("resources/config"); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
