You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/10/28 15:07:46 UTC
svn commit: r1536357 - 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
Author: bdelacretaz
Date: Mon Oct 28 14:07:46 2013
New Revision: 1536357
URL: http://svn.apache.org/r1536357
Log:
SLING-3205 - avoid confusing warning on config files
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=1536357&r1=1536356&r2=1536357&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 Mon Oct 28 14:07:46 2013
@@ -221,6 +221,21 @@ abstract class BundleListContentProvider
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
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
// 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
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();
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=1536357&r1=1536356&r2=1536357&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 Mon Oct 28 14:07:46 2013
@@ -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 BundleListContentProviderTe
private File resourceProviderRoot;
private File resourceProviderFile;
private File configDirectory;
+ private int logWarningsCount;
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
@@ -99,6 +103,18 @@ public class BundleListContentProviderTe
@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 BundleListContentProviderTe
}
@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");