Skip to content

Commit

Permalink
Fixing another java 9+ issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Jan 5, 2019
1 parent 5f00378 commit de924da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mpo/dayon/assistant/gui/Assistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void actionPerformed(ActionEvent ev) {
try {
final URI uri = SystemUtilities.getLocalIndexHtml();

if (uri != null && Desktop.isDesktopSupported()) {
if (uri!= null && Desktop.isDesktopSupported()) {
final Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri);
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/mpo/dayon/common/gui/common/BaseFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URI;
import java.util.Objects;
import java.net.URISyntaxException;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -184,10 +184,8 @@ public void mouseClicked(MouseEvent e) {

protected Action createShowHelpAction() {
final Action showHelp = new AbstractAction() {

public void actionPerformed(ActionEvent ev) {
final URI uri = SystemUtilities.getLocalIndexHtml();
browse(Objects.requireNonNull(uri).toString());
browse(SystemUtilities.getLocalIndexHtml());
}
};

Expand All @@ -197,13 +195,21 @@ public void actionPerformed(ActionEvent ev) {

return showHelp;
}

private static void browse(String url) {
try {
browse(new URI(url));
} catch (URISyntaxException ex) {
Log.warn(ex);
}
}

private static void browse(URI uri) {
try {
if (Desktop.isDesktopSupported()) {
final Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(new URI(url));
desktop.browse(uri);
}
}
} catch (Exception ex) {
Expand Down
70 changes: 28 additions & 42 deletions src/main/java/mpo/dayon/common/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,39 @@
public abstract class SystemUtilities {
@Nullable
private static File getInstallRoot() {
String path = null;
try {
final ClassLoader cl = Thread.currentThread().getContextClassLoader();

if (cl instanceof URLClassLoader) {
final URLClassLoader ucl = (URLClassLoader) cl;
final URL[] urls = ucl.getURLs();
for (final URL url : urls) {
if ("file".equals(url.getProtocol())) {
final String path = url.toExternalForm();

if (path.contains("/out/idea/")) {
final int pos = path.indexOf("/out");
return new File(new URI(path.substring(0, pos)));
} else if (path.contains("/lib/dayon.jar")) {
final int pos = path.indexOf("/lib");
return new File(new URI(path.substring(0, pos)));
} else if (path.contains("/target/classes")) {
final int pos = path.indexOf("/classes");
return new File(new URI(path.substring(0, pos)));
}
}
}
}
} catch (URISyntaxException ex) {
throw new RuntimeException(ex); // unlikely (!)
path = new URI(SystemUtilities.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getPath();
} catch (URISyntaxException e) {
Log.warn("Failed to retrieve InstallRoot", e);
}
int pos = 0;
if (path.contains("/lib/dayon.jar")) {
pos = path.indexOf("/lib");
} else if (path.contains("/target/classes")) {
pos = path.indexOf("/classes");
} else if (path.contains("/out/idea/")) {
pos = path.indexOf("/out");
}
if (pos != 0) {
return new File(path.substring(0, pos));
}
return null;
}

@Nullable
public static File getDayonJarPath() {
final File root = SystemUtilities.getInstallRoot();
if (root == null) {
final File rootPath = getInstallRoot();
if (rootPath == null) {
return null;
}

File path = new File(root, "dayon.jar");
File path = new File(rootPath, "dayon.jar");
if (path.exists() && path.isFile()) {
return root;
return rootPath;
}

path = new File(root, "out/ant/jars");
if (path.exists() && path.isDirectory()) {
return path;
}

path = new File(root, "lib");
path = new File(rootPath, "lib");
if (path.exists() && path.isDirectory()) {
return path;
}
Expand All @@ -77,13 +63,15 @@ public static File getDayonJarPath() {
@Nullable
public static URI getLocalIndexHtml() {
@Nullable
final File rootPATH = getInstallRoot();

if (rootPATH != null) {
final File rootPath = getInstallRoot();
if (rootPath != null) {
// Anchor not supported : #assistant-setup
File quickStart = new File(rootPATH, "doc/html/" + Babylon.translate("quickstart.html"));
File quickStart = new File(rootPath, "doc/html/" + Babylon.translate("quickstart.html"));
if (!quickStart.isFile()) {
quickStart = new File(rootPATH, "../docs/" + Babylon.translate("quickstart.html"));
// Must be running inside an IDE
if (rootPath.getAbsolutePath().endsWith("/target")) {
quickStart = new File(rootPath.getParent(), "docs/" + Babylon.translate("quickstart.html"));
}
}
return quickStart.toURI();
}
Expand All @@ -92,9 +80,7 @@ public static URI getLocalIndexHtml() {

@Nullable
private static synchronized File getOrCreateAppDir() {
final String homeDir = System.getProperty("user.home"); // *.log4j.xml
// are using
// that one (!)
final String homeDir = System.getProperty("user.home"); // *.log4j.xml are using that one (!)
if (homeDir == null) {
Log.warn("Home directory [user.home] is null!");
return null;
Expand Down

0 comments on commit de924da

Please sign in to comment.