sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Add a splash screen. Fix destination directory of log file.
Date Thu, 13 Aug 2020 23:59:30 GMT
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 40e66933c357571fb14358f26aad032a1991b335
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Aug 13 16:52:23 2020 +0200

    Add a splash screen. Fix destination directory of log file.
---
 application/sis-javafx/src/main/artifact/bin/sisfx |   5 +-
 .../src/main/artifact/conf/logging.properties      |   5 ++
 .../sis-javafx/src/main/artifact/lib/logo.jpg      | Bin 0 -> 44981 bytes
 .../sis/internal/setup/LoggingConfiguration.java   |  82 +++++++++++++++++++++
 .../apache/sis/internal/setup/package-info.java    |  29 ++++++++
 5 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/application/sis-javafx/src/main/artifact/bin/sisfx b/application/sis-javafx/src/main/artifact/bin/sisfx
index 89b0086..b2d9448 100755
--- a/application/sis-javafx/src/main/artifact/bin/sisfx
+++ b/application/sis-javafx/src/main/artifact/bin/sisfx
@@ -24,10 +24,11 @@ SIS_DATA="${SIS_DATA:-$BASE_DIR/data}"
 export SIS_DATA
 
 # Execute SIS with any optional JAR that the user may put in the `lib` directory.
-java --add-modules javafx.graphics,javafx.controls \
+java -splash:"$BASE_DIR/lib/logo.jpg" \
+     --add-modules javafx.graphics,javafx.controls \
      --module-path $PATH_TO_FX \
      --class-path "$BASE_DIR/lib/*" \
+     -Djava.util.logging.config.class="org.apache.sis.internal.setup.LoggingConfiguration"
\
      -Djava.util.logging.config.file="$BASE_DIR/conf/logging.properties" \
-     -Djava.util.logging.FileHandler.pattern="$BASE_DIR/log/system.log" \
      -Dderby.stream.error.file="$BASE_DIR/log/derby.log" \
      org.apache.sis.gui.DataViewer $SIS_OPTS "$@"
diff --git a/application/sis-javafx/src/main/artifact/conf/logging.properties b/application/sis-javafx/src/main/artifact/conf/logging.properties
index 0ccf4a9..159cab5 100644
--- a/application/sis-javafx/src/main/artifact/conf/logging.properties
+++ b/application/sis-javafx/src/main/artifact/conf/logging.properties
@@ -44,6 +44,10 @@ java.util.logging.ConsoleHandler.level = WARNING
 #   - java.util.logging.SimpleFormatter
 #   - org.apache.sis.util.logging.MonolineFormatter
 #
+# FileHandler pattern accepts %t, %h, %g, %u (see Javadoc for details).
+# The %p pattern is SIS-specific and stands for the parent directory of
+# this configuration file.
+#
 # By default, MonolineFormatter displays only the log level
 # and the message. Additional options can be specified here:
 #
@@ -56,6 +60,7 @@ java.util.logging.ConsoleHandler.level = WARNING
 #         Valid argument values are "none", "logger:short", "logger:long",
 #         "class:short", "class:long" and "class.method".
 
+java.util.logging.FileHandler.pattern      = %p/log/system.log
 java.util.logging.FileHandler.formatter    = org.apache.sis.util.logging.MonolineFormatter
 java.util.logging.ConsoleHandler.formatter = org.apache.sis.util.logging.MonolineFormatter
 org.apache.sis.util.logging.MonolineFormatter.source = logger:long
diff --git a/application/sis-javafx/src/main/artifact/lib/logo.jpg b/application/sis-javafx/src/main/artifact/lib/logo.jpg
new file mode 100644
index 0000000..8bab417
Binary files /dev/null and b/application/sis-javafx/src/main/artifact/lib/logo.jpg differ
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/LoggingConfiguration.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/LoggingConfiguration.java
new file mode 100644
index 0000000..3601b33
--- /dev/null
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/LoggingConfiguration.java
@@ -0,0 +1,82 @@
+/*
+ * 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.setup;
+
+import java.util.logging.LogManager;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+
+/**
+ * Loads {@code conf/logging.properties} file and filter the {@code %b} pattern
+ * before to delegate to Java logging system. The filtering replaces {@code "%p"}
+ * by the parent directory of configuration file.
+ *
+ * <p>This class should not use any SIS classes because it may be invoked early
+ * while the application is still initializing.</p>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+public final class LoggingConfiguration {
+    /**
+     * The property to filter.
+     */
+    private static final String PROPERTY = "java.util.logging.FileHandler.pattern";
+
+    /**
+     * The pattern to replace.
+     */
+    private static final String PATTERN = "%p";
+
+    /**
+     * Invoked by Java if the {@code java.util.logging.config.class} property is set
+     * to this class name. This constructor filters {@code conf/logging.properties},
+     * then delegate to Java logging system.
+     *
+     * @throws IOException if an error occurred while reading the configuration file.
+     */
+    public LoggingConfiguration() throws IOException {
+        final String file = System.getProperty("java.util.logging.config.file");
+        if (file != null) {
+            final Path path = Paths.get(file).normalize();
+            final StringBuilder buffer = new StringBuilder(600);
+            for (String line : Files.readAllLines(path)) {
+                if (!(line = line.trim()).isEmpty() && line.charAt(0) != '#') {
+                    final int base = buffer.length();
+                    buffer.append(line).append('\n');
+                    if (line.startsWith(PROPERTY)) {
+                        final int i = buffer.indexOf(PATTERN, base + PROPERTY.length());
+                        if (i >= 0) {
+                            Path replacement = path;
+                            for (int j=Math.min(replacement.getNameCount(), 2); --j >=
0;) {
+                                replacement = replacement.getParent();
+                            }
+                            buffer.replace(i, i + PATTERN.length(), replacement.toString());
+                        }
+                    }
+                }
+            }
+            LogManager.getLogManager().readConfiguration​(new ByteArrayInputStream(buffer.toString().getBytes()));
+        }
+    }
+}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/package-info.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/package-info.java
new file mode 100644
index 0000000..0b9d164
--- /dev/null
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/package-info.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+/**
+ * Helper classes for SIS application setup.
+ *
+ * This package is for internal use by SIS only. Classes in this package
+ * may change in incompatible ways in any future version without notice.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.1
+ * @since   1.1
+ * @module
+ */
+package org.apache.sis.internal.setup;


Mime
View raw message