Skip to content

Commit

Permalink
Find manifest file more reliably; Version 1.29 release
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Winning <jason.winning@gmail.com>
  • Loading branch information
jasonwinning committed Oct 24, 2024
1 parent 47c8251 commit eeacc7a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
12 changes: 8 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -131,11 +131,14 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Expand Down Expand Up @@ -173,7 +176,8 @@
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version>
</dependency>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down Expand Up @@ -239,7 +243,7 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.17.0</version>
</dependency>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/hypernomicon/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class Const
public static final String

HDB_DEFAULT_FILENAME = "database.hdb",
BLANK_DB_RESOURCE_NAME = "resources/blank_db.zip",

PREF_KEY_SETTINGS_VERSION = "settingsVersion",
PREF_KEY_NOTIFY_USER_NOT_LINKED = "notifyUnlinked",
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/hypernomicon/dialogs/LockedDlgCtrlr.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.hypernomicon.HyperTask.HyperThread;
import org.hypernomicon.InterComputerMsg;
import org.hypernomicon.util.DesktopUtil;
Expand Down Expand Up @@ -130,19 +129,17 @@ else if (sentMsg.getType() == hmtEchoRequest)
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

public LockedDlgCtrlr(String title, Throwable e)
public LockedDlgCtrlr(String title, String text)
{
super("LockedDlg", title, true);

otherHostName = "";
otherCompName = "";

String stacktrace = ExceptionUtils.getStackTrace(e);

taOutput.setText(stacktrace);
taOutput.setText(text);

btnTryTerminate.setText("Copy to Clipboard");
btnTryTerminate.setOnAction(event -> copyToClipboard(stacktrace));
btnTryTerminate.setOnAction(event -> copyToClipboard(text));

setAllVisible(false, btnTryComm, btnOverride, btnStop, lblSeconds);
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/hypernomicon/util/UIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javafx.beans.value.ObservableDoubleValue;

import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.controlsfx.control.MasterDetailPane;
import org.hypernomicon.dialogs.LockedDlgCtrlr;
Expand Down Expand Up @@ -634,12 +635,20 @@ private static void scalePropertiesForDPI(DoubleProperty... props)
}
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

public static void showLongMessage(String title, String text)
{
new LockedDlgCtrlr(title, text).showModal();
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

public static void showStackTrace(Throwable e)
{
new LockedDlgCtrlr("Error", e).showModal();
showLongMessage("Error", ExceptionUtils.getStackTrace(e));
}

//---------------------------------------------------------------------------
Expand Down
46 changes: 41 additions & 5 deletions src/main/java/org/hypernomicon/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.hypernomicon.HyperTask.HyperThread;
import org.hypernomicon.util.filePath.FilePath;

import static org.hypernomicon.Const.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,9 +42,11 @@
import java.nio.file.AccessDeniedException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.security.CodeSource;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.ProtectionDomain;
import java.text.NumberFormat;
import java.time.Instant;
import java.time.ZoneId;
Expand All @@ -67,6 +71,8 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -779,14 +785,44 @@ public static String convertToEnglishCharsWithMap(String input, List<Integer> po

public static String manifestValue(String key)
{
URL url = App.class.getResource("/META-INF/MANIFEST.MF");
URL jarUrl;

if (url != null) try
try
{
jarUrl = nullSwitch(nullSwitch(App.class.getProtectionDomain(), null, ProtectionDomain::getCodeSource), null, CodeSource::getLocation);

if (jarUrl != null)
{
try (InputStream jarStream = jarUrl.openStream())
{
if (jarStream != null) try (JarInputStream jis = new JarInputStream(jarStream))
{
Manifest manifest = jis.getManifest();

return manifest == null ? "" : nullSwitch(manifest.getMainAttributes(), "", attributes -> safeStr(attributes.getValue(key)));
}
}
}
}
catch (SecurityException | IOException e)
{
URLConnection c = url.openConnection();
noOp();
}

// Security exception likely happened so try less reliable method

if (c instanceof JarURLConnection jarURLConnection)
return safeStr(nullSwitch(jarURLConnection.getManifest(), "", manifest -> manifest.getMainAttributes().getValue(key)));
jarUrl = App.class.getResource(BLANK_DB_RESOURCE_NAME); // Get the URL for a resource that will only exist in the Hypernomicon jar file.
// Most jar files will have META-INF/MANIFEST.MF so we are likely to get the
if (jarUrl != null) try // wrong URL if we search for that resource name (even though it is the one we
{ // really want, from the Hypernomicon jar file).
URLConnection conn = jarUrl.openConnection();

if (conn instanceof JarURLConnection jarURLConnection)
{
Manifest manifest = jarURLConnection.getManifest();

return manifest == null ? "" : nullSwitch(manifest.getMainAttributes(), "", attributes -> safeStr(attributes.getValue(key)));
}
}
catch (IOException e) { noOp(); }

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/hypernomicon/view/MainCtrlr.java
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ private boolean createNewDB(FilePath rootPath)
{
FilePath srcFilePath = null;

try (ZipInputStream zis = new ZipInputStream(App.class.getResourceAsStream("resources/blank_db.zip")))
try (ZipInputStream zis = new ZipInputStream(App.class.getResourceAsStream(BLANK_DB_RESOURCE_NAME)))
{
ZipEntry entry;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/hypernomicon/NewDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NewDBTest
@Test
void newDBTemplateTest()
{
try (ZipInputStream zis = new ZipInputStream(App.class.getResourceAsStream("resources/blank_db.zip")))
try (ZipInputStream zis = new ZipInputStream(App.class.getResourceAsStream(BLANK_DB_RESOURCE_NAME)))
{
ZipEntry entry;

Expand Down

0 comments on commit eeacc7a

Please sign in to comment.