|
4 | 4 | import com.google.common.base.Throwables; |
5 | 5 |
|
6 | 6 | import static com.google.common.base.Preconditions.checkArgument; |
7 | | -import static com.google.common.base.Preconditions.checkNotNull; |
8 | 7 |
|
9 | 8 | /** |
10 | 9 | * This object holds settings that are saved in project files. This includes things like team numbers, which need to |
11 | 10 | * be preserved when deploying the project. |
12 | 11 | */ |
13 | 12 | public class ProjectSettings implements Cloneable { |
14 | 13 |
|
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") |
16 | 15 | private int teamNumber = 0; |
17 | 16 |
|
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); |
22 | 20 |
|
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); |
26 | 24 |
|
| 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 | + */ |
27 | 38 | public void setTeamNumber(int teamNumber) { |
28 | 39 | checkArgument(teamNumber >= 0, "Team number cannot be negative"); |
| 40 | + |
| 41 | + final String oldFrcAddress = computeFRCAddress(this.teamNumber); |
| 42 | + final String newFrcAddress = computeFRCAddress(teamNumber); |
| 43 | + |
29 | 44 | 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 | + } |
30 | 55 | } |
31 | 56 |
|
32 | 57 | public int getTeamNumber() { |
33 | 58 | return teamNumber; |
34 | 59 | } |
35 | 60 |
|
36 | 61 | 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; |
39 | 63 | } |
40 | 64 |
|
41 | 65 | public String getPublishAddress() { |
42 | 66 | return publishAddress; |
43 | 67 | } |
44 | 68 |
|
45 | 69 | public void setDeployAddress(String deployAddress) { |
46 | | - this.deployAddress = checkNotNull(deployAddress, "Deploy Address can not be null"); |
| 70 | + if (deployAddress != null) this.deployAddress = deployAddress; |
47 | 71 | } |
48 | 72 |
|
49 | 73 | public String getDeployAddress() { |
50 | 74 | return deployAddress; |
51 | 75 | } |
52 | 76 |
|
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; |
60 | 79 | } |
61 | 80 |
|
62 | | - public String computeDeployAddress() { |
63 | | - return computeFRCAddress(deployAddress); |
| 81 | + public void setDeployDir(String deployDir) { |
| 82 | + if (deployDir != null) this.deployDir = deployDir; |
64 | 83 | } |
65 | 84 |
|
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"; |
72 | 103 | } |
73 | 104 |
|
74 | 105 | @Override |
75 | 106 | public String toString() { |
76 | 107 | return MoreObjects.toStringHelper(this) |
77 | | - .add("publishAddress", publishAddress) |
78 | 108 | .add("deployAddress", deployAddress) |
| 109 | + .add("deployDir", deployDir) |
| 110 | + .add("deployUser", deployUser) |
| 111 | + .add("deployJavaHome", deployJavaHome) |
| 112 | + .add("publishAddress", publishAddress) |
79 | 113 | .add("teamNumber", teamNumber) |
80 | 114 | .toString(); |
81 | 115 | } |
|
0 commit comments