1010import edu .wpi .grip .core .settings .ProjectSettings ;
1111import edu .wpi .grip .ui .util .StringInMemoryFile ;
1212import javafx .application .Platform ;
13+ import javafx .beans .binding .Bindings ;
1314import javafx .beans .property .BooleanProperty ;
1415import javafx .beans .property .SimpleBooleanProperty ;
1516import javafx .fxml .FXML ;
@@ -50,27 +51,31 @@ public class DeployController {
5051 @ FXML private TextField user ;
5152 @ FXML private TextField password ;
5253 @ FXML private TextField javaHome ;
54+ @ FXML private TextField jvmArgs ;
5355 @ FXML private TextField deployDir ;
5456 @ FXML private ProgressIndicator progress ;
57+ @ FXML private Label command ;
5558 @ FXML private Button deployButton ;
5659 @ FXML private Label status ;
5760 @ FXML private TextArea console ;
5861
5962 @ Inject private EventBus eventBus ;
6063 @ Inject private Project project ;
6164 @ Inject private Pipeline pipeline ;
62- @ Inject private Logger logger ;
6365
66+ @ Inject private Logger logger ;
6467 private final BooleanProperty deploying = new SimpleBooleanProperty (this , "deploying" , false );
6568 private Optional <Thread > deployThread = Optional .empty ();
6669
6770 @ FXML
6871 public void initialize () {
69- loadSettings (pipeline .getProjectSettings ());
70-
7172 deployButton .disableProperty ().bind (deploying );
7273 progress .disableProperty ().bind (deploying .not ());
7374 deploying .addListener ((o , b , d ) -> progress .setProgress (d ? ProgressIndicator .INDETERMINATE_PROGRESS : 0 ));
75+ command .textProperty ().bind (Bindings .concat (javaHome .textProperty (), "/bin/java " , jvmArgs .textProperty (),
76+ " -jar '" , deployDir .textProperty (), "/" , GRIP_JAR , "' '" , deployDir .textProperty (), "/" , PROJECT_FILE , "'" ));
77+
78+ loadSettings (pipeline .getProjectSettings ());
7479 }
7580
7681 @ Subscribe
@@ -85,6 +90,7 @@ private void loadSettings(ProjectSettings settings) {
8590 address .setText (settings .getDeployAddress ());
8691 user .setText (settings .getDeployUser ());
8792 javaHome .setText (settings .getDeployJavaHome ());
93+ jvmArgs .setText (settings .getDeployJvmOptions ());
8894 deployDir .setText (settings .getDeployDir ());
8995 }
9096
@@ -95,6 +101,7 @@ private void saveSettings() {
95101 settings .setDeployAddress (address .getText ());
96102 settings .setDeployUser (user .getText ());
97103 settings .setDeployJavaHome (javaHome .getText ());
104+ settings .setDeployJvmOptions (jvmArgs .getText ());
98105 settings .setDeployDir (deployDir .getText ());
99106 eventBus .post (new ProjectSettingsChangedEvent (settings ));
100107 }
@@ -107,8 +114,7 @@ public void onDeploy() {
107114 console .clear ();
108115
109116 // Start the deploy in a new thread, so the GUI doesn't freeze
110- deployThread = Optional .of (new Thread (() ->
111- deploy (address .getText (), user .getText (), password .getText (), javaHome .getText (), deployDir .getText ())));
117+ deployThread = Optional .of (new Thread (this ::deploy ));
112118 deployThread .get ().setDaemon (true );
113119 deployThread .get ().start ();
114120 }
@@ -124,13 +130,13 @@ public void onStop() {
124130 * Upload and run the GRIP project using the current deploy settings. This is run in a separate thread, and it
125131 * periodically updates the GUI to inform the user of the current status of the deployment.
126132 */
127- private void deploy (String address , String user , String password , String javaHome , String deployDir ) {
128- setStatusAsync ("Connecting to " + address , false );
133+ private void deploy () {
134+ setStatusAsync ("Connecting to " + address . getText () , false );
129135
130136 try (SSHClient ssh = new SSHClient ()) {
131137 ssh .addHostKeyVerifier ((hostname , port , key ) -> true );
132- ssh .connect (address );
133- ssh .authPassword (user , password );
138+ ssh .connect (address . getText () );
139+ ssh .authPassword (user . getText () , password . getText () );
134140
135141 // Update the progress bar and status text while uploading files
136142 SCPFileTransfer scp = ssh .newSCPFileTransfer ();
@@ -151,8 +157,8 @@ public StreamCopier.Listener file(String name, long size) {
151157 project .save (projectWriter );
152158
153159 // Upload the GRIP core JAR and the serialized project to the robot
154- scp .upload (new StringInMemoryFile (PROJECT_FILE , projectWriter .toString ()), deployDir + "/" );
155- scp .upload (new FileSystemFile (LOCAL_GRIP_JAR ), deployDir + "/" + GRIP_JAR );
160+ scp .upload (new StringInMemoryFile (PROJECT_FILE , projectWriter .toString ()), deployDir . getText () + "/" );
161+ scp .upload (new FileSystemFile (LOCAL_GRIP_JAR ), deployDir . getText () + "/" + GRIP_JAR );
156162
157163 // Stop the pipeline before running it remotely, so the two instances of GRIP don't try to publish to the
158164 // same NetworkTables keys.
@@ -162,8 +168,9 @@ public StreamCopier.Listener file(String name, long size) {
162168 setStatusAsync ("Running GRIP" , false );
163169 Session session = ssh .startSession ();
164170 session .allocateDefaultPTY ();
165- Session .Command cmd = session .exec (javaHome + "/bin/java -jar " + deployDir + "/" + GRIP_JAR + "' '"
166- + deployDir + "/" + PROJECT_FILE + "'" );
171+
172+ logger .info ("Executing " + command .getText ());
173+ Session .Command cmd = session .exec (command .getText ());
167174
168175 LineReader inputReader = new LineReader (new InputStreamReader (cmd .getInputStream ()));
169176 while (isNotCanceled ()) {
@@ -175,7 +182,7 @@ public StreamCopier.Listener file(String name, long size) {
175182 Platform .runLater (() -> console .setText (console .getText () + line + "\n " ));
176183 }
177184 } catch (UnknownHostException e ) {
178- setStatusAsync ("Unknown host: " + address , true );
185+ setStatusAsync ("Unknown host: " + address . getText () , true );
179186 } catch (UserAuthException e ) {
180187 setStatusAsync ("Invalid username or password (should be \" lvuser\" and blank for roboRIO)" , true );
181188 } catch (InterruptedIOException e ) {
0 commit comments