Skip to content

Commit daa79f0

Browse files
committed
Add JVM arguments deploy option
The deploy dialog has been slightly rearranged to make room for it. It now also includes a preview of the exact command that will be executed.
1 parent 201dcbb commit daa79f0

4 files changed

Lines changed: 68 additions & 26 deletions

File tree

core/src/main/java/edu/wpi/grip/core/settings/ProjectSettings.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class ProjectSettings implements Cloneable {
3131
@Setting(label = "Deploy Java home", description = "Where Java is installed on the robot.")
3232
private String deployJavaHome = "/usr/local/frc/JRE/";
3333

34+
@Setting(label = "Deploy JVM options", description = "Command line options passed to the roboRIO JVM")
35+
private String deployJvmOptions = "-Xmx50m";
36+
3437
/**
3538
* Set the FRC team number. If the deploy address and NetworkTables server address haven't been manually
3639
* overridden, this also changes them to the mDNS hostname of the team's roboRIO.
@@ -98,6 +101,14 @@ public void setDeployJavaHome(String deployJavaHome) {
98101
if (deployJavaHome != null) this.deployJavaHome = deployJavaHome;
99102
}
100103

104+
public String getDeployJvmOptions() {
105+
return deployJvmOptions;
106+
}
107+
108+
public void setDeployJvmOptions(String deployJvmOptions) {
109+
this.deployJvmOptions = deployJvmOptions;
110+
}
111+
101112
private String computeFRCAddress(int teamNumber) {
102113
return "roborio-" + teamNumber + "-frc.local";
103114
}
@@ -109,6 +120,7 @@ public String toString() {
109120
.add("deployDir", deployDir)
110121
.add("deployUser", deployUser)
111122
.add("deployJavaHome", deployJavaHome)
123+
.add("deployJvmOptions", deployJvmOptions)
112124
.add("publishAddress", publishAddress)
113125
.add("teamNumber", teamNumber)
114126
.toString();

ui/src/main/java/edu/wpi/grip/ui/DeployController.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import edu.wpi.grip.core.settings.ProjectSettings;
1111
import edu.wpi.grip.ui.util.StringInMemoryFile;
1212
import javafx.application.Platform;
13+
import javafx.beans.binding.Bindings;
1314
import javafx.beans.property.BooleanProperty;
1415
import javafx.beans.property.SimpleBooleanProperty;
1516
import 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) {

ui/src/main/resources/edu/wpi/grip/ui/Deploy.fxml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?language javascript ?>
3+
<?language javascript?>
44

55
<?import edu.wpi.grip.ui.util.DPIUtility?>
6-
<?import edu.wpi.grip.ui.DeployController?>
6+
<?import javafx.beans.property.SimpleBooleanProperty?>
77
<?import javafx.scene.control.*?>
88
<?import javafx.scene.image.Image?>
99
<?import javafx.scene.image.ImageView?>
1010
<?import javafx.scene.layout.*?>
1111
<VBox styleClass="deploy-pane" maxWidth="Infinity" xmlns:fx="http://javafx.com/fxml/1"
12+
onKeyPressed="if (event.code == javafx.scene.input.KeyCode.ENTER) { controller.onDeploy() }"
1213
xmlns="http://javafx.com/javafx/null" fx:controller="edu.wpi.grip.ui.DeployController">
1314
<GridPane maxHeight="Infinity">
1415
<columnConstraints>
15-
<ColumnConstraints hgrow="NEVER"/>
16+
<ColumnConstraints hgrow="NEVER" halignment="RIGHT"/>
17+
<ColumnConstraints hgrow="ALWAYS"/>
18+
<ColumnConstraints hgrow="NEVER">
19+
<prefWidth>
20+
<DPIUtility fx:constant="FONT_SIZE"/>
21+
</prefWidth>
22+
</ColumnConstraints>
23+
<ColumnConstraints hgrow="NEVER" halignment="RIGHT"/>
1624
<ColumnConstraints hgrow="ALWAYS"/>
1725
</columnConstraints>
1826

@@ -21,23 +29,32 @@
2129
GridPane.rowIndex="0"/>
2230

2331
<Label disable="${deployButton.disabled}" text="User" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
24-
<TextField disable="${deployButton.disabled}" fx:id="user" promptText="User" GridPane.columnIndex="1"
32+
<TextField disable="${deployButton.disabled}" fx:id="user" promptText="Username" GridPane.columnIndex="1"
2533
GridPane.rowIndex="1"/>
2634

2735
<Label disable="${deployButton.disabled}" text="Password" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
2836
<PasswordField disable="${deployButton.disabled}" fx:id="password" promptText="Password"
2937
GridPane.columnIndex="1" GridPane.rowIndex="2"/>
3038

31-
<Label disable="${deployButton.disabled}" text="Java Home" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
39+
<Label disable="${deployButton.disabled}" text="Deploy Directory" GridPane.columnIndex="3"
40+
GridPane.rowIndex="0"/>
41+
<TextField disable="${deployButton.disabled}" fx:id="deployDir" promptText="Deploy Directory"
42+
GridPane.columnIndex="4" GridPane.rowIndex="0"/>
43+
44+
<Label disable="${deployButton.disabled}" text="Java Home" GridPane.columnIndex="3" GridPane.rowIndex="1"/>
3245
<TextField disable="${deployButton.disabled}" fx:id="javaHome" promptText="Java Home"
33-
GridPane.columnIndex="1" GridPane.rowIndex="3"/>
46+
GridPane.columnIndex="4" GridPane.rowIndex="1"/>
3447

35-
<Label disable="${deployButton.disabled}" text="Deploy Directory" GridPane.columnIndex="0"
36-
GridPane.rowIndex="4"/>
37-
<TextField disable="${deployButton.disabled}" fx:id="deployDir" promptText="Deploy Directory"
38-
GridPane.columnIndex="1" GridPane.rowIndex="4"/>
48+
<Label disable="${deployButton.disabled}" text="JVM Arguments" GridPane.columnIndex="3" GridPane.rowIndex="2"/>
49+
<TextField disable="${deployButton.disabled}" fx:id="jvmArgs" promptText="JVM Arguments"
50+
GridPane.columnIndex="4" GridPane.rowIndex="2"/>
51+
52+
<Label disable="${deployButton.disabled}" text="Command" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
53+
<Label fx:id="command" disable="${deployButton.disabled}" GridPane.columnIndex="1" GridPane.columnSpan="4"
54+
GridPane.rowIndex="3" style="-fx-font-family: monospace"/>
3955
</GridPane>
4056

57+
4158
<ButtonBar>
4259
<buttons>
4360
<Button fx:id="deployButton" defaultButton="true" onMouseClicked="#onDeploy" text="Deploy"
@@ -65,5 +82,5 @@
6582
<Label fx:id="status"/>
6683
</StackPane>
6784

68-
<TextArea fx:id="console" editable="false" styleClass="console" prefRowCount="24" prefColumnCount="80"/>
85+
<TextArea fx:id="console" editable="false" styleClass="console" prefRowCount="24" prefColumnCount="100"/>
6986
</VBox>

ui/src/main/resources/edu/wpi/grip/ui/GRIP.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ VBox.sockets {
189189
-fx-background-color: grey;
190190
}
191191

192-
.property-sheet .property-pane, .deploy-pane GridPane {
192+
.property-sheet .property-pane {
193193
-fx-hgap: 4em;
194194
-fx-vgap: 1em;
195195
-fx-padding: 0;
@@ -207,6 +207,12 @@ VBox.sockets {
207207
-fx-spacing: 1em;
208208
}
209209

210+
.deploy-pane GridPane {
211+
-fx-hgap: 1em;
212+
-fx-vgap: 1em;
213+
-fx-padding: 0;
214+
}
215+
210216
.deploy-pane StackPane {
211217
-fx-pref-height: 2em;
212218
}

0 commit comments

Comments
 (0)