Skip to content

Commit

Permalink
Merge branch 'IEP-88' into 'master'
Browse files Browse the repository at this point in the history
IEP-88: Fix for sdkconfig editor launch issue in Windows OS

Closes IEP-88 and IEP-91

See merge request idf/idf-eclipse-plugin!81
  • Loading branch information
kolipakakondal committed Nov 11, 2019
2 parents b45efcb + c775f93 commit 120495d
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bundles/com.aptana.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: com.aptana.core;singleton:=true
Bundle-Version: 3.3.0.qualifier
Bundle-Version: 3.3.1.qualifier
Bundle-Activator: com.aptana.core.CorePlugin
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
Expand Down
2 changes: 1 addition & 1 deletion bundles/com.aptana.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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>
<artifactId>com.aptana.core</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.equinox.preferences,
org.eclipse.cdt.core,
org.eclipse.debug.core,
com.aptana.core;visibility:=reexport
com.aptana.core;visibility:=reexport,
org.eclipse.ui.console
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.espressif.idf.sdk.config.core
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ public enum CommandType
/**
* SET COMMAND - Save the changes to cache. It won't be saved to the file system until save command is invoked
*/
SET
SET,

/**
* To represent server connection is closed
*/
CONNECTION_CLOSED
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
*******************************************************************************/
package com.espressif.idf.sdk.config.core.server;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;

/**
* @author Kondal Kolipaka <[email protected]>
*
Expand All @@ -20,7 +17,6 @@ public class JsonConfigProcessor
*/
public String getInitialOutput(String jsonConfigOp)
{
Logger.log(SDKConfigCorePlugin.getPlugin(), jsonConfigOp);
int startIndex = jsonConfigOp.indexOf("{\"version\":"); //$NON-NLS-1$
startIndex = (startIndex == -1) ? jsonConfigOp.indexOf("{\"ranges\":") : startIndex; //$NON-NLS-1$
if (startIndex != -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.ui.console.MessageConsoleStream;
import org.json.simple.parser.ParseException;

import com.aptana.core.ShellExecutable;
import com.aptana.core.util.ProcessRunner;
import com.espressif.idf.core.IDFConstants;
import com.espressif.idf.core.IDFEnvironmentVariables;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.StringUtil;
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;

/**
Expand All @@ -31,6 +32,7 @@
public class JsonConfigServer implements IMessagesHandlerNotifier
{

protected MessageConsoleStream console;
private List<IMessageHandlerListener> listeners;
private IProject project;
private JsonConfigServerRunnable runnable;
Expand Down Expand Up @@ -80,22 +82,44 @@ public void removeListener(IMessageHandlerListener listener)
public void start()
{
IPath workingDir = project.getLocation();
Map<String, String> envMap = new IDFEnvironmentVariables().getEnvMap();
Map<String, String> idfEnvMap = new IDFEnvironmentVariables().getEnvMap();

// Disable buffering of output
envMap.put("PYTHONUNBUFFERED", "1");
idfEnvMap.put("PYTHONUNBUFFERED", "1");

File idfPythonScriptFile = IDFUtil.getIDFPythonScriptFile();
String pythonPath = IDFUtil.getIDFPythonEnvPath();
List<String> arguments = new ArrayList<String>(
Arrays.asList(pythonPath, idfPythonScriptFile.getAbsolutePath(), IDFConstants.CONF_SERVER_CMD));
Logger.log(arguments.toString());
ProcessRunner processRunner = new ProcessRunner();
Process process;

try
{
process = processRunner.run(workingDir, envMap, arguments.toArray(new String[arguments.size()]));

ProcessBuilder processBuilder = new ProcessBuilder(arguments);
if (workingDir != null)
{
processBuilder.directory(workingDir.toFile());
}
Map<String, String> environment = processBuilder.environment();
environment.putAll(idfEnvMap);

Logger.log(environment.toString());

String idfPath = environment.get("PATH"); //$NON-NLS-1$
String processPath = environment.get("Path"); //$NON-NLS-1$
if (!StringUtil.isEmpty(idfPath) && !StringUtil.isEmpty(processPath)) // if both exist!
{
idfPath = idfPath.concat(";").concat(processPath); //$NON-NLS-1$
environment.put("PATH", idfPath); //$NON-NLS-1$
environment.remove("Path");//$NON-NLS-1$
}

Logger.log(environment.toString());

// redirect error stream to input stream
processBuilder.redirectErrorStream(true);

Process process = processBuilder.start();
runnable = new JsonConfigServerRunnable(process, this);
Thread t = new Thread(runnable);
t.start();
Expand Down Expand Up @@ -136,4 +160,10 @@ public IJsonConfigOutput getOutput()
{
return configOutput;
}

public void addConsole(MessageConsoleStream console)
{
this.console = console;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@

package com.espressif.idf.sdk.config.core.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import com.aptana.core.util.ProcessRunnable;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.StringUtil;
import com.espressif.idf.sdk.config.core.IJsonServerConfig;
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;

/**
Expand All @@ -23,7 +29,6 @@
public class JsonConfigServerRunnable extends ProcessRunnable
{

private StringBuilder builder;
private JsonConfigServer configServer;
private OutputStream in;
private InputStream out;
Expand All @@ -33,6 +38,7 @@ public JsonConfigServerRunnable(Process process, JsonConfigServer configServer)
{
super(process, null, true);
this.configServer = configServer;

}

public void destory()
Expand All @@ -46,7 +52,7 @@ public void destory()
public void executeCommand(String command, CommandType type)
{
this.type = type;

String msg = MessageFormat.format(Messages.JsonConfigServerRunnable_CmdToBeExecuted, command);
Logger.log(SDKConfigCorePlugin.getPlugin(), msg);

Expand All @@ -70,69 +76,81 @@ public boolean isAlive(Process p)

public void run()
{
builder = new StringBuilder();
BufferedReader br = null;
StringBuilder builder = new StringBuilder();

try
{

out = p.getInputStream();
in = p.getOutputStream();

byte[] buffer = new byte[4000];
while (isAlive(p))

// sleep to make process.getErrorStream()/getInputStream() to return an available stream.
p.waitFor(3000, TimeUnit.MILLISECONDS);
boolean isAlive = true;
while (isAlive)
{
int no = out.available();
if (no == 0 && !builder.toString().isEmpty())
String output = builder.toString();
if (no == 0 && !output.isEmpty() && isValidJson(output))
{
// notify and reset
configServer.notifyHandler(builder.toString(), type);
configServer.notifyHandler(output, type);
builder = new StringBuilder();
}
else if (no > 0)
{
int n = out.read(buffer, 0, Math.min(no, buffer.length));
String string = new String(buffer, 0, n);
System.out.println(string);
configServer.console.print(string);
configServer.console.flush();
builder.append(string);
}

int ni = System.in.available();
if (ni > 0)
{
int n = System.in.read(buffer, 0, Math.min(ni, buffer.length));
in.write(buffer, 0, n);
in.flush();
}
p.waitFor(100, TimeUnit.MILLISECONDS);
isAlive = p.isAlive();

try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
}
}

configServer.notifyHandler("Server connection closed", CommandType.CONNECTION_CLOSED); //$NON-NLS-1$

}

catch (IOException e)
{
//ignore
} finally
Logger.log(e);
}
catch (InterruptedException e1)
{
if (br != null)
}

}

protected boolean isValidJson(String output)
{
String jsonOutput = new JsonConfigProcessor().getInitialOutput(output);
if (StringUtil.isEmpty(jsonOutput))
{
return false;
}
try
{
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
if (jsonObj != null)
{
try
{
br.close();
}
catch (Exception e)
if (jsonObj.get(IJsonServerConfig.VISIBLE) != null && jsonObj.get(IJsonServerConfig.VALUES) != null
&& jsonObj.get(IJsonServerConfig.RANGES) != null)
{
return true;
}
}
monitor.done();
}
catch (ParseException e)
{
return false;
}

return false;
}


}
3 changes: 2 additions & 1 deletion bundles/com.espressif.idf.sdk.config.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.ui.editors,
org.eclipse.text,
com.espressif.idf.sdk.config.core
com.espressif.idf.sdk.config.core,
org.eclipse.ui.console
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.espressif.idf.sdkconfig.ui
Bundle-ActivationPolicy: lazy
Loading

0 comments on commit 120495d

Please sign in to comment.