1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Moved some initialization code from Base to BaseNoGui.

This commit is contained in:
Claudio Indellicati 2014-08-21 18:43:13 +02:00 committed by Cristian Maglie
parent e83462b508
commit 1bb2da83c1
2 changed files with 66 additions and 51 deletions

View File

@ -28,14 +28,9 @@ import java.io.*;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*; import javax.swing.*;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.commons.logging.impl.NoOpLog;
import cc.arduino.packages.DiscoveryManager; import cc.arduino.packages.DiscoveryManager;
import processing.app.debug.TargetBoard; import processing.app.debug.TargetBoard;
import processing.app.debug.TargetPackage; import processing.app.debug.TargetPackage;
@ -108,52 +103,17 @@ public class Base {
static final String portableSketchbookFolder = "sketchbook"; static final String portableSketchbookFolder = "sketchbook";
static public void main(String args[]) throws Exception { static public void main(String args[]) throws Exception {
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName()); BaseNoGui.initLogger();
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
initPlatform(); initPlatform();
BaseNoGui.initPortableFolder(); BaseNoGui.initPortableFolder();
String preferencesFile = null; BaseNoGui.prescanParameters(args);
// Do a first pass over the commandline arguments, the rest of them BaseNoGui.initVersion();
// will be processed by the Base constructor. Note that this loop VERSION_NAME = BaseNoGui.VERSION_NAME;
// does not look at the last element of args, to prevent crashing RELEASE = BaseNoGui.RELEASE;
// when no parameter was specified to an option. Later, Base() will
// then show an error for these.
for (int i = 0; i < args.length - 1; i++) {
if (args[i].equals("--preferences-file")) {
++i;
preferencesFile = args[i];
continue;
}
if (args[i].equals("--curdir")) {
i++;
currentDirectory = args[i];
continue;
}
}
// run static initialization that grabs all the prefs
Preferences.init(absoluteFile(preferencesFile));
try {
File versionFile = getContentFile("lib/version.txt");
if (versionFile.exists()) {
String version = PApplet.loadStrings(versionFile)[0];
if (!version.equals(VERSION_NAME) && !version.equals("${version}")) {
VERSION_NAME = version;
RELEASE = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
// help 3rd party installers find the correct hardware path
Preferences.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
Preferences.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
// if (System.getProperty("mrj.version") != null) { // if (System.getProperty("mrj.version") != null) {
// //String jv = System.getProperty("java.version"); // //String jv = System.getProperty("java.version");
@ -204,7 +164,7 @@ public class Base {
// Set the look and feel before opening the window // Set the look and feel before opening the window
try { try {
BaseNoGui.getPlatform().setLookAndFeel(); getPlatform().setLookAndFeel();
} catch (Exception e) { } catch (Exception e) {
String mess = e.getMessage(); String mess = e.getMessage();
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) { if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
@ -260,7 +220,7 @@ public class Base {
protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF }; protected static enum ACTION { GUI, NOOP, VERIFY, UPLOAD, GET_PREF };
public Base(String[] args) throws Exception { public Base(String[] args) throws Exception {
BaseNoGui.getPlatform().init(this); getPlatform().init(this);
// Get the sketchbook path, and make sure it's set properly // Get the sketchbook path, and make sure it's set properly
String sketchbookPath = Preferences.get("sketchbook.path"); String sketchbookPath = Preferences.get("sketchbook.path");
@ -1901,7 +1861,7 @@ public class Base {
} else { } else {
try { try {
settingsFolder = BaseNoGui.getPlatform().getSettingsFolder(); settingsFolder = getPlatform().getSettingsFolder();
} catch (Exception e) { } catch (Exception e) {
showError(_("Problem getting data folder"), showError(_("Problem getting data folder"),
_("Error getting the Arduino data folder."), e); _("Error getting the Arduino data folder."), e);
@ -2108,7 +2068,7 @@ public class Base {
File sketchbookFolder = null; File sketchbookFolder = null;
try { try {
sketchbookFolder = BaseNoGui.getPlatform().getDefaultSketchbookFolder(); sketchbookFolder = getPlatform().getDefaultSketchbookFolder();
} catch (Exception e) { } } catch (Exception e) { }
if (sketchbookFolder == null) { if (sketchbookFolder == null) {
@ -2164,7 +2124,7 @@ public class Base {
*/ */
static public void openURL(String url) { static public void openURL(String url) {
try { try {
BaseNoGui.getPlatform().openURL(url); getPlatform().openURL(url);
} catch (Exception e) { } catch (Exception e) {
showWarning(_("Problem Opening URL"), showWarning(_("Problem Opening URL"),

View File

@ -5,9 +5,15 @@ import static processing.app.I18n._;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.commons.logging.impl.NoOpLog;
import processing.app.debug.TargetBoard; import processing.app.debug.TargetBoard;
import processing.app.debug.TargetPackage; import processing.app.debug.TargetPackage;
@ -184,6 +190,11 @@ public class BaseNoGui {
return list; return list;
} }
static public void initLogger() {
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
Logger.getLogger("javax.jmdns").setLevel(Level.OFF);
}
static public void initPackages() { static public void initPackages() {
packages = new HashMap<String, TargetPackage>(); packages = new HashMap<String, TargetPackage>();
loadHardware(getHardwareFolder()); loadHardware(getHardwareFolder());
@ -219,6 +230,25 @@ public class BaseNoGui {
portableFolder = null; portableFolder = null;
} }
static public void initVersion() {
try {
File versionFile = getContentFile("lib/version.txt");
if (versionFile.exists()) {
String version = PApplet.loadStrings(versionFile)[0];
if (!version.equals(VERSION_NAME) && !version.equals("${version}")) {
VERSION_NAME = version;
RELEASE = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
// help 3rd party installers find the correct hardware path
Preferences.set("last.ide." + VERSION_NAME + ".hardwarepath", getHardwarePath());
Preferences.set("last.ide." + VERSION_NAME + ".daterun", "" + (new Date()).getTime() / 1000);
}
static protected void loadHardware(File folder) { static protected void loadHardware(File folder) {
if (!folder.isDirectory()) return; if (!folder.isDirectory()) return;
@ -250,6 +280,31 @@ public class BaseNoGui {
importToLibraryTable = new HashMap<String, Library>(); importToLibraryTable = new HashMap<String, Library>();
} }
static public void prescanParameters(String args[]) {
String preferencesFile = null;
// Do a first pass over the commandline arguments, the rest of them
// will be processed by the Base constructor. Note that this loop
// does not look at the last element of args, to prevent crashing
// when no parameter was specified to an option. Later, Base() will
// then show an error for these.
for (int i = 0; i < args.length - 1; i++) {
if (args[i].equals("--preferences-file")) {
++i;
preferencesFile = args[i];
continue;
}
if (args[i].equals("--curdir")) {
i++;
currentDirectory = args[i];
continue;
}
}
// run static initialization that grabs all the prefs
Preferences.init(absoluteFile(preferencesFile));
}
/** /**
* Spew the contents of a String object out to a file. * Spew the contents of a String object out to a file.
*/ */