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 2021/09/17 13:32:18 UTC
[sis] 02/02: Following removal of "sis-gdal" module in previous
commit,
remove (for now) the `SpecializedOperationFactory` interface. Remove also
the code for loading a native library (not used anymore).
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 32936ed8d4bcec29f82d0c302b0a3bcf031127f0
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Sep 17 15:15:49 2021 +0200
Following removal of "sis-gdal" module in previous commit,
remove (for now) the `SpecializedOperationFactory` interface.
Remove also the code for loading a native library (not used anymore).
---
.../referencing/SpecializedOperationFactory.java | 55 ------
.../operation/CoordinateOperationFinder.java | 19 --
.../operation/CoordinateOperationRegistry.java | 9 +-
.../DefaultCoordinateOperationFactory.java | 28 ---
.../java/org/apache/sis/internal/system/OS.java | 196 ---------------------
.../apache/sis/util/logging/MonolineFormatter.java | 3 +-
ide-project/NetBeans/build.xml | 7 -
7 files changed, 2 insertions(+), 315 deletions(-)
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/SpecializedOperationFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/SpecializedOperationFactory.java
deleted file mode 100644
index a036ce9..0000000
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/SpecializedOperationFactory.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.sis.internal.referencing;
-
-import java.util.Set;
-import org.opengis.util.FactoryException;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import org.opengis.referencing.operation.CoordinateOperation;
-
-
-/**
- * Implemented by extension modules capable to provide coordinate operations for some particular pairs of CRS.
- * Implementations of this interface are not general-purpose factories;
- * they should not process any pair of CRS other than the one for which they are designed.
- *
- * <div class="note"><b>Example:</b>
- * a module doing the bindings between Apache SIS and another map projection library may create wrappers
- * around the transformation method of that other library when {@code findOperations(…)} recognizes the
- * given CRS as wrappers around their data structures.</div>
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 0.8
- * @since 0.8
- * @module
- */
-public interface SpecializedOperationFactory {
- /**
- * Returns operations between the given pair of CRS, or an empty set if this factory does not recognize them.
- * Non-empty sets have precedence over EPSG geodetic dataset or other mechanism used by Apache SIS, so should
- * be used sparsely.
- *
- * @param sourceCRS the coordinate reference system of source points (before transformation).
- * @param targetCRS the coordinate reference system of target points (after transformation).
- * @return the coordinate operations from source to target CRS, or an empty set if this factory
- * does not recognize the given pair of CRSs.
- * @throws FactoryException if this factory recognizes the CRSs given in arguments,
- * but an error occurred while creating the coordinate operation.
- */
- Set<CoordinateOperation> findOperations(CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS)
- throws FactoryException;
-}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
index a3ab4b1..94f9495 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
@@ -48,7 +48,6 @@ import org.apache.sis.internal.referencing.provider.Geographic3Dto2D;
import org.apache.sis.internal.referencing.provider.GeographicToGeocentric;
import org.apache.sis.internal.referencing.provider.GeocentricToGeographic;
import org.apache.sis.internal.referencing.provider.GeocentricAffine;
-import org.apache.sis.internal.referencing.SpecializedOperationFactory;
import org.apache.sis.internal.referencing.Resources;
import org.apache.sis.internal.util.Constants;
import org.apache.sis.measure.Units;
@@ -266,24 +265,6 @@ public class CoordinateOperationFinder extends CoordinateOperationRegistry {
areaOfInterest = CoordinateOperationContext.setGeographicBoundingBox(areaOfInterest, bbox);
}
/*
- * Verify if some extension module handles this pair of CRS in a special way. For example it may
- * be the "sis-gdal" module checking if the given CRS are wrappers around Proj.4 data structure.
- */
- { // For keeping `operations` list locale.
- final List<CoordinateOperation> operations = new ArrayList<>();
- for (final SpecializedOperationFactory sp : factorySIS.getSpecializedFactories()) {
- for (final CoordinateOperation op : sp.findOperations(sourceCRS, targetCRS)) {
- if (filter(op)) {
- operations.add(op);
- }
- }
- }
- if (!operations.isEmpty()) {
- CoordinateOperationSorter.sort(operations, bbox);
- return operations;
- }
- }
- /*
* Verify in the EPSG dataset if the operation is explicitly defined by an authority.
*/
if (registry != null) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
index 299f63e..f81df93 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/CoordinateOperationRegistry.java
@@ -626,7 +626,7 @@ class CoordinateOperationRegistry {
* FactoryException propagate.
*/
operation = complete(operation, sourceCRS, targetCRS);
- if (filter(operation)) {
+ if (filter == null || filter.test(operation)) {
if (stopAtFirst) {
operations.clear();
operations.add(operation);
@@ -641,13 +641,6 @@ class CoordinateOperationRegistry {
}
/**
- * Returns {@code true} if the given operation can be accepted.
- */
- final boolean filter(final CoordinateOperation op) {
- return filter == null || filter.test(op);
- }
-
- /**
* Creates the inverse of the given single operation.
* If this operation succeed, then the returned coordinate operations has the following properties:
*
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
index 45efa18..7b9484c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCoordinateOperationFactory.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-import java.util.ServiceLoader;
import org.opengis.util.FactoryException;
import org.opengis.util.NoSuchIdentifierException;
import org.opengis.parameter.ParameterValueGroup;
@@ -36,11 +35,9 @@ import org.opengis.referencing.crs.SingleCRS;
import org.opengis.referencing.crs.CRSFactory;
import org.opengis.referencing.cs.CSFactory;
import org.opengis.referencing.datum.Datum;
-import org.apache.sis.internal.referencing.LazySet;
import org.apache.sis.internal.referencing.Resources;
import org.apache.sis.internal.referencing.MergedProperties;
import org.apache.sis.internal.referencing.CoordinateOperations;
-import org.apache.sis.internal.referencing.SpecializedOperationFactory;
import org.apache.sis.internal.referencing.ReferencingFactoryContainer;
import org.apache.sis.internal.referencing.ReferencingUtilities;
import org.apache.sis.internal.system.DefaultFactories;
@@ -130,17 +127,6 @@ public class DefaultCoordinateOperationFactory extends AbstractFactory implement
private volatile MathTransformFactory mtFactory;
/**
- * Factories specialized to some particular pair of CRS. For example a module doing the bindings between
- * Apache SIS and another map projection library may create wrappers around the transformation method of
- * that other library when {@code SpecializedOperationFactory.tryCreateOperation(…)} recognizes the given
- * CRS as wrappers around their data structures.
- *
- * <p>This array is created when first needed. After creation, the array shall not be modified anymore.</p>
- */
- @SuppressWarnings("VolatileArrayField")
- private volatile SpecializedOperationFactory[] specializedFactories;
-
- /**
* Weak references to existing objects.
* This set is used in order to return a pre-existing object instead of creating a new one.
* This applies to objects created explicitly, not to coordinate operations inferred by a
@@ -277,20 +263,6 @@ public class DefaultCoordinateOperationFactory extends AbstractFactory implement
}
/**
- * Returns all known factories specialized in the creation of coordinate operations between some particular
- * pairs of CRS.
- */
- final SpecializedOperationFactory[] getSpecializedFactories() {
- SpecializedOperationFactory[] factories = specializedFactories;
- if (factories == null) {
- final LazySet<SpecializedOperationFactory> set =
- new LazySet<>(ServiceLoader.load(SpecializedOperationFactory.class).iterator());
- specializedFactories = factories = set.toArray(new SpecializedOperationFactory[set.size()]);
- }
- return factories;
- }
-
- /**
* Returns the operation method of the given name. The given argument shall be either a method
* {@linkplain DefaultOperationMethod#getName() name} (e.g. <cite>"Transverse Mercator"</cite>)
* or one of its {@linkplain DefaultOperationMethod#getIdentifiers() identifiers} (e.g. {@code "EPSG:9807"}).
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java b/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
deleted file mode 100644
index 2a53697..0000000
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/system/OS.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * 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.sis.internal.system;
-
-import java.net.URL;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
-import org.apache.sis.util.logging.Logging;
-import org.apache.sis.util.resources.Errors;
-
-
-/**
- * The operation system on which SIS is running.
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 0.8
- * @since 0.3
- * @module
- */
-public enum OS {
- /**
- * Unknown system.
- */
- UNKNOWN(null, false),
-
- /**
- * Windows.
- */
- WINDOWS("windows", false),
-
- /**
- * Mac OS.
- */
- MAC_OS("darwin", true),
-
- /**
- * Linux.
- */
- LINUX("linux", true);
-
- /**
- * The sub-directory where to look for native files ({@code .so} or {@code .dll}).
- * Those subdirectories are not standard (as far as we know) and could change in
- * any future Apache SIS version. The directory is {@code null} for unknown OS.
- */
- private final String libdir;
-
- /**
- * {@code true} if this OS is a kind of Unix.
- */
- public final boolean unix;
-
- /**
- * Creates a new enumeration.
- */
- private OS(final String libdir, final boolean unix) {
- this.libdir = libdir;
- this.unix = unix;
- }
-
- /**
- * Returns the name value of {@code "os.name"} property, or {@code null} if the security manager
- * does not allow us to access this information.
- *
- * <div class="note"><b>Note:</b> {@code uname} is an Unix command providing the same information.</div>
- *
- * @return the operation system name, or {@code null} if this information is not available.
- */
- public static String uname() {
- try {
- return System.getProperty("os.name");
- } catch (SecurityException e) {
- Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), OS.class, "uname", e);
- return null;
- }
- }
-
- /**
- * Returns the operating system SIS is currently on.
- *
- * @return the operation system.
- */
- public static OS current() {
- final String name = uname();
- if (name != null) {
- if (name.contains("Windows")) return WINDOWS;
- if (name.contains("Mac OS")) return MAC_OS;
- if (name.contains("Linux")) return LINUX;
- }
- return UNKNOWN;
- }
-
- /**
- * Loads the native library of the given name from the JAR file of the given class.
- * This method searches for a resource in the {@code /native/<os>} directory where
- * {@code <os>} is {@code windows}, {@code darwin} or {@code linux}.
- *
- * @param caller a class in the JAR file where to look for native resources.
- * @param name the native library name without {@code ".so"} or {@code ".dll"} extension.
- * @throws UnsatisfiedLinkError if the native library can not be loaded for the current OS.
- *
- * @see System#load(String)
- */
- public static void load(final Class<?> caller, final String name) {
- try {
- System.load(current().nativeLibrary(caller, name));
- } catch (IOException | SecurityException e) {
- throw (UnsatisfiedLinkError) new UnsatisfiedLinkError(e.getMessage()).initCause(e);
- }
- }
-
- /**
- * Returns an absolute path to the library of the given name in the JAR file.
- * If the resources can not be accessed by an absolute path, then this method
- * copies the resource in a temporary file.
- *
- * @param caller a class in the JAR file where to look for native resources.
- * @param name the native library name without {@code ".so"} or {@code ".dll"} extension.
- * @return absolute path to the library (may be a temporary file).
- * @throws IOException if an error occurred while copying the library to a temporary file.
- * @throws SecurityException if the security manager denies loading resource, creating absolute path, <i>etc</i>.
- * @throws UnsatisfiedLinkError if no native resource has been found for the current OS.
- *
- * @see System#load(String)
- */
- private String nativeLibrary(final Class<?> caller, final String name) throws IOException {
- if (libdir != null) {
- final String ext = unix ? ".so" : ".dll";
- final String path = libdir + '/' + name + ext;
- final ClassLoader loader = caller.getClassLoader();
- /*
- * First, verify if the "linux", "darwin" or "windows" directory exists at the same level
- * than the JAR file containing the caller class. If it exists, then we will use it. This
- * check avoid the need to copy the ".so" or ".dll" file in a temporary location. If the
- * directory does not exist, then we do NOT create it in order to reduce the risk to mess
- * with user's installation.
- *
- * Example of URL for a JAR entry: jar:file:/home/…/sis-gdal.jar!/org/apache/…/PJ.class
- */
- URL res = loader.getResource(caller.getName().replace('.', '/').concat(".class"));
- if (res != null && "jar".equals(res.getProtocol())) {
- String file = res.getPath();
- final int s = file.indexOf('!');
- if (s >= 0) try {
- File location = new File(new URI(file.substring(0, s)));
- location = new File(location.getParentFile(), path);
- if (location.canExecute()) {
- return location.getAbsolutePath();
- }
- } catch (IllegalArgumentException | URISyntaxException e) {
- Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), OS.class, "nativeLibrary", e);
- }
- }
- /*
- * If we didn't found an existing "linux", "darwin" or "windows" directory with native library,
- * copy the library in a temporary file. That file will be deleted on JVM exists, so a new file
- * will be copied each time the application is executed.
- */
- res = loader.getResource("native/".concat(path));
- if (res != null) {
- try {
- return new File(res.toURI()).getAbsolutePath();
- } catch (IllegalArgumentException | URISyntaxException e) {
- Logging.recoverableException(Logging.getLogger(Loggers.SYSTEM), OS.class, "nativeLibrary", e);
- }
- final Path tmp = Files.createTempFile(name, ext).toAbsolutePath();
- tmp.toFile().deleteOnExit();
- try (InputStream in = res.openStream()) {
- Files.copy(in, tmp, StandardCopyOption.REPLACE_EXISTING);
- }
- return tmp.toString();
- }
- }
- throw new UnsatisfiedLinkError(Errors.format(Errors.Keys.NativeInterfacesNotFound_2, uname(), name));
- }
-}
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
index ec6ffd4..c8b352d 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
@@ -33,7 +33,6 @@ import java.util.Comparator;
import java.util.ResourceBundle;
import java.util.logging.*;
import org.apache.sis.internal.system.Modules;
-import org.apache.sis.internal.system.OS;
import org.apache.sis.internal.util.X364;
import org.apache.sis.internal.util.Strings;
import org.apache.sis.internal.util.AutoMessageFormat;
@@ -345,7 +344,7 @@ public class MonolineFormatter extends Formatter {
if (handler instanceof ConsoleHandler && X364.isAnsiSupported()) {
resetLevelColors();
}
- faintSupported = OS.current() != OS.MAC_OS;
+ faintSupported = System.getProperty("os.name", "").contains("Mac OS");
/*
* Creates the buffer and the printer. We will expand the tabulations with 4 characters.
* This apply to the stack trace formatted by Throwable.printStackTrace(PrintWriter);
diff --git a/ide-project/NetBeans/build.xml b/ide-project/NetBeans/build.xml
index 746e465..b76f00a 100644
--- a/ide-project/NetBeans/build.xml
+++ b/ide-project/NetBeans/build.xml
@@ -229,13 +229,6 @@
</fileset>
</concat>
- <!-- SpecializedOperationFactory implementations to be loaded by ServiceLoader. -->
- <concat destfile="${build.classes.dir}/META-INF/services/org.apache.sis.internal.referencing.SpecializedOperationFactory" encoding="UTF-8" fixlastline="yes">
- <fileset dir="${project.root}">
- <include name="*/*/src/main/resources/META-INF/services/org.apache.sis.internal.referencing.SpecializedOperationFactory"/>
- </fileset>
- </concat>
-
<!-- DataStoreProvider implementations to be loaded by ServiceLoader. -->
<concat destfile="${build.classes.dir}/META-INF/services/org.apache.sis.storage.DataStoreProvider" encoding="UTF-8" fixlastline="yes">
<fileset dir="${project.root}">