sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1801475 - in /sis/branches/JDK8: ./ core/sis-utility/src/main/java/org/apache/sis/internal/system/ storage/sis-gdal/ storage/sis-gdal/src/main/ storage/sis-gdal/src/main/c/ storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/ storag...
Date Mon, 10 Jul 2017 14:33:12 GMT
Author: desruisseaux
Date: Mon Jul 10 14:33:12 2017
New Revision: 1801475

URL: http://svn.apache.org/viewvc?rev=1801475&view=rev
Log:
Avoid the use of dlopen for use of libproj.so native file (change by Jean-Loup Amiot).
Log a warning if a .so file is not found.

Removed:
    sis/branches/JDK8/storage/sis-gdal/src/main/c/sharedLibraryAccess.h
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/system/Modules.java
    sis/branches/JDK8/pom.xml
    sis/branches/JDK8/storage/sis-gdal/   (props changed)
    sis/branches/JDK8/storage/sis-gdal/src/main/Makefile
    sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c
    sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java
    sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
    sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java

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=1801475&r1=1801474&r2=1801475&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] Mon Jul 10 14:33:12 2017
@@ -73,6 +73,11 @@ public final class Modules {
     public static final String EARTH_OBSERVATION = "org.apache.sis.storage.earth-observation";
 
     /**
+     * The {@value} module name.
+     */
+    public static final String GDAL = "org.apache.sis.storage.gdal";
+
+    /**
      * The major version number of all Apache SIS modules.
      *
      * @see org.apache.sis.util.Version

Modified: sis/branches/JDK8/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Mon Jul 10 14:33:12 2017
@@ -583,6 +583,7 @@ Apache SIS is a free software, Java lang
           <compilerArgs>
             <arg>-Xlint:all</arg>
             <arg>-Xdoclint:syntax,html,missing/protected,accessibility/protected</arg>
+            <arg>-h</arg> <arg>${project.build.sourceDirectory}/../c</arg>
           </compilerArgs>
         </configuration>
       </plugin>

Propchange: sis/branches/JDK8/storage/sis-gdal/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 10 14:33:12 2017
@@ -0,0 +1,10 @@
+.project
+.settings
+.classpath
+.jetproperties
+.wtpmodules
+target
+bin
+cobertura.ser
+nbproject
+nbactions.xml

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/Makefile
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/Makefile?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/Makefile (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/Makefile Mon Jul 10 14:33:12 2017
@@ -1,10 +1,10 @@
 FLAG=-shared -fPIC
 INCLUDE_DIR=-I$(JAVA_HOME)include -I$(JAVA_HOME)include/linux -I/home/amiotj/Documents/geomatys/proj.4/src
-LIB=-lm -ldl
-
+LIB=-lm -ldl -lproj
+SRC=c/org_apache_sis_storage_gdal_PJ.c
 OUT=libproj-binding.so
 
 
 all:
-    gcc $(FLAG) -o $(OUT) c/jniproj.c $(INCLUDE_DIR) $(LIB)
-    mv $(OUT) resources/
+	gcc $(FLAG) -o $(OUT) $(SRC) $(INCLUDE_DIR) $(LIB)
+	mv $(OUT) resources/

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.c [UTF-8]
Mon Jul 10 14:33:12 2017
@@ -15,14 +15,11 @@
  * limitations under the License.
  */
 #include <proj_config.h>
-
 #include <math.h>
 #include <string.h>
 #include <projects.h>
 #include <stdbool.h>
 #include <jni.h>
-
-#include "sharedLibraryAccess.h"
 #include "org_apache_sis_storage_gdal_PJ.h"
 
 
@@ -31,52 +28,6 @@
 
 
 
-void throw_exception(JNIEnv* env, const char* message) {
-    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), NULL);
-}
-
-bool isInit = false;
-
-const char* (*pj_get_release_ptr)();
-projPJ      (*pj_init_plus_ptr)(const char* definition);
-projPJ      (*pj_latlong_from_proj_ptr)(projPJ pj_in);
-char*       (*pj_get_def_ptr)(projPJ pj, int options);
-void        (*pj_dalloc_ptr)(void* ptr);
-int         (*pj_is_latlong_ptr)(projPJ pj);
-int         (*pj_is_geocent_ptr)(projPJ pj);
-int         (*pj_transform_ptr)(projPJ srcdefn, projPJ dstdefn, long point_count, int point_offset,
double* x, double* y, double *z);
-char*       (*pj_strerrno_ptr)(int);
-int         (*pj_ctx_get_errno_ptr)(projCtx ctx);
-void        (*pj_free_ptr)(projPJ pj);
-
-void Java_org_apache_sis_storage_gdal_PJ_init(JNIEnv* env, jclass class) {
-    void* handle = dlopen("libproj.so", RTLD_LAZY);
-    if (!handle) {
-        throw_exception(env, "Can't open .so");
-        return;
-    }
-    dlerror();
-
-    pj_get_release_ptr =       dlsym(handle, "pj_get_release");
-    pj_init_plus_ptr =         dlsym(handle, "pj_init_plus");
-    pj_latlong_from_proj_ptr = dlsym(handle, "pj_latlong_from_proj");
-    pj_get_def_ptr =           dlsym(handle, "pj_get_def");
-    pj_dalloc_ptr =            dlsym(handle, "pj_dalloc");
-    pj_is_latlong_ptr =        dlsym(handle, "pj_is_latlong");
-    pj_is_geocent_ptr =        dlsym(handle, "pj_is_geocent");
-    pj_transform_ptr =         dlsym(handle, "pj_transform");
-    pj_strerrno_ptr =          dlsym(handle, "pj_strerrno");
-    pj_ctx_get_errno_ptr =     dlsym(handle, "pj_ctx_get_errno");
-    pj_free_ptr =              dlsym(handle, "pj_free");
-
-    char* error = dlerror();
-    if (error) {
-        throw_exception(env, error);
-        return;
-    }
-    isInit = true;
-}
-
 /*!
  * \brief
  * Internal method returning the address of the PJ structure wrapped by the given Java object.
@@ -105,7 +56,7 @@ PJ *getPJ(JNIEnv *env, jobject object)
 JNIEXPORT jstring JNICALL Java_org_apache_sis_storage_gdal_PJ_getVersion
   (JNIEnv *env, jclass class)
 {
-    const char *desc = pj_get_release_ptr();
+    const char *desc = pj_get_release();
     return (desc) ? (*env)->NewStringUTF(env, desc) : NULL;
 }
 
@@ -123,7 +74,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
 {
     const char *def_utf = (*env)->GetStringUTFChars(env, definition, NULL);
     if (!def_utf) return 0;             // OutOfMemoryError already thrown.
-    PJ *pj = pj_init_plus_ptr(def_utf);
+    PJ *pj = pj_init_plus(def_utf);
     (*env)->ReleaseStringUTFChars(env, definition, def_utf);
     return (jlong) pj;
 }
@@ -141,7 +92,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_
   (JNIEnv *env, jclass class, jobject projected)
 {
     PJ *pj = getPJ(env, projected);
-    return (pj) ? (jlong) pj_latlong_from_proj_ptr(pj) : 0;
+    return (pj) ? (jlong) pj_latlong_from_proj(pj) : 0;
 }
 
 /*!
@@ -157,10 +108,10 @@ JNIEXPORT jstring JNICALL Java_org_apach
 {
     PJ *pj = getPJ(env, object);
     if (pj) {
-        const char *desc = pj_get_def_ptr(pj, 0);
+        const char *desc = pj_get_def(pj, 0);
         if (desc) {
             jstring str = (*env)->NewStringUTF(env, desc);
-            pj_dalloc_ptr(desc);
+            pj_dalloc(desc);
             return str;
         }
     }
@@ -204,9 +155,9 @@ JNIEXPORT jobject JNICALL Java_org_apach
     PJ *pj = getPJ(env, object);
     if (pj) {
         const char *type;
-        if (pj_is_latlong_ptr(pj)) {
+        if (pj_is_latlong(pj)) {
             type = "GEOGRAPHIC";
-        } else if (pj_is_geocent_ptr(pj)) {
+        } else if (pj_is_geocent(pj)) {
             type = "GEOCENTRIC";
         } else {
             type = "PROJECTED";
@@ -348,10 +299,10 @@ JNIEXPORT jdouble JNICALL Java_org_apach
  */
 void convertAngularOrdinates(PJ *pj, double* data, jint numPts, int dimension, double factor)
{
     int dimToSkip;
-    if (pj_is_latlong_ptr(pj)) {
+    if (pj_is_latlong(pj)) {
         // Convert only the 2 first ordinates and skip all the other dimensions.
         dimToSkip = dimension - 2;
-    } else if (pj_is_geocent_ptr(pj)) {
+    } else if (pj_is_geocent(pj)) {
         // Convert only the 3 first ordinates and skip all the other dimensions.
         dimToSkip = dimension - 3;
     } else {
@@ -416,12 +367,12 @@ JNIEXPORT void JNICALL Java_org_apache_s
             double *y = x + 1;
             double *z = (dimension >= 3) ? y+1 : NULL;
             convertAngularOrdinates(src_pj, x, numPts, dimension, M_PI/180);
-            int err = pj_transform_ptr(src_pj, dst_pj, numPts, dimension, x, y, z);
+            int err = pj_transform(src_pj, dst_pj, numPts, dimension, x, y, z);
             convertAngularOrdinates(dst_pj, x, numPts, dimension, 180/M_PI);
             (*env)->ReleasePrimitiveArrayCritical(env, coordinates, data, 0);
             if (err) {
                 jclass c = (*env)->FindClass(env, "org/opengis/referencing/operation/TransformException");
-                if (c) (*env)->ThrowNew(env, c, pj_strerrno_ptr(err));
+                if (c) (*env)->ThrowNew(env, c, pj_strerrno(err));
             }
         }
     }
@@ -440,9 +391,9 @@ JNIEXPORT jstring JNICALL Java_org_apach
 {
     PJ *pj = getPJ(env, object);
     if (pj) {
-        int err = pj_ctx_get_errno_ptr(pj->ctx);
+        int err = pj_ctx_get_errno(pj->ctx);
         if (err) {
-            return (*env)->NewStringUTF(env, pj_strerrno_ptr(err));
+            return (*env)->NewStringUTF(env, pj_strerrno(err));
         }
     }
     return NULL;
@@ -468,7 +419,7 @@ JNIEXPORT void JNICALL Java_org_apache_s
         PJ *pj = (PJ*) (*env)->GetLongField(env, object, id);
         if (pj) {
             (*env)->SetLongField(env, object, id, (jlong) 0);
-            pj_free_ptr(pj);
+            pj_free(pj);
         }
     }
 }

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/c/org_apache_sis_storage_gdal_PJ.h [UTF-8]
Mon Jul 10 14:33:12 2017
@@ -11,14 +11,6 @@ extern "C" {
 #define org_apache_sis_storage_gdal_PJ_DIMENSION_MAX 100L
 /*
  * Class:     org_apache_sis_storage_gdal_PJ
- * Method:    init
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_org_apache_sis_storage_gdal_PJ_init
-  (JNIEnv *, jclass);
-
-/*
- * Class:     org_apache_sis_storage_gdal_PJ
  * Method:    allocatePJ
  * Signature: (Ljava/lang/String;)J
  */

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java [UTF-8]
(original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJ.java [UTF-8]
Mon Jul 10 14:33:12 2017
@@ -51,16 +51,9 @@ class PJ {
      */
     static {
         System.load("libproj-binding.so");
-        init();
     }
 
     /**
-     * Initializes the bindings to the Proj4 library.
-     * This method needs to be invoked exactly once before any method in the {@code PJ} class.
-     */
-    private static native void init();
-
-    /**
      * The pointer to {@code PJ} structure allocated in the C/C++ heap. This value has no
      * meaning in Java code. <strong>Do not modify</strong>, since this value
is used by Proj4.
      * Do not rename neither, unless you update accordingly the C code in JNI wrappers.
@@ -74,6 +67,7 @@ class PJ {
      * @throws IllegalArgumentException if the PJ structure can not be created from the given
string.
      */
     public PJ(final String definition) throws IllegalArgumentException {
+        Objects.requireNonNull(definition);
         ptr = allocatePJ(definition);
         if (ptr == 0) {
             throw new IllegalArgumentException(definition);
@@ -81,20 +75,16 @@ class PJ {
     }
 
     /**
-     * Creates a new {@code PJ} structure derived from an existing {@code PJ} object.
+     * Creates a new {@code PJ} structure for the geographic part of the given {@code PJ}
object.
      * This constructor is usually for getting the
      * {@linkplain org.opengis.referencing.crs.ProjectedCRS#getBaseCRS() base geographic
CRS}
      * from a {@linkplain org.opengis.referencing.crs.ProjectedCRS projected CRS}.
      *
      * @param  crs   the CRS (usually projected) from which to derive a new CRS.
-     * @param  type  the type of the new CRS. Currently, only {@link Type#GEOGRAPHIC} is
supported.
      * @throws IllegalArgumentException if the PJ structure can not be created.
      */
-    public PJ(final PJ crs, final Type type) throws IllegalArgumentException {
-        Objects.requireNonNull(crs, "The CRS must be non-null.");
-        if (type != Type.GEOGRAPHIC) {
-            throw new IllegalArgumentException("Can not derive the " + type + " type.");
-        }
+    public PJ(final PJ crs) throws IllegalArgumentException {
+        Objects.requireNonNull(crs);
         ptr = allocateGeoPJ(crs);
         if (ptr == 0) {
             throw new IllegalArgumentException(crs.getLastError());
@@ -150,7 +140,7 @@ class PJ {
      * In the Proj4 library, a CRS can only be geographic, geocentric or projected,
      * without distinction between 2D and 3D CRS.
      */
-    public enum Type {
+    enum Type {
         /*
          * IMPLEMENTATION NOTE: Do not rename those fields, unless you update the
          * native C code accordingly.
@@ -280,5 +270,6 @@ class PJ {
      * <strong>NEVER INVOKE THIS METHOD EXPLICITELY, NEVER OVERRIDE</strong>.
      */
     @Override
+    @SuppressWarnings("FinalizeDeclaration")
     protected final native void finalize();
 }

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/PJDatum.java
[UTF-8] Mon Jul 10 14:33:12 2017
@@ -86,7 +86,7 @@ final class PJDatum extends PJ implement
      * Creates the base CRS of the given projected CRS.
      */
     PJDatum(final PJDatum projected) throws IllegalArgumentException {
-        super(projected, Type.GEOGRAPHIC);
+        super(projected);
         definition = super.getDefinition();
         name = projected.name;
     }

Modified: sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/main/java/org/apache/sis/storage/gdal/Proj4.java
[UTF-8] Mon Jul 10 14:33:12 2017
@@ -20,6 +20,8 @@ import org.opengis.metadata.Identifier;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.CoordinateOperation;
+import org.apache.sis.internal.system.Modules;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.Static;
 
 
@@ -34,9 +36,9 @@ import org.apache.sis.util.Static;
  */
 public final class Proj4 extends Static {
     /**
-     * The Proj4 parameter used for declaration of axis order. This parameter is handled
in a special
-     * way by this factory: it be a comma-separated list of axis order definitions, in which
case the
-     * second value is used as the axis order of the {@link org.opengis.referencing.crs.ProjectedCRS#getBaseCRS()}.
+     * The Proj4 parameter used for declaration of axis order. This parameter is handled
in a special way
+     * by the factories: it be a comma-separated list of axis order definitions, in which
case the second
+     * value is used as the axis order of the {@link org.opengis.referencing.crs.ProjectedCRS#getBaseCRS()}.
      *
      * <p>An other departure from Proj.4 is that Proj.4 expect the axis parameter to
be exactly
      * 3 characters long, which our code accepts 2 characters as well. We relax the Proj.4
@@ -51,9 +53,28 @@ public final class Proj4 extends Static
     static final char AXIS_ORDER_SEPARATOR = ',';
 
     /**
-     * For sub-class constructors only.
+     * Do not allow instantiation of this class.
      */
-    protected Proj4() {
+    private Proj4() {
+    }
+
+    /**
+     * Returns the version number of the Proj4 library.
+     * Returns {@code null} if Proj.4 is not installed on the current system.
+     *
+     * @return the Proj4 release string, or {@code null} if no installation has been found.
+     */
+    public static String getVersion() {
+        try {
+            return PJ.getVersion();
+        } catch (UnsatisfiedLinkError e) {
+            // Thrown the first time that we try to use the library.
+            Logging.unexpectedException(Logging.getLogger(Modules.GDAL), Proj4.class, "version",
e);
+        } catch (NoClassDefFoundError e) {
+            // Thrown on all attempts after the first one.
+            Logging.recoverableException(Logging.getLogger(Modules.GDAL), Proj4.class, "version",
e);
+        }
+        return null;
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java?rev=1801475&r1=1801474&r2=1801475&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-gdal/src/test/java/org/apache/sis/storage/gdal/PJTest.java
[UTF-8] Mon Jul 10 14:33:12 2017
@@ -63,7 +63,7 @@ public class PJTest {
         assertEquals(PJ.Type.PROJECTED, pj.getType());
         assertArrayEquals(new char[] {'e', 'n', 'u'}, pj.getAxisDirections());
         assertEquals(1.0, pj.getLinearUnitToMetre(true), 0.0);
-        assertIsWGS84(new PJ(pj, PJ.Type.GEOGRAPHIC));
+        assertIsWGS84(new PJ(pj));
     }
 
     /**



Mime
View raw message