Skip to content

Commit 7776ffa

Browse files
bitroncmaglie
authored andcommitted
Moved packages, currentDirectory and portableFolder (and related methods) from Base to BaseNoGui (work in progress).
1 parent 118826e commit 7776ffa

File tree

5 files changed

+148
-82
lines changed

5 files changed

+148
-82
lines changed

app/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import cc.arduino.packages.BoardPort;
3333
import cc.arduino.packages.Discovery;
3434
import cc.arduino.packages.discoverers.network.*;
35-
import processing.app.Base;
35+
import processing.app.BaseNoGui;
3636
import processing.app.helpers.NetUtils;
3737
import processing.app.helpers.PreferencesMap;
3838
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
@@ -140,7 +140,7 @@ public void serviceResolved(ServiceEvent serviceEvent) {
140140

141141
String label = name + " at " + address;
142142
if (board != null) {
143-
String boardName = Base.getPlatform().resolveDeviceByBoardID(Base.packages, board);
143+
String boardName = Base.getPlatform().resolveDeviceByBoardID(BaseNoGui.packages, board);
144144
label += " (" + boardName + ")";
145145
}
146146

app/src/cc/arduino/packages/discoverers/SerialDiscovery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434

35-
import processing.app.Base;
35+
import processing.app.BaseNoGui;
3636
import processing.app.Platform;
3737
import processing.app.Serial;
3838
import processing.app.helpers.PreferencesMap;
@@ -51,7 +51,7 @@ public List<BoardPort> discovery() {
5151
List<String> ports = Serial.list();
5252

5353
for (String port : ports) {
54-
String boardName = os.resolveDeviceAttachedTo(port, Base.packages, devicesListOutput);
54+
String boardName = os.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput);
5555
String label = port;
5656
if (boardName != null)
5757
label += " (" + boardName + ")";

app/src/processing/app/Base.java

Lines changed: 27 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import processing.app.debug.TargetBoard;
4141
import processing.app.debug.TargetPackage;
4242
import processing.app.debug.TargetPlatform;
43-
import processing.app.debug.TargetPlatformException;
4443
import processing.app.helpers.FileUtils;
4544
import processing.app.helpers.OSUtils;
4645
import processing.app.helpers.PreferencesMap;
@@ -100,14 +99,12 @@ public class Base {
10099
// found in the sketchbook)
101100
static public String librariesClassPath;
102101

103-
static public Map<String, TargetPackage> packages;
104-
105102
// Location for untitled items
106103
static File untitledFolder;
107104

108105
// Current directory to use for relative paths specified on the
109106
// commandline
110-
static String currentDirectory = System.getProperty("user.dir");
107+
static String currentDirectory = BaseNoGui.currentDirectory;
111108

112109
// p5 icon for the window
113110
// static Image icon;
@@ -116,7 +113,6 @@ public class Base {
116113
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
117114
Editor activeEditor;
118115

119-
static File portableFolder = null;
120116
static final String portableSketchbookFolder = "sketchbook";
121117

122118
static public void main(String args[]) throws Exception {
@@ -125,10 +121,7 @@ static public void main(String args[]) throws Exception {
125121

126122
initPlatform();
127123

128-
// Portable folder
129-
portableFolder = getContentFile("portable");
130-
if (!portableFolder.exists())
131-
portableFolder = null;
124+
BaseNoGui.initPortableFolder();
132125

133126
String preferencesFile = null;
134127

@@ -283,13 +276,7 @@ static protected void initRequirements() {
283276
// directory when starting the IDE (which is not the same as the
284277
// current working directory!).
285278
static public File absoluteFile(String path) {
286-
if (path == null) return null;
287-
288-
File file = new File(path);
289-
if (!file.isAbsolute()) {
290-
file = new File(currentDirectory, path);
291-
}
292-
return file;
279+
return BaseNoGui.absoluteFile(path);
293280
}
294281

295282
protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
@@ -304,8 +291,8 @@ public Base(String[] args) throws Exception {
304291
// If it doesn't, warn the user that the sketchbook folder is being reset.
305292
if (sketchbookPath != null) {
306293
File sketchbookFolder;
307-
if (portableFolder != null)
308-
sketchbookFolder = new File(portableFolder, sketchbookPath);
294+
if (BaseNoGui.getPortableFolder() != null)
295+
sketchbookFolder = new File(BaseNoGui.getPortableFolder(), sketchbookPath);
309296
else
310297
sketchbookFolder = Base.absoluteFile(sketchbookPath);
311298
if (!sketchbookFolder.exists()) {
@@ -322,7 +309,7 @@ public Base(String[] args) throws Exception {
322309
// If no path is set, get the default sketchbook folder for this platform
323310
if (sketchbookPath == null) {
324311
File defaultFolder = getDefaultSketchbookFolder();
325-
if (portableFolder != null)
312+
if (BaseNoGui.getPortableFolder() != null)
326313
Preferences.set("sketchbook.path", portableSketchbookFolder);
327314
else
328315
Preferences.set("sketchbook.path", defaultFolder.getAbsolutePath());
@@ -331,13 +318,7 @@ public Base(String[] args) throws Exception {
331318
}
332319
}
333320

334-
packages = new HashMap<String, TargetPackage>();
335-
loadHardware(getHardwareFolder());
336-
loadHardware(getSketchbookHardwareFolder());
337-
if (packages.size() == 0) {
338-
System.out.println(_("No valid configured cores found! Exiting..."));
339-
System.exit(3);
340-
}
321+
BaseNoGui.initPackages();
341322

342323
// Setup board-dependent variables.
343324
onBoardOrPortChange();
@@ -643,8 +624,8 @@ protected boolean restoreSketches() throws Exception {
643624
int opened = 0;
644625
for (int i = 0; i < count; i++) {
645626
String path = Preferences.get("last.sketch" + i + ".path");
646-
if (portableFolder != null) {
647-
File absolute = new File(portableFolder, path);
627+
if (BaseNoGui.getPortableFolder() != null) {
628+
File absolute = new File(BaseNoGui.getPortableFolder(), path);
648629
try {
649630
path = absolute.getCanonicalPath();
650631
} catch (IOException e) {
@@ -689,8 +670,8 @@ protected void storeSketches() {
689670
!editor.getSketch().isModified()) {
690671
continue;
691672
}
692-
if (portableFolder != null) {
693-
path = FileUtils.relativePath(portableFolder.toString(), path);
673+
if (BaseNoGui.getPortableFolder() != null) {
674+
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
694675
if (path == null)
695676
continue;
696677
}
@@ -713,8 +694,8 @@ protected void storeSketchPath(Editor editor, int index) {
713694
if (path.startsWith(untitledPath)) {
714695
path = "";
715696
} else
716-
if (portableFolder != null) {
717-
path = FileUtils.relativePath(portableFolder.toString(), path);
697+
if (BaseNoGui.getPortableFolder() != null) {
698+
path = FileUtils.relativePath(BaseNoGui.getPortableFolder().toString(), path);
718699
if (path == null)
719700
path = "";
720701
}
@@ -1456,15 +1437,15 @@ public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
14561437

14571438
// Generate custom menus for all platforms
14581439
Set<String> titles = new HashSet<String>();
1459-
for (TargetPackage targetPackage : packages.values()) {
1440+
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
14601441
for (TargetPlatform targetPlatform : targetPackage.platforms())
14611442
titles.addAll(targetPlatform.getCustomMenus().values());
14621443
}
14631444
for (String title : titles)
14641445
makeBoardCustomMenu(toolsMenu, _(title));
14651446

14661447
// Cycle through all packages
1467-
for (TargetPackage targetPackage : packages.values()) {
1448+
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
14681449
// For every package cycle through all platform
14691450
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
14701451

@@ -1674,7 +1655,7 @@ public static void selectSerialPort(String port) {
16741655
public void rebuildProgrammerMenu(JMenu menu) {
16751656
menu.removeAll();
16761657
ButtonGroup group = new ButtonGroup();
1677-
for (TargetPackage targetPackage : packages.values()) {
1658+
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
16781659
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
16791660
for (String programmer : targetPlatform.getProgrammers().keySet()) {
16801661
String id = targetPackage.getId() + ":" + programmer;
@@ -1860,30 +1841,7 @@ static public String[] headerListFromIncludePath(File path) throws IOException {
18601841
}
18611842

18621843
protected void loadHardware(File folder) {
1863-
if (!folder.isDirectory()) return;
1864-
1865-
String list[] = folder.list(new OnlyDirs());
1866-
1867-
// if a bad folder or something like that, this might come back null
1868-
if (list == null) return;
1869-
1870-
// alphabetize list, since it's not always alpha order
1871-
// replaced hella slow bubble sort with this feller for 0093
1872-
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
1873-
1874-
for (String target : list) {
1875-
// Skip reserved 'tools' folder.
1876-
if (target.equals("tools"))
1877-
continue;
1878-
File subfolder = new File(folder, target);
1879-
1880-
try {
1881-
packages.put(target, new TargetPackage(target, subfolder));
1882-
} catch (TargetPlatformException e) {
1883-
System.out.println("WARNING: Error loading hardware folder " + target);
1884-
System.out.println(" " + e.getMessage());
1885-
}
1886-
}
1844+
BaseNoGui.loadHardware(folder);
18871845
}
18881846

18891847

@@ -1987,8 +1945,8 @@ static public String getPlatformName() {
19871945

19881946

19891947
static public File getSettingsFolder() {
1990-
if (portableFolder != null)
1991-
return portableFolder;
1948+
if (BaseNoGui.getPortableFolder() != null)
1949+
return BaseNoGui.getPortableFolder();
19921950

19931951
File settingsFolder = null;
19941952

@@ -2120,7 +2078,7 @@ static public String getAvrBasePath() {
21202078
* @return
21212079
*/
21222080
static public TargetPackage getTargetPackage(String packageName) {
2123-
return packages.get(packageName);
2081+
return BaseNoGui.packages.get(packageName);
21242082
}
21252083

21262084
/**
@@ -2129,9 +2087,7 @@ static public TargetPackage getTargetPackage(String packageName) {
21292087
* @return
21302088
*/
21312089
static public TargetPlatform getTargetPlatform() {
2132-
String packageName = Preferences.get("target_package");
2133-
String platformName = Preferences.get("target_platform");
2134-
return getTargetPlatform(packageName, platformName);
2090+
return BaseNoGui.getTargetPlatform();
21352091
}
21362092

21372093
/**
@@ -2143,10 +2099,7 @@ static public TargetPlatform getTargetPlatform() {
21432099
*/
21442100
static public TargetPlatform getTargetPlatform(String packageName,
21452101
String platformName) {
2146-
TargetPackage p = packages.get(packageName);
2147-
if (p == null)
2148-
return null;
2149-
return p.get(platformName);
2102+
return BaseNoGui.getTargetPlatform(packageName, platformName);
21502103
}
21512104

21522105
static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
@@ -2176,7 +2129,7 @@ public static TargetBoard getTargetBoard() {
21762129
}
21772130

21782131
static public File getPortableFolder() {
2179-
return portableFolder;
2132+
return BaseNoGui.getPortableFolder();
21802133
}
21812134

21822135

@@ -2186,9 +2139,7 @@ static public String getPortableSketchbookFolder() {
21862139

21872140

21882141
static public File getSketchbookFolder() {
2189-
if (portableFolder != null)
2190-
return new File(portableFolder, Preferences.get("sketchbook.path"));
2191-
return absoluteFile(Preferences.get("sketchbook.path"));
2142+
return BaseNoGui.getSketchbookFolder();
21922143
}
21932144

21942145

@@ -2215,13 +2166,13 @@ static public String getSketchbookLibrariesPath() {
22152166

22162167

22172168
static public File getSketchbookHardwareFolder() {
2218-
return new File(getSketchbookFolder(), "hardware");
2169+
return BaseNoGui.getSketchbookHardwareFolder();
22192170
}
22202171

22212172

22222173
protected File getDefaultSketchbookFolder() {
2223-
if (portableFolder != null)
2224-
return new File(portableFolder, portableSketchbookFolder);
2174+
if (BaseNoGui.getPortableFolder() != null)
2175+
return new File(BaseNoGui.getPortableFolder(), portableSketchbookFolder);
22252176

22262177
File sketchbookFolder = null;
22272178
try {

0 commit comments

Comments
 (0)