Skip to content

Commit 1bb2da8

Browse files
bitroncmaglie
authored andcommitted
Moved some initialization code from Base to BaseNoGui.
1 parent e83462b commit 1bb2da8

File tree

2 files changed

+66
-51
lines changed

2 files changed

+66
-51
lines changed

app/src/processing/app/Base.java

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@
2828
import java.util.*;
2929
import java.util.List;
3030
import java.util.concurrent.ConcurrentHashMap;
31-
import java.util.logging.Level;
32-
import java.util.logging.Logger;
3331

3432
import javax.swing.*;
3533

36-
import org.apache.commons.logging.impl.LogFactoryImpl;
37-
import org.apache.commons.logging.impl.NoOpLog;
38-
3934
import cc.arduino.packages.DiscoveryManager;
4035
import processing.app.debug.TargetBoard;
4136
import processing.app.debug.TargetPackage;
@@ -108,52 +103,17 @@ public class Base {
108103
static final String portableSketchbookFolder = "sketchbook";
109104

110105
static public void main(String args[]) throws Exception {
111-
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
112-
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
106+
BaseNoGui.initLogger();
113107

114108
initPlatform();
115109

116110
BaseNoGui.initPortableFolder();
117111

118-
String preferencesFile = null;
119-
120-
// Do a first pass over the commandline arguments, the rest of them
121-
// will be processed by the Base constructor. Note that this loop
122-
// does not look at the last element of args, to prevent crashing
123-
// when no parameter was specified to an option. Later, Base() will
124-
// then show an error for these.
125-
for (int i = 0; i < args.length - 1; i++) {
126-
if (args[i].equals("--preferences-file")) {
127-
++i;
128-
preferencesFile = args[i];
129-
continue;
130-
}
131-
if (args[i].equals("--curdir")) {
132-
i++;
133-
currentDirectory = args[i];
134-
continue;
135-
}
136-
}
137-
138-
// run static initialization that grabs all the prefs
139-
Preferences.init(absoluteFile(preferencesFile));
140-
141-
try {
142-
File versionFile = getContentFile("lib/version.txt");
143-
if (versionFile.exists()) {
144-
String version = PApplet.loadStrings(versionFile)[0];
145-
if (!version.equals(VERSION_NAME) && !version.equals("${version}")) {
146-
VERSION_NAME = version;
147-
RELEASE = true;
148-
}
149-
}
150-
} catch (Exception e) {
151-
e.printStackTrace();
152-
}
153-
154-
// help 3rd party installers find the correct hardware path
155-
Preferences.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
156-
Preferences.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
112+
BaseNoGui.prescanParameters(args);
113+
114+
BaseNoGui.initVersion();
115+
VERSION_NAME = BaseNoGui.VERSION_NAME;
116+
RELEASE = BaseNoGui.RELEASE;
157117

158118
// if (System.getProperty("mrj.version") != null) {
159119
// //String jv = System.getProperty("java.version");
@@ -204,7 +164,7 @@ static public void main(String args[]) throws Exception {
204164

205165
// Set the look and feel before opening the window
206166
try {
207-
BaseNoGui.getPlatform().setLookAndFeel();
167+
getPlatform().setLookAndFeel();
208168
} catch (Exception e) {
209169
String mess = e.getMessage();
210170
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
@@ -260,7 +220,7 @@ static public File absoluteFile(String path) {
260220
protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
261221

262222
public Base(String[] args) throws Exception {
263-
BaseNoGui.getPlatform().init(this);
223+
getPlatform().init(this);
264224

265225
// Get the sketchbook path, and make sure it's set properly
266226
String sketchbookPath = Preferences.get("sketchbook.path");
@@ -1901,7 +1861,7 @@ static public File getSettingsFolder() {
19011861

19021862
} else {
19031863
try {
1904-
settingsFolder = BaseNoGui.getPlatform().getSettingsFolder();
1864+
settingsFolder = getPlatform().getSettingsFolder();
19051865
} catch (Exception e) {
19061866
showError(_("Problem getting data folder"),
19071867
_("Error getting the Arduino data folder."), e);
@@ -2108,7 +2068,7 @@ protected File getDefaultSketchbookFolder() {
21082068

21092069
File sketchbookFolder = null;
21102070
try {
2111-
sketchbookFolder = BaseNoGui.getPlatform().getDefaultSketchbookFolder();
2071+
sketchbookFolder = getPlatform().getDefaultSketchbookFolder();
21122072
} catch (Exception e) { }
21132073

21142074
if (sketchbookFolder == null) {
@@ -2164,7 +2124,7 @@ static protected File promptSketchbookLocation() {
21642124
*/
21652125
static public void openURL(String url) {
21662126
try {
2167-
BaseNoGui.getPlatform().openURL(url);
2127+
getPlatform().openURL(url);
21682128

21692129
} catch (Exception e) {
21702130
showWarning(_("Problem Opening URL"),

app/src/processing/app/BaseNoGui.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
import java.io.File;
66
import java.io.IOException;
77
import java.util.Arrays;
8+
import java.util.Date;
89
import java.util.HashMap;
910
import java.util.List;
1011
import java.util.Map;
12+
import java.util.logging.Level;
13+
import java.util.logging.Logger;
14+
15+
import org.apache.commons.logging.impl.LogFactoryImpl;
16+
import org.apache.commons.logging.impl.NoOpLog;
1117

1218
import processing.app.debug.TargetBoard;
1319
import processing.app.debug.TargetPackage;
@@ -184,6 +190,11 @@ static public String[] headerListFromIncludePath(File path) throws IOException {
184190
return list;
185191
}
186192

193+
static public void initLogger() {
194+
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
195+
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
196+
}
197+
187198
static public void initPackages() {
188199
packages = new HashMap<String, TargetPackage>();
189200
loadHardware(getHardwareFolder());
@@ -219,6 +230,25 @@ static public void initPortableFolder() {
219230
portableFolder = null;
220231
}
221232

233+
static public void initVersion() {
234+
try {
235+
File versionFile = getContentFile("lib/version.txt");
236+
if (versionFile.exists()) {
237+
String version = PApplet.loadStrings(versionFile)[0];
238+
if (!version.equals(VERSION_NAME) && !version.equals("${version}")) {
239+
VERSION_NAME = version;
240+
RELEASE = true;
241+
}
242+
}
243+
} catch (Exception e) {
244+
e.printStackTrace();
245+
}
246+
247+
// help 3rd party installers find the correct hardware path
248+
Preferences.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
249+
Preferences.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
250+
}
251+
222252
static protected void loadHardware(File folder) {
223253
if (!folder.isDirectory()) return;
224254

@@ -250,6 +280,31 @@ static public void newImportToLibraryTable() {
250280
importToLibraryTable = new HashMap<String, Library>();
251281
}
252282

283+
static public void prescanParameters(String args[]) {
284+
String preferencesFile = null;
285+
286+
// Do a first pass over the commandline arguments, the rest of them
287+
// will be processed by the Base constructor. Note that this loop
288+
// does not look at the last element of args, to prevent crashing
289+
// when no parameter was specified to an option. Later, Base() will
290+
// then show an error for these.
291+
for (int i = 0; i < args.length - 1; i++) {
292+
if (args[i].equals("--preferences-file")) {
293+
++i;
294+
preferencesFile = args[i];
295+
continue;
296+
}
297+
if (args[i].equals("--curdir")) {
298+
i++;
299+
currentDirectory = args[i];
300+
continue;
301+
}
302+
}
303+
304+
// run static initialization that grabs all the prefs
305+
Preferences.init(absoluteFile(preferencesFile));
306+
}
307+
253308
/**
254309
* Spew the contents of a String object out to a file.
255310
*/

0 commit comments

Comments
 (0)