Skip to content

Commit 9024fe4

Browse files
committed
When using cores from other packages also the referenced platforms.txt is imported
See #1157
1 parent acc477a commit 9024fe4

File tree

8 files changed

+338
-144
lines changed

8 files changed

+338
-144
lines changed

app/src/processing/app/Base.java

Lines changed: 183 additions & 103 deletions
Large diffs are not rendered by default.

app/src/processing/app/Editor.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class Editor extends JFrame implements RunnerListener {
150150
Runnable exportAppHandler;
151151

152152

153-
public Editor(Base ibase, String path, int[] location) {
153+
public Editor(Base ibase, String path, int[] location) throws Exception {
154154
super("Arduino");
155155
this.base = ibase;
156156

@@ -476,7 +476,7 @@ protected void applyPreferences() {
476476
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
477477

478478

479-
protected void buildMenuBar() {
479+
protected void buildMenuBar() throws Exception {
480480
JMenuBar menubar = new JMenuBar();
481481
menubar.add(buildFileMenu());
482482
menubar.add(buildEditMenu());
@@ -494,15 +494,23 @@ protected JMenu buildFileMenu() {
494494
item = newJMenuItem(_("New"), 'N');
495495
item.addActionListener(new ActionListener() {
496496
public void actionPerformed(ActionEvent e) {
497-
base.handleNew();
497+
try {
498+
base.handleNew();
499+
} catch (Exception e1) {
500+
e1.printStackTrace();
501+
}
498502
}
499503
});
500504
fileMenu.add(item);
501505

502506
item = Editor.newJMenuItem(_("Open..."), 'O');
503507
item.addActionListener(new ActionListener() {
504508
public void actionPerformed(ActionEvent e) {
505-
base.handleOpenPrompt();
509+
try {
510+
base.handleOpenPrompt();
511+
} catch (Exception e1) {
512+
e1.printStackTrace();
513+
}
506514
}
507515
});
508516
fileMenu.add(item);
@@ -662,7 +670,7 @@ public void actionPerformed(ActionEvent e) {
662670
}
663671

664672

665-
protected JMenu buildToolsMenu() {
673+
protected JMenu buildToolsMenu() throws Exception {
666674
toolsMenu = new JMenu(_("Tools"));
667675
JMenu menu = toolsMenu;
668676
JMenuItem item;
@@ -690,6 +698,11 @@ public void actionPerformed(ActionEvent e) {
690698

691699
if (boardsMenus == null) {
692700
boardsMenus = new LinkedList<JMenu>();
701+
702+
JMenu boardsMenu = new JMenu(_("Board"));
703+
Editor.boardsMenus.add(boardsMenu);
704+
toolsMenu.add(boardsMenu);
705+
693706
base.rebuildBoardsMenu(toolsMenu, this);
694707
//Debug: rebuild imports
695708
importMenu.removeAll();

app/src/processing/app/EditorToolbar.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,13 @@ public void mousePressed(MouseEvent e) {
335335

336336
case NEW:
337337
if (shiftPressed) {
338-
editor.base.handleNew();
338+
try {
339+
editor.base.handleNew();
340+
} catch (Exception e1) {
341+
e1.printStackTrace();
342+
}
339343
} else {
340-
editor.base.handleNewReplace();
344+
editor.base.handleNewReplace();
341345
}
342346
break;
343347

app/src/processing/app/debug/Compiler.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ private PreferencesMap createBuildPreferences(String _buildPath,
132132
throw re;
133133
}
134134

135-
TargetPlatform targetPlatform = Base.getTargetPlatform();
135+
TargetBoard targetBoard = Base.getTargetBoard();
136+
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
136137

137138
// Merge all the global preference configuration in order of priority
138139
PreferencesMap p = new PreferencesMap();
139140
p.putAll(Preferences.getMap());
140-
p.putAll(targetPlatform.getPreferences());
141+
p.putAll(targetBoard.getMergedPlatformPreferences());
141142
p.putAll(Base.getBoardPreferences());
142143
for (String k : p.keySet()) {
143144
if (p.get(k) == null)
@@ -146,28 +147,23 @@ private PreferencesMap createBuildPreferences(String _buildPath,
146147

147148
p.put("build.path", _buildPath);
148149
p.put("build.project_name", _primaryClassName);
149-
targetArch = targetPlatform.getName();
150+
targetArch = targetPlatform.getId();
150151
p.put("build.arch", targetArch.toUpperCase());
151152

152153
if (!p.containsKey("compiler.path"))
153154
p.put("compiler.path", Base.getAvrBasePath());
154155

155156
// Core folder
156-
String core = p.get("build.core");
157-
TargetPlatform tp;
158-
if (!core.contains(":")) {
159-
tp = targetPlatform;
160-
} else {
161-
String[] split = core.split(":", 2);
162-
tp = Base.getTargetPlatform(split[0], Preferences.get("target_platform"));
163-
core = split[1];
164-
}
157+
TargetPlatform tp = targetBoard.getReferencedPlatform();
158+
if (tp == null)
159+
tp = targetBoard.getContainerPlatform();
165160
File coreFolder = new File(tp.getFolder(), "cores");
161+
String core = p.get("build.core");
166162
coreFolder = new File(coreFolder, core);
167163
p.put("build.core.path", coreFolder.getAbsolutePath());
168164

169165
// System Folder
170-
File systemFolder = targetPlatform.getFolder();
166+
File systemFolder = tp.getFolder();
171167
systemFolder = new File(systemFolder, "system");
172168
p.put("build.system.path", systemFolder.getAbsolutePath());
173169

app/src/processing/app/debug/TargetBoard.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package processing.app.debug;
22

3+
import static processing.app.I18n._;
4+
import static processing.app.I18n.format;
5+
36
import java.util.LinkedHashMap;
47
import java.util.Map;
8+
import java.util.Set;
59

610
import processing.app.helpers.PreferencesMap;
711

@@ -10,20 +14,35 @@ public class TargetBoard {
1014
private String id;
1115
private PreferencesMap prefs;
1216
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
17+
private TargetPlatform containerPlatform;
18+
19+
private String referencedPackageId;
20+
private TargetPlatform referencedPlatform;
21+
private TargetPackage referencedPackage;
1322

1423
/**
1524
* Create a TargetBoard based on preferences passed as argument.
1625
*
1726
* @param _prefs
1827
* @return
1928
*/
20-
public TargetBoard(String _id, PreferencesMap _prefs) {
29+
public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
30+
containerPlatform = parent;
2131
id = _id;
2232
prefs = new PreferencesMap(_prefs);
2333

34+
// Setup sub-menus
2435
PreferencesMap menus = prefs.firstLevelMap().get("menu");
2536
if (menus != null)
2637
menuOptions = menus.firstLevelMap();
38+
39+
// Setup referenced platform
40+
String core = prefs.get("build.core");
41+
if (core.contains(":")) {
42+
String[] split = core.split(":");
43+
referencedPackageId = split[0];
44+
prefs.put("build.core", split[1]);
45+
}
2746
}
2847

2948
/**
@@ -44,6 +63,15 @@ public String getId() {
4463
return id;
4564
}
4665

66+
/**
67+
* Get the package this board refers to
68+
*
69+
* @return
70+
*/
71+
public String getReferencedPackageId() {
72+
return referencedPackageId;
73+
}
74+
4775
/**
4876
* Get the full preferences map of the board with a given identifier
4977
*
@@ -88,6 +116,10 @@ public String getMenuLabel(String menuId, String selectionId) {
88116
return getMenuLabels(menuId).get(selectionId);
89117
}
90118

119+
public Set<String> getMenuIds() {
120+
return menuOptions.keySet();
121+
}
122+
91123
/**
92124
* Returns the configuration parameters to override (as a PreferenceMap) when
93125
* the specified option in the specified menu is selected
@@ -98,7 +130,46 @@ public String getMenuLabel(String menuId, String selectionId) {
98130
* The option ID
99131
* @return
100132
*/
101-
public PreferencesMap getMenuConfiguration(String menuId, String selectionId) {
133+
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
102134
return menuOptions.get(menuId).subTree(selectionId);
103135
}
136+
137+
public TargetPlatform getContainerPlatform() {
138+
return containerPlatform;
139+
}
140+
141+
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
142+
throws Exception {
143+
if (referencedPackageId == null)
144+
return;
145+
146+
if (!packages.containsKey(referencedPackageId))
147+
throw new Exception(
148+
format(_("Can't find referenced package ({1}) for board {0}"), id,
149+
referencedPackageId));
150+
referencedPackage = packages.get(referencedPackageId);
151+
152+
Map<String, TargetPlatform> platforms = referencedPackage.getPlatforms();
153+
154+
String ourPlatformId = getContainerPlatform().getId();
155+
if (!platforms.containsKey(ourPlatformId))
156+
throw new Exception(
157+
format(_("Can't find referenced package ({1}) for board {0}"), id,
158+
referencedPackageId));
159+
referencedPlatform = platforms.get(ourPlatformId);
160+
}
161+
162+
public TargetPlatform getReferencedPlatform() {
163+
return referencedPlatform;
164+
}
165+
166+
public PreferencesMap getMergedPlatformPreferences() {
167+
PreferencesMap res = new PreferencesMap();
168+
if (referencedPlatform != null)
169+
res.putAll(referencedPlatform.getPreferences());
170+
if (containerPlatform.getPreferences() != null)
171+
res.putAll(containerPlatform.getPreferences());
172+
return res;
173+
}
174+
104175
}

app/src/processing/app/debug/TargetPackage.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,22 @@
3232

3333
public class TargetPackage {
3434

35-
private String name;
35+
private String id;
3636

3737
Map<String, TargetPlatform> platforms = new LinkedHashMap<String, TargetPlatform>();
3838

39-
public TargetPackage(String packageName, File packageFolder)
40-
throws TargetPlatformException {
41-
name = packageName;
39+
public TargetPackage(String _id, File _folder) throws TargetPlatformException {
40+
id = _id;
4241

43-
File[] folders = packageFolder.listFiles(new OnlyDirs());
42+
File[] folders = _folder.listFiles(new OnlyDirs());
4443
if (folders == null)
4544
return;
4645

47-
for (File folder : folders) {
48-
if (!folder.exists() || !folder.canRead())
46+
for (File subFolder : folders) {
47+
if (!subFolder.exists() || !subFolder.canRead())
4948
continue;
50-
String arch = folder.getName();
51-
TargetPlatform platform = new TargetPlatform(arch, folder);
49+
String arch = subFolder.getName();
50+
TargetPlatform platform = new TargetPlatform(arch, subFolder, this);
5251
platforms.put(arch, platform);
5352
}
5453
}
@@ -65,7 +64,13 @@ public TargetPlatform get(String platform) {
6564
return platforms.get(platform);
6665
}
6766

68-
public String getName() {
69-
return name;
67+
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
68+
throws Exception {
69+
for (TargetPlatform platform : getPlatforms().values())
70+
platform.resolveReferencedPlatforms(packages);
71+
}
72+
73+
public String getId() {
74+
return id;
7075
}
7176
}

app/src/processing/app/debug/TargetPlatform.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636

3737
public class TargetPlatform {
3838

39-
private String name;
39+
private String id;
4040
private File folder;
41+
private TargetPackage containerPackage;
4142

4243
/**
4344
* Contains preferences for every defined board
@@ -59,10 +60,12 @@ public class TargetPlatform {
5960
*/
6061
private PreferencesMap customMenus = new PreferencesMap();
6162

62-
public TargetPlatform(String _name, File _folder)
63+
public TargetPlatform(String _name, File _folder, TargetPackage parent)
6364
throws TargetPlatformException {
64-
name = _name;
65+
66+
id = _name;
6567
folder = _folder;
68+
containerPackage = parent;
6669

6770
// If there is no boards.txt, this is not a valid 1.5 hardware folder
6871
File boardsFile = new File(folder, "boards.txt");
@@ -85,7 +88,7 @@ public TargetPlatform(String _name, File _folder)
8588
// Create boards
8689
for (String id : boardsPreferences.keySet()) {
8790
PreferencesMap preferences = boardsPreferences.get(id);
88-
TargetBoard board = new TargetBoard(id, preferences);
91+
TargetBoard board = new TargetBoard(id, preferences, this);
8992
boards.put(id, board);
9093
}
9194
} catch (IOException e) {
@@ -116,8 +119,8 @@ public TargetPlatform(String _name, File _folder)
116119
}
117120
}
118121

119-
public String getName() {
120-
return name;
122+
public String getId() {
123+
return id;
121124
}
122125

123126
public File getFolder() {
@@ -132,7 +135,7 @@ public PreferencesMap getCustomMenus() {
132135
return customMenus;
133136
}
134137

135-
public Set<String> getCustomMenusKeys() {
138+
public Set<String> getCustomMenuIds() {
136139
return customMenus.keySet();
137140
}
138141

@@ -155,4 +158,22 @@ public PreferencesMap getPreferences() {
155158
public TargetBoard getBoard(String boardId) {
156159
return boards.get(boardId);
157160
}
161+
162+
public TargetPackage getContainerPackage() {
163+
return containerPackage;
164+
}
165+
166+
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
167+
throws Exception {
168+
for (TargetBoard board : getBoards().values())
169+
board.resolveReferencedPlatforms(packages);
170+
}
171+
172+
@Override
173+
public String toString() {
174+
String res = "TargetPlatform: name=" + id + " boards={\n";
175+
for (String boardId : boards.keySet())
176+
res += " " + boardId + " = " + boards.get(boardId) + "\n";
177+
return res + "}";
178+
}
158179
}

app/src/processing/app/macosx/ThinkDifferent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ public void handleOpenApplication(ApplicationEvent ae) {
9696
public void handleOpenFile(ApplicationEvent ae) {
9797
// System.out.println("got open file event " + ae.getFilename());
9898
String filename = ae.getFilename();
99-
base.handleOpen(filename);
99+
try {
100+
base.handleOpen(filename);
101+
} catch (Exception e) {
102+
e.printStackTrace();
103+
}
100104
ae.setHandled(true);
101105
}
102106

0 commit comments

Comments
 (0)