From 51d3ed57e3259dd9be5b113ad0bea332140f0e31 Mon Sep 17 00:00:00 2001 From: romanman Date: Tue, 27 May 2014 10:17:11 +0300 Subject: [PATCH] Packaging the application for production structure --- build-post-package.xml | 51 +++++++++++++++ ethereumj-core/pom.xml | 65 +++++++++++++------ .../org/ethereum/config/SystemProperties.java | 32 +++++++-- .../main/java/org/ethereum/geodb/IpGeoDB.java | 13 ++-- .../org/ethereum/gui/ContractCallDialog.java | 1 + .../main/java/org/ethereum/gui/ToolBar.java | 10 +-- .../java/org/ethereum/manager/MainData.java | 6 +- .../org/ethereum/net/client/PeerData.java | 2 +- .../src/main/resources/config/run.bat | 2 + .../src/main/resources/system.properties | 3 +- 10 files changed, 144 insertions(+), 41 deletions(-) create mode 100644 build-post-package.xml create mode 100644 ethereumj-core/src/main/resources/config/run.bat diff --git a/build-post-package.xml b/build-post-package.xml new file mode 100644 index 00000000..90d022c0 --- /dev/null +++ b/build-post-package.xml @@ -0,0 +1,51 @@ + + + + simple example build file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ethereumj-core/pom.xml b/ethereumj-core/pom.xml index d39055eb..b1dd82d4 100644 --- a/ethereumj-core/pom.xml +++ b/ethereumj-core/pom.xml @@ -4,18 +4,14 @@ org.ethereum ethereumj jar - 0.1-SNAPSHOT + 0.5.1 EthereumJ http://www.ethereumj.org @@ -85,6 +81,13 @@ mvn clean package -Dmaven.test.skip=true 4.1 + + org.javassist + javassist + 3.15.0-GA + + + @@ -149,25 +152,22 @@ mvn clean package -Dmaven.test.skip=true - maven-assembly-plugin - 2.2.1 - - - - org.ethereum.gui.ToolBar - - - - jar-with-dependencies - - + org.apache.maven.plugins + maven-dependency-plugin + 2.8 - make-assembly - prepare-package + copy-dependencies + package - single + copy-dependencies + + ${project.build.directory}/dependency + false + false + true + @@ -185,6 +185,29 @@ mvn clean package -Dmaven.test.skip=true + + + maven-antrun-plugin + 1.3 + + + package + + + + + + + + + + run + + + + + + diff --git a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java index c81d4817..9b7cb9a7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -1,5 +1,7 @@ package org.ethereum.config; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; @@ -23,12 +25,23 @@ public class SystemProperties { public SystemProperties() { try { - String filename = "system.properties"; - input = SystemProperties.class.getClassLoader().getResourceAsStream(filename); - if (input == null) { - logger.warn("Sorry, unable to find " + filename); - return; - } + + File file = null; + String dir = System.getProperty("user.dir"); + String fileName = dir + "/config/system.properties"; + file = new File(fileName); + + if (file.exists()){ + input = new FileInputStream(file); + } else{ + fileName = "system.properties"; + input = SystemProperties.class.getClassLoader().getResourceAsStream(fileName); + if (input == null) { + logger.error("Sorry, unable to find " + fileName); + return; + } + } + //load a properties file from class path, inside static method prop.load(input); @@ -70,10 +83,15 @@ public class SystemProperties { public String peerDiscoveryIP(){ - if(prop.isEmpty()) return ""; + if(prop.isEmpty()) return "54.201.28.117"; return prop.getProperty("peer.discovery.ip"); } + public int peerDiscoveryPort(){ + if(prop.isEmpty()) return 30303; + return Integer.parseInt(prop.getProperty("peer.discovery.port")); + } + public String toString() { Enumeration e = prop.propertyNames(); while (e.hasMoreElements()) { diff --git a/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java b/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java index 81a92263..bb718ea3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java +++ b/ethereumj-core/src/main/java/org/ethereum/geodb/IpGeoDB.java @@ -19,13 +19,16 @@ public class IpGeoDB { // change File file = null; try { - URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat"); - file = new File(geiIpDBFile.toURI()); - } catch (Throwable th) { - String dir = System.getProperty("user.dir"); - String fileName = dir + "/db/GeoLiteCity.dat"; + String fileName = dir + "/config/GeoLiteCity.dat"; file = new File(fileName); + if (!file.exists()){ + URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat"); + file = new File(geiIpDBFile.toURI()); + } + } catch (Throwable th) { + th.printStackTrace(); + System.exit(-1); } cl = new LookupService(file); } catch (Throwable e) { diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java index b2f666dd..e4c14470 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java @@ -235,6 +235,7 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog{ return; } + // todo: check up how the HEX value is encoded Object[] lexaList = msgDataTA.getText().split(","); byte[] data = ByteUtil.encodeDataList(lexaList); diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java index a7a58f20..87e74430 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java @@ -1,5 +1,6 @@ package org.ethereum.gui; +import org.apache.log4j.PropertyConfigurator; import org.ethereum.manager.MainData; import org.ethereum.util.Utils; import org.slf4j.Logger; @@ -18,6 +19,7 @@ import java.awt.event.ItemListener; */ public class ToolBar extends JFrame { + Logger logger = LoggerFactory.getLogger(getClass()); Logger introLogger = LoggerFactory.getLogger("Intro"); @@ -31,10 +33,10 @@ public class ToolBar extends JFrame { public ToolBar() throws HeadlessException { introLogger.info(""); - introLogger.info("♢ EthereumJ [v0.5.1] by RomanJ"); - introLogger.info("♢ Code by Roman Mandeleil, (c) 2014."); - introLogger.info("♢ Contribution: Nick Savers "); - introLogger.info("♢ Based on a design by Vitalik Buterin."); + introLogger.info("<> EthereumJ [v0.5.1] by RomanJ"); + introLogger.info("<> Code by Roman Mandeleil, (c) 2014."); + introLogger.info("<> Contribution: Nick Savers "); + introLogger.info("<> Based on a design by Vitalik Buterin."); introLogger.info(""); introLogger.info("java.version: " + System.getProperty("java.version")); introLogger.info("java.home: " + System.getProperty("java.home")); diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java index 08fc7e93..ae8dbaad 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java @@ -51,15 +51,17 @@ public class MainData { public MainData() { InetAddress ip = null; + int port = 0; try { ip = InetAddress.getByName(CONFIG.peerDiscoveryIP()); + port = CONFIG.peerDiscoveryPort(); } catch (UnknownHostException e) { - System.exit(-1); e.printStackTrace(); + System.exit(-1); } PeerData peer = new PeerData( - ip.getAddress(), (short) 30303, new byte[]{00}); + ip.getAddress(), port, new byte[]{00}); peers.add(peer); byte[] cowAddr = HashUtil.sha3("cow".getBytes()); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java index 59bc5273..84e78129 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java @@ -19,7 +19,7 @@ public class PeerData { private transient boolean isOnline = false; private transient long lastCheckTime = 0; - public PeerData(byte[] ip, short port, byte[] peerId) { + public PeerData(byte[] ip, int port, byte[] peerId) { this.ip = ip; this.port = port & 0xFFFF; this.peerId = peerId; diff --git a/ethereumj-core/src/main/resources/config/run.bat b/ethereumj-core/src/main/resources/config/run.bat new file mode 100644 index 00000000..e0a3c7d6 --- /dev/null +++ b/ethereumj-core/src/main/resources/config/run.bat @@ -0,0 +1,2 @@ +call java -Dlog4j.configuration=file:./config/log4j.properties -jar ethereumj.jar +pause \ No newline at end of file diff --git a/ethereumj-core/src/main/resources/system.properties b/ethereumj-core/src/main/resources/system.properties index 1f947c5a..9d5a96c0 100644 --- a/ethereumj-core/src/main/resources/system.properties +++ b/ethereumj-core/src/main/resources/system.properties @@ -6,8 +6,9 @@ server.acceptConnections = false # one default access point to start -# discover the network e.g. [54.201.28.117] +# discover the network e.g. ip: [54.201.28.117] port: [30303] peer.discovery.ip = 54.201.28.117 +peer.discovery.port = 30303 # specify if the mechanism # to discover more and more