Skip to content

Commit ab7b735

Browse files
author
Federico Fissore
committed
Removed lots of calls to BaseNoGui.getPlatform(): static is evil
1 parent 46e065b commit ab7b735

File tree

11 files changed

+84
-136
lines changed

11 files changed

+84
-136
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import cc.arduino.contributions.ui.*;
3838
import cc.arduino.utils.Progress;
3939
import com.google.common.base.Predicate;
40+
import processing.app.BaseNoGui;
41+
import processing.app.Platform;
4042

4143
import javax.swing.*;
4244
import java.awt.*;
@@ -49,8 +51,9 @@
4951
@SuppressWarnings("serial")
5052
public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
5153

52-
private LibrariesIndexer indexer;
5354
private final JComboBox typeChooser;
55+
private final Platform platform;
56+
private LibrariesIndexer indexer;
5457
private Predicate<ContributedLibrary> typeFilter;
5558

5659
@Override
@@ -86,8 +89,9 @@ protected void onRemove(ContributedLibrary library) {
8689
};
8790
}
8891

89-
public LibraryManagerUI(Frame parent) {
92+
public LibraryManagerUI(Frame parent, Platform platform) {
9093
super(parent, "Library Manager", Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
94+
this.platform = platform;
9195

9296
filtersContainer.add(new JLabel(_("Topic")), 1);
9397
filtersContainer.remove(2);
@@ -177,7 +181,7 @@ public void setIndexer(LibrariesIndexer indexer) {
177181
filterField.setEnabled(contribModel.getRowCount() > 0);
178182

179183
// Create LibrariesInstaller tied with the provided index
180-
installer = new LibraryInstaller(indexer) {
184+
installer = new LibraryInstaller(indexer, platform) {
181185
@Override
182186
public void onProgress(Progress progress) {
183187
setProgress(progress);

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import cc.arduino.contributions.DownloadableContribution;
3535
import cc.arduino.contributions.ui.*;
3636
import cc.arduino.utils.Progress;
37+
import processing.app.BaseNoGui;
3738
import processing.app.I18n;
39+
import processing.app.Platform;
3840

3941
import javax.swing.*;
4042
import java.awt.*;
@@ -47,7 +49,7 @@
4749
@SuppressWarnings("serial")
4850
public class ContributionManagerUI extends InstallerJDialog {
4951

50-
// private ContributedPlatformTableCell cellEditor;
52+
private final Platform platform;
5153

5254
@Override
5355
protected FilteredAbstractTableModel createContribModel() {
@@ -82,8 +84,9 @@ protected void onRemove(ContributedPlatform installedPlatform) {
8284
};
8385
}
8486

85-
public ContributionManagerUI(Frame parent) {
87+
public ContributionManagerUI(Frame parent, Platform platform) {
8688
super(parent, _("Boards Manager"), Dialog.ModalityType.APPLICATION_MODAL, _("Unable to reach Arduino.cc due to possible network issues."));
89+
this.platform = platform;
8790
}
8891

8992
public void setIndexer(ContributionsIndexer indexer) {
@@ -113,7 +116,7 @@ public void setIndexer(ContributionsIndexer indexer) {
113116
}
114117

115118
// Create ConstributionInstaller tied with the provided index
116-
installer = new ContributionInstaller(indexer) {
119+
installer = new ContributionInstaller(indexer, platform) {
117120
@Override
118121
public void onProgress(Progress progress) {
119122
setProgress(progress);

app/src/processing/app/Base.java

Lines changed: 11 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ static public void guardedMain(String args[]) throws Exception {
145145

146146
BaseNoGui.notifier = new GUIUserNotifier();
147147

148-
initPlatform();
148+
BaseNoGui.initPlatform();
149149

150-
getPlatform().init();
150+
BaseNoGui.getPlatform().init();
151151

152152
BaseNoGui.initPortableFolder();
153153

@@ -206,7 +206,7 @@ static public void guardedMain(String args[]) throws Exception {
206206

207207
// Set the look and feel before opening the window
208208
try {
209-
getPlatform().setLookAndFeel();
209+
BaseNoGui.getPlatform().setLookAndFeel();
210210
} catch (Exception e) {
211211
String mess = e.getMessage();
212212
if (mess.indexOf("ch.randelshofer.quaqua.QuaquaLookAndFeel") == -1) {
@@ -261,23 +261,6 @@ static protected boolean isCommandLine() {
261261
return commandLine;
262262
}
263263

264-
265-
static protected void initPlatform() {
266-
BaseNoGui.initPlatform();
267-
}
268-
269-
270-
static protected void initRequirements() {
271-
try {
272-
Class.forName("com.sun.jdi.VirtualMachine");
273-
} catch (ClassNotFoundException cnfe) {
274-
showError(_("Please install JDK 1.5 or later"),
275-
_("Arduino requires a full JDK (not just a JRE)\n" +
276-
"to run. Please install JDK 1.5 or later.\n" +
277-
"More information can be found in the reference."), cnfe);
278-
}
279-
}
280-
281264
// Returns a File object for the given pathname. If the pathname
282265
// is not absolute, it is interpreted relative to the current
283266
// directory when starting the IDE (which is not the same as the
@@ -349,8 +332,8 @@ public Base(String[] args) throws Exception {
349332
PreferencesData.save();
350333

351334
if (parser.isInstallBoard()) {
352-
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
353-
ContributionInstaller installer = new ContributionInstaller(indexer) {
335+
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
336+
ContributionInstaller installer = new ContributionInstaller(indexer, BaseNoGui.getPlatform()) {
354337
private String lastStatus = "";
355338

356339
@Override
@@ -396,8 +379,8 @@ protected void onProgress(Progress progress) {
396379
System.exit(0);
397380

398381
} else if (parser.isInstallLibrary()) {
399-
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder()));
400-
LibraryInstaller installer = new LibraryInstaller(indexer) {
382+
LibrariesIndexer indexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform()));
383+
LibraryInstaller installer = new LibraryInstaller(indexer, BaseNoGui.getPlatform()) {
401384
private String lastStatus = "";
402385

403386
@Override
@@ -929,7 +912,7 @@ protected Editor handleOpen(File file, int[] location, boolean showEditor) throw
929912
// }
930913

931914
// System.err.println(" creating new editor");
932-
Editor editor = new Editor(this, file, location);
915+
Editor editor = new Editor(this, file, location, BaseNoGui.getPlatform());
933916
// Editor editor = null;
934917
// try {
935918
// editor = new Editor(this, path, location);
@@ -1302,7 +1285,7 @@ public void onBoardOrPortChange() {
13021285

13031286
private void openManageLibrariesDialog() {
13041287
@SuppressWarnings("serial")
1305-
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor) {
1288+
LibraryManagerUI managerUI = new LibraryManagerUI(activeEditor, BaseNoGui.getPlatform()) {
13061289
@Override
13071290
protected void onIndexesUpdated() throws Exception {
13081291
BaseNoGui.initPackages();
@@ -1325,7 +1308,7 @@ protected void onIndexesUpdated() throws Exception {
13251308
private void openInstallBoardDialog(final String filterText) throws Exception {
13261309
// Create dialog for contribution manager
13271310
@SuppressWarnings("serial")
1328-
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
1311+
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor, BaseNoGui.getPlatform()) {
13291312
@Override
13301313
protected void onIndexesUpdated() throws Exception {
13311314
BaseNoGui.initPackages();
@@ -1829,65 +1812,6 @@ public void handlePrefs() {
18291812
dialog.setVisible(true);
18301813
}
18311814

1832-
1833-
// ...................................................................
1834-
1835-
1836-
/**
1837-
* Get list of platform constants.
1838-
*/
1839-
// static public int[] getPlatforms() {
1840-
// return platforms;
1841-
// }
1842-
1843-
1844-
// static public int getPlatform() {
1845-
// String osname = System.getProperty("os.name");
1846-
//
1847-
// if (osname.indexOf("Mac") != -1) {
1848-
// return PConstants.MACOSX;
1849-
//
1850-
// } else if (osname.indexOf("Windows") != -1) {
1851-
// return PConstants.WINDOWS;
1852-
//
1853-
// } else if (osname.equals("Linux")) { // true for the ibm vm
1854-
// return PConstants.LINUX;
1855-
//
1856-
// } else {
1857-
// return PConstants.OTHER;
1858-
// }
1859-
// }
1860-
static public Platform getPlatform() {
1861-
return BaseNoGui.getPlatform();
1862-
}
1863-
1864-
1865-
static public String getPlatformName() {
1866-
String osname = System.getProperty("os.name");
1867-
1868-
if (osname.indexOf("Mac") != -1) {
1869-
return "macosx";
1870-
1871-
} else if (osname.indexOf("Windows") != -1) {
1872-
return "windows";
1873-
1874-
} else if (osname.equals("Linux")) { // true for the ibm vm
1875-
return "linux";
1876-
1877-
} else {
1878-
return "other";
1879-
}
1880-
}
1881-
1882-
1883-
// .................................................................
1884-
1885-
1886-
static public File getSettingsFolder() {
1887-
return BaseNoGui.getSettingsFolder();
1888-
}
1889-
1890-
18911815
/**
18921816
* Convenience method to get a File object for the specified filename inside
18931817
* the settings folder.
@@ -2092,7 +2016,7 @@ static protected File promptSketchbookLocation() {
20922016
*/
20932017
static public void openURL(String url) {
20942018
try {
2095-
getPlatform().openURL(url);
2019+
BaseNoGui.getPlatform().openURL(url);
20962020

20972021
} catch (Exception e) {
20982022
showWarning(_("Problem Opening URL"),

app/src/processing/app/Editor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
@SuppressWarnings("serial")
7171
public class Editor extends JFrame implements RunnerListener {
7272

73+
private final Platform platform;
74+
7375
private static class ShouldSaveIfModified implements Predicate<Sketch> {
7476

7577
@Override
@@ -184,9 +186,10 @@ public boolean apply(Sketch sketch) {
184186
Runnable exportAppHandler;
185187

186188

187-
public Editor(Base ibase, File file, int[] location) throws Exception {
189+
public Editor(Base ibase, File file, int[] location, Platform platform) throws Exception {
188190
super("Arduino");
189191
this.base = ibase;
192+
this.platform = platform;
190193

191194
Base.setIcon(this);
192195

@@ -992,7 +995,7 @@ protected SketchTextArea createTextArea() throws IOException {
992995
@Override
993996
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
994997
try {
995-
base.getPlatform().openURL(hyperlinkEvent.getURL().toExternalForm());
998+
platform.openURL(hyperlinkEvent.getURL().toExternalForm());
996999
} catch (Exception e) {
9971000
Base.showWarning(e.getMessage(), e.getMessage(), e);
9981001
}
@@ -1129,7 +1132,7 @@ protected void populatePortMenu() {
11291132

11301133
List<BoardPort> ports = Base.getDiscoveryManager().discovery();
11311134

1132-
ports = Base.getPlatform().filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
1135+
ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
11331136

11341137
Collections.sort(ports, new Comparator<BoardPort>() {
11351138
@Override

app/test/processing/app/AbstractGUITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public void startUpTheIDE() throws Exception {
5050

5151
FailOnThreadViolationRepaintManager.install();
5252

53-
Base.initPlatform();
53+
BaseNoGui.initPlatform();
5454
Preferences.init(null);
5555
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
5656
Theme.init();
57-
Base.getPlatform().setLookAndFeel();
57+
BaseNoGui.getPlatform().setLookAndFeel();
5858
Base.untitledFolder = Base.createTempFolder("untitled");
5959
DeleteFilesOnShutdown.add(Base.untitledFolder);
6060

app/test/processing/app/AbstractWithPreferencesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public abstract class AbstractWithPreferencesTest {
3737
@Before
3838
public void init() throws Exception {
3939
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
40-
Base.initPlatform();
41-
Base.getPlatform().init();
40+
BaseNoGui.initPlatform();
41+
BaseNoGui.getPlatform().init();
4242
Preferences.init(null);
4343
Theme.init();
4444

arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import cc.arduino.utils.ArchiveExtractor;
3434
import cc.arduino.utils.MultiStepProgress;
3535
import cc.arduino.utils.Progress;
36-
import processing.app.BaseNoGui;
3736
import processing.app.I18n;
37+
import processing.app.Platform;
3838
import processing.app.helpers.FileUtils;
3939

4040
import java.io.File;
@@ -60,10 +60,12 @@ public class LibraryInstaller {
6060

6161
private final LibrariesIndexer indexer;
6262
private final DownloadableContributionsDownloader downloader;
63+
private final Platform platform;
6364

64-
public LibraryInstaller(LibrariesIndexer _indexer) {
65-
indexer = _indexer;
66-
File stagingFolder = _indexer.getStagingFolder();
65+
public LibraryInstaller(LibrariesIndexer indexer, Platform platform) {
66+
this.indexer = indexer;
67+
this.platform = platform;
68+
File stagingFolder = indexer.getStagingFolder();
6769
downloader = new DownloadableContributionsDownloader(stagingFolder) {
6870
@Override
6971
protected void onProgress(Progress progress) {
@@ -126,7 +128,7 @@ public void install(ContributedLibrary lib, ContributedLibrary replacedLib) thro
126128
File libsFolder = indexer.getSketchbookLibrariesFolder();
127129
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
128130
try {
129-
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(lib.getDownloadedFile(), tmpFolder, 1);
131+
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
130132
} catch (Exception e) {
131133
if (tmpFolder.exists())
132134
FileUtils.recursiveDelete(tmpFolder);

arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
package cc.arduino.contributions.packages;
3030

3131
import cc.arduino.contributions.DownloadableContribution;
32-
import processing.app.BaseNoGui;
32+
import processing.app.Platform;
3333

3434
import java.util.List;
3535

@@ -41,21 +41,27 @@ public abstract class ContributedTool {
4141

4242
public abstract List<HostDependentDownloadableContribution> getSystems();
4343

44-
public DownloadableContribution getDownloadableContribution() {
44+
public DownloadableContribution getDownloadableContribution(Platform platform) {
4545
for (HostDependentDownloadableContribution c : getSystems()) {
46-
if (c.isCompatible(BaseNoGui.getPlatform()))
46+
if (c.isCompatible(platform))
4747
return c;
4848
}
4949
return null;
5050
}
5151

5252
@Override
5353
public String toString() {
54+
return toString(null);
55+
}
56+
57+
public String toString(Platform platform) {
5458
String res;
5559
res = "Tool name : " + getName() + " " + getVersion() + "\n";
5660
for (HostDependentDownloadableContribution sys : getSystems()) {
5761
res += " sys";
58-
res += sys.isCompatible(BaseNoGui.getPlatform()) ? "*" : " ";
62+
if (platform != null) {
63+
res += sys.isCompatible(platform) ? "*" : " ";
64+
}
5965
res += " : " + sys + "\n";
6066
}
6167
return res;

0 commit comments

Comments
 (0)