From 5a04af595b259d123c471f589e9552222cabc8d3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 7 Jul 2014 18:59:55 +0200 Subject: [PATCH] packed into mac app --- bitsquare.xml | 8 ----- pom.xml | 11 ------- src/main/java/io/bitsquare/BitSquare.java | 4 ++- src/main/java/io/bitsquare/RelayNode.java | 25 ++++++++++++++ .../bitsquare/btc/BitSquareWalletAppKit.java | 2 +- .../io/bitsquare/util/StorageDirectory.java | 33 +++++++------------ src/main/resources/logback.xml | 11 ++++++- 7 files changed, 50 insertions(+), 44 deletions(-) diff --git a/bitsquare.xml b/bitsquare.xml index b0fef2e870..bda0d1bae2 100644 --- a/bitsquare.xml +++ b/bitsquare.xml @@ -146,10 +146,6 @@ - - - - @@ -259,7 +255,6 @@ - @@ -287,7 +282,6 @@ - @@ -318,7 +312,6 @@ - @@ -349,7 +342,6 @@ - diff --git a/pom.xml b/pom.xml index efb31f7d9e..b38551acd6 100644 --- a/pom.xml +++ b/pom.xml @@ -108,11 +108,6 @@ bitcoinj 0.11.3 - - com.madgag - sc-light-jdk15on - 1.47.0.2 - net.tomp2p @@ -189,12 +184,6 @@ 1.3 - - com.madgag.spongycastle - core - 1.50.0.0 - - com.google.code.findbugs jsr305 diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index d3fbc66c78..db1b2bc84e 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); + public static String ID = "bitsquare"; private static Stage primaryStage; private WalletFacade walletFacade; @@ -59,11 +60,12 @@ public class BitSquare extends Application log.trace("Startup: start"); BitSquare.primaryStage = primaryStage; + Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable))); + // use a local data dir as default storage dir (can be overwritten in the settings) // TODO save root preferences always in app dir top get preferred storage location StorageDirectory.setStorageDirectory(new File(StorageDirectory.getApplicationDirectory().getAbsolutePath() + "/data")); - Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable))); // currently there is not SystemTray support for java fx (planned for version 3) so we use the old AWT AWTSystemTray.createSystemTray(primaryStage); diff --git a/src/main/java/io/bitsquare/RelayNode.java b/src/main/java/io/bitsquare/RelayNode.java index aab891689f..e5b9631c66 100755 --- a/src/main/java/io/bitsquare/RelayNode.java +++ b/src/main/java/io/bitsquare/RelayNode.java @@ -3,12 +3,17 @@ package io.bitsquare; import net.tomp2p.p2p.Peer; import net.tomp2p.p2p.PeerMaker; import net.tomp2p.peers.Number160; +import net.tomp2p.peers.PeerAddress; +import net.tomp2p.peers.PeerMapChangeListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Network node for relaying p2p msg */ class RelayNode { + private static final Logger log = LoggerFactory.getLogger(RelayNode.class); private static final Number160 ID = Number160.createHash(1); private static Peer masterPeer = null; @@ -32,6 +37,26 @@ class RelayNode masterPeer = new PeerMaker(ID).setPorts(port).makeAndListen(); // masterPeer = new PeerMaker(ID).setPorts(port).setBagSize(100).makeAndListen(); // setBagSize cause sync problems... masterPeer.getBroadcastRPC().getConnectionBean().getConnectionReservation().reserve(3).awaitUninterruptibly(); + masterPeer.getConnectionHandler().getPeerBean().getPeerMap().addPeerMapChangeListener(new PeerMapChangeListener() + { + @Override + public void peerInserted(PeerAddress peerAddress) + { + log.info("peerInserted " + peerAddress); + } + + @Override + public void peerRemoved(PeerAddress peerAddress) + { + log.info("peerRemoved " + peerAddress); + } + + @Override + public void peerUpdated(PeerAddress peerAddress) + { + log.info("peerUpdated " + peerAddress); + } + }); } } } diff --git a/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java b/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java index 5a2926cb17..459c8c61aa 100644 --- a/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java +++ b/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java @@ -29,7 +29,7 @@ public class BitSquareWalletAppKit extends WalletAppKit { if (!directory.mkdir()) { - throw new IOException("Could not create named directory."); + throw new IOException("Could not create named directory " + directory.getAbsolutePath()); } } FileInputStream walletStream = null; diff --git a/src/main/java/io/bitsquare/util/StorageDirectory.java b/src/main/java/io/bitsquare/util/StorageDirectory.java index 17ccc4b695..056675cdbe 100644 --- a/src/main/java/io/bitsquare/util/StorageDirectory.java +++ b/src/main/java/io/bitsquare/util/StorageDirectory.java @@ -41,28 +41,17 @@ public class StorageDirectory public static File getApplicationDirectory() { - File propertiesFile = new File(USER_PROPERTIES_FILE_NAME); - if (propertiesFile.exists()) - { - return new File(""); - } + File executionRoot = new File(StorageDirectory.class.getProtectionDomain().getCodeSource().getLocation().getFile()); + log.trace("executionRoot " + executionRoot.getAbsolutePath()); + // check if it is packed into a mac app (e.g.: "/Users/mk/Desktop/bitsquare.app/Contents/Java/bitsquare.jar") + if (executionRoot.getAbsolutePath().endsWith("/bitsquare.app/Contents/Java/bitsquare.jar") && System.getProperty("os.name").startsWith("Mac")) + return executionRoot.getParentFile().getParentFile().getParentFile().getParentFile(); + else if (executionRoot.getAbsolutePath().endsWith("/target/classes")) + return executionRoot.getParentFile(); // dev e.g.: /Users/mk/Documents/_intellij/bitsquare/target/classes -> use target as root + else if (executionRoot.getAbsolutePath().endsWith("/bitsquare.jar")) + return executionRoot.getParentFile(); // dev with jar e.g.: Users/mk/Documents/_intellij/bitsquare/out/artifacts/bitsquare2/bitsquare.jar -> use target as root else - { - // when running form a packed app the file structure is different on mac - String operatingSystemName = System.getProperty("os.name"); - if (operatingSystemName != null && operatingSystemName.startsWith("Mac")) - { - if (new File("../../../../" + USER_PROPERTIES_FILE_NAME).exists()) - { - return new File("../../../.."); - } - else - { - return null; - } - } - return null; - } + return executionRoot; } public static File getSystemApplicationDataDirectory() @@ -82,7 +71,7 @@ public class StorageDirectory { boolean created = storageDirectory.mkdir(); if (!created) - log.error("Could not create the application data directory of '" + storageDirectory + "'"); + throw new RuntimeException("Could not create the application data directory of '" + storageDirectory + "'"); } } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 141836409e..acac07e8f6 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -9,14 +9,23 @@ + + bitsquare_out.log + false + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %xEx%n + + + + - +