Skip to content

Commit 536f0cc

Browse files
adding spaces support (#435)
Co-authored-by: Kondal Kolipaka <[email protected]>
1 parent 89f6a91 commit 536f0cc

File tree

12 files changed

+111
-52
lines changed

12 files changed

+111
-52
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
186186
}
187187

188188
// Check for spaces in the project path
189-
if (project.getLocation().toOSString().contains(" ")) //$NON-NLS-1$
189+
if (!IDFUtil.checkIfIdfSupportsSpaces() && project.getLocation().toOSString().contains(" ")) //$NON-NLS-1$
190190
{
191191
console.getErrorStream()
192192
.write("Project path can’t include space " + project.getLocation().toOSString()); //$NON-NLS-1$
@@ -395,6 +395,7 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
395395
e));
396396
}
397397
}
398+
398399

399400
public void update(IProject project) {
400401
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);

bundles/com.espressif.idf.core/src/com/espressif/idf/core/resources/ResourceChangeListener.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
public class ResourceChangeListener implements IResourceChangeListener
4141
{
4242

43-
private static final String cmakeProjectNamePattern = "(project[(].+[)])"; //$NON-NLS-1$
44-
4543
@Override
4644
public void resourceChanged(IResourceChangeEvent event)
4745
{
@@ -61,12 +59,9 @@ public boolean visit(final IResourceDelta delta) throws CoreException
6159
updateLaunchBar(resource, kind, flags);
6260
boolean isProjectAdded = (((resource.getType() & IResource.PROJECT) != 0)
6361
&& resource.getProject().isOpen() && kind == IResourceDelta.ADDED);
64-
6562
if (isProjectAdded)
6663
{
6764
cleanupBuildFolder(resource);
68-
renameProjectInCmakeList(resource);
69-
7065
}
7166
boolean isProjectRenamed = resource.getType() == IResource.PROJECT
7267
&& kind == IResourceDelta.ADDED && ((flags & IResourceDelta.MOVED_FROM) != 0);
@@ -140,33 +135,6 @@ private void updateLaunchBar(IResource resource, int kind, int flags) throws Cor
140135
}
141136
}
142137

143-
private void renameProjectInCmakeList(IResource resource)
144-
{
145-
IProject project = (IProject) resource;
146-
Path cMakeListLocation = new File(project.getLocation() + "/CMakeLists.txt").toPath(); //$NON-NLS-1$
147-
List<String> fileContent;
148-
try
149-
{
150-
fileContent = new ArrayList<>(Files.readAllLines(cMakeListLocation));
151-
for (int i = 0; i < fileContent.size(); i++)
152-
{
153-
154-
Pattern p = Pattern.compile(cmakeProjectNamePattern);
155-
Matcher m = p.matcher(fileContent.get(i));
156-
if (m.find())
157-
{
158-
fileContent.set(i, "project(" + project.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
159-
break;
160-
}
161-
}
162-
163-
Files.write(cMakeListLocation, fileContent, StandardCharsets.UTF_8);
164-
}
165-
catch (IOException e)
166-
{
167-
Logger.log(e);
168-
}
169-
}
170138
private void cleanupBuildFolder(IResource resource)
171139
{
172140

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
*/
4040
public class IDFUtil
4141
{
42+
private static Boolean idfSupportsSpaces;
43+
4244
/**
4345
* @return sysviewtrace_proc.py file path based on the IDF_PATH defined in the environment variables
4446
*/
@@ -152,6 +154,18 @@ public static String getIDFPythonEnvPath()
152154
return findCommandFromBuildEnvPath(IDFConstants.PYTHON_CMD);
153155

154156
}
157+
158+
public static boolean checkIfIdfSupportsSpaces() {
159+
160+
if(idfSupportsSpaces != null) {
161+
return idfSupportsSpaces;
162+
}
163+
String version = getEspIdfVersion();
164+
Pattern p = Pattern.compile("([0-9][.][0-9])"); //$NON-NLS-1$
165+
Matcher m = p.matcher(version);
166+
idfSupportsSpaces = m.find() && Double.parseDouble(m.group(0)) >= 5.0;
167+
return idfSupportsSpaces;
168+
}
155169

156170
public static String getPythonExecutable()
157171
{

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ParitionSizeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void checkRemainingSize()
102102
{
103103
String partitionTableContent = getPartitionTable();
104104
Path path = Paths.get(project.getLocation() + File.separator + IDFConstants.BUILD_FOLDER + File.separator
105-
+ project.getName() + ".bin"); //$NON-NLS-1$
105+
+ project.getName().replace(" ", "_") + ".bin"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
106106
long imageSize = Files.size(path);
107107

108108
String[] lines = partitionTableContent.split("\n"); //$NON-NLS-1$

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/IDFDownloadPage.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import java.text.MessageFormat;
1111
import java.util.Map;
1212
import java.util.Set;
13+
import java.util.regex.Matcher;
14+
import java.util.regex.Pattern;
1315

1416
import org.eclipse.jface.dialogs.IDialogConstants;
17+
import org.eclipse.jface.dialogs.MessageDialog;
1518
import org.eclipse.jface.wizard.WizardPage;
1619
import org.eclipse.swt.SWT;
1720
import org.eclipse.swt.events.ModifyEvent;
@@ -24,6 +27,7 @@
2427
import org.eclipse.swt.widgets.Combo;
2528
import org.eclipse.swt.widgets.Composite;
2629
import org.eclipse.swt.widgets.DirectoryDialog;
30+
import org.eclipse.swt.widgets.Display;
2731
import org.eclipse.swt.widgets.Group;
2832
import org.eclipse.swt.widgets.Label;
2933
import org.eclipse.swt.widgets.Link;
@@ -283,11 +287,11 @@ private void validate()
283287
setPageComplete(false);
284288
return;
285289
}
286-
287290
if (idfPath.contains(" ")) //$NON-NLS-1$
288291
{
289292
setErrorMessage(Messages.IDFDownloadPage_IDFBuildNotSupported);
290293
setPageComplete(false);
294+
showMessage();
291295
return;
292296
}
293297

@@ -305,13 +309,24 @@ private void validate()
305309
}
306310
else
307311
{
312+
boolean supportSpaces = false;
313+
if (versionCombo.getText() == "master") //$NON-NLS-1$
314+
{
315+
supportSpaces = true;
316+
}
317+
else
318+
{
319+
Pattern p = Pattern.compile("([0-9][.][0-9])"); //$NON-NLS-1$
320+
Matcher m = p.matcher(versionCombo.getText());
321+
supportSpaces = m.find() && Double.parseDouble(m.group(0)) >= 5.0;
322+
}
308323
if (StringUtil.isEmpty(directoryTxt.getText()))
309324
{
310325
setPageComplete(false);
311326
return;
312327
}
313328

314-
if (directoryTxt.getText().contains(" ")) //$NON-NLS-1$
329+
if (!supportSpaces && directoryTxt.getText().contains(" ")) //$NON-NLS-1$
315330
{
316331
setErrorMessage(Messages.IDFDownloadPage_IDFBuildNotSupported);
317332
setPageComplete(false);
@@ -346,5 +361,23 @@ public boolean isConfigureExistingEnabled()
346361
{
347362
return fileSystemBtn.getSelection();
348363
}
364+
365+
private void showMessage()
366+
{
367+
Display.getDefault().asyncExec(new Runnable()
368+
{
369+
370+
@Override
371+
public void run() {
372+
boolean allowToCreateProjectWithSpaces = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.IDFDownloadWizard_AllowSpacesTitle,
373+
Messages.IDFDownloadWizard_AllowSpacesMsg);
374+
375+
if (allowToCreateProjectWithSpaces) {
376+
setErrorMessage(null);
377+
setPageComplete(true);
378+
}
379+
}
380+
});
381+
}
349382

350383
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class Messages extends NLS
3737
public static String IDFDownloadWizard_DownloadingMessage;
3838
public static String IDFDownloadWizard_ErrorTitle;
3939
public static String IDFDownloadWizard_MessageTitle;
40+
public static String IDFDownloadWizard_AllowSpacesTitle;
41+
public static String IDFDownloadWizard_AllowSpacesMsg;
4042
static
4143
{
4244
// initialize resource bundle

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/install/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ IDFDownloadWizard_DownloadingJobMsg=Downloading ESP-IDF {0}...
2929
IDFDownloadWizard_DownloadingMessage=Downloading {0}...
3030
IDFDownloadWizard_ErrorTitle=Error
3131
IDFDownloadWizard_MessageTitle=Message
32+
IDFDownloadWizard_AllowSpacesTitle=Space detected!
33+
IDFDownloadWizard_AllowSpacesMsg=Detected a whitespace character in path. Spaces in IDF_PATH and project paths are allowed in versions 5.0 and higher. By clicking "Yes", you confirm that your version supports spaces.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeConstants.java

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

7-
import java.util.ArrayList;
8-
import java.util.List;
9-
import java.util.Map;
107
import java.util.regex.Matcher;
118
import java.util.regex.Pattern;
129

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tracing/AppLvlTracingDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private String wrapOutputFilePath(String baseFilePath) {
394394
public void setProjectPath(IResource project) {
395395
pathToProject = project.getLocation().toString();
396396

397-
elfFilePath = project.getProject().getFolder("build").getFile(project.getName().concat(".elf")).getLocation() //$NON-NLS-1$ //$NON-NLS-2$
397+
elfFilePath = project.getProject().getFolder("build").getFile(project.getName().replace(" ", "_").concat(".elf")).getLocation() //$NON-NLS-1$ //$NON-NLS-2$
398398
.toString();
399399
pathToProject = wrapOutputFilePath(pathToProject);
400400

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tracing/heaptracing/HeapTracingAnalysisEditor.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
package com.espressif.idf.ui.tracing.heaptracing;
77

8-
import java.util.ArrayList;
9-
import java.util.Arrays;
10-
import java.util.List;
11-
import java.util.Map;
12-
import java.util.stream.Collectors;
13-
148
import org.eclipse.core.resources.IFile;
159
import org.eclipse.core.resources.IProject;
1610
import org.eclipse.core.runtime.IProgressMonitor;
@@ -52,7 +46,7 @@ public void init(IEditorSite site, IEditorInput input) throws PartInitException
5246
memoryDumpFile = editorInput.getFile();
5347
project = memoryDumpFile.getProject();
5448
setPartName(project.getName());
55-
elfSymbolsFile = project.getFolder("build").getFile(project.getName().concat(".elf"));
49+
elfSymbolsFile = project.getFolder("build").getFile(project.getName().replace(" ", "_").concat(".elf")); //$NON-NLS-1$ //$NON-NLS-2$
5650
try
5751
{
5852
tracingJsonParser = new TracingJsonParser(memoryDumpFile.getRawLocation().toOSString(),

0 commit comments

Comments
 (0)