Javac Bugzilla id-https://bugs.eclipse.org/bugs/show_bug.cgi?id=571608.

Changes to detect javac path for solidity compilation and minimum java
version restricted to 11.
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 5b7238b..8f8e4f9 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
@@ -158,9 +158,13 @@
 			final IResource outputDir) throws IOException, InterruptedException, ClassNotFoundException {

 		String solcCompilerPath = InstanceScope.INSTANCE.getNode(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE)

 				.get(SecoBlocksPreferenceConstants.SOLIDITY_COMPILER_PREF_KEY, "");

+		String jdkPath = getJavaCPath();

 		if (solcCompilerPath.isEmpty()) {

 			return "Compiler is not set... Please set it in solidity preference page";

 		}

+		if(jdkPath.equals("\"\"")) {

+			return "Java-11 jdk should be either set in global path environment variable or jdk home path should be set in Secoblocks -> Java JDK Preference";

+		}

 		for (IResource solFile : solidityFiles) {

 			String tempLocation = outputDir.getLocation().toOSString() + File.separator + "temp";

 			File tempOutputDir = new File(tempLocation);

@@ -228,8 +232,8 @@
 					.replace("output-directory", getCmdLinePath(outputDir.getLocation().toOSString()));

 			Process web3jExe = Runtime.getRuntime().exec("cmd");

 

-			cmdRead(web3jExe, inputStream, false);

-			cmdReadError(web3jExe, errorStream, false);

+			cmdRead(web3jExe, inputStream, true);

+			cmdReadError(web3jExe, errorStream, true);

 

 			writer = new PrintWriter(web3jExe.getOutputStream());

 

@@ -238,8 +242,9 @@
 			 */

 			writer.println("cd " + getCmdLinePath(unzipAndGetWeb3jPath()));

 

-			writer.println("set JAVA_HOME=" + getJDKPath());

-

+			writer.println("set JAVA_HOME=" + jdkPath);

+			//get jdk path if empty then do not proceed and show error			

+			

 			writer.println(web3jCmd);

 

 			ClassLoader classLoader = CoreCommandExecutor.class.getClassLoader();

@@ -250,7 +255,7 @@
 				cp = cp + c.getBundleFile().getBaseFile().toString() + ";";

 			}

 

-			writer.println("javac "

+			writer.println(jdkPath + "\\bin\\javac "

 					+ getCmdLinePath(outputDir.getLocation().toOSString() + File.separator + "com" + File.separator

 							+ "bosch" + File.separator + solFile.getName().replace(".sol", ".java"))

 					+ " -cp " + getCmdLinePath(cp));

@@ -341,19 +346,19 @@
 	 * @throws IOException          -

 	 * @throws InterruptedException -

 	 */

-	public String getJDKPath() throws IOException, InterruptedException {

+	public String getJavaCPath() throws IOException, InterruptedException {

 		String jdkPath = "";

 		Process process = Runtime.getRuntime().exec("cmd");

 		PrintWriter writer = new PrintWriter(process.getOutputStream());

 

 		StringJoiner readJDKPath = new StringJoiner(System.lineSeparator());

 		cmdRead(process, readJDKPath, true);

+		cmdReadError(process, readJDKPath, true);

 

 		writer.println("where javac");

 		writer.close();

 

 		process.waitFor();

-		process.destroy();

 

 		String[] lines = readJDKPath.toString().split(System.lineSeparator());

 		for (String line : lines) {

@@ -363,8 +368,54 @@
 			}

 		}

 

+		if(!isValidJDKPath(jdkPath)) {

+			jdkPath = "";

+			//Retrieve java jdk path from preference

+			jdkPath = getJavaJDKFromPreference();

+			if(!isValidJDKPath(jdkPath)) {

+				jdkPath = "";

+			}

+		}else {

+			//Valid java jdk

+			//jdkPath = jdkPath + "\\bin\\javac.exe";

+		}

+		

+		process.destroy();

 		return getCmdLinePath(jdkPath);

 	}

+	

+	private String getJavaJDKFromPreference() {

+		return InstanceScope.INSTANCE.getNode(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE).get(SecoBlocksPreferenceConstants.JAVA_JDK_PREF_KEY, "");

+	}

+	

+	public boolean isValidJDKPath(String jdkPath) throws IOException, InterruptedException {

+		boolean result = false;

+		Process process = Runtime.getRuntime().exec("cmd");

+		PrintWriter writer = new PrintWriter(process.getOutputStream());

+		StringJoiner jdkPathSJ = new StringJoiner(System.lineSeparator());

+		//cmdRead(process, jdkPathSJ, true);

+		cmdReadError(process, jdkPathSJ, true);

+		

+		if(!jdkPath.isEmpty()) {

+			//Jdk 11 check

+			writer.println(jdkPath+"\\bin\\java -version");

+			writer.close();

+			

+			process.waitFor();

+			

+			String[] lines = jdkPathSJ.toString().split(System.lineSeparator());

+			for (String line : lines) {

+				if (line.contains("version")) {

+					if(line.contains("11")) {

+						result = true;

+					}

+					break;

+				}

+			}

+		}

+		process.destroy();

+		return result;

+	}

 

 	private void storeABIinSolidityMap(final String abiPath, final String solidityFilePath) throws IOException {

 		String abiJson = readABI(abiPath);

diff --git a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/SecoBlocksPreferenceConstants.java b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/SecoBlocksPreferenceConstants.java
index 8e26389..8ac4837 100644
--- a/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/SecoBlocksPreferenceConstants.java
+++ b/org.eclipse.blockchain.core/src/org/eclipse/blockchain/core/SecoBlocksPreferenceConstants.java
@@ -27,7 +27,8 @@
 	public static final String SOLIDITY_COMPILER_PREF_KEY = "soliditypreference";

 	public static final String SOLIDITY_GIT_URL = "https://github.com/ethereum/solidity/releases";

 	public static final String ENVIRONMENT_PREF_KEY = "environmentpreference";

-

+	public static final String JAVA_JDK_PREF_KEY = "javajdkpreference";

+	

 	public static final String[] versionList = {"v0.5.17", "v0.6.4", "v0.6.3",

 			"v0.6.2", "v0.6.1", "v0.5.16", "v0.6.0"};

 	public static final String PREF_KEY_VersionList = "versionList";

diff --git a/org.eclipse.blockchain.rcp/blockchain.product b/org.eclipse.blockchain.rcp/blockchain.product
index 497dc02..911a26a 100644
--- a/org.eclipse.blockchain.rcp/blockchain.product
+++ b/org.eclipse.blockchain.rcp/blockchain.product
@@ -11,7 +11,7 @@
    </configIni>

 

    <launcherArgs>

-      <vmArgs>-Xms512m -Xmx3G -XX:MinHeapFreeRatio=50 -XX:MaxHeapFreeRatio=60 -XX:+UseParallelGC -Xss1536k -Dosgi.framework.extensions=org.eclipse.fx.osgi -Dosgi.module.lock.timeout=100 -Dorg.eclipse.ecf.provider.filetransfer.retrieve.closeTimeout=30000 -Dorg.eclipse.ecf.provider.filetransfer.retrieve.readTimeout=30000 -Djavax.xml.accessExternalSchema=all -Dosgi.locking=java.io -Djava.net.preferIPv4Stack=true -Djdk.lang.Process.allowAmbigousCommands=true -Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4 -Dequinox.resolver.batch.timeout=5000

+      <vmArgs>-Xms512m -Xmx3G -XX:MinHeapFreeRatio=50 -XX:MaxHeapFreeRatio=60 -XX:+UseParallelGC -Xss1536k -Dosgi.requiredJavaVersion=11 -Dosgi.framework.extensions=org.eclipse.fx.osgi -Dosgi.module.lock.timeout=100 -Dorg.eclipse.ecf.provider.filetransfer.retrieve.closeTimeout=30000 -Dorg.eclipse.ecf.provider.filetransfer.retrieve.readTimeout=30000 -Djavax.xml.accessExternalSchema=all -Dosgi.locking=java.io -Djava.net.preferIPv4Stack=true -Djdk.lang.Process.allowAmbigousCommands=true -Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4 -Dequinox.resolver.batch.timeout=5000

       </vmArgs>

       <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts

       </vmArgsMac>

diff --git a/org.eclipse.blockchain.ui/plugin.xml b/org.eclipse.blockchain.ui/plugin.xml
index 0b18dda..dde95ed 100644
--- a/org.eclipse.blockchain.ui/plugin.xml
+++ b/org.eclipse.blockchain.ui/plugin.xml
@@ -146,6 +146,12 @@
             id="org.eclipse.blockchain.ui.enironment.preference"

             name="Environment">

       </page>

+      <page

+            category="org.eclipse.blockchain.ui.preference.root"

+            class="org.eclipse.blockchain.ui.preference.JavaJDKPreference"

+            id="org.eclipse.blockchain.ui.java.jdk.preference"

+            name="Java JDK">

+      </page>

    </extension>

    <extension

          point="org.eclipse.ui.startup">

diff --git a/org.eclipse.blockchain.ui/src/org/eclipse/blockchain/ui/preference/JavaJDKPreference.java b/org.eclipse.blockchain.ui/src/org/eclipse/blockchain/ui/preference/JavaJDKPreference.java
new file mode 100644
index 0000000..7a2664f
--- /dev/null
+++ b/org.eclipse.blockchain.ui/src/org/eclipse/blockchain/ui/preference/JavaJDKPreference.java
@@ -0,0 +1,100 @@
+/*******************************************************************************

+ * Copyright (c) 2020 RBEI and others.

+ *

+ * This program and the accompanying materials

+ * are made available under the terms of the Eclipse Public License v. 2.0

+ * which accompanies this distribution, and is available at

+ * https://www.eclipse.org/legal/epl-2.0/

+ *

+ * SPDX-License-Identifier: EPL-2.0

+ *

+ * Contributors:

+ *		ADG5COB

+ *******************************************************************************/

+

+package org.eclipse.blockchain.ui.preference;

+

+import java.io.IOException;

+

+import org.eclipse.blockchain.core.BlockchainCore;

+import org.eclipse.blockchain.core.CoreCommandExecutor;

+import org.eclipse.blockchain.core.SecoBlocksPreferenceConstants;

+import org.eclipse.blockchain.ui.Activator;

+import org.eclipse.core.runtime.Platform;

+import org.eclipse.core.runtime.preferences.IEclipsePreferences;

+import org.eclipse.core.runtime.preferences.InstanceScope;

+import org.eclipse.jface.dialogs.MessageDialog;

+import org.eclipse.jface.preference.PreferencePage;

+import org.eclipse.swt.SWT;

+import org.eclipse.swt.layout.GridData;

+import org.eclipse.swt.layout.GridLayout;

+import org.eclipse.swt.widgets.Composite;

+import org.eclipse.swt.widgets.Control;

+import org.eclipse.swt.widgets.Label;

+import org.eclipse.swt.widgets.Text;

+import org.eclipse.ui.IWorkbench;

+import org.eclipse.ui.IWorkbenchPreferencePage;

+import org.osgi.service.prefs.BackingStoreException;

+

+/**

+ * @author ADG5COB

+ *

+ */

+public class JavaJDKPreference extends PreferencePage implements IWorkbenchPreferencePage{

+	private String currentJavaJDKPath = "";

+	private Text jdkPathText;

+

+	@Override

+	public void init(IWorkbench workbench) {

+		currentJavaJDKPath = Platform.getPreferencesService().getString(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE, SecoBlocksPreferenceConstants.JAVA_JDK_PREF_KEY, "", null);

+	}

+

+	@Override

+	protected Control createContents(Composite parent) {

+		Composite container = new Composite(parent, SWT.NONE);

+		container.setLayout(new GridLayout(2, false));

+		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

+		

+		Label pathLabel = new Label(container, SWT.NONE);

+		pathLabel.setText("Java11 JDK Path");

+		pathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

+		

+		jdkPathText = new Text(container, SWT.NONE);

+		jdkPathText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

+		jdkPathText.setText(currentJavaJDKPath);

+		

+		return container;

+	}

+

+	@Override

+	public boolean performOk() {

+		String newJavaJDKPath = getText();

+		try {

+			if(!CoreCommandExecutor.getInstance().isValidJDKPath(newJavaJDKPath)) {

+				setErrorMessage("Invalid JDK Path. JDK 11 required.");

+				return false;

+			}else {

+				setErrorMessage(null);

+				if(!currentJavaJDKPath.equals(newJavaJDKPath)) {

+					IEclipsePreferences node = InstanceScope.INSTANCE.getNode(SecoBlocksPreferenceConstants.SECOBLOCKS_PREF_NODE);

+					node.put(SecoBlocksPreferenceConstants.JAVA_JDK_PREF_KEY, newJavaJDKPath);

+					try {

+						node.flush();

+					} catch (BackingStoreException e) {

+						BlockchainCore.getInstance().logException(Activator.PLUGIN_ID,

+								e.getMessage(), e);

+					}

+				}

+			}

+		} catch (IOException | InterruptedException e) {

+			BlockchainCore.getInstance().logException(Activator.PLUGIN_ID,

+					e.getMessage(), e);

+			MessageDialog.openError(getShell(), "Error occured during jdk path validation", e.getMessage());

+		}

+		return super.performOk();

+	}

+	

+	private String getText() {

+		return jdkPathText.getText();

+	}

+}