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/01/28 15:11:10 UTC
[sis] branch geoapi-4.0 updated (2ca318c -> adde8f4)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.
from 2ca318c Fix a `NullPointerException` when `bin/sisfx` is invoked while `apache-sis-<version>` is the current directory.
new a29d04c Disable "Download" button if browser is not available.
new 4086b33 Path to JavaFX installation directory should be relative to $BASE_DIR when possible.
new adde8f4 Replace Map.get/put/replace(…) by Map.compute(…) operations.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/sis/internal/setup/FXFinder.java | 49 +++++++++++++++++++++-
.../java/org/apache/sis/internal/setup/Wizard.java | 16 ++++---
.../org/apache/sis/internal/setup/WizardPage.java | 2 +-
.../java/org/apache/sis/portrayal/Observable.java | 47 ++++++---------------
4 files changed, 69 insertions(+), 45 deletions(-)
[sis] 02/03: Path to JavaFX installation directory should be
relative to $BASE_DIR when possible.
Posted by de...@apache.org.
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 4086b3382feda7f772af1df82d5c341847382c95
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Jan 28 15:43:56 2021 +0100
Path to JavaFX installation directory should be relative to $BASE_DIR when possible.
---
.../org/apache/sis/internal/setup/FXFinder.java | 49 +++++++++++++++++++++-
.../java/org/apache/sis/internal/setup/Wizard.java | 3 +-
2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/FXFinder.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/FXFinder.java
index 9184d56..b8bca0a 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/FXFinder.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/FXFinder.java
@@ -124,6 +124,12 @@ public final class FXFinder {
private Inflater inflater;
/**
+ * Whether to use the relative path {@code $BASE_DIR/opt/javafx-sdk} instead than an absolute path.
+ * This is {@code true} if we have decompressed the JavaFX ZIP file with the {@link Inflater}.
+ */
+ boolean useRelativePath;
+
+ /**
* {@code true} if this operation systems is Windows, or {@code false} if assumed Unix (Linux or MacOS).
*/
private final boolean isWindows;
@@ -367,6 +373,11 @@ public final class FXFinder {
if (isWindows) {
command = "SET " + command; // Microsoft Windows syntax.
}
+ /*
+ * Read content of `setenv.sh` file excluding the line starting with `command` if any.
+ * We remember the position where we found `command` in order to insert replacement at
+ * the same line.
+ */
final ArrayList<String> content = new ArrayList<>();
int insertAt = -1;
for (String line : Files.readAllLines(setenv)) {
@@ -380,7 +391,43 @@ public final class FXFinder {
if (insertAt < 0) {
insertAt = content.size();
}
- content.add(insertAt, command + '=' + validated);
+ /*
+ * Insert the new line for setting the `PATH_TO_FX` variable.
+ * It will be either an absolute path, or a path relative to
+ * the SIS installation directory.
+ */
+ final StringBuilder value = new StringBuilder(100).append(command).append('=');
+ if (useRelativePath) {
+ final File relative = relativeToBase(validated);
+ if (relative != null) {
+ value.append(isWindows ? "%BASE_DIR%" : "$BASE_DIR")
+ .append(File.separatorChar).append(relative);
+ } else {
+ useRelativePath = false;
+ }
+ }
+ if (!useRelativePath) {
+ value.append(validated);
+ }
+ content.add(insertAt, value.toString());
Files.write(setenv, content, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
}
+
+ /**
+ * Makes the current directory relative to the SIS base directory. This method assumes that
+ * the last directory named {@value #SIS_UNZIP_DIRECTORY} is the first directory relative to
+ * the base. This is okay only if the JavaFX zip file does not contain directory of that name.
+ */
+ private static File relativeToBase(final File dir) {
+ if (dir != null) {
+ if (SIS_UNZIP_DIRECTORY.equals(dir.getName())) {
+ return new File(SIS_UNZIP_DIRECTORY);
+ }
+ final File parent = relativeToBase(dir.getParentFile());
+ if (parent != null) {
+ return new File(parent, dir.getName());
+ }
+ }
+ return null;
+ }
}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
index fe62296..814a464 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
@@ -500,6 +500,7 @@ final class Wizard extends FileFilter implements ActionListener, PropertyChangeL
} else {
isValid = setJavafxPath(destination);
}
+ javafxFinder.useRelativePath = isValid; // Must be before the call to `nextOrPreviousPage(…)`.
nextOrPreviousPage(isValid ? +1 : -1);
}
@@ -745,7 +746,7 @@ final class Wizard extends FileFilter implements ActionListener, PropertyChangeL
*/
final String diagnostic = javafxFinder.diagnostic();
if (diagnostic != null) {
- JOptionPane.showMessageDialog(null, diagnostic, "Configuration error", JOptionPane.ERROR);
+ JOptionPane.showMessageDialog(null, diagnostic, "Configuration error", JOptionPane.ERROR_MESSAGE);
return false;
} else {
final Wizard wizard = new Wizard(javafxFinder);
[sis] 03/03: Replace Map.get/put/replace(…) by Map.compute(…) operations.
Posted by de...@apache.org.
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 adde8f486564b9431769f51d48fa8a04a8ba1472
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Jan 28 15:49:56 2021 +0100
Replace Map.get/put/replace(…) by Map.compute(…) operations.
---
.../java/org/apache/sis/portrayal/Observable.java | 47 ++++++----------------
1 file changed, 13 insertions(+), 34 deletions(-)
diff --git a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Observable.java b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Observable.java
index e68e4af..5fc33b6 100644
--- a/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Observable.java
+++ b/core/sis-portrayal/src/main/java/org/apache/sis/portrayal/Observable.java
@@ -16,12 +16,10 @@
*/
package org.apache.sis.portrayal;
+import java.util.Map;
+import java.util.HashMap;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.Arrays;
-import java.util.ConcurrentModificationException;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.ArraysExt;
@@ -72,22 +70,9 @@ abstract class Observable {
if (listeners == null) {
listeners = new HashMap<>(4); // Assume few properties will be listened.
}
- final PropertyChangeListener[] oldList = listeners.get(propertyName);
- final PropertyChangeListener[] newList;
- final boolean success;
- if (oldList != null) {
- final int n = oldList.length;
- newList = Arrays.copyOf(oldList, n+1);
- newList[n] = listener;
- success = listeners.replace(propertyName, oldList, newList);
- } else {
- newList = new PropertyChangeListener[] {listener};
- success = (listeners.putIfAbsent(propertyName, newList) == null);
- }
- if (!success) {
- // Opportunistic safety against some multi-threading misuse.
- throw new ConcurrentModificationException();
- }
+ listeners.compute(propertyName, (key, oldList) ->
+ (oldList != null) ? ArraysExt.append(oldList, listener)
+ : new PropertyChangeListener[] {listener});
}
/**
@@ -104,23 +89,18 @@ abstract class Observable {
ArgumentChecks.ensureNonEmpty("propertyName", propertyName);
ArgumentChecks.ensureNonNull("listener", listener);
if (listeners != null) {
- final PropertyChangeListener[] oldList = listeners.get(propertyName);
- if (oldList != null) {
+ listeners.computeIfPresent(propertyName, (key, oldList) -> {
for (int i=oldList.length; --i >= 0;) {
if (oldList[i] == listener) {
if (oldList.length != 1) {
- final PropertyChangeListener[] newList = ArraysExt.remove(oldList, i, 1);
- if (listeners.replace(propertyName, oldList, newList)) {
- return;
- }
- } else if (listeners.remove(propertyName, oldList)) {
- return;
+ return ArraysExt.remove(oldList, i, 1);
+ } else {
+ return null;
}
- // Opportunistic safety against some multi-threading misuse.
- throw new ConcurrentModificationException();
}
}
- }
+ return oldList;
+ });
}
}
@@ -150,17 +130,16 @@ abstract class Observable {
}
/**
- * Notifies all registered listeners that a property of the given name changed its value.
+ * Notifies all registered listeners that a property changed its value.
* It is caller responsibility to verify that the event source and property name are valid.
*
- * @param event the event to forward, can not be null.
+ * @param event the event to forward. Can not be null.
*
* @see PropertyChangeEvent
* @see PropertyChangeListener
*/
protected void firePropertyChange(final PropertyChangeEvent event) {
ArgumentChecks.ensureNonNull("event", event);
-
if (listeners != null) {
final PropertyChangeListener[] list = listeners.get(event.getPropertyName());
if (list != null) {
[sis] 01/03: Disable "Download" button if browser is not available.
Posted by de...@apache.org.
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 a29d04cc5a8706f584be743b4f1b2ee4c8c148e4
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Jan 28 11:34:16 2021 +0100
Disable "Download" button if browser is not available.
---
.../src/main/java/org/apache/sis/internal/setup/Wizard.java | 13 +++++--------
.../main/java/org/apache/sis/internal/setup/WizardPage.java | 2 +-
2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
index 6ef160e..fe62296 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/Wizard.java
@@ -328,7 +328,9 @@ final class Wizard extends FileFilter implements ActionListener, PropertyChangeL
content.add(Box.createVerticalStrut(30));
switch (page) {
case DOWNLOAD_JAVAFX: {
- createButton(content, JAVAFX_HOME).setToolTipText(FXFinder.JAVAFX_HOME);
+ final JButton button = createButton(content, JAVAFX_HOME);
+ button.setToolTipText(FXFinder.JAVAFX_HOME);
+ button.setEnabled(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE));
final JLabel instruction = new JLabel(WizardPage.downloadSteps());
instruction.setFont(font.deriveFont(12f));
content.add(instruction);
@@ -520,15 +522,10 @@ final class Wizard extends FileFilter implements ActionListener, PropertyChangeL
* for opening the {@value Constants#JAVAFX_HOME} URL in a browser.
*/
private void openJavafxHomePage() {
- if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) try {
+ try {
Desktop.getDesktop().browse(new URI(FXFinder.JAVAFX_HOME));
- nextOrPreviousPage(1);
- } catch (URISyntaxException | IOException e) {
+ } catch (URISyntaxException | IOException | RuntimeException e) {
JOptionPane.showMessageDialog(wizard, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
- } else {
- JOptionPane.showMessageDialog(wizard, "Can not find internet browser on this computer.\n"
- + "See " + FXFinder.JAVAFX_HOME + " for download information.",
- "JavaFX download", JOptionPane.INFORMATION_MESSAGE);
}
}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/WizardPage.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/WizardPage.java
index 29cf5ef..a5ba9ab 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/WizardPage.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/setup/WizardPage.java
@@ -50,7 +50,7 @@ enum WizardPage {
+ "This application requires <i>JavaFX</i> (or <i>OpenJFX</i>) version " + FXFinder.JAVAFX_VERSION + " or later. "
+ "OpenJFX is free software, licensed under the GPL with the class path exception. "
+ "Click on <u>Open JavaFX home page</u> for opening the JavaFX home page. "
- + "If JavaFX or OpenJFX has already been downloaded on this computer, "
+ + "If JavaFX has already been downloaded on this computer, "
+ "skip download and click on <u>Next</u> for specifying its installation directory."
+ "</p></html>"),