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 ju...@apache.org on 2014/02/19 14:27:31 UTC

svn commit: r1569736 - in /jackrabbit/oak/trunk/oak-core: pom.xml src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java

Author: jukka
Date: Wed Feb 19 13:27:30 2014
New Revision: 1569736

URL: http://svn.apache.org/r1569736
Log:
OAK-1434: Cleanup dependencies of oak-core

Just copy the PropertiesUtil class from Sling instead of using complex dependency tricks

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/pom.xml
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java

Modified: jackrabbit/oak/trunk/oak-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/pom.xml?rev=1569736&r1=1569735&r2=1569736&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-core/pom.xml Wed Feb 19 13:27:30 2014
@@ -101,7 +101,6 @@
               org.apache.felix.jaas.boot
             </DynamicImport-Package>
             <Embed-Dependency>
-              org.apache.sling.commons.osgi;inline=org/apache/sling/commons/osgi/PropertiesUtil.class,
               json-simple;inline=true
             </Embed-Dependency>
           </instructions>
@@ -168,14 +167,6 @@
       <scope>provided</scope>
     </dependency>
 
-    <!-- Classes from this jar are inlined via Embed-Dependency tag as
-    we do not want to depend on Sling jar in OSGi env-->
-    <dependency>
-      <groupId>org.apache.sling</groupId>
-      <artifactId>org.apache.sling.commons.osgi</artifactId>
-      <version>2.1.0</version>
-      <optional>true</optional>
-    </dependency>
     <dependency>
       <groupId>biz.aQute.bnd</groupId>
       <artifactId>bndlib</artifactId>

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1569736&r1=1569735&r2=1569736&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Wed Feb 19 13:27:30 2014
@@ -42,7 +42,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
-import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java?rev=1569736&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java Wed Feb 19 13:27:30 2014
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+// !! THIS UTILITY CLASS IS A COPY FROM APACHE SLING !!
+// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+/**
+ * The <code>PropertiesUtil</code> is a utility class providing some
+ * usefull utility methods for converting property types.
+ *
+ * @since 2.1
+ */
+class PropertiesUtil {
+
+    /**
+     * Returns the boolean value of the parameter or the
+     * <code>defaultValue</code> if the parameter is <code>null</code>.
+     * If the parameter is not a <code>Boolean</code> it is converted
+     * by calling <code>Boolean.valueOf</code> on the string value of the
+     * object.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default boolean value
+     */
+    public static boolean toBoolean(Object propValue, boolean defaultValue) {
+        propValue = toObject(propValue);
+        if (propValue instanceof Boolean) {
+            return (Boolean) propValue;
+        } else if (propValue != null) {
+            return Boolean.valueOf(String.valueOf(propValue));
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a string or the
+     * <code>defaultValue</code> if the parameter is <code>null</code>.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default string value
+     */
+    public static String toString(Object propValue, String defaultValue) {
+        propValue = toObject(propValue);
+        return (propValue != null) ? propValue.toString() : defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a long or the
+     * <code>defaultValue</code> if the parameter is <code>null</code> or if
+     * the parameter is not a <code>Long</code> and cannot be converted to
+     * a <code>Long</code> from the parameter's string value.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default long value
+     */
+    public static long toLong(Object propValue, long defaultValue) {
+        propValue = toObject(propValue);
+        if (propValue instanceof Long) {
+            return (Long) propValue;
+        } else if (propValue != null) {
+            try {
+                return Long.valueOf(String.valueOf(propValue));
+            } catch (NumberFormatException nfe) {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as an integer or the
+     * <code>defaultValue</code> if the parameter is <code>null</code> or if
+     * the parameter is not an <code>Integer</code> and cannot be converted to
+     * an <code>Integer</code> from the parameter's string value.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default integer value
+     */
+    public static int toInteger(Object propValue, int defaultValue) {
+        propValue = toObject(propValue);
+        if (propValue instanceof Integer) {
+            return (Integer) propValue;
+        } else if (propValue != null) {
+            try {
+                return Integer.valueOf(String.valueOf(propValue));
+            } catch (NumberFormatException nfe) {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a double or the
+     * <code>defaultValue</code> if the parameter is <code>null</code> or if
+     * the parameter is not a <code>Double</code> and cannot be converted to
+     * a <code>Double</code> from the parameter's string value.
+     * @param propValue the property value or <code>null</code>
+     * @param defaultValue the default double value
+     */
+    public static double toDouble(Object propValue, double defaultValue) {
+        propValue = toObject(propValue);
+        if (propValue instanceof Double) {
+            return (Double) propValue;
+        } else if (propValue != null) {
+            try {
+                return Double.valueOf(String.valueOf(propValue));
+            } catch (NumberFormatException nfe) {
+                // don't care, fall through to default value
+            }
+        }
+
+        return defaultValue;
+    }
+
+    /**
+     * Returns the parameter as a single value. If the
+     * parameter is neither an array nor a <code>java.util.Collection</code> the
+     * parameter is returned unmodified. If the parameter is a non-empty array,
+     * the first array element is returned. If the property is a non-empty
+     * <code>java.util.Collection</code>, the first collection element is returned.
+     * Otherwise <code>null</code> is returned.
+     * @param propValue the parameter to convert.
+     */
+    public static Object toObject(Object propValue) {
+        if (propValue == null) {
+            return null;
+        } else if (propValue.getClass().isArray()) {
+            Object[] prop = (Object[]) propValue;
+            return prop.length > 0 ? prop[0] : null;
+        } else if (propValue instanceof Collection<?>) {
+            Collection<?> prop = (Collection<?>) propValue;
+            return prop.isEmpty() ? null : prop.iterator().next();
+        } else {
+            return propValue;
+        }
+    }
+
+    /**
+     * Returns the parameter as an array of Strings. If
+     * the parameter is a scalar value its string value is returned as a single
+     * element array. If the parameter is an array, the elements are converted to
+     * String objects and returned as an array. If the parameter is a collection, the
+     * collection elements are converted to String objects and returned as an array.
+     * Otherwise (if the parameter is <code>null</code>) <code>null</code> is
+     * returned.
+     * @param propValue The object to convert.
+     */
+    public static String[] toStringArray(Object propValue) {
+        return toStringArray(propValue, null);
+    }
+
+    /**
+     * Returns the parameter as an array of Strings. If
+     * the parameter is a scalar value its string value is returned as a single
+     * element array. If the parameter is an array, the elements are converted to
+     * String objects and returned as an array. If the parameter is a collection, the
+     * collection elements are converted to String objects and returned as an array.
+     * Otherwise (if the property is <code>null</code>) a provided default value is
+     * returned.
+     * @param propValue The object to convert.
+     * @param defaultArray The default array to return.
+     */
+    public static String[] toStringArray(Object propValue, String[] defaultArray) {
+        if (propValue == null) {
+            // no value at all
+            return defaultArray;
+
+        } else if (propValue instanceof String) {
+            // single string
+            return new String[] { (String) propValue };
+
+        } else if (propValue instanceof String[]) {
+            // String[]
+            return (String[]) propValue;
+
+        } else if (propValue.getClass().isArray()) {
+            // other array
+            Object[] valueArray = (Object[]) propValue;
+            List<String> values = new ArrayList<String>(valueArray.length);
+            for (Object value : valueArray) {
+                if (value != null) {
+                    values.add(value.toString());
+                }
+            }
+            return values.toArray(new String[values.size()]);
+
+        } else if (propValue instanceof Collection<?>) {
+            // collection
+            Collection<?> valueCollection = (Collection<?>) propValue;
+            List<String> valueList = new ArrayList<String>(valueCollection.size());
+            for (Object value : valueCollection) {
+                if (value != null) {
+                    valueList.add(value.toString());
+                }
+            }
+            return valueList.toArray(new String[valueList.size()]);
+        }
+
+        return defaultArray;
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/PropertiesUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native