Skip to content

Commit ba29f88

Browse files
committed
Deployment fixes code from review
1 parent c7b006f commit ba29f88

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ private class StreamToTextArea extends OutputStream {
5050
private final TextArea outputArea;
5151

5252
public StreamToTextArea(TextArea outputArea) {
53+
super();
5354
this.outputArea = outputArea;
5455
}
5556

@@ -76,6 +77,7 @@ public interface Factory {
7677
}
7778

7879
@FXML
80+
@SuppressWarnings("PMD.UnusedPrivateMethod")
7981
private void initialize() {
8082
final Supplier<OutputStream> out = () ->
8183
new PrintStream(new StreamToTextArea(stdOutStreamTextArea).reset(), false);
@@ -89,6 +91,10 @@ private void initialize() {
8991
.collect(Collectors.toList()));
9092
}
9193

94+
/**
95+
* Calls {@link DeployedInstanceManager#deploy()} and displays the result to the UI.
96+
* @param manager The manager to call deploy on
97+
*/
9298
private void onDeploy(DeployedInstanceManager manager) {
9399
Platform.runLater(() -> {
94100
progressIndicator.setProgress(0);

ui/src/main/java/edu/wpi/grip/ui/deployment/DeploymentOptionsController.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import java.net.InetAddress;
2020
import java.util.function.Consumer;
2121

22+
/**
23+
* A simple UI component that can be used to display options for deploying to a remote device using
24+
* asynchronous callbacks.
25+
*/
2226
@ParametrizedController(url = "DeploymentOptions.fxml")
2327
public abstract class DeploymentOptionsController {
2428

@@ -59,6 +63,7 @@ protected final void initialize() {
5963
protected abstract Promise<DeployedInstanceManager, String, String> onDeploy();
6064

6165
@FXML
66+
@SuppressWarnings("PMD.UnusedPrivateMethod")
6267
private void deploy() {
6368
deploySpinner.setVisible(true);
6469
deployButton.setDisable(true);
@@ -99,15 +104,21 @@ public TitledPane getRoot() {
99104
return root;
100105
}
101106

102-
protected static Promise<InetAddress, Throwable, String> checkInetAddressReachable(SupplierWithIO<InetAddress> address){
107+
/**
108+
* Checks that an InetAddress is reachable asynchronously
109+
*
110+
* @param address The address supplier to check
111+
* @return A promise that is resolved when the InetAddress is determined to be reachable.
112+
*/
113+
protected static Promise<InetAddress, Throwable, String> checkInetAddressReachable(SupplierWithIO<InetAddress> address) {
103114
final DeferredManager checkAddressDeferred = new DefaultDeferredManager();
104115
return checkAddressDeferred.when(new DeferredCallable<InetAddress, String>() {
105116
@Override
106-
public InetAddress call() throws Exception {
117+
public InetAddress call() throws IOException {
107118
final InetAddress inetAddress = address.getWithIO();
108119
final int attemptCount = 5;
109120
for (int i = 0; i < attemptCount; i++) {
110-
if(inetAddress.isReachable(1000)) {
121+
if (inetAddress.isReachable(1000)) {
111122
return inetAddress;
112123
} else {
113124
notify("Attempt " + i + "/" + attemptCount + " failed");

ui/src/main/java/edu/wpi/grip/ui/deployment/FRCAdvancedDeploymentOptionsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected void postInit() {
5050
this.address.textProperty().addListener((observable, oldValue, newValue) -> {
5151
// Enable the "Deploy" button only if the user has entered something.
5252
// Note: InetAddresses.isInetAddress only works for IP address not mdns names
53-
if (newValue.equals("")) {
53+
if ("".equals(newValue)) {
5454
getDeployButton().setDisable(true);
5555
} else {
5656
getDeployButton().setDisable(false);

ui/src/main/java/edu/wpi/grip/ui/deployment/FRCDeploymentOptionsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ FRCDeploymentOptionsController create(
4343
}
4444

4545
@Override
46+
@SuppressWarnings("PMD.IfElseStmtsMustUseBraces")
4647
protected void postInit() {
4748
final Label label = new Label("Team Number");
4849
final SpinnerValueFactory.IntegerSpinnerValueFactory spinnerValueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 190);
4950
this.teamNumberSpinner = new Spinner(spinnerValueFactory);
5051
this.teamNumberSpinner.setEditable(true);
5152
// Ensure the value entered is only a number
5253
this.teamNumberSpinner.getEditor().textProperty().addListener((observable, oldValue, newValue) -> {
53-
if (newValue.equals("")) {
54+
if ("".equals(newValue)) {
5455
teamNumberSpinner.getEditor().setText(Integer.toString(0));
5556
} else try {
5657
int value = Integer.parseInt(newValue);

ui/src/main/java/edu/wpi/grip/ui/util/deployment/DeployedInstanceManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.nio.file.Paths;
2929
import java.util.Optional;
3030
import java.util.function.Supplier;
31+
import java.util.logging.Level;
32+
import java.util.logging.Logger;
3133

3234
import static com.google.common.base.Preconditions.checkNotNull;
3335

@@ -36,6 +38,7 @@
3638
*/
3739
public class DeployedInstanceManager implements StartStoppable {
3840

41+
private final Logger logger = Logger.getLogger(DeployedInstanceManager.class.getName());
3942
private final EventBus eventBus;
4043
private final File coreJar;
4144
private final File projectFile;
@@ -125,7 +128,7 @@ public synchronized Promise<DeployedInstanceManager, Throwable, Double> deploy()
125128

126129
return deferred.when(new DeferredCallable<DeployedInstanceManager, Double>() {
127130
@Override
128-
public DeployedInstanceManager call() throws Exception {
131+
public DeployedInstanceManager call() throws IOException {
129132
notify(0.2);
130133
scpFileToTarget(coreJar);
131134
notify(0.5);
@@ -209,15 +212,18 @@ public synchronized void stop() throws IOException {
209212
wait(50);
210213
} catch (InterruptedException e) {
211214
Thread.currentThread().interrupt();
212-
//TODO: Move this into a logging framework
213-
System.err.println("Caught Exception:");
214-
e.printStackTrace();
215+
logger.log(Level.WARNING, "Wait interrupted", e);
215216
}
216217
runStop();
217218
} while (isStarted() && !Thread.interrupted());
218219
eventBus.post(new StartedStoppedEvent(this));
219220
}
220221

222+
/**
223+
* Makes an SSH connection to the remote and runs the kill command.
224+
* Should block until the command has executed.
225+
* @throws IOException If the shell fails.
226+
*/
221227
private void runStop() throws IOException {
222228
final Shell.Plain gripShell = new Shell.Plain(new Shell.Safe(details.createSSHShell()));
223229
gripShell.exec(deploymentCommands.getKillCommand(coreJar.getName()));

0 commit comments

Comments
 (0)