Skip to content

Commit 7dc3d72

Browse files
committed
Update project settings for new deploy stuff
This generally makes ProjectSettings a little more cleaned up, but mostly makes it work nicely with the deploy settings. The deploy variables are all now saved persistantly in the project settings, and things like the deploy URL are calculated in a way that makes a little more sense (so the user actually sees the calculated value)
1 parent bcea46a commit 7dc3d72

4 files changed

Lines changed: 94 additions & 54 deletions

File tree

core/src/main/java/edu/wpi/grip/core/operations/networktables/NTManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void updateSettings(ProjectSettingsChangedEvent event) {
6464

6565
synchronized (NetworkTable.class) {
6666
NetworkTable.shutdown();
67-
NetworkTable.setIPAddress(projectSettings.computePublishAddress());
67+
NetworkTable.setIPAddress(projectSettings.getPublishAddress());
6868
}
6969
}
7070

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

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,112 @@
44
import com.google.common.base.Throwables;
55

66
import static com.google.common.base.Preconditions.checkArgument;
7-
import static com.google.common.base.Preconditions.checkNotNull;
87

98
/**
109
* This object holds settings that are saved in project files. This includes things like team numbers, which need to
1110
* be preserved when deploying the project.
1211
*/
1312
public class ProjectSettings implements Cloneable {
1413

15-
@Setting(label = "FRC Team Number", description = "The team number, if used for FRC")
14+
@Setting(label = "FRC team number", description = "The team number, if used for FRC")
1615
private int teamNumber = 0;
1716

18-
@Setting(label = "NetworkTables Server Address", description = "The host that runs the Network Protocol server. " +
19-
"If not specified and NetworkTables is specified as the protocol, the hostname is derived from the team " +
20-
"number.")
21-
private String publishAddress = "";
17+
@Setting(label = "NetworkTables server address", description = "The host that runs the NetworkTables server. If " +
18+
"not specified and NetworkTables is used, the hostname is derived from the team number.")
19+
private String publishAddress = computeFRCAddress(teamNumber);
2220

23-
@Setting(label = "Deploy Address", description = "The remote host that grip should be remotely deployed to. If " +
24-
"not specified, the hostname is derived from the team number.")
25-
private String deployAddress = "";
21+
@Setting(label = "Deploy address", description = "The remote host that grip should be deployed to. " +
22+
"If not specified, the hostname is derived from the team number.")
23+
private String deployAddress = computeFRCAddress(teamNumber);
2624

25+
@Setting(label = "Deploy directory", description = "The directory on the remote host to deploy GRIP to.")
26+
private String deployDir = "/home/lvuser";
27+
28+
@Setting(label = "Deploy user", description = "The username to log in with when deploying over SSH.")
29+
private String deployUser = "lvuser";
30+
31+
@Setting(label = "Deploy Java home", description = "Where Java is installed on the robot.")
32+
private String deployJavaHome = "/usr/local/frc/JRE/";
33+
34+
/**
35+
* Set the FRC team number. If the deploy address and NetworkTables server address haven't been manually
36+
* overridden, this also changes them to the mDNS hostname of the team's roboRIO.
37+
*/
2738
public void setTeamNumber(int teamNumber) {
2839
checkArgument(teamNumber >= 0, "Team number cannot be negative");
40+
41+
final String oldFrcAddress = computeFRCAddress(this.teamNumber);
42+
final String newFrcAddress = computeFRCAddress(teamNumber);
43+
2944
this.teamNumber = teamNumber;
45+
46+
// If the deploy address and/or NetworkTables server address was previously the default for the old team
47+
// number (ie: it was roborio-xxx-frc.local), update it with the new team number
48+
if (oldFrcAddress.equals(getDeployAddress())) {
49+
setDeployAddress(newFrcAddress);
50+
}
51+
52+
if (oldFrcAddress.equals(getPublishAddress())) {
53+
setPublishAddress(newFrcAddress);
54+
}
3055
}
3156

3257
public int getTeamNumber() {
3358
return teamNumber;
3459
}
3560

3661
public void setPublishAddress(String publishAddress) {
37-
this.publishAddress =
38-
checkNotNull(publishAddress, "Network Protocol Server Address cannot be null");
62+
if (publishAddress != null) this.publishAddress = publishAddress;
3963
}
4064

4165
public String getPublishAddress() {
4266
return publishAddress;
4367
}
4468

4569
public void setDeployAddress(String deployAddress) {
46-
this.deployAddress = checkNotNull(deployAddress, "Deploy Address can not be null");
70+
if (deployAddress != null) this.deployAddress = deployAddress;
4771
}
4872

4973
public String getDeployAddress() {
5074
return deployAddress;
5175
}
5276

53-
/**
54-
* @return The address of the machine that the NetworkTables server is running on. If
55-
* {@link #setPublishAddress} is specified, that is returned, otherwise this is based on the team
56-
* number.
57-
*/
58-
public String computePublishAddress() {
59-
return computeFRCAddress(publishAddress);
77+
public String getDeployDir() {
78+
return deployDir;
6079
}
6180

62-
public String computeDeployAddress() {
63-
return computeFRCAddress(deployAddress);
81+
public void setDeployDir(String deployDir) {
82+
if (deployDir != null) this.deployDir = deployDir;
6483
}
6584

66-
private String computeFRCAddress(String address) {
67-
if (address == null || address.isEmpty()) {
68-
return "roborio-" + teamNumber + "-frc.local";
69-
} else {
70-
return address;
71-
}
85+
public String getDeployUser() {
86+
return deployUser;
87+
}
88+
89+
public void setDeployUser(String deployUser) {
90+
if (deployUser != null) this.deployUser = deployUser;
91+
}
92+
93+
public String getDeployJavaHome() {
94+
return deployJavaHome;
95+
}
96+
97+
public void setDeployJavaHome(String deployJavaHome) {
98+
if (deployJavaHome != null) this.deployJavaHome = deployJavaHome;
99+
}
100+
101+
private String computeFRCAddress(int teamNumber) {
102+
return "roborio-" + teamNumber + "-frc.local";
72103
}
73104

74105
@Override
75106
public String toString() {
76107
return MoreObjects.toStringHelper(this)
77-
.add("publishAddress", publishAddress)
78108
.add("deployAddress", deployAddress)
109+
.add("deployDir", deployDir)
110+
.add("deployUser", deployUser)
111+
.add("deployJavaHome", deployJavaHome)
112+
.add("publishAddress", publishAddress)
79113
.add("teamNumber", teamNumber)
80114
.toString();
81115
}

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

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import edu.wpi.grip.core.events.ProjectSettingsChangedEvent;
88
import edu.wpi.grip.core.events.StopPipelineEvent;
99
import edu.wpi.grip.core.serialization.Project;
10+
import edu.wpi.grip.core.settings.ProjectSettings;
1011
import edu.wpi.grip.ui.util.StringInMemoryFile;
1112
import javafx.application.Platform;
1213
import javafx.beans.property.BooleanProperty;
@@ -40,13 +41,6 @@
4041
* based on the project settings.
4142
*/
4243
public class DeployController {
43-
44-
// Default deploy information for FRC. This can be overridden by the user for applications outside of FRC or not
45-
// using the roboRIO (ie: coprocessors)
46-
public final static String DEFAULT_USER = "lvuser";
47-
public final static String DEFAULT_JAVA_HOME = "/usr/local/frc/JRE/";
48-
public final static String DEFAULT_DIR = "/home/" + DEFAULT_USER;
49-
5044
private final static String GRIP_JAR = "grip.jar";
5145
private final static String PROJECT_FILE = "project.grip";
5246

@@ -70,19 +64,43 @@ public class DeployController {
7064

7165
@FXML
7266
public void initialize() {
73-
address.setText(pipeline.getProjectSettings().computeDeployAddress());
67+
loadSettings(pipeline.getProjectSettings());
68+
7469
deployButton.disableProperty().bind(deploying);
7570
progress.disableProperty().bind(deploying.not());
7671
deploying.addListener((o, b, d) -> progress.setProgress(d ? ProgressIndicator.INDETERMINATE_PROGRESS : 0));
7772
}
7873

7974
@Subscribe
80-
public void updateSettings(ProjectSettingsChangedEvent event) {
81-
Platform.runLater(() -> address.setText(event.getProjectSettings().computeDeployAddress()));
75+
public void onSettingsChanged(ProjectSettingsChangedEvent event) {
76+
Platform.runLater(() -> loadSettings(event.getProjectSettings()));
77+
}
78+
79+
private void loadSettings(ProjectSettings settings) {
80+
// Almost all of the deploy settings can be persistently saved in the project settings. Whenever the project
81+
// settings are updated (either the user has edited them or a new project has been opened), we should update
82+
// the fields with the new setting values.
83+
address.setText(settings.getDeployAddress());
84+
user.setText(settings.getDeployUser());
85+
javaHome.setText(settings.getDeployJavaHome());
86+
deployDir.setText(settings.getDeployDir());
87+
}
88+
89+
private void saveSettings() {
90+
// If the settings are updated in the deploy dialog, we still want to save them in the persistent project
91+
// settings, so they don't get reset the next time the project is opened to the settings are edited.
92+
final ProjectSettings settings = pipeline.getProjectSettings();
93+
settings.setDeployAddress(address.getText());
94+
settings.setDeployUser(user.getText());
95+
settings.setDeployJavaHome(javaHome.getText());
96+
settings.setDeployDir(deployDir.getText());
97+
eventBus.post(new ProjectSettingsChangedEvent(settings));
8298
}
8399

84100
@FXML
85101
public void onDeploy() {
102+
saveSettings();
103+
86104
deploying.setValue(true);
87105
console.clear();
88106

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,20 @@
2222

2323
<Label disable="${deployButton.disabled}" text="User" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
2424
<TextField disable="${deployButton.disabled}" fx:id="user" promptText="User" GridPane.columnIndex="1"
25-
GridPane.rowIndex="1">
26-
<text>
27-
<DeployController fx:constant="DEFAULT_USER"/>
28-
</text>
29-
</TextField>
25+
GridPane.rowIndex="1"/>
3026

3127
<Label disable="${deployButton.disabled}" text="Password" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
3228
<PasswordField disable="${deployButton.disabled}" fx:id="password" promptText="Password"
3329
GridPane.columnIndex="1" GridPane.rowIndex="2"/>
3430

3531
<Label disable="${deployButton.disabled}" text="Java Home" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
3632
<TextField disable="${deployButton.disabled}" fx:id="javaHome" promptText="Java Home"
37-
GridPane.columnIndex="1" GridPane.rowIndex="3">
38-
<text>
39-
<DeployController fx:constant="DEFAULT_JAVA_HOME"/>
40-
</text>
41-
</TextField>
33+
GridPane.columnIndex="1" GridPane.rowIndex="3"/>
4234

4335
<Label disable="${deployButton.disabled}" text="Deploy Directory" GridPane.columnIndex="0"
4436
GridPane.rowIndex="4"/>
4537
<TextField disable="${deployButton.disabled}" fx:id="deployDir" promptText="Deploy Directory"
46-
GridPane.columnIndex="1" GridPane.rowIndex="4">
47-
<text>
48-
<DeployController fx:constant="DEFAULT_DIR"/>
49-
</text>
50-
</TextField>
38+
GridPane.columnIndex="1" GridPane.rowIndex="4"/>
5139
</GridPane>
5240

5341
<ButtonBar>

0 commit comments

Comments
 (0)