Skip to content

Commit 52f8253

Browse files
authored
Merge pull request #1528 from Sloeber/open_close_stops_indexing
Completely redesigned the indexcontroller #1491
2 parents f3b698b + 5c7ea16 commit 52f8253

File tree

7 files changed

+115
-97
lines changed

7 files changed

+115
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.sloeber.core.api;
22

3+
import static io.sloeber.core.common.Const.*;
4+
35
import java.util.ArrayList;
46

57
/**
@@ -15,32 +17,32 @@ public class ConfigurationDescriptor {
1517
public final boolean DebugCompilerSettings;
1618

1719
public ConfigurationDescriptor(String Name, String ToolchainID, boolean DebugCompilerSettings) {
18-
this.configName = Name;
19-
this.ToolchainID = ToolchainID;
20-
this.DebugCompilerSettings = DebugCompilerSettings;
20+
this.configName = Name;
21+
this.ToolchainID = ToolchainID;
22+
this.DebugCompilerSettings = DebugCompilerSettings;
2123
}
2224

2325
static public ArrayList<ConfigurationDescriptor> getDefaultDescriptors() {
24-
ArrayList<ConfigurationDescriptor> alCfgs = new ArrayList<>();
26+
ArrayList<ConfigurationDescriptor> alCfgs = new ArrayList<>();
2527

26-
ConfigurationDescriptor cfgTCidPair = new ConfigurationDescriptor("Release", //$NON-NLS-1$
27-
"io.sloeber.core.toolChain.release", false); //$NON-NLS-1$
28-
alCfgs.add(cfgTCidPair);
29-
return alCfgs;
28+
ConfigurationDescriptor cfgTCidPair = new ConfigurationDescriptor(RELEASE, "io.sloeber.core.toolChain.release", //$NON-NLS-1$
29+
false);
30+
alCfgs.add(cfgTCidPair);
31+
return alCfgs;
3032
}
3133

3234
static public ArrayList<ConfigurationDescriptor> getReleaseAndDebug() {
33-
ArrayList<ConfigurationDescriptor> alCfgs = new ArrayList<>();
35+
ArrayList<ConfigurationDescriptor> alCfgs = new ArrayList<>();
3436

35-
ConfigurationDescriptor cfgTCidPair = new ConfigurationDescriptor("Release",
36-
"io.sloeber.core.toolChain.release", false);
37-
alCfgs.add(cfgTCidPair); // Always have the release build here
37+
ConfigurationDescriptor cfgTCidPair = new ConfigurationDescriptor(RELEASE, "io.sloeber.core.toolChain.release",
38+
false);
39+
alCfgs.add(cfgTCidPair); // Always have the release build here
3840

39-
// Debug has same toolchain as release
40-
ConfigurationDescriptor cfgTCidPair2 = new ConfigurationDescriptor("Debug_AVaRICE",
41-
"io.sloeber.core.toolChain.release", true);
42-
alCfgs.add(cfgTCidPair2);
41+
// Debug has same toolchain as release
42+
ConfigurationDescriptor cfgTCidPair2 = new ConfigurationDescriptor("Debug_AVaRICE",
43+
"io.sloeber.core.toolChain.release", true);
44+
alCfgs.add(cfgTCidPair2);
4345

44-
return alCfgs;
46+
return alCfgs;
4547
}
4648
}

io.sloeber.core/src/io/sloeber/core/api/Sketch.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.eclipse.cdt.core.model.CoreModel;
1010
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
1111
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
12+
import org.eclipse.core.resources.IFile;
1213
import org.eclipse.core.resources.IProject;
1314
import org.eclipse.core.runtime.CoreException;
1415
import org.eclipse.core.runtime.IPath;
@@ -77,13 +78,18 @@ public static void reAttachLibrariesToProject(IProject iProject) {
7778
}
7879

7980
public static boolean isSketch(IProject proj) {
80-
try {
81-
return proj.hasNature(ARDUINO_NATURE_ID);
82-
} catch (CoreException e) {
83-
// ignore
84-
e.printStackTrace();
85-
}
86-
return false;
81+
return getConfigLocalFile(proj).exists();
82+
}
83+
84+
public static IFile getConfigVersionFile(IProject proj) {
85+
return proj.getFile(SLOEBER_CFG);
86+
}
87+
88+
/*
89+
* Get the sloeber configuration file
90+
*/
91+
public static IFile getConfigLocalFile(IProject proj) {
92+
return proj.getFile(SLOEBER_PROJECT);
8793
}
8894

8995
public static boolean removeLibrariesFromProject(IProject project, ICProjectDescription projDesc,

io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java

+52-31
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,8 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
130130
SloeberProject sloeberProject = new SloeberProject(project);
131131
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
132132
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project, true);
133-
if (upgradeArduinoProject(sloeberProject, prjCDesc)) {
134-
try {
135-
cCorePlugin.setProjectDescription(project, prjCDesc);
136-
} catch (CoreException e) {
137-
e.printStackTrace();
138-
}
139-
}
133+
upgradeArduinoProject(sloeberProject, prjCDesc);
140134
if (!sloeberProject.readConfigFromFiles()) {
141-
String RELEASE = "Release";
142135
sloeberProject.setBoardDescription(RELEASE, new BoardDescription(), false);
143136
sloeberProject.setCompileDescription(RELEASE, new CompileDescription());
144137
sloeberProject.setOtherDescription(RELEASE, new OtherDescription());
@@ -182,7 +175,6 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
182175

183176
ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);
184177

185-
prjCDesc = cCorePlugin.getProjectDescription(project);
186178
ICConfigurationDescription activeConfig = prjCDesc.getActiveConfiguration();
187179

188180
for (String curConfigName : sloeberProject.myBoardDescriptions.keySet()) {
@@ -361,7 +353,7 @@ public void run(IProgressMonitor internalMonitor) throws CoreException {
361353
/**
362354
* This method asks for a Sloeber project in an old form and creates a sloeber
363355
* project in a new for
364-
* currently only 1 conversion is implemented
356+
* currently only the conversion storage in CDT to .sProject is implemented
365357
*
366358
* returns true if the projectdescription needs to be saved
367359
*/
@@ -475,11 +467,33 @@ public synchronized boolean configure(ICProjectDescription prjCDesc, boolean prj
475467

476468
setAllEnvironmentVars();
477469

470+
List<String> newConfigs = newConfigsNeededInCDT(prjCDesc);
478471
if (prjDescWritable) {
479-
List<String> newConfigs = newConfigNeededInCDT(prjCDesc);
480472
if (newConfigs.size() > 0) {
481473
saveProjDesc = saveProjDesc || createNeededCDTConfigs(newConfigs, prjCDesc);
482474
}
475+
} else {
476+
saveProjDesc = saveProjDesc || (newConfigs.size() > 0);
477+
if (saveProjDesc) {
478+
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
479+
try {
480+
workspace.run(new ICoreRunnable() {
481+
482+
@Override
483+
public void run(IProgressMonitor monitor) throws CoreException {
484+
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
485+
ICProjectDescription prjCDescSave = cCorePlugin.getProjectDescription(myProject, true);
486+
if (configure(prjCDescSave, true)) {
487+
cCorePlugin.setProjectDescription(myProject, prjCDescSave, false, null);
488+
}
489+
490+
}
491+
}, null, IWorkspace.AVOID_UPDATE, null);
492+
} catch (Exception e) {
493+
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
494+
"Failed to do posponed confdesc saving for project " + myProject.getName(), e)); //$NON-NLS-1$
495+
}
496+
}
483497
}
484498

485499
myIsInMemory = true;
@@ -610,7 +624,7 @@ private boolean readConfigFromCDT(ICProjectDescription prjCDesc) {
610624
* @param prjCDesc
611625
* @return a list of sloeber known configurationNames unknown to CDT
612626
*/
613-
private List<String> newConfigNeededInCDT(ICProjectDescription prjCDesc) {
627+
private List<String> newConfigsNeededInCDT(ICProjectDescription prjCDesc) {
614628
List<String> ret = new LinkedList<>();
615629
for (String curConfName : myBoardDescriptions.keySet()) {
616630
ICConfigurationDescription curConfDesc = prjCDesc.getConfigurationByName(curConfName);
@@ -628,7 +642,7 @@ private List<String> newConfigNeededInCDT(ICProjectDescription prjCDesc) {
628642
* @param configs
629643
* @param prjCDesc
630644
* @return true if at least one config was created (basically only false if
631-
* configs is empty)
645+
* configs is empty oe error conditions)
632646
*/
633647
private static boolean createNeededCDTConfigs(List<String> configs, ICProjectDescription prjCDesc) {
634648
boolean ret = false;
@@ -639,6 +653,7 @@ private static boolean createNeededCDTConfigs(List<String> configs, ICProjectDes
639653
ret = true;
640654
} catch (Exception e) {
641655
// ignore as we will try again later
656+
e.printStackTrace();
642657
}
643658
}
644659
return ret;
@@ -823,8 +838,11 @@ public static SloeberProject getSloeberProject(IProject project) {
823838
try {
824839
sessionProperty = project.getSessionProperty(sloeberQualifiedName);
825840
if (null != sessionProperty) {
826-
SloeberProject ret = (SloeberProject) sessionProperty;
827-
return ret;
841+
SloeberProject sloeberProject = (SloeberProject) sessionProperty;
842+
if (sloeberProject.isInMemory()) {
843+
IndexerController.index(project);
844+
}
845+
return sloeberProject;
828846
}
829847
} catch (CoreException e) {
830848
e.printStackTrace();
@@ -939,14 +957,14 @@ private static String getOtherPrefix(String confDescName) {
939957
* Get the file that Sloeber maintains and that is meant to be stored in version control
940958
*/
941959
private IFile getConfigVersionFile() {
942-
return myProject.getFile(SLOEBER_CFG);
960+
return Sketch.getConfigVersionFile(myProject);
943961
}
944962

945963
/*
946964
* Get the sloeber configuration file
947965
*/
948966
private IFile getConfigLocalFile() {
949-
return myProject.getFile(".sproject"); //$NON-NLS-1$
967+
return Sketch.getConfigLocalFile(myProject);
950968
}
951969

952970
public void configChangeAboutToApply(ICProjectDescription newProjDesc, ICProjectDescription oldProjDesc) {
@@ -1037,20 +1055,23 @@ public void configChangeAboutToApply(ICProjectDescription newProjDesc, ICProject
10371055
*
10381056
*/
10391057
public void sloeberCfgChanged() {
1040-
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
1041-
ICProjectDescription projDesc = cCorePlugin.getProjectDescription(myProject, true);
1042-
ICConfigurationDescription activeConfig = projDesc.getActiveConfiguration();
1058+
//CCorePlugin cCorePlugin = CCorePlugin.getDefault();
1059+
//ICProjectDescription projDesc = cCorePlugin.getProjectDescription(myProject, true);
1060+
///ICConfigurationDescription activeConfig = projDesc.getActiveConfiguration();
10431061
myIsInMemory = false;
1044-
boolean projDescNeedsSaving = configure(projDesc, true);
1045-
Helpers.deleteBuildFolder(myProject, activeConfig.getName());
1046-
projDescNeedsSaving = projDescNeedsSaving || setActiveConfig(activeConfig);
1047-
if (projDescNeedsSaving) {
1048-
try {
1049-
cCorePlugin.setProjectDescription(myProject, projDesc);
1050-
} catch (CoreException e) {
1051-
e.printStackTrace();
1052-
}
1053-
}
1062+
configure();
1063+
//all configs may have changed so only deleting the active config does not make sense
1064+
//Helpers.deleteBuildFolder(myProject, activeConfig.getName());
1065+
1066+
//This code is only triggered when sloeber.cfg changed so no need to set the active config
1067+
//projDescNeedsSaving = projDescNeedsSaving || setActiveConfig(activeConfig);
1068+
// if (projDescNeedsSaving) {
1069+
// try {
1070+
// cCorePlugin.setProjectDescription(myProject, projDesc);
1071+
// } catch (CoreException e) {
1072+
// e.printStackTrace();
1073+
// }
1074+
// }
10541075

10551076
}
10561077

@@ -1116,7 +1137,7 @@ private IStatus BuildTarget(String targetName) {
11161137

11171138
try {
11181139
IMakeTargetManager targetManager = MakeCorePlugin.getDefault().getTargetManager();
1119-
IContainer targetResource = myProject.getFolder("Release"); //$NON-NLS-1$
1140+
IContainer targetResource = myProject.getFolder(RELEASE);
11201141
IMakeTarget target = targetManager.findTarget(targetResource, targetName);
11211142
if (target == null) {
11221143
target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); //$NON-NLS-1$

io.sloeber.core/src/io/sloeber/core/common/Const.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class Const {
7979
public static final String ARDUINO_VARIANT_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + VARIANT;
8080
public static final String ARDUINO_CODE_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + CORE;
8181
public static final String SLOEBER_CFG = "sloeber.cfg";
82+
public static final String SLOEBER_PROJECT = ".sproject";
8283

8384
// Environment variable stuff
8485
public static final String ENV_KEY_SLOEBER_START = "sloeber" + DOT;
@@ -124,7 +125,9 @@ public class Const {
124125
public static final String SAM = "sam";
125126
public static final String SAMD = "samd";
126127

127-
public static final String JSSC_SERIAL_FILTER_PATTERN_KEY = "jssc_serial_filter_pattern";
128-
public static final String JSSC_MAC_DEFAULT_FILTER_PATTERN = "^cu\\..*(UART|serial|usb).*";
128+
public static final String JSSC_SERIAL_FILTER_PATTERN_KEY = "jssc_serial_filter_pattern";
129+
public static final String JSSC_MAC_DEFAULT_FILTER_PATTERN = "^cu\\..*(UART|serial|usb).*";
130+
131+
public static final String RELEASE = "Release";
129132

130133
}

io.sloeber.core/src/io/sloeber/core/listeners/IndexerController.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public boolean postponeIndexerSetup(ICProject cProject) {
3333
if (ret) {
3434
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), "pospone index " + project.getName())); //$NON-NLS-1$
3535
indexingPosponedProjects.add(project);
36-
} else {
37-
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),
38-
"do not pospone index " + project.getName())); //$NON-NLS-1$
39-
}
36+
} /* else {
37+
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),
38+
"do not pospone index " + project.getName())); //$NON-NLS-1$
39+
}*/
4040
return ret;
4141
}
4242

@@ -51,8 +51,9 @@ public static void doNotIndex(IProject project) {
5151
}
5252

5353
public static void index(IProject project) {
54-
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), "index " + project.getName())); //$NON-NLS-1$
55-
doNotIndexProjects.remove(project);
54+
if (doNotIndexProjects.remove(project)) {
55+
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), "index " + project.getName())); //$NON-NLS-1$
56+
}
5657
if (indexingPosponedProjects.contains(project)) {
5758
indexingPosponedProjects.remove(project);
5859
ICProject cProject = CoreModel.getDefault().getCModel().getCProject(project.getName());

io.sloeber.core/src/io/sloeber/core/listeners/IndexerListener.java

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import org.eclipse.cdt.core.index.IIndexerStateEvent;
1313
import org.eclipse.cdt.core.index.IIndexerStateListener;
1414
import org.eclipse.core.resources.IProject;
15-
import org.eclipse.core.runtime.CoreException;
1615
import org.eclipse.core.runtime.IStatus;
1716
import org.eclipse.core.runtime.Status;
1817

1918
import io.sloeber.core.Activator;
2019
import io.sloeber.core.Messages;
20+
import io.sloeber.core.api.Sketch;
2121
import io.sloeber.core.common.Common;
2222
import io.sloeber.core.common.Const;
2323
import io.sloeber.core.common.InstancePreferences;
@@ -33,19 +33,13 @@ public void indexChanged(IIndexChangeEvent event) {
3333
// Do not update libraries if project is in creation
3434
return;
3535
}
36-
try {
37-
if (project.hasNature(Const.ARDUINO_NATURE_ID)) {
38-
if (!newChangedProjects.contains(project)) {
39-
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),
40-
"Index of project changed :" + project.getName())); //$NON-NLS-1$
41-
newChangedProjects.add(project);
42-
}
36+
if (Sketch.isSketch(project)) {
37+
if (!newChangedProjects.contains(project)) {
38+
Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(),
39+
"Index of project changed :" + project.getName())); //$NON-NLS-1$
40+
newChangedProjects.add(project);
4341
}
44-
} catch (CoreException e) {
45-
// ignore
46-
e.printStackTrace();
4742
}
48-
4943
}
5044

5145
@Override

io.sloeber.core/src/io/sloeber/core/listeners/resourceChangeListener.java

+13-22
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,24 @@ public void resourceChanged(IResourceChangeEvent event) {
3535
IResourceDelta sloeberCfgDelta = projectDelta.findMember(new Path(SLOEBER_CFG));
3636
if (sloeberCfgDelta != null) {
3737
if (sloeberCfgDelta.getKind() != IResourceDelta.REMOVED) {
38+
//the sloeber.cfg file has been added or changed
3839
IProject iProject = sloeberCfgDelta.getResource().getProject();
3940
// stop the indexer
40-
IndexerController.doNotIndex(iProject);
41+
//IndexerController.doNotIndex(iProject);
4142

42-
// log to process later
43-
changedSloeberCfgFiles.add(iProject);
44-
}
45-
} else {
46-
// it is not a new type Sloeber project check whether it is an old type Sloeber
47-
// project
48-
IResourceDelta cProjectDelta = projectDelta.findMember(new Path(".cproject")); //$NON-NLS-1$
49-
if (cProjectDelta != null)
50-
if (projectDelta.getFlags() == IResourceDelta.OPEN) {
51-
// as it is a open of a cdt project assume it is a sloeber project.
52-
// We will find out later if not
53-
IProject iProject = cProjectDelta.getResource().getProject();
54-
SloeberProject curSloeberProject = SloeberProject.getSloeberProject(iProject);
55-
if (curSloeberProject != null) {
56-
if (!curSloeberProject.isInMemory()) {
57-
// stop the indexer
58-
IndexerController.doNotIndex(iProject);
59-
curSloeberProject.configure();
60-
}
43+
SloeberProject curSloeberProject = SloeberProject.getSloeberProject(iProject);
44+
if (curSloeberProject == null) {
45+
// this should not happen as we have a sloeber.cfg file
46+
} else {
47+
//no use updating the cfg if it wasn't read already
48+
if (curSloeberProject.isInMemory()) {
49+
curSloeberProject.sloeberCfgChanged();
6150
}
62-
// log to process later
63-
//changedSloeberCfgFiles.add(iProject);
6451
}
52+
53+
// log to process later
54+
//changedSloeberCfgFiles.add(iProject);
55+
}
6556
}
6657
}
6758

0 commit comments

Comments
 (0)