From 83c61376e0795136ad1eeee02703bd7ac269b403 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Mon, 25 Aug 2014 12:13:45 +0200 Subject: [PATCH] Split UploaderAndMonitorFactory in two distinct classes. --- app/src/cc/arduino/packages/MonitorFactory.java | 17 +++++++++++++++++ ...MonitorFactory.java => UploaderFactory.java} | 13 +------------ app/src/processing/app/Editor.java | 4 ++-- app/src/processing/app/Sketch.java | 4 ++-- .../app/debug/UploaderFactoryTest.java | 8 ++++---- 5 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 app/src/cc/arduino/packages/MonitorFactory.java rename app/src/cc/arduino/packages/{UploaderAndMonitorFactory.java => UploaderFactory.java} (84%) diff --git a/app/src/cc/arduino/packages/MonitorFactory.java b/app/src/cc/arduino/packages/MonitorFactory.java new file mode 100644 index 000000000..5ece88231 --- /dev/null +++ b/app/src/cc/arduino/packages/MonitorFactory.java @@ -0,0 +1,17 @@ +package cc.arduino.packages; + +import processing.app.AbstractMonitor; +import processing.app.NetworkMonitor; +import processing.app.SerialMonitor; + +public class MonitorFactory { + + public AbstractMonitor newMonitor(BoardPort port) { + if ("network".equals(port.getProtocol())) { + return new NetworkMonitor(port); + } + + return new SerialMonitor(port); + } + +} diff --git a/app/src/cc/arduino/packages/UploaderAndMonitorFactory.java b/app/src/cc/arduino/packages/UploaderFactory.java similarity index 84% rename from app/src/cc/arduino/packages/UploaderAndMonitorFactory.java rename to app/src/cc/arduino/packages/UploaderFactory.java index 8c991246e..0efd5f062 100644 --- a/app/src/cc/arduino/packages/UploaderAndMonitorFactory.java +++ b/app/src/cc/arduino/packages/UploaderFactory.java @@ -31,12 +31,9 @@ package cc.arduino.packages; import cc.arduino.packages.uploaders.SSHUploader; import cc.arduino.packages.uploaders.SerialUploader; -import processing.app.AbstractMonitor; -import processing.app.NetworkMonitor; -import processing.app.SerialMonitor; import processing.app.debug.TargetBoard; -public class UploaderAndMonitorFactory { +public class UploaderFactory { public Uploader newUploader(TargetBoard board, BoardPort port) { if ("true".equals(board.getPreferences().get("upload.via_ssh")) && port != null && "network".equals(port.getProtocol())) { @@ -46,12 +43,4 @@ public class UploaderAndMonitorFactory { return new SerialUploader(); } - public AbstractMonitor newMonitor(BoardPort port) { - if ("network".equals(port.getProtocol())) { - return new NetworkMonitor(port); - } - - return new SerialMonitor(port); - } - } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index dffa9e871..c1bc951ad 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -22,7 +22,7 @@ package processing.app; -import cc.arduino.packages.UploaderAndMonitorFactory; +import cc.arduino.packages.MonitorFactory; import com.jcraft.jsch.JSchException; @@ -2518,7 +2518,7 @@ public class Editor extends JFrame implements RunnerListener { return; } - serialMonitor = new UploaderAndMonitorFactory().newMonitor(port); + serialMonitor = new MonitorFactory().newMonitor(port); serialMonitor.setIconImage(getIconImage()); boolean success = false; diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 92d37aa54..49bc21191 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -24,7 +24,7 @@ package processing.app; import cc.arduino.packages.BoardPort; -import cc.arduino.packages.UploaderAndMonitorFactory; +import cc.arduino.packages.UploaderFactory; import cc.arduino.packages.Uploader; import processing.app.debug.Compiler; import processing.app.debug.Compiler.ProgressListener; @@ -1198,7 +1198,7 @@ public class Sketch { BoardPort boardPort = Base.getDiscoveryManager().find(Preferences.get("serial.port")); - Uploader uploader = new UploaderAndMonitorFactory().newUploader(target.getBoards().get(board), boardPort); + Uploader uploader = new UploaderFactory().newUploader(target.getBoards().get(board), boardPort); boolean success = false; do { diff --git a/app/test/processing/app/debug/UploaderFactoryTest.java b/app/test/processing/app/debug/UploaderFactoryTest.java index a785f835e..e10430f70 100644 --- a/app/test/processing/app/debug/UploaderFactoryTest.java +++ b/app/test/processing/app/debug/UploaderFactoryTest.java @@ -2,7 +2,7 @@ package processing.app.debug; import cc.arduino.packages.BoardPort; import cc.arduino.packages.Uploader; -import cc.arduino.packages.UploaderAndMonitorFactory; +import cc.arduino.packages.UploaderFactory; import cc.arduino.packages.uploaders.SSHUploader; import cc.arduino.packages.uploaders.SerialUploader; import org.junit.Before; @@ -29,7 +29,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest { boardPort.setBoardName("yun"); boardPort.setAddress("192.168.0.1"); boardPort.setProtocol("network"); - Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort); + Uploader uploader = new UploaderFactory().newUploader(board, boardPort); assertTrue(uploader instanceof SSHUploader); } @@ -41,7 +41,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest { boardPort.setBoardName("myyun"); boardPort.setAddress("192.168.0.1"); boardPort.setProtocol("network"); - Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort); + Uploader uploader = new UploaderFactory().newUploader(board, boardPort); assertTrue(uploader instanceof SerialUploader); } @@ -53,7 +53,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest { boardPort.setBoardName("Arduino Leonardo"); boardPort.setAddress("/dev/ttyACM0"); boardPort.setProtocol("serial"); - Uploader uploader = new UploaderAndMonitorFactory().newUploader(board, boardPort); + Uploader uploader = new UploaderFactory().newUploader(board, boardPort); assertTrue(uploader instanceof SerialUploader); }