sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1747373 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ ...
Date Wed, 08 Jun 2016 11:02:45 GMT
Author: desruisseaux
Date: Wed Jun  8 11:02:45 2016
New Revision: 1747373

URL: http://svn.apache.org/viewvc?rev=1747373&view=rev
Log:
Make the search for services more robust to environments having a too "poor" context ClassLoader.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -19,7 +19,6 @@ package org.apache.sis.internal.metadata
 import java.util.Locale;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.ServiceLoader;
 import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
@@ -38,6 +37,7 @@ import javax.naming.event.EventContext;
 import javax.naming.event.NamingEvent;
 import javax.naming.event.NamingExceptionEvent;
 import javax.naming.event.ObjectChangeListener;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.DataDirectory;
 import org.apache.sis.internal.system.Shutdown;
 import org.apache.sis.internal.system.Loggers;
@@ -61,7 +61,7 @@ import java.nio.file.Paths;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public abstract class Initializer {
@@ -181,7 +181,7 @@ public abstract class Initializer {
                  */
                 Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), Listener.class,
"objectChanged", e);
             }
-            for (Initializer init : ServiceLoader.load(Initializer.class)) {
+            for (Initializer init : DefaultFactories.createServiceLoader(Initializer.class))
{
                 init.dataSourceChanged();
             }
         }
@@ -292,7 +292,7 @@ public abstract class Initializer {
                 final Method m = source.getClass().getMethod("setCreateDatabase", String.class);
                 m.invoke(source, "create");
                 try (Connection c = source.getConnection()) {
-                    for (Initializer init : ServiceLoader.load(Initializer.class)) {
+                    for (Initializer init : DefaultFactories.createServiceLoader(Initializer.class))
{
                         init.createSchema(c);
                     }
                 } finally {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -33,7 +33,7 @@ import org.apache.sis.metadata.Modifiabl
 import org.apache.sis.internal.jaxb.IdentifierMapAdapter;
 import org.apache.sis.internal.jaxb.ModifiableIdentifierMap;
 import org.apache.sis.internal.metadata.MetadataUtilities;
-import org.apache.sis.internal.util.Utilities;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.util.collection.Containers;
 
 import static org.apache.sis.util.collection.Containers.isNullOrEmpty;
@@ -96,7 +96,7 @@ public class ISOMetadata extends Modifia
                  * without invoking super.getIdentifiers(), in which case their identifiers
will not be copied.
                  * For safety, we will do this optimization only if the implementation is
an Apache SIS one.
                  */
-                if (Utilities.isSIS(object.getClass())) {
+                if (object.getClass().getName().startsWith(Modules.CLASSNAME_PREFIX)) {
                     return;
                 }
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.factory.sql;
 
 import java.util.Locale;
-import java.util.ServiceLoader;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -32,6 +31,7 @@ import java.io.BufferedReader;
 import org.apache.sis.util.StringBuilders;
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.metadata.sql.SQLUtilities;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.util.Fallback;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Exceptions;
@@ -49,7 +49,7 @@ import static org.apache.sis.internal.ut
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 final class EPSGInstaller extends ScriptRunner {
@@ -268,7 +268,7 @@ final class EPSGInstaller extends Script
      */
     private static InstallationResources lookupProvider(final Locale locale) throws IOException
{
         InstallationResources fallback = null;
-        for (final InstallationResources provider : ServiceLoader.load(InstallationResources.class))
{
+        for (final InstallationResources provider : DefaultFactories.createServiceLoader(InstallationResources.class))
{
             if (provider.getAuthorities().contains(EPSG)) {
                 if (provider.getClass().isAnnotationPresent(Fallback.class)) {
                     return provider;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/NormalizedProjection.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -47,8 +47,8 @@ import org.apache.sis.referencing.operat
 import org.apache.sis.internal.referencing.provider.MapProjection;
 import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.util.Constants;
-import org.apache.sis.internal.util.Utilities;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.resources.Errors;
 
@@ -594,7 +594,7 @@ public abstract class NormalizedProjecti
             group = DESCRIPTORS.get(type);
             if (group == null) {
                 final ParameterBuilder builder = new ParameterBuilder().setRequired(true);
-                if (Utilities.isSIS(type)) {
+                if (type.getName().startsWith(Modules.CLASSNAME_PREFIX)) {
                     builder.setCodeSpace(Citations.SIS, Constants.SIS);
                 }
                 final String[] names = getInternalParameterNames();

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/converter/SystemRegistry.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -17,11 +17,11 @@
 package org.apache.sis.internal.converter;
 
 import java.util.Date;
-import java.util.ServiceLoader;
 import org.opengis.util.CodeList;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.ObjectConverter;
 import org.apache.sis.util.UnconvertibleObjectException;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.Modules;
 
@@ -50,7 +50,7 @@ import org.apache.sis.internal.system.Mo
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  */
 public final class SystemRegistry extends ConverterRegistry {
@@ -105,7 +105,7 @@ public final class SystemRegistry extend
      */
     @Override
     protected void initialize() {
-        for (ObjectConverter<?,?> converter : ServiceLoader.load(ObjectConverter.class,
getClass().getClassLoader())) {
+        for (ObjectConverter<?,?> converter : DefaultFactories.createServiceLoader(ObjectConverter.class))
{
             if (converter instanceof SystemConverter<?,?>) {
                 converter = ((SystemConverter<?,?>) converter).unique();
             }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -18,13 +18,13 @@ package org.apache.sis.internal.jaxb;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.ServiceLoader;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
+import org.apache.sis.internal.system.DefaultFactories;
 
 
 /**
@@ -40,7 +40,7 @@ import org.apache.sis.internal.system.Sy
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see org.apache.sis.xml.MarshallerPool
@@ -92,7 +92,7 @@ public abstract class TypeRegistration {
          * 2) The ClassLoader between different invocations may be different in an OSGi context.
          */
         final ArrayList<Class<?>> types = new ArrayList<>();
-        for (final TypeRegistration t : ServiceLoader.load(TypeRegistration.class)) {
+        for (final TypeRegistration t : DefaultFactories.createServiceLoader(TypeRegistration.class))
{
             t.getTypes(types);
         }
         return types.toArray(new Class<?>[types.size()]);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/DefaultFactories.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -16,11 +16,13 @@
  */
 package org.apache.sis.internal.system;
 
+import java.util.Set;
 import java.util.Map;
+import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.ServiceLoader;
 import java.util.ServiceConfigurationError;
-import org.apache.sis.internal.util.Utilities;
+import org.apache.sis.util.logging.Logging;
 
 
 /**
@@ -31,7 +33,7 @@ import org.apache.sis.internal.util.Util
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Guilhem Legal (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  *
  * @see <a href="https://jcp.org/en/jsr/detail?id=330">JSR-330</a>
@@ -87,8 +89,8 @@ public final class DefaultFactories exte
         T factory = type.cast(FACTORIES.get(type));
         if (factory == null && !FACTORIES.containsKey(type)) {
             T fallback = null;
-            for (final T candidate : ServiceLoader.load(type)) {
-                if (Utilities.isSIS(candidate.getClass())) {
+            for (final T candidate : createServiceLoader(type)) {
+                if (candidate.getClass().getName().startsWith(Modules.CLASSNAME_PREFIX))
{
                     if (factory != null) {
                         throw new ServiceConfigurationError("Found two implementations of
" + type);
                     }
@@ -157,4 +159,77 @@ public final class DefaultFactories exte
         }
         return impl.cast(factory);
     }
+
+    /**
+     * Returns a service loader for the given type using the default class loader.
+     * The default is the current thread {@linkplain Thread#getContextClassLoader() context
class loader},
+     * provided that it can access at least the Apache SIS stores.
+     *
+     * @param  <T> The compile-time value of {@code service} argument.
+     * @param  service The interface or abstract class representing the service.
+     * @return A new service loader for the given service type.
+     *
+     * @since 0.8
+     */
+    public static <T> ServiceLoader<T> createServiceLoader(final Class<T>
service) {
+        try {
+            return ServiceLoader.load(service, getContextClassLoader());
+        } catch (SecurityException e) {
+            /*
+             * We were not allowed to invoke Thread.currentThread().getContextClassLoader().
+             * But ServiceLoader.load(Class) may be allowed to, since it is part of JDK.
+             */
+            Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM),
+                    DefaultFactories.class, "createServiceLoader", e);
+            return ServiceLoader.load(service);
+        }
+    }
+
+    /**
+     * Returns the context class loader, but makes sure that it has Apache SIS on its classpath.
+     * First, this method invokes {@link Thread#getContextClassLoader()} for the current
thread.
+     * Then this method scans over all Apache SIS classes on the stack trace. For each SIS
class,
+     * its loader is compared to the above-cited context class loader. If the context class
loader
+     * is equal or is a child of the SIS loader, then it is left unchanged. Otherwise the
context
+     * class loader is replaced by the SIS one.
+     *
+     * <p>The intend of this method is to ensure that {@link ServiceLoader#load(Class)}
will find the
+     * Apache SIS services even in an environment that defined an unsuitable context class
loader.</p>
+     *
+     * @return The context class loader if suitable, or another class loader otherwise.
+     * @throws SecurityException if this method is not allowed to get the current thread
+     *         context class loader or one of its parent.
+     *
+     * @since 0.8
+     */
+    private static ClassLoader getContextClassLoader() throws SecurityException {
+        final Thread thread = Thread.currentThread();
+        ClassLoader loader = thread.getContextClassLoader();
+        final Set<ClassLoader> parents = new HashSet<>();
+        for (ClassLoader c = loader; c != null; c = c.getParent()) {
+            parents.add(c);
+        }
+        boolean warnings = false;
+        for (final StackTraceElement trace : thread.getStackTrace()) {
+            final String element = trace.getClassName();
+            if (element.startsWith(Modules.CLASSNAME_PREFIX)) try {
+                ClassLoader c = Class.forName(element).getClassLoader();
+                if (!parents.contains(c)) {
+                    loader = c;
+                    parents.clear();
+                    while (c != null) {
+                        parents.add(c);
+                        c = c.getParent();
+                    }
+                }
+            } catch (SecurityException | ClassNotFoundException e) {
+                if (!warnings) {
+                    warnings = true;
+                    Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM),
+                            DefaultFactories.class, "getContextClassLoader", e);
+                }
+            }
+        }
+        return loader;
+    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -77,6 +77,16 @@ public final class Modules {
     public static final int MINOR_VERSION = 8;
 
     /**
+     * The prefix of all classnames in Apache SIS, including a trailing dot.
+     */
+    public static final String CLASSNAME_PREFIX = "org.apache.sis.";
+
+    /**
+     * The prefix of all internal classnames in Apache SIS, including a trailing dot.
+     */
+    public static final String INTERNAL_CLASSNAME_PREFIX = CLASSNAME_PREFIX + "internal.";
+
+    /**
      * Do not allow instantiation of this class.
      */
     private Modules() {

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/LazySet.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.ServiceLoader;
 import java.util.NoSuchElementException;
 import org.apache.sis.util.Workaround;
+import org.apache.sis.internal.system.DefaultFactories;
 
 // Branch-specific imports
 import java.util.Objects;
@@ -44,9 +45,9 @@ import java.util.Objects;
  *
  * @param <E> The type of elements in the set.
  *
- * @author  Martin Desruisseaux (IRD)
+ * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.6
- * @version 0.7
+ * @version 0.8
  * @module
  */
 @Workaround(library="JDK", version="1.8.0_31-b13")
@@ -155,7 +156,7 @@ public class LazySet<E> extends SetOfUnk
      */
     private boolean canPullMore() {
         if (sourceIterator == null && cachedElements == null) {
-            sourceIterator = ServiceLoader.load(service).iterator();
+            sourceIterator = DefaultFactories.createServiceLoader(service).iterator();
             if (createCache()) {
                 return true;
             }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -28,7 +28,7 @@ import org.apache.sis.util.CharSequences
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.8
  * @module
  */
 public final class Utilities extends Static {
@@ -39,16 +39,6 @@ public final class Utilities extends Sta
     }
 
     /**
-     * Returns {@code true} if the given class is an Apache SIS class.
-     *
-     * @param  type The class to verify.
-     * @return {@code true} if the given class is an Apache SIS class.
-     */
-    public static boolean isSIS(final Class<?> type) {
-        return type.getName().startsWith("org.apache.sis.");
-    }
-
-    /**
      * Appends to the given buffer only the characters that are valid for a Unicode identifier.
      * The given separator character is append before the given {@code text} only if the
buffer
      * is not empty and at least one {@code text} character is valid.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -25,6 +25,7 @@ import org.apache.sis.util.Configuration
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.Classes;
+import org.apache.sis.internal.system.Modules;
 
 
 /**
@@ -170,8 +171,9 @@ public final class Logging extends Stati
         String name = classe.getName();
         final int separator = name.lastIndexOf('.');
         name = (separator >= 1) ? name.substring(0, separator) : "";
-        if (name.startsWith("org.apache.sis.internal.")) {
-            name = "org.apache.sis" + name.substring(23);       // Remove the "internal"
part from SIS package name.
+        if (name.startsWith(Modules.INTERNAL_CLASSNAME_PREFIX)) {
+            // Remove the "internal" part from Apache SIS package names.
+            name = Modules.CLASSNAME_PREFIX + name.substring(Modules.INTERNAL_CLASSNAME_PREFIX.length());
         }
         return getLogger(name);
     }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -29,6 +29,7 @@ import org.apache.sis.util.logging.Loggi
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.system.DelayedExecutor;
 import org.apache.sis.internal.system.DelayedRunnable;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.jaxb.AdapterReplacement;
 import org.apache.sis.internal.jaxb.TypeRegistration;
 import org.apache.sis.util.ArgumentChecks;
@@ -57,7 +58,7 @@ import org.apache.sis.util.ArgumentCheck
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see XML
@@ -184,7 +185,7 @@ public class MarshallerPool {
     public MarshallerPool(final JAXBContext context, final Map<String,?> properties)
throws JAXBException {
         ArgumentChecks.ensureNonNull("context", context);
         this.context = context;
-        replacements = ServiceLoader.load(AdapterReplacement.class);
+        replacements = DefaultFactories.createServiceLoader(AdapterReplacement.class);
         /*
          * Detects if we are using the endorsed JAXB implementation (i.e. the one provided
in
          * separated JAR files) or the one bundled in JDK 6. We use the JAXB context package

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/LogRecordCollector.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -23,6 +23,7 @@ import java.util.logging.Handler;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.io.IOException;
+import org.apache.sis.internal.system.Modules;
 import org.apache.sis.io.TableAppender;
 import org.junit.runner.Description;
 
@@ -96,7 +97,7 @@ final class LogRecordCollector extends H
                 method = "<unknown>";
                 for (final StackTraceElement t : Thread.currentThread().getStackTrace())
{
                     final String c = t.getClassName();
-                    if (c.startsWith("org.apache.sis.") && c.endsWith(TestSuite.CLASSNAME_SUFFIX))
{
+                    if (c.startsWith(Modules.CLASSNAME_PREFIX) && c.endsWith(TestSuite.CLASSNAME_SUFFIX))
{
                         cname  = c;
                         method = t.getMethodName();
                         break;

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestCase.java [UTF-8]
Wed Jun  8 11:02:45 2016
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.logging.MonolineFormatter;
 import org.junit.runner.RunWith;
@@ -131,7 +132,7 @@ public abstract strictfp class TestCase
      * The parent logger of all Apache SIS loggers.
      * Needs to be retained by strong reference.
      */
-    static final Logger LOGGER = Logger.getLogger("org.apache.sis");
+    static final Logger LOGGER = Logger.getLogger(Loggers.ROOT);
 
     /**
      * Initializes {@link MonolineFormatter} if it has been specified in the {@code logging.properties}

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java?rev=1747373&r1=1747372&r2=1747373&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/DataStoreRegistry.java
[UTF-8] Wed Jun  8 11:02:45 2016
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.LinkedList;
 import java.util.Iterator;
 import java.util.ServiceLoader;
+import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
@@ -39,7 +40,7 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.8
  * @module
  */
 final class DataStoreRegistry {
@@ -51,19 +52,20 @@ final class DataStoreRegistry {
     private final ServiceLoader<DataStoreProvider> loader;
 
     /**
-     * Creates a new registry which will use the current thread
-     * {@linkplain Thread#getContextClassLoader() context class loader}.
+     * Creates a new registry which will look for data stores accessible to the default class
loader.
+     * The default is the current thread {@linkplain Thread#getContextClassLoader() context
class loader},
+     * provided that it can access at least the Apache SIS stores.
      */
-    DataStoreRegistry() {
-        loader = ServiceLoader.load(DataStoreProvider.class);
+    public DataStoreRegistry() {
+        loader = DefaultFactories.createServiceLoader(DataStoreProvider.class);
     }
 
     /**
-     * Creates a new registry which will use the given class loader.
+     * Creates a new registry which will look for data stores accessible to the given class
loader.
      *
      * @param loader The class loader to use for loading {@link DataStoreProvider} implementations.
      */
-    DataStoreRegistry(final ClassLoader loader) {
+    public DataStoreRegistry(final ClassLoader loader) {
         ArgumentChecks.ensureNonNull("loader", loader);
         this.loader = ServiceLoader.load(DataStoreProvider.class, loader);
     }



Mime
View raw message