You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2017/06/19 08:48:56 UTC
svn commit: r1799158 - in /jackrabbit/oak/trunk/oak-run/src:
main/java/org/apache/jackrabbit/oak/run/cli/
test/java/org/apache/jackrabbit/oak/run/cli/
Author: chetanm
Date: Mon Jun 19 08:48:56 2017
New Revision: 1799158
URL: http://svn.apache.org/viewvc?rev=1799158&view=rev
Log:
OAK-6363 - BlobStoreFixtureProvider should support '.cfg' files also
- .config file would be read via Felix ConfigurationHandler
- Any other extension would be read via normal properties mode
- Added another option name for s3config i.e. s3-config-path which was
used by Tika command (for backward comparability)
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreOptions.java
jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProviderTest.java
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java?rev=1799158&r1=1799157&r2=1799158&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProvider.java Mon Jun 19 08:48:56 2017
@@ -23,6 +23,7 @@ import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Map;
@@ -35,6 +36,7 @@ import com.google.common.collect.Maps;
import com.google.common.io.Closer;
import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
import org.apache.felix.cm.file.ConfigurationHandler;
import org.apache.jackrabbit.core.data.DataStore;
import org.apache.jackrabbit.core.data.DataStoreException;
@@ -105,8 +107,18 @@ public class BlobStoreFixtureProvider {
return new DataStoreFixture(blobStore, closer, !options.getCommonOpts().isReadWrite());
}
- private static Properties loadConfig(String cfgPath) throws IOException {
- Properties props = loadAndTransformProps(cfgPath);
+ static Properties loadConfig(String cfgPath) throws IOException {
+ String extension = FilenameUtils.getExtension(cfgPath);
+ Properties props;
+ if ("config".equals(extension)){
+ props = loadAndTransformProps(cfgPath);
+ } else {
+ props = new Properties();
+ try(InputStream is = FileUtils.openInputStream(new File(cfgPath))){
+ props.load(is);
+ }
+ }
+
configureDefaultProps(props);
return props;
}
Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreOptions.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreOptions.java?rev=1799158&r1=1799157&r2=1799158&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreOptions.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/cli/BlobStoreOptions.java Mon Jun 19 08:48:56 2017
@@ -45,7 +45,7 @@ public class BlobStoreOptions implements
fakeDsPathOption = parser.acceptsAll(asList("fake-ds-path"), "Path to be used to construct a Fake " +
"FileDataStore. It return an empty stream for any Blob but allows writes if used in read-write mode. (for testing purpose only)")
.withRequiredArg().ofType(String.class);
- s3Option = parser.accepts("s3ds", "S3DataStore config path")
+ s3Option = parser.acceptsAll(asList("s3ds", "s3-config-path"), "S3DataStore config path")
.withRequiredArg().ofType(String.class);
azureOption = parser.acceptsAll(asList("azureblobds", "azureds"), "AzureBlobStorageDataStore config path")
.withRequiredArg().ofType(String.class);
@@ -64,7 +64,8 @@ public class BlobStoreOptions implements
@Override
public String description() {
return "Options related to configuring a BlobStore. All config options here (except --fds-path) refer to " +
- "the path of the config file. The file should be a '.config' file in the OSGi config admin format.";
+ "the path of the config file. The file can be a '.config' file in the OSGi config admin format or " +
+ "properties file with '.cfg' and '.properties' extensions.";
}
@Override
Modified: jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProviderTest.java?rev=1799158&r1=1799157&r2=1799158&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProviderTest.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/test/java/org/apache/jackrabbit/oak/run/cli/BlobStoreFixtureProviderTest.java Mon Jun 19 08:48:56 2017
@@ -22,8 +22,14 @@ package org.apache.jackrabbit.oak.run.cl
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
import joptsimple.OptionParser;
+import org.apache.commons.io.FileUtils;
+import org.apache.felix.cm.file.ConfigurationHandler;
import org.apache.jackrabbit.oak.plugins.blob.BlobTrackingStore;
import org.apache.jackrabbit.oak.plugins.blob.datastore.TypedDataStore;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
@@ -33,6 +39,8 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@@ -71,6 +79,41 @@ public class BlobStoreFixtureProviderTes
}
}
+ @Test
+ public void configLoading() throws Exception {
+ Properties p = new Properties();
+ p.put("foo", "bar");
+ p.put("a", "b");
+
+ File config = new File(temporaryFolder.getRoot(), "test.cfg");
+ try (OutputStream os = FileUtils.openOutputStream(config)) {
+ p.store(os, null);
+ }
+
+ Properties p2 = BlobStoreFixtureProvider.loadConfig(config.getAbsolutePath());
+ assertEquals("bar", p2.getProperty("foo"));
+ assertNotNull(p2.getProperty("secret"));
+ }
+
+ @Test
+ public void configLoading_OSGi() throws Exception {
+ Dictionary<String, Object> p = new Hashtable<String, Object>();
+ p.put("foo", "bar");
+ p.put("a", 1);
+ p.put("b", new int[]{1, 2});
+
+ File config = new File(temporaryFolder.getRoot(), "test.config");
+ try (OutputStream os = FileUtils.openOutputStream(config)) {
+ ConfigurationHandler.write(os, p);
+ }
+
+ Properties p2 = BlobStoreFixtureProvider.loadConfig(config.getAbsolutePath());
+ assertEquals("bar", p2.getProperty("foo"));
+ assertEquals(1, p2.get("a"));
+ assertArrayEquals(new int[]{1, 2}, (int[]) p2.get("b"));
+ assertNotNull(p2.getProperty("secret"));
+ }
+
private Options createFDSOptions(String... args) throws IOException {
OptionParser parser = new OptionParser();
Options opts = new Options().withDisableSystemExit();