-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixing esp-idf terminal and idf.py reconfigure not working on wi…
…ndows
- Loading branch information
Showing
8 changed files
with
159 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ConsoleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
* Use is subject to license terms. | ||
*******************************************************************************/ | ||
|
||
package com.espressif.idf.core.util; | ||
|
||
import org.eclipse.ui.console.ConsolePlugin; | ||
import org.eclipse.ui.console.IConsole; | ||
import org.eclipse.ui.console.MessageConsole; | ||
|
||
public class ConsoleManager | ||
{ | ||
|
||
private ConsoleManager() | ||
{ | ||
} | ||
|
||
public static MessageConsole getConsole(String consoleName) | ||
{ | ||
MessageConsole console = findConsole(consoleName); | ||
if (console == null) | ||
{ | ||
console = new MessageConsole(consoleName, null); | ||
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); | ||
} | ||
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console); | ||
return console; | ||
} | ||
|
||
private static MessageConsole findConsole(String consoleName) | ||
{ | ||
for (IConsole existing : ConsolePlugin.getDefault().getConsoleManager().getConsoles()) | ||
{ | ||
if (consoleName.equals(existing.getName())) | ||
{ | ||
return (MessageConsole) existing; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
* Use is subject to license terms. | ||
*******************************************************************************/ | ||
|
||
package com.espressif.idf.core.util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.ui.console.MessageConsole; | ||
import org.eclipse.ui.console.MessageConsoleStream; | ||
|
||
import com.espressif.idf.core.IDFCorePlugin; | ||
import com.espressif.idf.core.IDFEnvironmentVariables; | ||
import com.espressif.idf.core.ProcessBuilderFactory; | ||
import com.espressif.idf.core.logging.Logger; | ||
|
||
public class IdfCommandExecutor | ||
{ | ||
|
||
private final String target; | ||
private final MessageConsole console; | ||
|
||
public IdfCommandExecutor(String target, MessageConsole console) | ||
{ | ||
this.target = target; | ||
this.console = console; | ||
} | ||
|
||
public IStatus executeReconfigure(IProject project) | ||
{ | ||
console.activate(); | ||
return runIdfReconfigureCommand(project); | ||
} | ||
|
||
private IStatus runIdfReconfigureCommand(IProject project) | ||
{ | ||
ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); | ||
List<String> arguments = prepareArguments(); | ||
Map<String, String> environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap()); | ||
|
||
try (MessageConsoleStream messageConsoleStream = console.newMessageStream()) | ||
{ | ||
return runProcess(arguments, environment, processRunner, project, messageConsoleStream); | ||
} | ||
catch (IOException e1) | ||
{ | ||
Logger.log(e1); | ||
return IDFCorePlugin.errorStatus(e1.getMessage(), e1); | ||
} | ||
} | ||
|
||
private List<String> prepareArguments() | ||
{ | ||
List<String> arguments = new ArrayList<>(); | ||
arguments.add(IDFUtil.getIDFPythonEnvPath()); | ||
arguments.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath()); | ||
arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$ | ||
arguments.add("reconfigure"); //$NON-NLS-1$ | ||
return arguments; | ||
} | ||
|
||
private IStatus runProcess(List<String> arguments, Map<String, String> environment, | ||
ProcessBuilderFactory processRunner, IProject project, MessageConsoleStream messageConsoleStream) | ||
{ | ||
StringBuilder output = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader( | ||
processRunner.run(arguments, project.getLocation(), environment).getInputStream()))) | ||
{ | ||
String line; | ||
while ((line = reader.readLine()) != null) | ||
{ | ||
output.append(line).append(System.lineSeparator()); | ||
messageConsoleStream.println(line); | ||
} | ||
return new Status(IStatus.OK, IDFCorePlugin.PLUGIN_ID, output.toString()); | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.log(e); | ||
return IDFCorePlugin.errorStatus(e.getMessage(), e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
* @author Kondal Kolipaka <[email protected]> | ||
* | ||
*/ | ||
public class Messages extends NLS { | ||
public class Messages extends NLS | ||
{ | ||
private static final String BUNDLE_NAME = "com.espressif.idf.ui.wizard.messages"; //$NON-NLS-1$ | ||
public static String ImportIDFProjectWizard_0; | ||
public static String ImportIDFProjectWizardPage_0; | ||
|
@@ -41,12 +42,15 @@ public class Messages extends NLS { | |
public static String NewComponentWizardPage_CantCreateCompErr; | ||
public static String NewComponentWizardPage_ProjectDoesntExistErr; | ||
public static String NewComponentWizardPage_ProjectNameLbl; | ||
|
||
static { | ||
public static String IdfReconfigureJobName; | ||
|
||
static | ||
{ | ||
// initialize resource bundle | ||
NLS.initializeMessages(BUNDLE_NAME, Messages.class); | ||
} | ||
|
||
private Messages() { | ||
private Messages() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters