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 34937242d77a3554cb57177d972f737691b879b0 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Oct 6 12:19:39 2024 +0200 More accurate warning message when the EPSG tables are not found. --- .../org/apache/sis/metadata/sql/privy/Initializer.java | 2 +- .../sis/referencing/factory/sql/EPSGFactory.java | 18 ++++++++---------- .../factory/sql/InstallationScriptProvider.java | 2 +- .../sis/referencing/factory/sql/SQLTranslator.java | 15 +++++++++++++-- .../org/apache/sis/referencing/internal/Resources.java | 6 ++++++ .../sis/referencing/internal/Resources.properties | 1 + .../sis/referencing/internal/Resources_fr.properties | 1 + .../sis/referencing/factory/TestFactorySource.java | 7 ++++--- .../main/org/apache/sis/util/resources/Errors.java | 7 +------ .../org/apache/sis/util/resources/Errors.properties | 1 - .../org/apache/sis/util/resources/Errors_fr.properties | 1 - 11 files changed, 36 insertions(+), 25 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/privy/Initializer.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/privy/Initializer.java index eac980e9ea..330ae42857 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/privy/Initializer.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/privy/Initializer.java @@ -393,7 +393,7 @@ public abstract class Initializer { } /** - * Prepares a log record saying that a connection to the spatial metadata database has been created. + * Logs a record saying that a connection to the spatial metadata database has been created. * This method can be invoked after {@link DataSource#getConnection()}. When invoked for the first time, * the record level is set to {@link Level#CONFIG}. On next calls, the level become {@link Level#FINE}. * diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGFactory.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGFactory.java index 420f8dc5f9..6a33c156f5 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGFactory.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGFactory.java @@ -292,14 +292,7 @@ public class EPSGFactory extends ConcurrentAuthorityFactory<EPSGDataAccess> impl if (message == null) { message = Classes.getShortClassName(e); } - return canNotUse(message); - } - - /** - * Returns the message to put in an {@link UnavailableFactoryException} having the given cause. - */ - private String canNotUse(final String cause) { - return Resources.forLocale(locale).getString(Resources.Keys.CanNotUseGeodeticParameters_2, Constants.EPSG, cause); + return Resources.forLocale(locale).getString(Resources.Keys.CanNotUseGeodeticParameters_2, Constants.EPSG, message); } /** @@ -473,8 +466,13 @@ public class EPSGFactory extends ConcurrentAuthorityFactory<EPSGDataAccess> impl if (tr.isTableFound()) { return newDataAccess(connection, tr); } else { - connection.close(); - exception = new UnavailableFactoryException(canNotUse(SQLTranslator.tableNotFound(locale))); + String cause; + try { + cause = SQLTranslator.tableNotFound(connection.getMetaData(), locale); + } finally { + connection.close(); + } + exception = new UnavailableFactoryException(cause); } } catch (Exception e) { // Really want to catch all exceptions here. if (connection != null) try { diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java index d7265cbb8e..6aa9588098 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java @@ -333,7 +333,7 @@ public abstract class InstallationScriptProvider extends InstallationResources { } } } else { - directory = null; + directory = null; // Does not exist or is not a directory. } this.directory = directory; /* diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/SQLTranslator.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/SQLTranslator.java index b9b2ff0f97..d4f4953eb8 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/SQLTranslator.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/SQLTranslator.java @@ -30,6 +30,7 @@ import org.apache.sis.util.privy.Constants; import static org.apache.sis.util.privy.Strings.isNullOrEmpty; import org.apache.sis.metadata.sql.privy.Reflection; import org.apache.sis.metadata.sql.privy.SQLUtilities; +import org.apache.sis.referencing.internal.Resources; /** @@ -385,8 +386,18 @@ public class SQLTranslator implements Function<String,String> { /** * Returns the error message for the exception to throw if the EPSG tables are not found and we cannot create them. */ - static String tableNotFound(final Locale locale) { - return Errors.forLocale(locale).getString(Errors.Keys.TableNotFound_1, SENTINEL[MIXED_CASE]); + static String tableNotFound(final DatabaseMetaData md, final Locale locale) throws SQLException { + String db = md.getURL(); + if (db == null) { + db = "?"; + } else { + int s = db.indexOf('?'); + if (s >= 0 || (s = db.indexOf('#')) >= 0) { + db = db.substring(9, s); + } + } + return Resources.forLocale(locale).getString(Resources.Keys.TableNotFound_3, + Constants.EPSG, db, SENTINEL[MIXED_CASE]); } /** diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java index 0af68e9f8f..53f34f02a2 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.java @@ -553,6 +553,12 @@ public class Resources extends IndexedResourceBundle { */ public static final short SyntaxErrorForAlias_1 = 97; + /** + * Cannot use the {0} geodetic dataset because the database at “{1}” does not contain a “{2}” + * table and no script for automatic installation was found. + */ + public static final short TableNotFound_3 = 107; + /** * Combined URI contains unexpected components. */ diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties index e7eef826ce..e6cf43f04e 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources.properties @@ -123,6 +123,7 @@ ShallHaveSameConventionalRS = All members of a datum ensemble shall have t SingularMatrix = Matrix is singular. StartOrEndPointNotSet_1 = The {0,choice,0#start|1#end} point has not been specified. SyntaxErrorForAlias_1 = Syntax error for Well-Known Text alias at line {0}. +TableNotFound_3 = Cannot use the {0} geodetic dataset because the database at \u201c{1}\u201d does not contain a \u201c{2}\u201d table and no script for automatic installation was found. UnexpectedComponentInURI = Combined URI contains unexpected components. UnexpectedDimensionForCS_1 = Unexpected dimension for a coordinate system of type \u2018{0}\u2019. UnexpectedTextAtLine_2 = Unexpected text \u201c{1}\u201d at line {0}. WKT for new object should start with a non-indented line. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties index 9a58be876f..9313c58a53 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/Resources_fr.properties @@ -128,6 +128,7 @@ ShallHaveSameConventionalRS = Tous les membres d\u2019un ensemble de r\u00 SingularMatrix = La matrice est singuli\u00e8re. StartOrEndPointNotSet_1 = Le point {0,choice,0#de d\u00e9part|1#d\u2019arriv\u00e9} n\u2019a pas \u00e9t\u00e9 d\u00e9fini. SyntaxErrorForAlias_1 = Erreur de syntaxe pour l\u2019alias de \u00ab\u202fWell-Known Text\u202f\u00bb \u00e0 la ligne {0}. +TableNotFound_3 = Ne peut pas utiliser les param\u00e8tres g\u00e9od\u00e9siques {0} parce que la base de donn\u00e9es \u00ab\u202f{1}\u202f\u00bb ne contient pas de table \u00ab\u202f{2}\u202f\u00bb et aucun script d\u2019installation automatique n\u2019a \u00e9t\u00e9 trouv\u00e9. UnexpectedComponentInURI = L\u2019URI combin\u00e9 contient des composantes qui n\u2019\u00e9taient pas attendues. UnexpectedDimensionForCS_1 = Dimension inattendue pour un syst\u00e8me de coordonn\u00e9es de type \u2018{0}\u2019. UnexpectedTextAtLine_2 = Le texte \u00ab\u202f{1}\u202f\u00bb \u00e0 la ligne {0} est inattendu. Le WKT d\u2019un nouvel objet doit commencer par une ligne non-indent\u00e9e. diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/TestFactorySource.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/TestFactorySource.java index a7a610404c..3c090e0779 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/TestFactorySource.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/TestFactorySource.java @@ -108,8 +108,7 @@ public final class TestFactorySource { assertNotNull(crsFactory.createGeographicCRS("4326")); } catch (UnavailableFactoryException e) { isUnavailable = true; - GeodeticAuthorityFactory.LOGGER.warning(e.toString()); - abort("No connection to EPSG dataset."); + abort("No connection to EPSG dataset. Caused by:" + System.lineSeparator() + e); } return (EPSGFactory) crsFactory; } @@ -144,7 +143,9 @@ public final class TestFactorySource { success = true; } catch (UnavailableFactoryException e) { isUnavailable = true; - GeodeticAuthorityFactory.LOGGER.warning(e.toString()); + String message = "Tests that require the EPSG database cannot be run. Caused by:" + + System.lineSeparator() + e; + GeodeticAuthorityFactory.LOGGER.config(message); } finally { if (!success && factory != null) { factory.close(); diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.java b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.java index e0353bcf29..08388f6247 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.java +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.java @@ -131,7 +131,7 @@ public class Errors extends IndexedResourceBundle { /** * Cannot parse the Coordinate Reference System of “{0}”. */ - public static final short CanNotParseCRS_1 = 208; + public static final short CanNotParseCRS_1 = 155; /** * Cannot parse “{0}”. @@ -854,11 +854,6 @@ public class Errors extends IndexedResourceBundle { */ public static final short StalledThread_1 = 154; - /** - * Table “{0}” has not been found. - */ - public static final short TableNotFound_1 = 155; - /** * Expected at least {0,number} argument{0,choice,1#|2#s}, but got {1,number}. */ diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.properties b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.properties index dcfe0a066c..bf97140283 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.properties +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors.properties @@ -183,7 +183,6 @@ RecordNotFound_2 = No record found in \u201c{0}\u201d table for RecursiveCreateCallForKey_1 = Recursive call while creating an object for the \u201c{0}\u201d key. RequireDecimalSeparator = A decimal separator is required. StalledThread_1 = Thread \u201c{0}\u201d seems stalled. -TableNotFound_1 = Table \u201c{0}\u201d has not been found. TooFewArguments_2 = Expected at least {0,number} argument{0,choice,1#|2#s}, but got {1,number}. TooFewCollectionElements_3 = Collection \u201c{0}\u201d contains only {2,number} element{2,choice,1#|2#s} while at least {1,number} elements were expected. TooFewOccurrences_2 = Too few occurrences of \u201c{1}\u201d. Expected at least {0,number} of them. diff --git a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors_fr.properties b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors_fr.properties index adf40d2ae8..b1606bf17b 100644 --- a/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors_fr.properties +++ b/endorsed/src/org.apache.sis.util/main/org/apache/sis/util/resources/Errors_fr.properties @@ -179,7 +179,6 @@ RecordNotFound_2 = Aucune entr\u00e9e n\u2019a \u00e9t\u00e9 tr RecursiveCreateCallForKey_1 = Appel r\u00e9cursif lors de la cr\u00e9ation d\u2019un objet pour la cl\u00e9 \u00ab\u202f{0}\u202f\u00bb. RequireDecimalSeparator = Un s\u00e9parateur d\u00e9cimal est requis. StalledThread_1 = La t\u00e2che \u00ab\u202f{0}\u202f\u00bb semble bloqu\u00e9e. -TableNotFound_1 = La table \u00ab\u202f{0}\u202f\u00bb n\u2019a pas \u00e9t\u00e9 trouv\u00e9e. TooFewArguments_2 = Au moins {0,number} argument{0,choice,1# \u00e9tait attendu|2#s \u00e9taient attendus}, mais seulement {1,number} {1,choice,1#a \u00e9t\u00e9 sp\u00e9cifi\u00e9|2#ont \u00e9t\u00e9 sp\u00e9cifi\u00e9s}. TooFewCollectionElements_3 = L\u2019ensemble \u00ab\u202f{0}\u202f\u00bb ne contient que {2,number} \u00e9l\u00e9ment{2,choice,1#|2#s} alors qu\u2019au moins {1,number} \u00e9l\u00e9ments \u00e9taient attendus. TooFewOccurrences_2 = Trop peu d\u2019occurrences de \u00ab\u202f{1}\u202f\u00bb. Il en faut au moins {0,number}.