Skip to content

Commit e893f4c

Browse files
author
jan
committed
#1303 lots of impact but nothing core like
You still need to open the project properties->arduino apply close after installing the platform but at least everything is there
1 parent e60568b commit e893f4c

File tree

11 files changed

+80
-77
lines changed

11 files changed

+80
-77
lines changed

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sloeber.core;
22

3+
import static io.sloeber.core.common.Const.*;
34
import static org.eclipse.core.resources.IResource.*;
45

56
import java.io.File;
@@ -68,7 +69,7 @@ public class Activator extends Plugin {
6869
private char[] uri = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't',
6970
'/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'p', 'l', 'u',
7071
'g', 'i', 'n', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l', '?', 's', '=' };
71-
private static final String PLUGIN_ID = "io.sloeber.core";
72+
7273

7374
private static IResourceChangeListener myResourceChangelistener = new resourceChangeListener();
7475

io.sloeber.core/src/io/sloeber/core/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Messages extends NLS {
1313
public static final String PROJECT = "{PROJECT}"; //$NON-NLS-1$
1414
public static final String UPLOADER = "{UPLOADER}"; //$NON-NLS-1$
1515
public static final String MS = "{MS}"; //$NON-NLS-1$
16-
public static final String NAME = "{NAME}"; //$NON-NLS-1$
16+
public static final String NAMEFIELD = "{NAME}"; //$NON-NLS-1$
1717
public static final String ID = "{ID}"; //$NON-NLS-1$
1818
public static final String COMMAND = "{COMMAND}"; //$NON-NLS-1$
1919
public static final String TOOL = "{TOOL}"; //$NON-NLS-1$

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,7 @@ public BoardDescription(BoardDescription srcObject) {
363363
myOptions = srcObject.myOptions;
364364
}
365365

366-
protected BoardDescription(BoardTxtFile txtFile, String boardID) {
367-
this.myBoardID = boardID;
368-
this.myreferencingBoardsFile = txtFile.getTxtFile();
369-
this.myTxtFile = txtFile;
370-
setDefaultOptions();
371-
calculateDerivedFields();
372-
}
366+
373367

374368
public String getuploadTool() {
375369
return this.myUploadTool;
@@ -410,9 +404,6 @@ public void saveUserSelection() {
410404
myStorageNode.put(KEY_LAST_USED_BOARD_MENU_OPTIONS, KeyValue.makeString(this.myOptions));
411405
}
412406

413-
public String getPackage() {
414-
return this.myTxtFile.getPackage();
415-
}
416407

417408
public String getArchitecture() {
418409
return this.myTxtFile.getArchitecture();
@@ -754,6 +745,14 @@ private Map<String, String> getEnvVarsTxt() {
754745
return myTxtFile.getAllBoardEnvironVars(getBoardID());
755746
}
756747

748+
protected BoardDescription(File txtFile, String boardID) {
749+
this.myBoardID = boardID;
750+
this.myreferencingBoardsFile = txtFile;
751+
this.myTxtFile = new BoardTxtFile(txtFile);
752+
setDefaultOptions();
753+
calculateDerivedFields();
754+
}
755+
757756
BoardDescription(TxtFile configFile, String prefix) {
758757

759758
KeyValueTree tree = configFile.getData();
@@ -1134,4 +1133,9 @@ public boolean isValid() {
11341133
return myreferencingBoardsFile.exists();
11351134
}
11361135

1136+
public void reloadTxtFile() {
1137+
myTxtFile.reloadTxtFile();
1138+
1139+
}
1140+
11371141
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sloeber.core.api;
22

33
import static io.sloeber.core.Messages.*;
4+
import static io.sloeber.core.common.Const.*;
45
import static java.nio.file.StandardCopyOption.*;
56

67
import java.io.File;
@@ -59,10 +60,10 @@
5960
*/
6061
public class PackageManager {
6162

62-
public static final String LOCAL = "local"; //$NON-NLS-1$
63+
6364
protected static List<PackageIndex> packageIndices;
6465
private static boolean myHasbeenLogged = false;
65-
private static boolean platformsDirty = true;// reset global variables at startup
66+
private static boolean envVarsNeedUpdating = true;// reset global variables at startup
6667
private final static int MAX_HTTP_REDIRECTIONS = 5;
6768
private static HashMap<String, String> myWorkbenchEnvironmentVariables = new HashMap<>();
6869

@@ -159,7 +160,7 @@ public static void installsubsetOfLatestPlatforms(int fromIndex, int toIndex) {
159160
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
160161
return;
161162
}
162-
platformsDirty = true;
163+
envVarsNeedUpdating = true;
163164
int currPlatformIndex = 1;
164165
NullProgressMonitor monitor = new NullProgressMonitor();
165166
List<Package> allPackages = InternalPackageManager.getPackages();
@@ -187,7 +188,7 @@ public static void installLatestPlatform(String JasonName, String packageName, S
187188
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
188189
return;
189190
}
190-
platformsDirty = true;
191+
envVarsNeedUpdating = true;
191192
Package curPackage = InternalPackageManager.getPackage(JasonName, packageName);
192193
if (curPackage != null) {
193194
ArduinoPlatform curPlatform = curPackage.getLatestPlatform(architectureName, false);
@@ -574,7 +575,7 @@ public static IStatus setPlatformTree(PlatformTree platformTree, IProgressMonito
574575
if (!ConfigurationPreferences.getUpdateJasonFilesFlag()) {
575576
loadJsons(true);
576577
}
577-
platformsDirty = true;
578+
envVarsNeedUpdating = true;
578579
try {
579580
InternalPackageManager.setReady(false);
580581

@@ -598,6 +599,7 @@ public static IStatus setPlatformTree(PlatformTree platformTree, IProgressMonito
598599
// do nothing
599600
}
600601
InternalPackageManager.setReady(true);
602+
SloeberProject.reloadTxtFile();
601603
return status;
602604
}
603605

@@ -877,7 +879,7 @@ public static IPath getInstallationPath() {
877879
* explicitly define tools or platform dependencies Like private hardware
878880
*/
879881
public static Map<String, String> getEnvironmentVariables() {
880-
if (!platformsDirty) {
882+
if (!envVarsNeedUpdating) {
881883
return myWorkbenchEnvironmentVariables;
882884
}
883885
myWorkbenchEnvironmentVariables.clear();
@@ -913,7 +915,7 @@ public static Map<String, String> getEnvironmentVariables() {
913915
if( latestAvrPlatform!=null) {
914916
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestAvrPlatform, false));
915917
}
916-
platformsDirty = false;
918+
envVarsNeedUpdating = false;
917919
return myWorkbenchEnvironmentVariables;
918920
}
919921

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,33 @@ public void sloeberCfgChanged() {
10141014

10151015
}
10161016

1017+
/**
1018+
* When a board has been installed it may be that a boardDescription needs to
1019+
* reload the txt file
1020+
*/
1021+
public static void reloadTxtFile() {
1022+
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1023+
for (IProject curProject : workspaceRoot.getProjects()) {
1024+
if (curProject.isOpen()) {
1025+
SloeberProject sloeberProject = getSloeberProject(curProject, true);
1026+
if (sloeberProject != null) {
1027+
sloeberProject.internalReloadTxtFile();
1028+
}
1029+
}
1030+
}
1031+
}
1032+
1033+
/**
1034+
* When a board has been installed it may be that a boardDescription needs to
1035+
* reload the txt file
1036+
*/
1037+
private void internalReloadTxtFile() {
1038+
for (BoardDescription curBoardDescription : myBoardDescriptions.values()) {
1039+
curBoardDescription.reloadTxtFile();
1040+
}
1041+
1042+
}
1043+
10171044
private static Map<String, String> getConfigs(ICProjectDescription prjCDesc) {
10181045
Map<String, String> ret = new HashMap<>();
10191046
for (ICConfigurationDescription curconfig : prjCDesc.getConfigurations()) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ public class Const {
5757
public static final String REMOTE_SUFFIX = "_remote";
5858

5959
// General stuff
60+
public static final String PLUGIN_ID = "io.sloeber.core";
6061
public static final String CORE_PLUGIN_ID = "io.sloeber.arduino.core";
6162
public static final String ARDUINO_NATURE_ID = "io.sloeber.arduinonature";
6263
public static final String KEY_LAST_USED_EXAMPLES = "Last used Examples";
6364
public static final String SLOEBER_HOME = "SLOEBER_HOME";
65+
public static final String LOCAL = "local";
6466

6567
// Folder and file Information
6668
public static final String ARDUINO_HARDWARE_FOLDER_NAME = HARDWARE;

io.sloeber.core/src/io/sloeber/core/managers/ToolDependency.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
*******************************************************************************/
88
package io.sloeber.core.managers;
99

10+
import static io.sloeber.core.Messages.*;
11+
1012
import org.eclipse.core.runtime.IProgressMonitor;
1113
import org.eclipse.core.runtime.IStatus;
1214
import org.eclipse.core.runtime.Status;
1315

1416
import io.sloeber.core.Activator;
15-
import io.sloeber.core.Messages;
1617

1718
public class ToolDependency {
1819

19-
private static final CharSequence NAME = Messages.NAME;
20-
private static final CharSequence VERSION =Messages.VERSION;
2120
private String packager;
2221
private String name;
2322
private String version;
@@ -55,7 +54,7 @@ public IStatus install(IProgressMonitor monitor) {
5554
Tool tool = getTool();
5655
if (tool == null) {
5756
return new Status(IStatus.ERROR, Activator.getId(),
58-
Messages.ToolDependency_Tool_not_found.replace(NAME, this.name).replace(VERSION, this.version));
57+
ToolDependency_Tool_not_found.replace(NAMEFIELD, this.name).replace(VERSION, this.version));
5958
}
6059
return tool.install(monitor);
6160
}

io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.sloeber.core.txt;
22

3+
import static io.sloeber.core.Messages.*;
4+
import static io.sloeber.core.common.Const.*;
5+
36
import java.io.File;
47
import java.util.ArrayList;
58
import java.util.Arrays;
@@ -8,19 +11,11 @@
811
import java.util.Map.Entry;
912
import java.util.Set;
1013

11-
import io.sloeber.core.Messages;
1214

1315
public class BoardTxtFile extends TxtFile {
1416

15-
private static final String MENUITEMNAME = Messages.MENUITEMNAME;
16-
private static final String MENUITEMID = Messages.MENUITEMID;
17-
private static final String MENUID = Messages.MENUID;
18-
private static final String BOARDID = Messages.BOARDID;
19-
private File providedTxtFile = null;
20-
2117
public BoardTxtFile(File boardsFile) {
2218
super(getActualTxtFile(boardsFile));
23-
providedTxtFile = boardsFile;
2419
}
2520

2621
private static File getActualTxtFile(File boardsFile) {
@@ -43,7 +38,7 @@ public String getMenuItemIDFromMenuItemName(String boardID, String menuID, Strin
4338
return curOption.getKey();
4439
}
4540
}
46-
return Messages.Boards_Get_menu_item_id_from_name_failed.replace(MENUITEMNAME, menuItemName)
41+
return Boards_Get_menu_item_id_from_name_failed.replace(MENUITEMNAME, menuItemName)
4742
.replace(MENUID, menuID).replace(BOARDID, boardID);
4843
}
4944

@@ -112,7 +107,7 @@ public String getMenuItemNameFromMenuItemID(String boardID, String menuID, Strin
112107
// if (curOption.getKey().equalsIgnoreCase(lookupValue))
113108
// return curOption.getValue();
114109
// }
115-
return Messages.Boards_Get_menu_item_name_from_id_did_not_find.replace(MENUITEMID, menuItemID)
110+
return Boards_Get_menu_item_name_from_id_did_not_find.replace(MENUITEMID, menuItemID)
116111
.replace(MENUID, menuID).replace(BOARDID, boardID);
117112
}
118113

@@ -125,7 +120,7 @@ public String getMenuNameFromID(String menuID) {
125120
}
126121
}
127122
}
128-
return Messages.Boards_menu_ID_not_found.replace(ID, menuID);
123+
return Boards_menu_ID_not_found.replace(ID, menuID);
129124
}
130125

131126
/**
@@ -154,10 +149,6 @@ public Map<String, String> getMenus() {
154149
return getSection(MENU);
155150
}
156151

157-
@Override
158-
public File getTxtFile() {
159-
return providedTxtFile;
160-
}
161152

162153
/**
163154
* this is public String[] getAllSectionNames (String[] toaddNames) with a empty
@@ -211,4 +202,5 @@ String[] getAllSectionNames(String[] toaddNames) {
211202
public Map<String, String> getAllBoardEnvironVars(String boardID) {
212203
return myData.getChild(boardID).toKeyValues(EMPTY, false);
213204
}
205+
214206
}

io.sloeber.core/src/io/sloeber/core/txt/PlatformTxtFile.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package io.sloeber.core.txt;
22

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

68
public class PlatformTxtFile extends TxtFile {
7-
private File providedTxtFile = null;
89

910
public PlatformTxtFile(File boardsFile) {
1011
super(getActualTxtFile(boardsFile));
11-
providedTxtFile = boardsFile;
1212
}
1313

1414
private static File getActualTxtFile(File platformFile) {
@@ -18,11 +18,6 @@ private static File getActualTxtFile(File platformFile) {
1818
return platformFile;
1919
}
2020

21-
@Override
22-
public File getTxtFile() {
23-
return providedTxtFile;
24-
}
25-
2621

2722
public Map<String, String> getAllEnvironVars() {
2823
return getAllEnvironVars(EMPTY);

0 commit comments

Comments
 (0)