You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/03/02 22:28:48 UTC

svn commit: r1733371 - in /sis/branches/JDK7: ./ application/sis-console/src/main/artifact/bin/ application/sis-console/src/main/artifact/conf/ application/sis-console/src/main/artifact/data/ application/sis-console/src/main/artifact/lib/ application/s...

Author: desruisseaux
Date: Wed Mar  2 21:28:47 2016
New Revision: 1733371

URL: http://svn.apache.org/viewvc?rev=1733371&view=rev
Log:
Merge the command-line improvements from JDK8 branch.

Added:
    sis/branches/JDK7/application/sis-console/src/main/artifact/data/
      - copied from r1733370, sis/branches/JDK8/application/sis-console/src/main/artifact/data/
    sis/branches/JDK7/application/sis-console/src/main/artifact/lib/README
      - copied unchanged from r1733370, sis/branches/JDK8/application/sis-console/src/main/artifact/lib/README
    sis/branches/JDK7/application/sis-console/src/main/artifact/log/README
      - copied unchanged from r1733370, sis/branches/JDK8/application/sis-console/src/main/artifact/log/README
Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/application/sis-console/src/main/artifact/bin/sis
    sis/branches/JDK7/application/sis-console/src/main/artifact/conf/logging.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
    sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
    sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar  2 21:28:47 2016
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1733322
+/sis/branches/JDK8:1584960-1733370
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/application/sis-console/src/main/artifact/bin/sis
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/artifact/bin/sis?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/artifact/bin/sis [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/artifact/bin/sis [UTF-8] Wed Mar  2 21:28:47 2016
@@ -17,6 +17,8 @@
 # ------------------------------------------------------------------------
 
 BASE_DIR="`dirname $0`/.."
+SIS_DATA="${SIS_DATA:-$BASE_DIR/data}"
+export SIS_DATA
 
 # Unpack the JAR file when first needed.
 if [ ! -f $BASE_DIR/lib/sis.jar ]

Modified: sis/branches/JDK7/application/sis-console/src/main/artifact/conf/logging.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/artifact/conf/logging.properties?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/artifact/conf/logging.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/artifact/conf/logging.properties [ISO-8859-1] Wed Mar  2 21:28:47 2016
@@ -59,5 +59,5 @@ java.util.logging.ConsoleHandler.level =
 #         class:short and class:long.
 
 java.util.logging.ConsoleHandler.formatter = org.apache.sis.util.logging.MonolineFormatter
-org.apache.sis.util.logging.MonolineFormatter.source = class:short
+org.apache.sis.util.logging.MonolineFormatter.source = logger:long
 org.apache.sis.util.logging.MonolineFormatter.colors = true

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/DataDirectory.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -153,7 +153,7 @@ public enum DataDirectory {
                     else buffer.setCharAt(i, Character.toLowerCase(c));
                 }
                 final String name = buffer.toString();
-                final Path dir = root.resolve(name);
+                final Path dir = root.resolve(name).normalize();
                 try {
                     if (Files.isDirectory(dir)) {
                         directory = dir;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -170,6 +170,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.
+        }
         return getLogger(name);
     }
 

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -108,7 +108,7 @@ import org.apache.sis.util.Debug;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.7
  * @module
  *
  * @see SimpleFormatter
@@ -541,6 +541,7 @@ loop:   for (int i=0; ; i++) {
     /**
      * Returns the {@link #colors} map, creating it if needed.
      */
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
     private SortedMap<Level,X364> colors() {
         if (colors == null) {
             colors = new TreeMap<>(COMPARATOR);
@@ -639,19 +640,17 @@ loop:   for (int i=0; ; i++) {
              * This level will be formatted with a colorized background if ANSI escape sequences are enabled.
              */
             int margin = buffer.length();
+            String levelColor = "", levelReset = "";
             if (SHOW_LEVEL) {
                 if (colors) {
-                    buffer.append(colorAt(level));
+                    levelColor = colorAt(level);
+                    levelReset = X364.BACKGROUND_DEFAULT.sequence();
                 }
-                final int offset = buffer.length();
+                final int offset = buffer.append(levelColor).length();
                 buffer.append(level.getLocalizedName())
                       .append(CharSequences.spaces(levelWidth - (buffer.length() - offset)));
                 margin += buffer.length() - offset;
-                if (colors) {
-                    buffer.append(X364.BACKGROUND_DEFAULT.sequence());
-                }
-                buffer.append(' ');
-                margin++;
+                buffer.append(levelReset).append(' ');
             }
             /*
              * Appends the logger name or source class name, in long of short form.
@@ -689,8 +688,8 @@ loop:   for (int i=0; ; i++) {
              */
             String bodyLineSeparator = writer.getLineSeparator();
             final String lineSeparator = System.lineSeparator();
-            if (bodyLineSeparator.length() != lineSeparator.length() + margin) {
-                bodyLineSeparator = lineSeparator + CharSequences.spaces(margin);
+            if (bodyLineSeparator.length() != lineSeparator.length() + margin + 1) {
+                bodyLineSeparator = lineSeparator + levelColor + CharSequences.spaces(margin) + levelReset + ' ';
                 writer.setLineSeparator(bodyLineSeparator);
             }
             if (colors && !emphase) {

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/logging/EmptyWarningListeners.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -51,21 +51,12 @@ public final strictfp class EmptyWarning
      * Creates a new instance for the given locale and logger.
      *
      * @param locale The locale to be returned by {@link #getLocale()}. Can be {@code null}.
-     * @param logger The logger to be returned by {@link #getLogger()}.
+     * @param logger The name of the logger to be returned by {@link #getLogger()}.
      */
-    public EmptyWarningListeners(final Locale locale, final Logger logger) {
+    public EmptyWarningListeners(final Locale locale, final String logger) {
         ArgumentChecks.ensureNonNull("logger", logger);
         this.locale = locale;
-        this.logger = logger;
-    }
-
-    /**
-     * Convenience constructor for an instance with null locale and the logger of the given name.
-     *
-     * @param logger The name of the logger to be returned by {@link #getLogger()}.
-     */
-    public EmptyWarningListeners(final String logger) {
-        this(null, Logging.getLogger(logger));
+        this.logger = Logging.getLogger(logger);
     }
 
     /** Returns the value given at construction time. */ @Override public Locale getLocale() {return locale;}

Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/internal/netcdf/TestCase.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -46,8 +46,7 @@ public abstract strictfp class TestCase
     /**
      * A dummy list of listeners which can be given to the {@link Decoder} constructor.
      */
-    public static EmptyWarningListeners<Decoder> LISTENERS =
-            new EmptyWarningListeners<>(Modules.NETCDF);
+    public static EmptyWarningListeners<Decoder> LISTENERS = new EmptyWarningListeners<>(null, Modules.NETCDF);
 
     /**
      * The {@code searchPath} argument value to be given to the {@link Decoder#setSearchPath(String[])}

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/wkt/Store.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -16,21 +16,27 @@
  */
 package org.apache.sis.internal.storage.wkt;
 
+import java.util.List;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.io.Reader;
 import java.io.IOException;
+import java.text.ParsePosition;
+import java.text.ParseException;
 import org.opengis.metadata.Metadata;
 import org.opengis.referencing.ReferenceSystem;
-import org.opengis.util.FactoryException;
+import org.apache.sis.io.wkt.WKTFormat;
+import org.apache.sis.io.wkt.Warnings;
 import org.apache.sis.storage.DataStore;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.referencing.CRS;
 
-import static java.util.Collections.singleton;
-
 
 /**
  * A data store which creates data objects from a WKT definition.
@@ -53,10 +59,10 @@ final class Store extends DataStore {
     private Reader source;
 
     /**
-     * The parsed object, initialized only when first needed.
-     * May still {@code null} if the parsing failed.
+     * The parsed objects, filled only when first needed.
+     * May still be empty if the parsing failed.
      */
-    private Object object;
+    private final List<Object> objects;
 
     /**
      * The metadata object, created when first needed.
@@ -70,8 +76,9 @@ final class Store extends DataStore {
      * @throws DataStoreException If an error occurred while opening the stream.
      */
     public Store(final StorageConnector connector) throws DataStoreException {
-        name = connector.getStorageName();
-        source = connector.getStorageAs(Reader.class);
+        objects = new ArrayList<>();
+        name    = connector.getStorageName();
+        source  = connector.getStorageAs(Reader.class);
         connector.closeAllExcept(source);
         if (source == null) {
             throw new DataStoreException(Errors.format(Errors.Keys.CanNotOpen_1, name));
@@ -79,42 +86,70 @@ final class Store extends DataStore {
     }
 
     /**
-     * Parses the object, if not already done. Note that {@link #object} may still be null
+     * Parses the objects, if not already done. Note that {@link #objects} may still be empty
      * if an exception has been thrown at this invocation time or in previous invocation.
      *
-     * @return The metadata associated to the parsed object, or {@code null} if none.
-     * @throws DataStoreException If an error occurred during the parsing process.
+     * @throws DataStoreException if an error occurred during the parsing process.
      */
-    @Override
-    public Metadata getMetadata() throws DataStoreException {
-        if (metadata == null) {
-            final Reader in = source;
-            source = null;                      // Cleared first in case of error.
-            if (in != null) try {
+    private void parse() throws DataStoreException {
+        final Reader in = source;
+        if (in != null) try {
+            source = null;                                                  // Cleared first in case of error.
+            final String wkt;
+            try {
                 char[] buffer = new char[StoreProvider.READ_AHEAD_LIMIT];
                 int length = 0;
-                try {
-                    int n;
-                    while ((n = in.read(buffer, length, buffer.length - length)) >= 0) {
-                        if ((length += n) >= buffer.length) {
-                            if (n >= Integer.MAX_VALUE / 1024) {     // Arbitrary size limit.
-                                throw new DataStoreException(Errors.format(Errors.Keys.ExcessiveStringSize));
-                            }
-                            buffer = Arrays.copyOf(buffer, n << 1);
+                int n;
+                while ((n = in.read(buffer, length, buffer.length - length)) >= 0) {
+                    if ((length += n) >= buffer.length) {
+                        if (n >= Integer.MAX_VALUE / 1024) {     // Arbitrary size limit.
+                            throw new DataStoreException(Errors.format(Errors.Keys.ExcessiveStringSize));
                         }
+                        buffer = Arrays.copyOf(buffer, n << 1);
                     }
-                } finally {
-                    in.close();
                 }
-                object = CRS.fromWKT(String.valueOf(buffer, 0, length));
-            } catch (IOException | FactoryException e) {
-                throw new DataStoreException(Errors.format(Errors.Keys.CanNotRead_1, name), e);
+                wkt = String.valueOf(buffer, 0, length);
+            } finally {
+                in.close();
             }
-            if (object instanceof ReferenceSystem) {
-                final DefaultMetadata d = new DefaultMetadata();
-                d.setReferenceSystemInfo(singleton((ReferenceSystem) object));
-                metadata = d;
+            final ParsePosition pos = new ParsePosition(0);
+            final WKTFormat parser = new WKTFormat(null, null);
+            do {
+                objects.add(parser.parse(wkt, pos));
+                pos.setIndex(CharSequences.skipLeadingWhitespaces(wkt, pos.getIndex(), wkt.length()));
+                final Warnings warnings = parser.getWarnings();
+                if (warnings != null) {
+                    final LogRecord record = new LogRecord(Level.WARNING, warnings.toString());
+                    record.setSourceClassName(Store.class.getName());
+                    record.setSourceMethodName("getMetadata");          // Public facade for this method.
+                    listeners.warning(record);
+                }
+            } while (pos.getIndex() < wkt.length());
+        } catch (IOException | ParseException e) {
+            throw new DataStoreException(Errors.format(Errors.Keys.CanNotParseFile_2, "WKT", name), e);
+        }
+    }
+
+    /**
+     * Returns the metadata associated to the parsed objects, or {@code null} if none.
+     * The current implementation retains only instances of {@link ReferenceSystem}
+     * and ignore other cases.
+     *
+     * @return The metadata associated to the parsed object, or {@code null} if none.
+     * @throws DataStoreException if an error occurred during the parsing process.
+     */
+    @Override
+    public Metadata getMetadata() throws DataStoreException {
+        if (metadata == null) {
+            parse();
+            DefaultMetadata d = null;
+            for (final Object object : objects) {
+                if (object instanceof ReferenceSystem) {
+                    if (d == null) d = new DefaultMetadata();
+                    d.getReferenceSystemInfo().add((ReferenceSystem) object);
+                }
             }
+            metadata = d;
         }
         return metadata;
     }
@@ -128,7 +163,7 @@ final class Store extends DataStore {
     public void close() throws DataStoreException {
         final Reader s = source;
         source = null;                  // Cleared first in case of failure.
-        object = null;
+        objects.clear();
         if (s != null) try {
             s.close();
         } catch (IOException e) {

Modified: sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java?rev=1733371&r1=1733370&r2=1733371&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java [UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/Store.java [UTF-8] Wed Mar  2 21:28:47 2016
@@ -81,7 +81,7 @@ final class Store extends DataStore {
      * Creates a new XML store from the given file, URL or stream.
      *
      * @param  connector Information about the storage (URL, stream, <i>etc</i>).
-     * @throws DataStoreException If an error occurred while opening the stream.
+     * @throws DataStoreException if an error occurred while opening the stream.
      */
     public Store(final StorageConnector connector) throws DataStoreException {
         name = connector.getStorageName();
@@ -139,7 +139,7 @@ final class Store extends DataStore {
      * Unmarshal the object, if not already done. Note that {@link #object} may still be null
      * if an exception has been thrown at this invocation time or in previous invocation.
      *
-     * @throws DataStoreException If an error occurred during the unmarshalling process.
+     * @throws DataStoreException if an error occurred during the unmarshalling process.
      */
     private void unmarshal() throws DataStoreException {
         final StreamSource s = source;
@@ -162,12 +162,14 @@ final class Store extends DataStore {
      *
      * <ul>
      *   <li>If the unmarshalled object implements the {@link Metadata} interface, then it is returned directly.</li>
+     *   <li>Otherwise if the unmarshalled object implements {@link ReferenceSystem}, then it is wrapped in the
+     *       <cite>"reference system info"</cite> property of a new {@link DefaultMetadata} instance.</li>
      * </ul>
      *
      * Other cases may be added in any future SIS version.
      *
      * @return The metadata associated to the unmarshalled object, or {@code null} if none.
-     * @throws DataStoreException If an error occurred during the unmarshalling process.
+     * @throws DataStoreException if an error occurred during the unmarshalling process.
      */
     @Override
     public Metadata getMetadata() throws DataStoreException {
@@ -187,7 +189,7 @@ final class Store extends DataStore {
     /**
      * Closes this data store and releases any underlying resources.
      *
-     * @throws DataStoreException If an error occurred while closing this data store.
+     * @throws DataStoreException if an error occurred while closing this data store.
      */
     @Override
     public void close() throws DataStoreException {