Maven project structure and few code changes.
diff --git a/org.eclipse.blockchain.core/build.properties b/org.eclipse.blockchain.core/build.properties
index 9a7d974..bc8ddb6 100644
--- a/org.eclipse.blockchain.core/build.properties
+++ b/org.eclipse.blockchain.core/build.properties
@@ -14,7 +14,6 @@
lib/slf4j-api-1.7.26.jar,\
lib/utils-4.2.0.jar,\
lib/commons-io-2.4.jar,\
- web3j-4.3.0/,\
res/,\
lib/tuples-4.2.0.jar,\
lib/javapoet-1.7.0.jar,\
diff --git a/org.eclipse.blockchain.core/pom.xml b/org.eclipse.blockchain.core/pom.xml
new file mode 100644
index 0000000..126d3fe
--- /dev/null
+++ b/org.eclipse.blockchain.core/pom.xml
@@ -0,0 +1,16 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.blockchain</groupId>
+ <artifactId>org.eclipse.blockchain.tycho</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../org.eclipse.blockchain.tycho</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.blockchain</groupId>
+ <artifactId>org.eclipse.blockchain.core</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+
+</project>
\ No newline at end of file
diff --git a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/CoreCommandExecutor.java b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/CoreCommandExecutor.java
index 9dbe454..aa5efcc 100644
--- a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/CoreCommandExecutor.java
+++ b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/CoreCommandExecutor.java
@@ -153,9 +153,10 @@
}
tempOutputDir.mkdir();
- String compileCommand = this.solcCommand.replace("solc-path", solcCompilerPath + File.separator + "solc")
- .replace("solidity-file", solFile.getLocation().toOSString())
- .replace("output-directory", tempOutputDir.getAbsolutePath());
+ String compileCommand =
+ this.solcCommand.replace("solc-path", getCmdLinePath(solcCompilerPath + File.separator + "solc"))
+ .replace("solidity-file", getCmdLinePath(solFile.getLocation().toOSString()))
+ .replace("output-directory", getCmdLinePath(tempOutputDir.getAbsolutePath()));
Process solcExe = Runtime.getRuntime().exec("cmd");
StringJoiner inputStream = new StringJoiner(System.lineSeparator());
@@ -185,13 +186,16 @@
projectName, CoreCommandExecutor.getInstance().getSolABIMap(solFile.getLocation().toOSString())));
// Java Wrapper Creation
- String web3jCmd = this.web3jCommand.replace("web3j-path", unzipAndGetWeb3jPath() + File.separator + "web3j")
+ String web3jCmd = this.web3jCommand
+ .replace("web3j-path", getCmdLinePath(unzipAndGetWeb3jPath()) + File.separator + "web3j")
.replace("abi-path",
- outputDir.getLocation().toOSString() + File.separator + solFile.getName().replace(".sol", ".abi"))
+ getCmdLinePath(
+ outputDir.getLocation().toOSString() + File.separator + solFile.getName().replace(".sol", ".abi")))
.replace("bin-path",
- outputDir.getLocation().toOSString() + File.separator + solFile.getName().replace(".sol", ".bin"))
- .replace("output-directory", outputDir.getLocation().toOSString());
-
+ getCmdLinePath(
+ outputDir.getLocation().toOSString() + File.separator + solFile.getName().replace(".sol", ".bin")))
+ .replace("output-directory", getCmdLinePath(outputDir.getLocation().toOSString()));
+ EthereumLogService.INSTANCE.log("web3j command -> " + web3jCmd);
Process web3jExe = Runtime.getRuntime().exec("cmd");
cmdRead(web3jExe, inputStream);
@@ -211,8 +215,12 @@
cp = cp + c.getBundleFile().getBaseFile().toString() + ";";
}
- writer.println("javac " + outputDir.getLocation().toOSString() + File.separator + "com" + File.separator +
- "bosch" + File.separator + solFile.getName().replace(".sol", ".java") + " -cp " + cp);
+ writer
+ .println(
+ "javac " +
+ getCmdLinePath(outputDir.getLocation().toOSString() + File.separator + "com" + File.separator +
+ "bosch" + File.separator + solFile.getName().replace(".sol", ".java")) +
+ " -cp " + getCmdLinePath(cp));
writer.close();
web3jExe.waitFor();
@@ -226,6 +234,10 @@
return "";
}
+ private String getCmdLinePath(final String path) {
+ return "\"" + path + "\"";
+ }
+
private SolidityABI[] updateSolJavaTypes(final String projectName, final SolidityABI[] solABI)
throws ClassNotFoundException, IOException, InterruptedException {
SolidityABI[] updatedSolABI = new SolidityABI[solABI.length];
@@ -313,12 +325,13 @@
String[] lines = readJDKPath.toString().split(System.lineSeparator());
for (String line : lines) {
- if (line.contains("java_jdk")) {
+ if (line.contains("javac.exe")) {
jdkPath = line.replace("\\bin\\javac.exe", "").replace("\\", "\\\\");
+ break;
}
}
- return jdkPath;
+ return getCmdLinePath(jdkPath);
}
private void storeABIinSolidityMap(final String abiPath, final String solidityFilePath) throws IOException {
@@ -480,10 +493,10 @@
final Map<String, String> localGethOptions) {
PrintWriter processWriter = new PrintWriter(this.gethServer.getOutputStream());
if (!initFile.isEmpty() && !new File(dataDir + File.separator + "geth").exists()) {
- processWriter.println("geth --datadir " + dataDir + " init " + initFile);
+ processWriter.println("geth --datadir " + getCmdLinePath(dataDir) + " init " + getCmdLinePath(initFile) + "");
}
String args = constructGethArguments(localGethOptions);
- processWriter.println("geth --datadir " + dataDir + " " + args);
+ processWriter.println("geth --datadir " + getCmdLinePath(dataDir) + " " + args);
processWriter.close();
/**
* This below code is required because geth once started won't terminate and it should not terminate because its a
diff --git a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/Web3jHandler.java b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/Web3jHandler.java
index ee0e08d..02306c2 100644
--- a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/Web3jHandler.java
+++ b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/Web3jHandler.java
@@ -374,9 +374,12 @@
ContractGasProvider contractGasProvider = new DefaultGasProvider();
classInstance =
contract.getMethod("load", String.class, Web3j.class, Credentials.class, ContractGasProvider.class)
- .invoke(classInstance, ethProject.getContractAddress(ethProject.getProject().getFile(scAbsPath)),
+ .invoke(classInstance,
+ ethProject.getContractAddress(ethProject.getProject()
+ .getFile(scAbsPath.replace(ethProject.getProject().getLocation().toOSString(), ""))),
web3jInstance, creds, contractGasProvider);
- ethProject.updateLastUsedAccount(ethProject.getProject().getFile(scAbsPath), accountDetails);
+ ethProject.updateLastUsedAccount(ethProject.getProject()
+ .getFile(scAbsPath.replace(ethProject.getProject().getLocation().toOSString(), "")), accountDetails);
}
RemoteCall<?> dep = (RemoteCall<?>) contract.getMethod(funcDetails[0], funcArgs).invoke(classInstance,
@@ -482,7 +485,7 @@
}
- private String createGethInitFile() throws IOException {
+ private String createGethInitFile() throws IOException, InterruptedException {
String dataDir = CoreCommandExecutor.getInstance().getDataDir();
clearOldDataDir(dataDir);
File gethInitFile = new File(dataDir + File.separator + "genesis.json");
@@ -506,8 +509,23 @@
return gethInitFile.getAbsolutePath();
}
- private static void clearOldDataDir(final String dataDir) throws IOException {
- FileUtils.deleteDirectory(new File(dataDir + File.separator + "geth"));
+ private static void clearOldDataDir(final String dataDir) throws IOException, InterruptedException {
+ int maxTries = 3;
+ while (maxTries >= 1) {
+ try {
+ FileUtils.deleteDirectory(new File(dataDir + File.separator + "geth"));
+ break;
+ }
+ catch (IOException e) {
+ if (maxTries > 1) {
+ maxTries--;
+ Thread.sleep(500);
+ }
+ else {
+ throw e;
+ }
+ }
+ }
new File(dataDir + File.separator + "genesis.json").delete();// NOSONAR
}