Skip to content

Commit 120495d

Browse files
Merge branch 'IEP-88' into 'master'
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
2 parents b45efcb + c775f93 commit 120495d

File tree

11 files changed

+206
-63
lines changed

11 files changed

+206
-63
lines changed

bundles/com.aptana.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: com.aptana.core;singleton:=true
5-
Bundle-Version: 3.3.0.qualifier
5+
Bundle-Version: 3.3.1.qualifier
66
Bundle-Activator: com.aptana.core.CorePlugin
77
Bundle-Vendor: %providerName
88
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,

bundles/com.aptana.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<artifactId>com.aptana.core</artifactId>
6-
<version>3.3.0-SNAPSHOT</version>
6+
<version>3.3.1-SNAPSHOT</version>
77
<packaging>eclipse-plugin</packaging>
88

99
<parent>

bundles/com.espressif.idf.sdk.config.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
1010
org.eclipse.equinox.preferences,
1111
org.eclipse.cdt.core,
1212
org.eclipse.debug.core,
13-
com.aptana.core;visibility:=reexport
13+
com.aptana.core;visibility:=reexport,
14+
org.eclipse.ui.console
1415
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1516
Automatic-Module-Name: com.espressif.idf.sdk.config.core
1617
Bundle-ActivationPolicy: lazy

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/CommandType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@ public enum CommandType
2727
/**
2828
* SET COMMAND - Save the changes to cache. It won't be saved to the file system until save command is invoked
2929
*/
30-
SET
30+
SET,
31+
32+
/**
33+
* To represent server connection is closed
34+
*/
35+
CONNECTION_CLOSED
3136
}

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigProcessor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
*******************************************************************************/
55
package com.espressif.idf.sdk.config.core.server;
66

7-
import com.espressif.idf.core.logging.Logger;
8-
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;
9-
107
/**
118
* @author Kondal Kolipaka <[email protected]>
129
*
@@ -20,7 +17,6 @@ public class JsonConfigProcessor
2017
*/
2118
public String getInitialOutput(String jsonConfigOp)
2219
{
23-
Logger.log(SDKConfigCorePlugin.getPlugin(), jsonConfigOp);
2420
int startIndex = jsonConfigOp.indexOf("{\"version\":"); //$NON-NLS-1$
2521
startIndex = (startIndex == -1) ? jsonConfigOp.indexOf("{\"ranges\":") : startIndex; //$NON-NLS-1$
2622
if (startIndex != -1)

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigServer.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import org.eclipse.core.runtime.IPath;
1515
import org.eclipse.debug.core.DebugPlugin;
1616
import org.eclipse.debug.core.ILaunchManager;
17+
import org.eclipse.ui.console.MessageConsoleStream;
1718
import org.json.simple.parser.ParseException;
1819

1920
import com.aptana.core.ShellExecutable;
20-
import com.aptana.core.util.ProcessRunner;
2121
import com.espressif.idf.core.IDFConstants;
2222
import com.espressif.idf.core.IDFEnvironmentVariables;
2323
import com.espressif.idf.core.logging.Logger;
2424
import com.espressif.idf.core.util.IDFUtil;
25+
import com.espressif.idf.core.util.StringUtil;
2526
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;
2627

2728
/**
@@ -31,6 +32,7 @@
3132
public class JsonConfigServer implements IMessagesHandlerNotifier
3233
{
3334

35+
protected MessageConsoleStream console;
3436
private List<IMessageHandlerListener> listeners;
3537
private IProject project;
3638
private JsonConfigServerRunnable runnable;
@@ -80,22 +82,44 @@ public void removeListener(IMessageHandlerListener listener)
8082
public void start()
8183
{
8284
IPath workingDir = project.getLocation();
83-
Map<String, String> envMap = new IDFEnvironmentVariables().getEnvMap();
85+
Map<String, String> idfEnvMap = new IDFEnvironmentVariables().getEnvMap();
8486

8587
// Disable buffering of output
86-
envMap.put("PYTHONUNBUFFERED", "1");
88+
idfEnvMap.put("PYTHONUNBUFFERED", "1");
8789

8890
File idfPythonScriptFile = IDFUtil.getIDFPythonScriptFile();
8991
String pythonPath = IDFUtil.getIDFPythonEnvPath();
9092
List<String> arguments = new ArrayList<String>(
9193
Arrays.asList(pythonPath, idfPythonScriptFile.getAbsolutePath(), IDFConstants.CONF_SERVER_CMD));
9294
Logger.log(arguments.toString());
93-
ProcessRunner processRunner = new ProcessRunner();
94-
Process process;
95+
9596
try
9697
{
97-
process = processRunner.run(workingDir, envMap, arguments.toArray(new String[arguments.size()]));
98-
98+
ProcessBuilder processBuilder = new ProcessBuilder(arguments);
99+
if (workingDir != null)
100+
{
101+
processBuilder.directory(workingDir.toFile());
102+
}
103+
Map<String, String> environment = processBuilder.environment();
104+
environment.putAll(idfEnvMap);
105+
106+
Logger.log(environment.toString());
107+
108+
String idfPath = environment.get("PATH"); //$NON-NLS-1$
109+
String processPath = environment.get("Path"); //$NON-NLS-1$
110+
if (!StringUtil.isEmpty(idfPath) && !StringUtil.isEmpty(processPath)) // if both exist!
111+
{
112+
idfPath = idfPath.concat(";").concat(processPath); //$NON-NLS-1$
113+
environment.put("PATH", idfPath); //$NON-NLS-1$
114+
environment.remove("Path");//$NON-NLS-1$
115+
}
116+
117+
Logger.log(environment.toString());
118+
119+
// redirect error stream to input stream
120+
processBuilder.redirectErrorStream(true);
121+
122+
Process process = processBuilder.start();
99123
runnable = new JsonConfigServerRunnable(process, this);
100124
Thread t = new Thread(runnable);
101125
t.start();
@@ -136,4 +160,10 @@ public IJsonConfigOutput getOutput()
136160
{
137161
return configOutput;
138162
}
163+
164+
public void addConsole(MessageConsoleStream console)
165+
{
166+
this.console = console;
167+
}
168+
139169
}

bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigServerRunnable.java

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55

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

8-
import java.io.BufferedReader;
98
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.io.OutputStream;
1211
import java.io.PrintWriter;
1312
import java.text.MessageFormat;
13+
import java.util.concurrent.TimeUnit;
14+
15+
import org.json.simple.JSONObject;
16+
import org.json.simple.parser.JSONParser;
17+
import org.json.simple.parser.ParseException;
1418

1519
import com.aptana.core.util.ProcessRunnable;
1620
import com.espressif.idf.core.logging.Logger;
21+
import com.espressif.idf.core.util.StringUtil;
22+
import com.espressif.idf.sdk.config.core.IJsonServerConfig;
1723
import com.espressif.idf.sdk.config.core.SDKConfigCorePlugin;
1824

1925
/**
@@ -23,7 +29,6 @@
2329
public class JsonConfigServerRunnable extends ProcessRunnable
2430
{
2531

26-
private StringBuilder builder;
2732
private JsonConfigServer configServer;
2833
private OutputStream in;
2934
private InputStream out;
@@ -33,6 +38,7 @@ public JsonConfigServerRunnable(Process process, JsonConfigServer configServer)
3338
{
3439
super(process, null, true);
3540
this.configServer = configServer;
41+
3642
}
3743

3844
public void destory()
@@ -46,7 +52,7 @@ public void destory()
4652
public void executeCommand(String command, CommandType type)
4753
{
4854
this.type = type;
49-
55+
5056
String msg = MessageFormat.format(Messages.JsonConfigServerRunnable_CmdToBeExecuted, command);
5157
Logger.log(SDKConfigCorePlugin.getPlugin(), msg);
5258

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

7177
public void run()
7278
{
73-
builder = new StringBuilder();
74-
BufferedReader br = null;
79+
StringBuilder builder = new StringBuilder();
80+
7581
try
7682
{
77-
7883
out = p.getInputStream();
7984
in = p.getOutputStream();
8085

8186
byte[] buffer = new byte[4000];
82-
while (isAlive(p))
87+
88+
// sleep to make process.getErrorStream()/getInputStream() to return an available stream.
89+
p.waitFor(3000, TimeUnit.MILLISECONDS);
90+
boolean isAlive = true;
91+
while (isAlive)
8392
{
8493
int no = out.available();
85-
if (no == 0 && !builder.toString().isEmpty())
94+
String output = builder.toString();
95+
if (no == 0 && !output.isEmpty() && isValidJson(output))
8696
{
8797
// notify and reset
88-
configServer.notifyHandler(builder.toString(), type);
98+
configServer.notifyHandler(output, type);
8999
builder = new StringBuilder();
90100
}
91101
else if (no > 0)
92102
{
93103
int n = out.read(buffer, 0, Math.min(no, buffer.length));
94104
String string = new String(buffer, 0, n);
95-
System.out.println(string);
105+
configServer.console.print(string);
106+
configServer.console.flush();
96107
builder.append(string);
97108
}
98109

99-
int ni = System.in.available();
100-
if (ni > 0)
101-
{
102-
int n = System.in.read(buffer, 0, Math.min(ni, buffer.length));
103-
in.write(buffer, 0, n);
104-
in.flush();
105-
}
110+
p.waitFor(100, TimeUnit.MILLISECONDS);
111+
isAlive = p.isAlive();
106112

107-
try
108-
{
109-
Thread.sleep(10);
110-
}
111-
catch (InterruptedException e)
112-
{
113-
}
114113
}
114+
115+
configServer.notifyHandler("Server connection closed", CommandType.CONNECTION_CLOSED); //$NON-NLS-1$
116+
115117
}
116-
118+
117119
catch (IOException e)
118120
{
119-
//ignore
120-
} finally
121+
Logger.log(e);
122+
}
123+
catch (InterruptedException e1)
121124
{
122-
if (br != null)
125+
}
126+
127+
}
128+
129+
protected boolean isValidJson(String output)
130+
{
131+
String jsonOutput = new JsonConfigProcessor().getInitialOutput(output);
132+
if (StringUtil.isEmpty(jsonOutput))
133+
{
134+
return false;
135+
}
136+
try
137+
{
138+
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
139+
if (jsonObj != null)
123140
{
124-
try
125-
{
126-
br.close();
127-
}
128-
catch (Exception e)
141+
if (jsonObj.get(IJsonServerConfig.VISIBLE) != null && jsonObj.get(IJsonServerConfig.VALUES) != null
142+
&& jsonObj.get(IJsonServerConfig.RANGES) != null)
129143
{
144+
return true;
130145
}
131146
}
132-
monitor.done();
147+
}
148+
catch (ParseException e)
149+
{
150+
return false;
133151
}
134152

153+
return false;
135154
}
136-
137155

138156
}

bundles/com.espressif.idf.sdk.config.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
1010
org.eclipse.ui.ide,
1111
org.eclipse.ui.editors,
1212
org.eclipse.text,
13-
com.espressif.idf.sdk.config.core
13+
com.espressif.idf.sdk.config.core,
14+
org.eclipse.ui.console
1415
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1516
Automatic-Module-Name: com.espressif.idf.sdkconfig.ui
1617
Bundle-ActivationPolicy: lazy

0 commit comments

Comments
 (0)